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
00038 #ifndef __SNOW_Solver_h__
00039 #define __SNOW_Solver_h__
00040
00041 #include <UT/UT_HashTable.h>
00042 #include <UT/UT_Hash.h>
00043 #include <UT/UT_IStream.h>
00044 #include <UT/UT_VoxelArray.h>
00045 #include <GU/GU_DetailHandle.h>
00046 #include <SIM/SIM_OptionsUser.h>
00047 #include <SIM/SIM_SingleSolver.h>
00048 #include <SIM/SIM_Geometry.h>
00049
00050 #define SIM_NAME_BIRTHRATE "birthrate"
00051 #define SIM_NAME_ORIGINALDEPTH "originaldepth"
00052
00053 class SIM_Object;
00054 class GEO_Point;
00055 class SIM_Random;
00056
00057 typedef unsigned char u8;
00058
00059 namespace HDK_Sample {
00060
00061 class SNOW_VoxelArray;
00062
00063
00064 class SNOW_Solver : public SIM_SingleSolver,
00065 public SIM_OptionsUser
00066 {
00067 public:
00068
00069 GETSET_DATA_FUNCS_F(SIM_NAME_BIRTHRATE, BirthRate);
00070 GETSET_DATA_FUNCS_I(SIM_NAME_ORIGINALDEPTH, OriginalDepth);
00071
00072 protected:
00073 explicit SNOW_Solver(const SIM_DataFactory *factory);
00074 virtual ~SNOW_Solver();
00075
00076 SIM_Random *createRandomData(SIM_Object *obj) const;
00077
00078 virtual SIM_Result solveSingleObjectSubclass(SIM_Engine &engine,
00079 SIM_Object &object,
00080 SIM_ObjectArray &feedbacktoobjects,
00081 const SIM_Time ×tep,
00082 bool newobject);
00083
00084 int rand_choice(int numchoice, SIM_Random *rand) const;
00085 bool brownianize(int &v, int dv, int max,
00086 SIM_Random *rand) const;
00087 int clearInDirection(const SNOW_VoxelArray &snow,
00088 int sx, int sy, int sz,
00089 int dx, int dy, int dz,
00090 int &rx, int &ry, int &rz,
00091 int maxdist,
00092 SIM_Random *rand) const;
00093 void clearSnow(SNOW_VoxelArray &snow,
00094 int x, int y, int z,
00095 SIM_Random *rand) const;
00096
00097 void fillRow(SNOW_VoxelArray &snow,
00098 fpreal startx, fpreal endx,
00099 int y, int z,
00100 u8 voxeltype,
00101 SIM_Random *rand) const;
00102 void applyGeometry(SNOW_VoxelArray &snow,
00103 const GU_ConstDetailHandle &gdh,
00104 const UT_DMatrix4 &xform,
00105 u8 voxletype,
00106 SIM_Random *rand) const;
00107
00108 private:
00109 static const SIM_DopDescription *getSolverSNOWDopDescription();
00110
00111 void solveForObject(SIM_Object &object,
00112 SNOW_VoxelArray &snow,
00113 const SIM_Time ×tep) const;
00114 void setVoxelArrayAttributes(
00115 SNOW_VoxelArray *voxelarray) const;
00116
00117 DECLARE_STANDARD_GETCASTTOTYPE();
00118 DECLARE_DATAFACTORY(SNOW_Solver,
00119 SIM_SingleSolver,
00120 "SNOW Solver",
00121 getSolverSNOWDopDescription());
00122 };
00123
00124
00125 #define VOXEL_EMPTY 0
00126 #define VOXEL_SNOW 1
00127 #define VOXEL_COMPRESSED 2
00128 #define VOXEL_WALL 3
00129 #define VOXEL_OBJECT 4
00130
00131 #define SNOW_NAME_DIVISIONS "div"
00132 #define SNOW_NAME_CENTER "t"
00133 #define SNOW_NAME_SIZE "size"
00134
00135
00136 class SNOW_VoxelArray : public SIM_Geometry
00137
00138
00139 {
00140 public:
00141 GETSET_DATA_FUNCS_V3(SNOW_NAME_DIVISIONS, Divisions);
00142 GETSET_DATA_FUNCS_V3(SNOW_NAME_SIZE, Size);
00143 GETSET_DATA_FUNCS_V3(SNOW_NAME_CENTER, Center);
00144
00145
00146 u8 getVoxel(int x, int y, int z) const;
00147 void setVoxel(u8 voxel, int x, int y, int z);
00148
00149 void collapseAllTiles();
00150
00151 void pubHandleModification()
00152 { handleModification(); }
00153
00154 protected:
00155 explicit SNOW_VoxelArray(const SIM_DataFactory *factory);
00156 virtual ~SNOW_VoxelArray();
00157
00158
00159 virtual void initializeSubclass();
00160 virtual void makeEqualSubclass(const SIM_Data *source);
00161 virtual void saveSubclass(ostream &os) const;
00162 virtual bool loadSubclass(UT_IStream &is);
00163 virtual void handleModificationSubclass(int code);
00164
00165 virtual int64 getMemorySizeSubclass() const;
00166
00167
00168
00169 virtual void optionChangedSubclass(const char *name);
00170
00171
00172
00173 virtual GU_ConstDetailHandle getGeometrySubclass() const;
00174
00175 private:
00176 static const SIM_DopDescription *getVoxelArrayDopDescription();
00177
00178 GEO_Point *createOrFindPoint(GU_Detail *gdp, int x, int y, int z);
00179 void buildFace(GU_Detail *gdp,
00180 int x0, int y0, int z0,
00181 int x1, int y1, int z1,
00182 int x2, int y2, int z2,
00183 int x3, int y3, int z3);
00184 void buildGeometryFromArray();
00185 void freeArray() const;
00186 void allocateArray() const;
00187
00188 mutable GU_DetailHandle myDetailHandle;
00189 mutable UT_VoxelArray<u8> *myVoxelArray;
00190
00191 UT_HashTable myPointHash;
00192
00193 DECLARE_STANDARD_GETCASTTOTYPE();
00194 DECLARE_DATAFACTORY(SNOW_VoxelArray,
00195 SIM_Geometry,
00196 "hdk_VoxelArray",
00197 getVoxelArrayDopDescription()
00198 );
00199 };
00200
00201
00202 class SNOW_Visualize : public SIM_Data,
00203 public SIM_OptionsUser
00204 {
00205 public:
00206 GET_GUIDE_FUNC_B(SIM_NAME_SHOWGUIDE, ShowGuide, true);
00207 GET_GUIDE_FUNC_V3(SIM_NAME_COLOR, Color, (1, 1, 1));
00208 GET_GUIDE_FUNC_B("usebox", UseBox, false);
00209
00210 protected:
00211 explicit SNOW_Visualize(const SIM_DataFactory *factory);
00212 virtual ~SNOW_Visualize();
00213
00214
00215 virtual void initializeSubclass();
00216
00217 virtual bool getIsAlternateRepresentationSubclass() const;
00218 virtual void initAlternateRepresentationSubclass(const SIM_Data &);
00219 virtual SIM_Guide *createGuideObjectSubclass() const;
00220 virtual void buildGuideGeometrySubclass(const SIM_RootData &root,
00221 const SIM_Options &options,
00222 const GU_DetailHandle &gdh,
00223 UT_DMatrix4 *xform,
00224 const SIM_Time &t) const;
00225
00226 static void createBoundingBoxGuide(GU_Detail *gdp,
00227 const UT_BoundingBox &bbox,
00228 const UT_Vector3 &color);
00229
00230 private:
00231 static const SIM_DopDescription *getVisualizeDopDescription();
00232
00233 const SNOW_VoxelArray *myArray;
00234
00235 DECLARE_STANDARD_GETCASTTOTYPE();
00236 DECLARE_DATAFACTORY(SNOW_Visualize,
00237 SIM_Data,
00238 "hdk_SnowVisualize",
00239 getVisualizeDopDescription()
00240 );
00241 };
00242
00243 }
00244
00245 #endif
00246