00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __SIM_MatrixField__
00020 #define __SIM_MatrixField__
00021
00022 #include "SIM_API.h"
00023
00024 #include <UT/UT_VoxelArray.h>
00025
00026 #include "SIM_Names.h"
00027 #include "SIM_OptionsUser.h"
00028 #include "SIM_DataUtils.h"
00029 #include "SIM_RawField.h"
00030
00031 class UT_IStream;
00032 class SIM_Geometry;
00033 class SIM_ScalarField;
00034 class SIM_VectorField;
00035 class SIM_IndexField;
00036
00037
00038 class SIM_API SIM_MatrixField : public SIM_Data,
00039 public SIM_OptionsUser
00040 {
00041 public:
00042
00043 GETSET_DATA_FUNCS_I(SIM_NAME_UNIFORMVOXELS, UniformVoxels);
00044 GETSET_DATA_FUNCS_B(SIM_NAME_TWOD, TwoDField);
00045 GETSET_DATA_FUNCS_I(SIM_NAME_VOXELPLANE, VoxelPlane);
00046 GETSET_DATA_FUNCS_V3(SIM_NAME_DIV, RawDivisions);
00047 GETSET_DATA_FUNCS_I("uniformdiv", RawUniformDivisions);
00048 GETSET_DATA_FUNCS_V3(SIM_NAME_CENTER, RawCenter);
00049 GETSET_DATA_FUNCS_V3(SIM_NAME_SIZE, RawSize);
00050
00051 GETSET_DATA_FUNCS_V3("slicediv", SliceDivisions);
00052 GETSET_DATA_FUNCS_V3("sliceoverlapneg", SliceOverlapNeg);
00053 GETSET_DATA_FUNCS_V3("sliceoverlappos", SliceOverlapPos);
00054 GETSET_DATA_FUNCS_I("slice", Slice)
00055
00056 GETSET_DATA_FUNCS_F(SIM_NAME_TOLERANCE, Tolerance);
00057 GETSET_DATA_FUNCS_I(SIM_NAME_VOXELSAMPLE, VoxelSampleRaw);
00058 GETSET_DATA_FUNCS_I("border", RawBorder);
00059 UT_VoxelBorderType getBorder() const { return (UT_VoxelBorderType) getRawBorder(); }
00060
00061
00062
00063 void getBBox(UT_BoundingBox &bbox) const;
00064
00065 UT_Vector3 getOrig() const
00066 {
00067 return getCenter() - getSize()/2;
00068 }
00069
00070
00071
00072 UT_Vector3 getDivisions() const;
00073 UT_Vector3 getSize() const;
00074 UT_Vector3 getCenter() const;
00075
00076
00077
00078 void setDivisions(const UT_Vector3 &div);
00079 void setSize(const UT_Vector3 &div);
00080 void setCenter(const UT_Vector3 &div);
00081
00082
00083
00084
00085
00086
00087 void resizeKeepData(const UT_Vector3 &size, const UT_Vector3 ¢er);
00088
00089
00090
00091
00092 void matchField(const SIM_ScalarField *field);
00093 void matchField(const SIM_VectorField *field);
00094 void matchField(const SIM_MatrixField *field, bool matchsamples=false);
00095 void matchField(const SIM_IndexField *field);
00096
00097 bool isAligned(const SIM_ScalarField *field) const;
00098 bool isAligned(const SIM_VectorField *field) const;
00099 bool isAligned(const SIM_RawField *field) const;
00100
00101
00102 bool isAligned(const SIM_MatrixField *field) const;
00103
00104 SIM_FieldSample getVoxelSample(int i, int j) const;
00105 const UT_Vector3 &getVoxelSize(int i, int j) const;
00106 fpreal getVoxelDiameter(int i, int j) const;
00107
00108
00109
00110 UT_Matrix3 getValue(const UT_Vector3 &pos) const;
00111
00112
00113
00114 UT_Matrix3 getCellValue(int x, int y, int z) const;
00115
00116
00117
00118
00119 void addToCell(int x, int y, int z, const UT_Matrix3 &dv);
00120
00121
00122 void advect(const SIM_VectorField *vel, fpreal timestep,
00123 const SIM_RawField *collision = 0,
00124 SIM_FieldAdvection advectmethod = SIM_ADVECT_TRACE);
00125 void advect(sim_PointVelocity getVelocity, fpreal timestep,
00126 fpreal voxelsize,
00127 const SIM_RawField *collision = 0);
00128
00129
00130 void enforceBoundary(const SIM_ScalarField *collision=0,
00131 const SIM_MatrixField *cvel = 0);
00132
00133
00134 bool indexToPos(int i, int j, int x, int y, int z, UT_Vector3 &pos) const;
00135
00136
00137 bool posToIndex(int i, int j, const UT_Vector3 &pos, int &x, int &y, int &z) const;
00138
00139
00140 SIM_RawField *getField(int i, int j) const { return myFields[i][j]; }
00141
00142
00143
00144 void setField(int i, int j, SIM_RawField *field);
00145
00146
00147
00148 SIM_RawField *stealField(int i, int j);
00149
00150 void pubHandleModification()
00151 {
00152 handleModification();
00153 }
00154
00155
00156 GU_ConstDetailHandle createSmokeRepresentation(const SIM_RootData &root) const;
00157
00158
00159
00160 void addSmokeRepresentation(const SIM_RootData &root, GU_Detail *gdp) const;
00161
00162 protected:
00163 explicit SIM_MatrixField(const SIM_DataFactory *factory);
00164 virtual ~SIM_MatrixField();
00165
00166
00167 virtual void initializeSubclass();
00168
00169 virtual void makeEqualSubclass(const SIM_Data *source);
00170
00171
00172 virtual void saveSubclass(ostream &os) const;
00173
00174 virtual bool loadSubclass(UT_IStream &is);
00175
00176 virtual int64 getMemorySizeSubclass() const;
00177
00178
00179 virtual void optionChangedSubclass(const char *name);
00180
00181 private:
00182
00183 static const SIM_DopDescription *getMatrixFieldDopDescription();
00184
00185 SIM_RawField *myFields[3][3];
00186
00187 void rebuildFields();
00188
00189 DECLARE_STANDARD_GETCASTTOTYPE();
00190
00191 DECLARE_DATAFACTORY(SIM_MatrixField,
00192 SIM_Data,
00193 "MatrixField",
00194 getMatrixFieldDopDescription());
00195 };
00196 #endif
00197