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  bool 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_Vector3D computeNormalD() const override;
126  UT_Vector3 computeNormal() const override;
127  UT_Vector3 baryCenter() const override;
128  void reverse() override;
129  void copyPrimitive(const GEO_Primitive *src) override;
130  GEO_Primitive *copy(int preserve_shared_pts = 0) const override;
131  void copySubclassData(const GA_Primitive *source) override;
132  bool isDegenerate() const override;
133 #if !GA_PRIMITIVE_VERTEXLIST
134  virtual void addPointRefToGroup(GA_PointGroup &grp) const;
135 #endif
136 
137  // Take the whole set of points into consideration when applying the
138  // point removal operation to this primitive. The method returns 0 if
139  // successful, -1 if it failed because it would have become degenerate,
140  // and -2 if it failed because it would have had to remove the primitive
141  // altogether.
142  int detachPoints(GA_PointGroup &grp) override;
143 
144  /// Before a point is deleted, all primitives using the point will be
145  /// notified. The method should return "false" if it's impossible to
146  /// delete the point. Otherwise, the vertices should be removed.
147  GA_DereferenceStatus dereferencePoint(GA_Offset point,
148  bool dry_run=false) override;
149  GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q,
150  bool dry_run=false) override;
151 
152  // The following method simply computes the bounding box. If no
153  // particles exist, returns 0, else return 1.
154  int getPointBBox(UT_BoundingBox &bbox) const;
155 
156  /// @{
157  /// Retrieve the object specifying how this particle system should be
158  /// rendered.
159  GEO_PartRender &getRenderAttribs() { return myRenderAttribs; }
160  const GEO_PartRender &getRenderAttribs() const { return myRenderAttribs; }
161  /// @}
162 
163  /// Append a new particle. @sa giveBirth()
164  GA_Offset appendParticle(GA_Offset pt);
165 
166  /// Delete all particles not on the dead list that reference the supplied
167  /// point.
168  void deleteParticleByPoint(GA_Offset pt);
169 
170  /// Delete the specified particle.
171  /// @pre vtx belongs to this particle primitive and is not currently on
172  /// the dead list.
173  /// @sa deadParticle()
174  void deleteParticle(GA_Offset vtxoff);
175 
176  /// Resurrect a particle or give birth to a new one.
177  GA_Offset giveBirth();
178 
179  /// Move the specified particle to the dead list.
180  /// @pre vtx belongs to this particle primitive
181  /// Does not actually remove from our vertex list!
182  /// This builds a list of all vertices that should be deleted
183  /// so deleteDead() can do a single pass over them.
184  /// vtxindex is the index into our vertex list, not a vertex offset.
185  void deadParticle(GEO_ParticleVertexIndex vtxindex);
186 
187  /// Delete all dead particles.
188  void deleteDead();
189 
190  /// Returns the number of live particles.
191  int getNumParticles() const { return myVertexList.entries(); }
192 
193 #if !GA_PRIMITIVE_VERTEXLIST
194  ///
195  // Methods to handle vertex attributes for the attribute dictionary
196  ///
197  virtual bool vertexApply(bool (*apply)(GA_Offset vtx, void *),
198  void *data = 0) const;
199 
200  /// @note getVertexCount() includes dead particles.
201  virtual GA_Size getVertexCount() const;
202 
203  /// @warning Traverses the linked list of vertices.
204  virtual GA_Offset getVertexOffset(GA_Size index) const;
205 
206  void setVertexPoint(unsigned int i, GA_Offset pt)
207  {
208  if (i < myVertexList.entries())
209  wireVertex(myVertexList(i), pt);
210  }
211 
212  virtual void beginVertex(const_iterator &i) const;
213  virtual void nextVertex(const_iterator &i) const;
214 #endif
215 
217  { deleteLists(); }
218 
219  // Have we been deactivated and stashed?
220  void stashed(bool beingstashed,
221  GA_Offset offset = GA_INVALID_OFFSET) override;
222 
223  const GA_PrimitiveJSON *getJSON() const override;
224 
225  /// @warning vertexPoint() doesn't check the bounds. Use with caution.
227  { return getDetail().vertexPoint(myVertexList(i)); }
228 
230  { return myVertexList; }
231 
232 protected:
233 #if !GA_PRIMITIVE_VERTEXLIST
234  virtual void clearForDeletion();
235 #endif
236 
238  { return GA_FAMILY_NONE; }
239 
240  // Declare intrinsic attribute methods
241  GA_DECLARE_INTRINSICS(override)
242 
243 #if !GA_PRIMITIVE_VERTEXLIST
244  /// Defragmentation
245  virtual void swapVertexOffsets(const GA_Defragment &defrag);
246 #endif
247 
248  /// Resize our vertex array
249  void setSize(GA_Size sz);
250 
251  // Evaluate the position or the derivative at domain point (u,v), where
252  // u and v MUST be in [0,1]. "v" and "dv" will be ignored here. Return 0 if
253  // OK and -1 otherwise.
254  bool evaluatePointRefMap(
255  GA_Offset result_vtx,
256  GA_AttributeRefMap &hlist,
257  fpreal u, fpreal v,
258  unsigned du, unsigned dv) const override;
259  int evaluatePointV4(
260  UT_Vector4 &pos,
261  float u_unit, float=0,
262  unsigned du=0, unsigned = 0) const override;
264  GA_Offset result_vertex,
265  GA_AttributeRefMap &hlist) const override;
266 
267  // This is called by the subclass to get the
268  // memory used by myVertexList and myDeadList
269  int64 getBaseMemoryUsage() const;
270 
271  // This is called by the subclass to count the
272  // memory used by myVertexList and myDeadList
274 
275 private:
276  void deleteLists();
277  void deleteParticleVertex(GA_Offset vtxoff)
278  {
279  destroyVertex(vtxoff);
280  }
281 
282  GEO_PartRender myRenderAttribs;
283 #if !GA_PRIMITIVE_VERTEXLIST
285 #endif
287 
288  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimParticle &d)
289  {
290  d.saveH9(os, 0,
293  return os;
294  }
296 };
298 
299 #endif
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
Definition of a geometry attribute.
Definition: GA_Attribute.h:197
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
GLuint counter
Definition: glew.h:2745
virtual UT_Vector3 baryCenter() const
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:159
virtual void clearForDeletion()
Definition: GA_Primitive.h:673
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:206
virtual UT_Vector3D computeNormalD() const =0
const GEO_PartRender & getRenderAttribs() const
Definition: GEO_PrimPart.h:160
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
virtual void copySubclassData(const GA_Primitive *source)
Definition: GA_Primitive.h:499
int getNumParticles() const
Returns the number of live particles.
Definition: GEO_PrimPart.h:191
bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const override
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
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:88
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:35
Abstract base class for a range membership query object.
GLenum src
Definition: glcorearb.h:1793
4D Vector class.
Definition: UT_Vector4.h:172
virtual void swapVertexOffsets(const GA_Defragment &defrag)
static GA_PrimitiveFamilyMask buildFamilyMask()
Definition: GEO_PrimPart.h:237
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:234
SYS_FORCE_INLINE int64 getBaseMemoryUsage() const
Report approximate memory usage for myVertexList for subclasses.
Definition: GA_Primitive.h:831
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:677
friend std::ostream & operator<<(std::ostream &os, const GEO_PrimParticle &d)
Definition: GEO_PrimPart.h:288
GA_OffsetList myVertexList
Definition: GA_Primitive.h:872
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
virtual bool isDegenerate() const =0
Is the primitive degenerate.
void destroyVertex(GA_Offset vertex)
GA_Size GA_Offset
Definition: GA_Types.h:640
virtual bool enlargeBoundingSphere(UT_BoundingSphere &b, const GA_Attribute *P) const
const GLdouble * v
Definition: glcorearb.h:837
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
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.
GLfloat GLfloat p
Definition: glew.h:16656
Options during loading.
Definition: GA_LoadMap.h:42
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:528
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
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
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:229
fpreal64 fpreal
Definition: SYS_Types.h:277
void clearAndDestroy()
Definition: GEO_PrimPart.h:216
GA_Size GEO_ParticleVertexIndex
Definition: GEO_PrimPart.h:25
virtual bool getBBox(UT_BoundingBox *bbox) const =0
GLuint index
Definition: glcorearb.h:786
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
GLintptr offset
Definition: glcorearb.h:665
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)
Definition: format.h:895
GA_Offset vertexPoint(GA_Size i) const
Definition: GEO_PrimPart.h:226