00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __SIM_SolverSNOW_h__
00038 #define __SIM_SolverSNOW_h__
00039
00040 #include <UT/UT_HashTable.h>
00041 #include <UT/UT_Hash.h>
00042 #include <UT/UT_IStream.h>
00043 #include <UT/UT_VoxelArray.h>
00044 #include <GU/GU_DetailHandle.h>
00045 #include <SIM/SIM_OptionsUser.h>
00046 #include <SIM/SIM_SingleSolver.h>
00047 #include <SIM/SIM_Geometry.h>
00048
00049 #define SIM_NAME_SOURCEOBJECTS "sourceobjects"
00050 #define SIM_NAME_BIRTHRATE "birthrate"
00051 #define SIM_NAME_DIVISIONS "divisions"
00052 #define SIM_NAME_ORIGINALDEPTH "originaldepth"
00053
00054 class SIM_Object;
00055 class GEO_Point;
00056 class SIM_Random;
00057
00058 typedef unsigned char u8;
00059
00060 namespace HDK_Sample {
00061
00062 class SNOW_VoxelArray;
00063
00064
00065 class SIM_SolverSNOW : public SIM_SingleSolver,
00066 public SIM_OptionsUser
00067 {
00068 public:
00069
00070 GETSET_DATA_FUNCS_F(SIM_NAME_BIRTHRATE, BirthRate);
00071 GETSET_DATA_FUNCS_I(SIM_NAME_DIVISIONS, Divisions);
00072 GETSET_DATA_FUNCS_I(SIM_NAME_ORIGINALDEPTH, OriginalDepth);
00073
00074 protected:
00075 explicit SIM_SolverSNOW(const SIM_DataFactory *factory);
00076 virtual ~SIM_SolverSNOW();
00077
00078 SIM_Random *createRandomData(SIM_Object *obj) const;
00079
00080 virtual SIM_Result solveSingleObjectSubclass(SIM_Engine &engine,
00081 SIM_Object &object,
00082 SIM_ObjectArray &feedbacktoobjects,
00083 const SIM_Time ×tep,
00084 bool newobject);
00085
00086 int rand_choice(int numchoice, SIM_Random *rand) const;
00087 bool brownianize(int &v, int dv, int max,
00088 SIM_Random *rand) const;
00089 int clearInDirection(const SNOW_VoxelArray &snow,
00090 int sx, int sy, int sz,
00091 int dx, int dy, int dz,
00092 int &rx, int &ry, int &rz,
00093 int maxdist,
00094 SIM_Random *rand) const;
00095 void clearSnow(SNOW_VoxelArray &snow,
00096 int x, int y, int z,
00097 SIM_Random *rand) const;
00098
00099 void fillRow(SNOW_VoxelArray &snow,
00100 fpreal startx, fpreal endx,
00101 int y, int z,
00102 u8 voxeltype,
00103 SIM_Random *rand) const;
00104 void applyGeometry(SNOW_VoxelArray &snow,
00105 const GU_ConstDetailHandle &gdh,
00106 const UT_DMatrix4 &xform,
00107 u8 voxletype,
00108 SIM_Random *rand) const;
00109
00110 private:
00111 static const SIM_DopDescription *getSolverSNOWDopDescription();
00112
00113 void solveForObject(SIM_Object &object,
00114 SNOW_VoxelArray &snow,
00115 const SIM_Time ×tep) const;
00116 void setVoxelArrayAttributes(
00117 SNOW_VoxelArray *voxelarray) const;
00118
00119 DECLARE_STANDARD_GETCASTTOTYPE();
00120 DECLARE_DATAFACTORY(SIM_SolverSNOW,
00121 SIM_SingleSolver,
00122 "SNOW Solver",
00123 getSolverSNOWDopDescription());
00124 };
00125
00126
00127
00128 #define VOXEL_EMPTY 0
00129 #define VOXEL_SNOW 1
00130 #define VOXEL_COMPRESSED 2
00131 #define VOXEL_WALL 3
00132 #define VOXEL_OBJECT 4
00133
00134
00135 class SNOW_VoxelArray : public SIM_Geometry
00136 {
00137 public:
00138
00139 int getXDivisions() const;
00140 void setXDivisions(int divisions);
00141 int getYDivisions() const;
00142 void setYDivisions(int divisions);
00143 int getZDivisions() const;
00144 void setZDivisions(int divisions);
00145
00146
00147 u8 getVoxel(int x, int y, int z) const;
00148 void setVoxel(u8 voxel, int x, int y, int z);
00149
00150 void collapseAllTiles();
00151
00152 void pubHandleModification()
00153 { handleModification(); }
00154
00155 protected:
00156 explicit SNOW_VoxelArray(const SIM_DataFactory *factory);
00157 virtual ~SNOW_VoxelArray();
00158
00159
00160 virtual void initializeSubclass();
00161 virtual void makeEqualSubclass(const SIM_Data *source);
00162 virtual void saveSubclass(ostream &os) const;
00163 virtual bool loadSubclass(UT_IStream &is);
00164 virtual void handleModificationSubclass(int code);
00165
00166
00167
00168 virtual GU_ConstDetailHandle getGeometrySubclass() const;
00169
00170 private:
00171 GEO_Point *createOrFindPoint(GU_Detail *gdp, int x, int y, int z);
00172 void buildFace(GU_Detail *gdp,
00173 int x0, int y0, int z0,
00174 int x1, int y1, int z1,
00175 int x2, int y2, int z2,
00176 int x3, int y3, int z3);
00177 void buildGeometryFromArray();
00178 void freeArray() const;
00179 void allocateArray() const;
00180
00181 mutable GU_DetailHandle myDetailHandle;
00182 mutable UT_VoxelArray<u8> *myVoxelArray;
00183
00184 int myXDivisions;
00185 int myYDivisions;
00186 int myZDivisions;
00187 UT_HashTable myPointHash;
00188
00189 DECLARE_STANDARD_GETCASTTOTYPE();
00190 DECLARE_DATAFACTORY(SNOW_VoxelArray,
00191 SIM_Geometry,
00192 "Voxel Array",
00193 getEmptyDopDescription());
00194 };
00195
00196 }
00197
00198 #endif
00199