HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIM_IndexField.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SIM_IndexField.h ( SIM Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __SIM_IndexField__
12 #define __SIM_IndexField__
13 
14 #include "SIM_API.h"
15 
16 #include <UT/UT_VoxelArray.h>
17 
18 #include "SIM_Names.h"
19 #include "SIM_OptionsUser.h"
20 #include "SIM_DataUtils.h"
21 #include "SIM_RawField.h"
22 #include "SIM_RawIndexField.h"
23 
24 class UT_IStream;
25 class SIM_Geometry;
26 class SIM_ScalarField;
27 class SIM_VectorField;
28 class SIM_MatrixField;
29 
30 /// This class holds a three dimensional scalar field.
32  public SIM_OptionsUser
33 {
34 public:
36 
37  /// Accesses the relative path to the position data associated with
38  /// this geometry.
40 
41  /// Control the number of divisions.
45  GETSET_DATA_FUNCS_V3(SIM_NAME_DIV, RawDivisions);
46  GETSET_DATA_FUNCS_I("uniformdiv", RawUniformDivisions);
47  GETSET_DATA_FUNCS_F("divsize", RawDivisionSize);
50 
51  GETSET_DATA_FUNCS_V3("slicediv", SliceDivisions);
52  GETSET_DATA_FUNCS_V3("sliceoverlapneg", SliceOverlapNeg);
53  GETSET_DATA_FUNCS_V3("sliceoverlappos", SliceOverlapPos);
54  GETSET_DATA_FUNCS_I("slice", Slice)
55  exint getNumSlices() const { UT_Vector3D nslice = getSliceDivisions(); return exint(nslice.x() * nslice.y() * nslice.z()); }
56 
57  GETSET_DATA_FUNCS_I("totalvoxels", TotalVoxels);
58  GETSET_DATA_FUNCS_V3("totalvoxelres", TotalVoxelRes);
59 
61  GETSET_DATA_FUNCS_I("initialvalue", InitialValue);
62  GETSET_DATA_FUNCS_I("border", RawBorder);
63  UT_VoxelBorderType getBorder() const { return (UT_VoxelBorderType) getRawBorder(); }
64  void setBorder(UT_VoxelBorderType border) { setRawBorder(border); }
65 
66  /// Controls the dimensions of where the field is properly defined
67  /// in the field space.
68  void getBBox(UT_BoundingBox &bbox) const;
69 
71  {
72  return getCenter() - getSize()/2;
73  }
74 
75  /// Calculate the size and divisions according to options
76  /// such as 2d or equal sized voxels.
77  UT_Vector3 getDivisions() const;
78  UT_Vector3 getSize() const;
79  UT_Vector3 getCenter() const;
80 
81  /// Adjusts the size/divisions of this field, overriding
82  /// and twod or uniform voxel settings.
83  void setDivisions(const UT_Vector3 &div);
84  void setSize(const UT_Vector3 &div);
85  void setCenter(const UT_Vector3 &div);
86 
87  /// Resizes our field keeping our field data.
88  /// The final size will be an integer number of voxels matching
89  /// our current voxel size. The final center will be an integer
90  /// number of voxel offset from our current center. This allows
91  /// us to do a perfect copy of the data.
92  void resizeKeepData(const UT_Vector3 &size, const UT_Vector3 &center, bool keepdata, const char *address = 0, int port = -1);
93 
94  /// Match this field to the given reference field. We will
95  /// end up with the same size/divisions/twod/uniform,
96  /// but not the same sampling pattern
97  void matchField(const SIM_ScalarField *field);
98  void matchField(const SIM_VectorField *field);
99  void matchField(const SIM_MatrixField *field);
100  void matchField(const SIM_IndexField *field, bool matchsamples = false);
101 
102  SIM_FieldSample getVoxelSample() const;
103 
104  const UT_Vector3 &getVoxelSize() const;
105  fpreal getVoxelDiameter() const;
106  void setVoxelSize(const UT_Vector3 &voxelsize)
107  { myField->setVoxelSize(voxelsize); }
108 
109  /// Access the field value given a world space location.
110  /// This does closest point matching.
111  exint getValue(const UT_Vector3 &pos) const;
112 
113  /// Converts an integer index into a worldspace position.
114  bool indexToPos(int x, int y, int z, UT_Vector3 &pos) const;
115  bool indexToPos(exint x, exint y, exint z, UT_Vector3D &pos) const;
116 
117  /// Converts a worldspace position into an integer index.
118  bool posToIndex(const UT_Vector3 &pos, int &x, int &y, int &z) const;
119 
120  /// Retrieve raw field.
121  SIM_RawIndexField *getField() const { return myField; };
122 
123  /// Sets the field to the given field, gaining ownership of it.
124  void setField(SIM_RawIndexField *field);
125 
126  /// Can't have NANs in integer fields.
127  bool testForNan() const { return false; }
128 
129  /// True if we have a constant value. Ignores end conditions
130  /// in determining this. Used as a rough guess that the field
131  /// is unused.
132  bool appearsToBeUnused() const
133  { return getField()->field()->isConstant(0); }
134 
135  /// Steals the field, replacing this copy with an empty field and
136  /// returning the old version.
137  SIM_RawIndexField *stealField();
138 
139  /// Signals to the field that it has been altered externally.
141  {
143  }
144 
145  /// Recomputes total number of voxels to be stored
146  /// on our options data for ease of reading
147  void updateTotalVoxels();
148 
149  /// Creates a GDP with us as a Volume Primitive inside it.
150  GU_ConstDetailHandle createSmokeRepresentation(const SIM_RootData &root) const;
151 
152  /// Adds a volume primitive version of our field to the given
153  /// gdp.
154  void addSmokeRepresentation(const SIM_RootData &root, GU_Detail *gdp) const;
155 protected:
156  explicit SIM_IndexField(const SIM_DataFactory *factory);
157  virtual ~SIM_IndexField();
158 
159  /// Overrides to properly implement this class as a SIM_Data.
160  virtual void initializeSubclass();
161  /// myField aware copy constructor.
162  virtual void makeEqualSubclass(const SIM_Data *source);
163 
164  /// Saves our attributes, and our internal data if it has been set.
165  virtual void saveSubclass(std::ostream &os) const;
166  /// Loads our attributes and internal data if it was set when we saved.
167  virtual bool loadSubclass(UT_IStream &is);
168 
169  virtual exint getMemorySizeSubclass() const;
170 
171  /// Override the setDivisions to rebuild our voxel array on demand.
172  virtual void optionChangedSubclass(const char *name);
173 
174 private:
175  static const SIM_DopDescription *getIndexFieldDopDescription();
176 
177  /// Rebuilds our raw field so it matches our current parameters.
178  void rebuildField();
179 
180  SIM_RawIndexField *myField;
181 
182  /// When creating a new scalar field, we do the following:
183  /// 1) Load default values, triggering rebuildField()
184  /// 2) Call initialize()
185  /// 3) Load actual parameters values, triggering rebuildField()
186  /// We need to set the initial value in the third stage. The
187  /// problem is that if there is a non-zero default and the other
188  /// parameters are all default, stage 3 will be skipped. We thus
189  /// track our last default to avoid this case.
190  exint myStashedInitialValue;
191 
193 
195  SIM_Data,
196  "IndexField",
197  getIndexFieldDopDescription());
198 };
199 #endif
200 
#define SIM_NAME_VOXELPLANE
Definition: SIM_Names.h:217
#define SIM_NAME_POSITIONPATH
Definition: SIM_Names.h:168
virtual void makeEqualSubclass(const SIM_Data *source)
#define SIM_NAME_VOXELSAMPLE
Definition: SIM_Names.h:216
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:45
GA_API const UT_StringHolder div
virtual bool loadSubclass(UT_IStream &is)
virtual void optionChangedSubclass(const char *name)
SIM_RawIndexField rawfield_type
#define GETSET_DATA_FUNCS_B(DataName, FuncName)
#define SIM_NAME_CENTER
Definition: SIM_Names.h:82
#define GETSET_DATA_FUNCS_S(DataName, FuncName)
#define SIM_NAME_DIV
Definition: SIM_Names.h:108
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
virtual int64 getMemorySizeSubclass() const
UT_VoxelBorderType
Definition: UT_VoxelArray.h:69
GLint y
Definition: glcorearb.h:102
This class holds a three dimensional scalar field.
#define GETSET_DATA_FUNCS_F(DataName, FuncName)
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:581
#define GETSET_DATA_FUNCS_V3(DataName, FuncName)
GLsizeiptr size
Definition: glcorearb.h:663
SIM_FieldSample
Definition: SIM_RawField.h:38
bool testForNan() const
Can't have NANs in integer fields.
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:58
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:585
#define SIM_NAME_SIZE
Definition: SIM_Names.h:183
UT_VoxelBorderType getBorder() const
SIM_RawIndexField * getField() const
Retrieve raw field.
int64 exint
Definition: SYS_Types.h:115
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
virtual void saveSubclass(std::ostream &os) const
void setVoxelSize(const UT_Vector3 &voxelsize)
#define SIM_NAME_UNIFORMVOXELS
Definition: SIM_Names.h:207
#define GETSET_DATA_FUNCS_I(DataName, FuncName)
#define SIM_NAME_TWOD
Definition: SIM_Names.h:206
GLuint const GLchar * name
Definition: glcorearb.h:785
This class holds a three dimensional tensor field.
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:583
double fpreal
Definition: SYS_Types.h:269
GLint GLint GLsizei GLint border
Definition: glcorearb.h:107
UT_Vector3 getOrig() const
void handleModification(int code=-1)
#define SIM_API
Definition: SIM_API.h:10
GLint GLenum GLint x
Definition: glcorearb.h:408
This class holds a three dimensional scalar field.
void setBorder(UT_VoxelBorderType border)
void pubHandleModification()
Signals to the field that it has been altered externally.
bool appearsToBeUnused() const
This class holds a three dimensional vector field.
virtual void initializeSubclass()