00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __UT_HashGrid_h__
00025 #define __UT_HashGrid_h__
00026
00027 #ifdef WIN32
00028 #pragma warning(disable:4251)
00029 #pragma warning(disable:4275)
00030 #endif
00031
00032 #include "UT_HashTable.h"
00033 #include "UT_IntArray.h"
00034 #include "UT_PtrArray.h"
00035 #include "UT_RefArray.h"
00036 #include "UT_Vector3.h"
00037 #include "UT_Vector3Array.h"
00038
00039
00040 template <typename utPtr>
00041 class UT_HashGridCell {
00042 public:
00043 UT_HashGridCell() {}
00044 UT_HashGridCell(int i, int j, int k, int index)
00045 : myElements(15), myIndices(15), myXindex(i), myYindex(j),
00046 myZindex(k), myIndex(index), myNumEntries(0)
00047 {
00048 if (i > 1)
00049 {
00050 myIL = i + 2;
00051 myIR = i - 2;
00052 }
00053 else if (i == 1)
00054 {
00055 myIL = 0;
00056 myIR = 3;
00057 }
00058 else
00059 {
00060 myIL = 2;
00061 myIR = 1;
00062 }
00063
00064 if (j > 1)
00065 {
00066 myJL = j + 2;
00067 myJR = j - 2;
00068 }
00069 else if (j == 1)
00070 {
00071 myJL = 0;
00072 myJR = 3;
00073 }
00074 else
00075 {
00076 myJL = 2;
00077 myJR = 1;
00078 }
00079
00080 if (k > 1)
00081 {
00082 myKL = k + 2;
00083 myKR = k - 2;
00084 }
00085 else if (k == 1)
00086 {
00087 myKL = 0;
00088 myKR = 3;
00089 }
00090 else
00091 {
00092 myKL = 2;
00093 myKR = 1;
00094 }
00095 }
00096
00097 virtual ~UT_HashGridCell() {}
00098
00099 UT_PtrArray<utPtr> myElements;
00100 UT_IntArray myIndices;
00101
00102 int myXindex;
00103 int myYindex;
00104 int myZindex;
00105
00106 int myIL, myIR;
00107 int myJL, myJR;
00108 int myKL, myKR;
00109
00110 int myIndex;
00111
00112 int myNumEntries;
00113 };
00114
00115 template <typename utPtr>
00116 class UT_HashGrid {
00117
00118 public:
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 UT_HashGrid(fpreal cellsize, const UT_Vector3 &origin,
00138 bool fullinit, unsigned int sz = 0);
00139
00140
00141 virtual ~UT_HashGrid();
00142
00143
00144
00145
00146 bool insert(const UT_Vector3 &p, utPtr t);
00147
00148
00149
00150 inline void findCloseElements(const UT_Vector3 &p,
00151 UT_PtrArray<utPtr> &list);
00152
00153
00154
00155
00156 void reset(unsigned int sz = 0);
00157
00158
00159
00160 void reset(fpreal cellsize,
00161 const UT_Vector3 &origin,
00162 bool fullinit,
00163 unsigned int sz = 0);
00164
00165 protected:
00166 typedef UT_RefArray<UT_HashGridCell<utPtr> > ut_CellArray;
00167
00168
00169
00170 UT_HashGridCell<utPtr> *getCell(const UT_Vector3 &p,
00171 bool create = false);
00172 UT_HashGridCell<utPtr> *getCell(int i, int j, int k,
00173 bool create = false);
00174
00175 private:
00176 UT_Vector3 myOrigin;
00177 fpreal myCellWidth;
00178 fpreal myCellWidth2;
00179
00180 int myMaxElements;
00181
00182 UT_HashTable myGridSet;
00183 ut_CellArray myCellArray;
00184
00185 bool myFullInit;
00186
00187 UT_Vector3Array myPositions;
00188
00189 };
00190
00191 #if defined( WIN32 ) || defined( LINUX ) || defined(MBSD) || defined(GAMEOS)
00192 #include "UT_HashGrid.C"
00193 #endif
00194
00195 #endif