00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __SIM_RawIndexField__
00023 #define __SIM_RawIndexField__
00024
00025 #include "SIM_API.h"
00026
00027 #include <UT/UT_VoxelArray.h>
00028
00029 #include "SIM_RawField.h"
00030
00031
00032 struct SIM_API SIM_VoxelBox
00033 {
00034 SIM_VoxelBox();
00035 SIM_VoxelBox(
00036 const int xMin, const int yMin, const int zMin,
00037 const int xEnd, const int yEnd, const int zEnd
00038 );
00039
00040 bool contains(const int x, const int y, const int z) const;
00041
00042
00043 int begin[3];
00044 int end[3];
00045 };
00046
00047 class SIM_API SIM_RawIndexField
00048 {
00049 public:
00050 typedef UT_RefArray<int64> Indices;
00051 typedef SIM_VoxelBox Box;
00052 typedef UT_RefArray<Box> Boxes;
00053
00054 SIM_RawIndexField();
00055 virtual ~SIM_RawIndexField();
00056
00057
00058 SIM_RawIndexField(const SIM_RawIndexField &src);
00059
00060
00061 const SIM_RawIndexField &operator=(const SIM_RawIndexField &src);
00062
00063
00064
00065
00066
00067 void init(SIM_FieldSample sample,
00068 const UT_Vector3 &orig, const UT_Vector3 &size,
00069 int xres, int yres, int zres);
00070
00071
00072
00073 void match(const SIM_RawField &src);
00074 void match(const SIM_RawIndexField &src);
00075
00076
00077
00078 bool indexToPos(int x, int y, int z, UT_Vector3 &pos) const;
00079
00080
00081 bool posToIndex(UT_Vector3 pos, int &x, int &y, int &z) const;
00082
00083
00084
00085
00086
00087 bool isMatching(const SIM_RawIndexField *field) const;
00088
00089
00090
00091
00092 bool isAligned(const SIM_RawIndexField *field) const;
00093 bool isAligned(const SIM_RawField *field) const;
00094
00095 int64 getMemoryUsage() const;
00096
00097
00098
00099
00100 void getVoxelRes(int &xres, int &yres, int &zres) const;
00101
00102 const UT_Vector3 &getVoxelSize() const { return myVoxelSize; }
00103 fpreal getVoxelDiameter() const { return myVoxelDiameter; }
00104
00105
00106 bool isValidIndex(int x, int y, int z) const
00107 {
00108 return field()->isValidIndex(x, y, z);
00109 }
00110
00111
00112
00113
00114
00115 int64 buildIndex(const SIM_RawField *surface,
00116 const SIM_RawField *collision);
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 int64 buildPartitionedIndex(const SIM_RawField *surface,
00129 const SIM_RawField *collision,
00130 const bool allowSubdivide,
00131 Indices& setEnds);
00132
00133
00134
00135
00136
00137
00138
00139 THREADED_METHOD1(SIM_RawIndexField, shouldMultiThread(),
00140 buildCollisionLookup,
00141 const SIM_RawField *, collision)
00142 void buildCollisionLookupPartial(const SIM_RawField *collision,
00143 const UT_JobInfo &info);
00144
00145
00146
00147
00148
00149
00150 int64 computeConnectedComponents(const SIM_RawField &surface);
00151
00152
00153
00154
00155 int64 computeConnectedComponents(const SIM_RawIndexField &idx);
00156
00157
00158 bool shouldMultiThread() const
00159 {
00160 return field()->numTiles() > 1;
00161 }
00162
00163 int64 operator()(int x, int y, int z) const
00164 {
00165 return (*field())(x, y, z);
00166 }
00167 int64 getIndex(const UT_VoxelArrayIteratorF &vit) const
00168 {
00169 return (*field())(vit.x(), vit.y(), vit.z());
00170 }
00171
00172 int64 getValue(const UT_Vector3 &pos) const;
00173
00174 UT_VoxelArray<int64> *field() const { return myField; }
00175
00176 int64 maxIndex() const { return myMaxIndex; }
00177
00178 const UT_Vector3 &getOrig() const { return myOrig; }
00179 const UT_Vector3 &getSize() const { return mySize; }
00180 const UT_Vector3 &getBBoxOrig() const { return myBBoxOrig; }
00181 const UT_Vector3 &getBBoxSize() const { return myBBoxSize; }
00182
00183 SIM_FieldSample getSample() const { return mySample; }
00184
00185 protected:
00186
00187
00188
00189 int64 collapseClassIndices();
00190
00191
00192
00193 bool shouldConnectIndices(int64 idx1, int64 idx2) const;
00194
00195 UT_VoxelArray<int64> *myField;
00196 SIM_FieldSample mySample;
00197 int64 myMaxIndex;
00198
00199
00200
00201 UT_Vector3 myOrig, mySize;
00202
00203
00204 UT_Vector3 myBBoxOrig, myBBoxSize;
00205
00206
00207 UT_Vector3 myVoxelSize;
00208 fpreal myVoxelDiameter;
00209
00210
00211 void findRange
00212 (
00213 const SIM_RawField* surface,
00214 const SIM_RawField* collision,
00215 int begin[3],
00216 int end[3]
00217 ) const;
00218
00219
00220 int64 countVoxelsInBox
00221 (
00222 const SIM_RawField* surface,
00223 const SIM_RawField* collision,
00224 const Box& box
00225 ) const;
00226 };
00227
00228
00229 struct SIM_API SIM_PartitionedRawIndexField
00230 {
00231 SIM_RawIndexField myIndex;
00232
00233
00234 SIM_RawIndexField::Indices mySetEnds;
00235
00236
00237
00238 int64 buildIndex(const SIM_RawField *surface,
00239 const SIM_RawField *collision);
00240 };
00241
00242 #endif
00243