HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_PrimPart.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: Geometry Library (C++)
7  *
8  * COMMENTS:
9  * The className method is used for saving/loading so there should
10  * be no spaces in the name.
11  * This class is actually a system of particles instead of a single
12  * primitive. This is for efficiency.
13  *
14  */
15 
16 #ifndef __GEO_PrimParticle_H__
17 #define __GEO_PrimParticle_H__
18 
19 #include "GEO_API.h"
20 #include "GEO_Primitive.h"
21 #include "GEO_PrimType.h"
22 #include "GEO_PartRender.h"
23 
24 class GA_Detail;
26 
28 
29 #define PART_STATE_PRIMARY 0x0001
30 #define PART_STATE_DYING 0x0002
31 #define PART_STATE_STOPPED 0x0004
32 #define PART_STATE_COLLIDE 0x0008
33 #define PART_STATE_STUCK 0x0010
34 
35 // don't move point: dying or stuck or stopped
36 #define PART_STATE_DONTMOVE 0x0016
37 
38 // supress default rules
39 #define PART_STATE_SUPPALL 0x7f00
40 #define PART_STATE_SUPPPOS 0x0100
41 #define PART_STATE_SUPPVEL 0x0200
42 #define PART_STATE_SUPPUP 0x0400
43 #define PART_STATE_SUPPAGE 0x0800
44 #define PART_STATE_SUPPREAP 0x1000
45 #define PART_STATE_SUPPROT 0x2000
46 #define PART_STATE_SUPPANGVEL 0x4000
47 
48 // New state flags added in Version 6.0.
49 #define PART_STATE_SLIDING 0x8000
50 
51 
52 /// A GEO_PrimParticle represents a particle system, though a simulation may
53 /// consist of more than a single primitive. Each particle in the system is
54 /// a vertex in the primitive.
56 {
57 protected:
58  /// NOTE: The constructor should only be called from subclass
59  /// constructors.
61  : GEO_Primitive(d, offset)
62  {}
63 
64  /// NOTE: The destructor should only be called from subclass
65  /// destructors.
66  ~GEO_PrimParticle() override
67  {
68 #if !GA_PRIMITIVE_VERTEXLIST
69  deleteLists();
70 #endif
71  }
72 
73 public:
74  bool saveH9(std::ostream &os, bool binary,
75  const UT_Array<GA_AttribSaveDataH9> &prim_attribs,
76  const UT_Array<GA_AttribSaveDataH9> &vtx_attribs
77  ) const override;
78  bool loadH9(UT_IStream &is,
79  const UT_Array<GA_AttribLoadDataH9> &prim_attribs,
80  const UT_Array<GA_AttribLoadDataH9> &vtx_attribs
81  ) override;
82 
83  /// @{
84  /// Save/Load vertex list to a JSON stream
85  bool saveVertexArray(UT_JSONWriter &w,
86  const GA_SaveMap &map) const;
87  bool loadVertexArray(UT_JSONParser &p,
88  const GA_LoadMap &map);
89  /// @}
90  /// @{
91  /// Save/load render properties to a JSON stream
92  bool saveRenderProperties(UT_JSONWriter &w,
93  const GA_SaveMap &map) const;
94  bool saveRenderProperties(UT_JSONValue &v,
95  const GA_SaveMap &map) const;
96  bool loadRenderProperties(UT_JSONParser &p,
97  const GA_LoadMap &map);
98  bool loadRenderProperties(UT_JSONParser &p,
99  const UT_JSONValue &v,
100  const GA_LoadMap &map);
101  bool areRenderPropertiesEqual(
102  const GEO_PrimParticle &src) const;
103  /// @}
104 
105  int getBBox(UT_BoundingBox *bbox) const override;
106  void addToBSphere(
107  UT_BoundingSphere *bsphere) const override;
108  /// @{
109  /// Enlarge a bounding box by the bounding box of the primitive. A
110  /// return value of false indicates an error in the operation, most
111  /// likely an invalid P. Unlike getBBox(), velocity is ignored.
112  bool enlargeBoundingBox(
114  const GA_Attribute *P) const override;
115  bool enlargeBoundingBox(
116  UT_BoundingBox &b,
117  const GA_Attribute *P) const override;
118  /// @}
119  /// Enlarge a bounding sphere to encompass the primitive. A return value
120  /// of false indicates an error in the operation, most likely an invalid
121  /// P. Unlike getBBox(), velocity is ignored.
124  const GA_Attribute *P) const override;
125  UT_Vector3 computeNormal() const override;
126  UT_Vector3 baryCenter() const override;
127  void reverse() override;
128  void copyPrimitive(const GEO_Primitive *src) override;
129  GEO_Primitive *copy(int preserve_shared_pts = 0) const override;
130  void copySubclassData(const GA_Primitive *source) override;
131  bool isDegenerate() const override;
132 #if !GA_PRIMITIVE_VERTEXLIST
133  virtual void addPointRefToGroup(GA_PointGroup &grp) const;
134 #endif
135 
136  // Take the whole set of points into consideration when applying the
137  // point removal operation to this primitive. The method returns 0 if
138  // successful, -1 if it failed because it would have become degenerate,
139  // and -2 if it failed because it would have had to remove the primitive
140  // altogether.
141  int detachPoints(GA_PointGroup &grp) override;
142 
143  /// Before a point is deleted, all primitives using the point will be
144  /// notified. The method should return "false" if it's impossible to
145  /// delete the point. Otherwise, the vertices should be removed.
146  GA_DereferenceStatus dereferencePoint(GA_Offset point,
147  bool dry_run=false) override;
148  GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q,
149  bool dry_run=false) override;
150 
151  // The following method simply computes the bounding box. If no
152  // particles exist, returns 0, else return 1.
153  int getPointBBox(UT_BoundingBox &bbox) const;
154 
155  /// @{
156  /// Retrieve the object specifying how this particle system should be
157  /// rendered.
158  GEO_PartRender &getRenderAttribs() { return myRenderAttribs; }
159  const GEO_PartRender &getRenderAttribs() const { return myRenderAttribs; }
160  /// @}
161 
162  /// Append a new particle. @sa giveBirth()
163  GA_Offset appendParticle(GA_Offset pt);
164 
165  /// Delete all particles not on the dead list that reference the supplied
166  /// point.
167  void deleteParticleByPoint(GA_Offset pt);
168 
169  /// Delete the specified particle.
170  /// @pre vtx belongs to this particle primitive and is not currently on
171  /// the dead list.
172  /// @sa deadParticle()
173  void deleteParticle(GA_Offset vtxoff);
174 
175  /// Resurrect a particle or give birth to a new one.
176  GA_Offset giveBirth();
177 
178  /// Move the specified particle to the dead list.
179  /// @pre vtx belongs to this particle primitive
180  /// Does not actually remove from our vertex list!
181  /// This builds a list of all vertices that should be deleted
182  /// so deleteDead() can do a single pass over them.
183  /// vtxindex is the index into our vertex list, not a vertex offset.
184  void deadParticle(GEO_ParticleVertexIndex vtxindex);
185 
186  /// Delete all dead particles.
187  void deleteDead();
188 
189  /// Returns the number of live particles.
190  int getNumParticles() const { return myVertexList.entries(); }
191 
192 #if !GA_PRIMITIVE_VERTEXLIST
193  ///
194  // Methods to handle vertex attributes for the attribute dictionary
195  ///
196  virtual bool vertexApply(bool (*apply)(GA_Offset vtx, void *),
197  void *data = 0) const;
198 
199  /// @note getVertexCount() includes dead particles.
200  virtual GA_Size getVertexCount() const;
201 
202  /// @warning Traverses the linked list of vertices.
203  virtual GA_Offset getVertexOffset(GA_Size index) const;
204 
205  void setVertexPoint(unsigned int i, GA_Offset pt)
206  {
207  if (i < myVertexList.entries())
208  wireVertex(myVertexList(i), pt);
209  }
210 
211  virtual void beginVertex(const_iterator &i) const;
212  virtual void nextVertex(const_iterator &i) const;
213 #endif
214 
216  { deleteLists(); }
217 
218  // Have we been deactivated and stashed?
219  void stashed(bool beingstashed,
220  GA_Offset offset = GA_INVALID_OFFSET) override;
221 
222  const GA_PrimitiveJSON *getJSON() const override;
223 
224  /// @warning vertexPoint() doesn't check the bounds. Use with caution.
226  { return getDetail().vertexPoint(myVertexList(i)); }
227 
229  { return myVertexList; }
230 
231 protected:
232 #if !GA_PRIMITIVE_VERTEXLIST
233  virtual void clearForDeletion();
234 #endif
235 
237  { return GA_FAMILY_NONE; }
238 
239  // Declare intrinsic attribute methods
240  GA_DECLARE_INTRINSICS(override)
241 
242 #if !GA_PRIMITIVE_VERTEXLIST
243  /// Defragmentation
244  virtual void swapVertexOffsets(const GA_Defragment &defrag);
245 #endif
246 
247  /// Resize our vertex array
248  void setSize(GA_Size sz);
249 
250  // Evaluate the position or the derivative at domain point (u,v), where
251  // u and v MUST be in [0,1]. "v" and "dv" will be ignored here. Return 0 if
252  // OK and -1 otherwise.
253  bool evaluatePointRefMap(
254  GA_Offset result_vtx,
255  GA_AttributeRefMap &hlist,
256  fpreal u, fpreal v,
257  unsigned du, unsigned dv) const override;
258  int evaluatePointV4(
259  UT_Vector4 &pos,
260  float u_unit, float=0,
261  unsigned du=0, unsigned = 0) const override;
263  GA_Offset result_vertex,
264  GA_AttributeRefMap &hlist) const override;
265 
266  // This is called by the subclass to get the
267  // memory used by myVertexList and myDeadList
268  int64 getBaseMemoryUsage() const;
269 
270  // This is called by the subclass to count the
271  // memory used by myVertexList and myDeadList
273 
274 private:
275  void deleteLists();
276  void deleteParticleVertex(GA_Offset vtxoff)
277  {
278  destroyVertex(vtxoff);
279  }
280 
281  GEO_PartRender myRenderAttribs;
282 #if !GA_PRIMITIVE_VERTEXLIST
284 #endif
286 
287  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimParticle &d)
288  {
289  d.saveH9(os, 0,
292  return os;
293  }
295 };
297 
298 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:196
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
virtual UT_Vector3 baryCenter() const
GLenum src
Definition: glew.h:2410
SYS_FORCE_INLINE GA_Detail & getDetail() const
Definition: GA_Primitive.h:141
virtual void copyPrimitive(const GEO_Primitive *src)=0
GEO_PartRender & getRenderAttribs()
Definition: GEO_PrimPart.h:158
virtual void clearForDeletion()
Definition: GA_Primitive.h:658
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
SYS_FORCE_INLINE GA_Size getVertexCount() const
Return the number of vertices used by this primitive.
Definition: GA_Primitive.h:232
~GEO_PrimParticle() override
Definition: GEO_PrimPart.h:66
void setVertexPoint(unsigned int i, GA_Offset pt)
Definition: GEO_PrimPart.h:205
const GEO_PartRender & getRenderAttribs() const
Definition: GEO_PrimPart.h:159
GLuint index
Definition: glew.h:1814
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
virtual void copySubclassData(const GA_Primitive *source)
Definition: GA_Primitive.h:484
int getNumParticles() const
Returns the number of live particles.
Definition: GEO_PrimPart.h:190
bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const override
GLsizei GLsizei GLchar * source
Definition: glew.h:1832
virtual GA_DereferenceStatus dereferencePoint(GA_Offset point, bool dry_run=false)=0
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:76
void reverse() override=0
Reverse the order of vertices.
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *P) const override
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
Abstract base class for a range membership query object.
const GLdouble * v
Definition: glew.h:1391
4D Vector class.
Definition: UT_Vector4.h:166
virtual void swapVertexOffsets(const GA_Defragment &defrag)
static GA_PrimitiveFamilyMask buildFamilyMask()
Definition: GEO_PrimPart.h:236
void wireVertex(GA_Offset vertex, GA_Offset point)
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:233
SYS_FORCE_INLINE int64 getBaseMemoryUsage() const
Report approximate memory usage for myVertexList for subclasses.
Definition: GA_Primitive.h:813
virtual bool loadH9(UT_IStream &is, const UT_Array< GA_AttribLoadDataH9 > &prim_attribs, const UT_Array< GA_AttribLoadDataH9 > &vtx_attribs)
GA_PrimitiveFamilyMask
virtual UT_Vector3 computeNormal() const =0
Return a normal vector for the primitive.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:676
friend std::ostream & operator<<(std::ostream &os, const GEO_PrimParticle &d)
Definition: GEO_PrimPart.h:287
GA_OffsetList myVertexList
Definition: GA_Primitive.h:854
virtual bool isDegenerate() const =0
Is the primitive degenerate.
void destroyVertex(GA_Offset vertex)
GA_Size GA_Offset
Definition: GA_Types.h:639
virtual bool enlargeBoundingSphere(UT_BoundingSphere &b, const GA_Attribute *P) const
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
const GLuint GLenum const void * binary
Definition: glew.h:3502
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
virtual const GA_PrimitiveJSON * getJSON() const =0
Provide a JSON interface to a primitive.
#define GEO_API
Definition: GEO_API.h:14
long long int64
Definition: SYS_Types.h:116
A handle to simplify manipulation of multiple attributes.
Options during loading.
Definition: GA_LoadMap.h:42
virtual int getBBox(UT_BoundingBox *bbox) const =0
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
SYS_FORCE_INLINE GA_Offset vertexPoint(GA_Offset vertex) const
Given a vertex, return the point it references.
Definition: GA_Detail.h:480
void addPointRefToGroup(GA_PointGroup &grp) const
virtual GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q, bool dry_run=false)=0
virtual bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const
virtual bool evaluateBaryCenterRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map) const
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
virtual bool vertexApply(bool(*apply)(GA_Offset vtx, void *), void *data=0) const
virtual int detachPoints(GA_PointGroup &grp)=0
GEO_PrimParticle(GA_Detail *d, GA_Offset offset=GA_INVALID_OFFSET)
Definition: GEO_PrimPart.h:60
GLuint counter
Definition: glew.h:2740
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
const GA_OffsetList & getVertexList() const
Definition: GEO_PrimPart.h:228
fpreal64 fpreal
Definition: SYS_Types.h:277
void clearAndDestroy()
Definition: GEO_PrimPart.h:215
GA_Size GEO_ParticleVertexIndex
Definition: GEO_PrimPart.h:25
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:240
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:77
virtual bool evaluatePointRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map, fpreal u, fpreal v=0, uint du=0, uint dv=0) const =0
virtual void addToBSphere(UT_BoundingSphere *bsphere) const
Container class for all geometry.
Definition: GA_Detail.h:95
void countBaseMemory(UT_MemoryCounter &counter) const
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET)
GA_Offset vertexPoint(GA_Size i) const
Definition: GEO_PrimPart.h:225
GLintptr offset
Definition: glew.h:1682