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.
67  {
68 #if !GA_PRIMITIVE_VERTEXLIST
69  deleteLists();
70 #endif
71  }
72 
73 public:
74  virtual 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;
78  virtual bool loadH9(UT_IStream &is,
79  const UT_Array<GA_AttribLoadDataH9> &prim_attribs,
80  const UT_Array<GA_AttribLoadDataH9> &vtx_attribs);
81 
82  /// @{
83  /// Save/Load vertex list to a JSON stream
84  bool saveVertexArray(UT_JSONWriter &w,
85  const GA_SaveMap &map) const;
86  bool loadVertexArray(UT_JSONParser &p,
87  const GA_LoadMap &map);
88  /// @}
89  /// @{
90  /// Save/load render properties to a JSON stream
91  bool saveRenderProperties(UT_JSONWriter &w,
92  const GA_SaveMap &map) const;
93  bool saveRenderProperties(UT_JSONValue &v,
94  const GA_SaveMap &map) const;
95  bool loadRenderProperties(UT_JSONParser &p,
96  const GA_LoadMap &map);
97  bool loadRenderProperties(UT_JSONParser &p,
98  const UT_JSONValue &v,
99  const GA_LoadMap &map);
100  bool areRenderPropertiesEqual(
101  const GEO_PrimParticle &src) const;
102  /// @}
103 
104  virtual int getBBox(UT_BoundingBox *bbox) const;
105  virtual void addToBSphere(UT_BoundingSphere *bsphere) const;
106  /// @{
107  /// Enlarge a bounding box by the bounding box of the primitive. A
108  /// return value of false indicates an error in the operation, most
109  /// likely an invalid P. Unlike getBBox(), velocity is ignored.
110  virtual bool enlargeBoundingBox(UT_BoundingRect &b,
111  const GA_Attribute *P) const;
112  virtual bool enlargeBoundingBox(UT_BoundingBox &b,
113  const GA_Attribute *P) const;
114  /// @}
115  /// Enlarge a bounding sphere to encompass the primitive. A return value
116  /// of false indicates an error in the operation, most likely an invalid
117  /// P. Unlike getBBox(), velocity is ignored.
119  const GA_Attribute *P) const;
120  virtual UT_Vector3 computeNormal() const;
121  virtual UT_Vector3 baryCenter() const;
122  virtual void reverse();
123  virtual void copyPrimitive(const GEO_Primitive *src);
124  virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
125  virtual void copySubclassData(const GA_Primitive *source);
126  virtual bool isDegenerate() const;
127 #if !GA_PRIMITIVE_VERTEXLIST
128  virtual void addPointRefToGroup(GA_PointGroup &grp) const;
129 #endif
130 
131  // Take the whole set of points into consideration when applying the
132  // point removal operation to this primitive. The method returns 0 if
133  // successful, -1 if it failed because it would have become degenerate,
134  // and -2 if it failed because it would have had to remove the primitive
135  // altogether.
136  virtual int detachPoints (GA_PointGroup &grp);
137 
138  /// Before a point is deleted, all primitives using the point will be
139  /// notified. The method should return "false" if it's impossible to
140  /// delete the point. Otherwise, the vertices should be removed.
141  virtual GA_DereferenceStatus dereferencePoint(GA_Offset point,
142  bool dry_run=false);
143  virtual GA_DereferenceStatus dereferencePoints(
144  const GA_RangeMemberQuery &pt_q,
145  bool dry_run=false);
146 
147  // The following method simply computes the bounding box. If no
148  // particles exist, returns 0, else return 1.
149  int getPointBBox(UT_BoundingBox &bbox) const;
150 
151  /// @{
152  /// Retrieve the object specifying how this particle system should be
153  /// rendered.
154  GEO_PartRender &getRenderAttribs() { return myRenderAttribs; }
155  const GEO_PartRender &getRenderAttribs() const { return myRenderAttribs; }
156  /// @}
157 
158  /// Append a new particle. @sa giveBirth()
159  GA_Offset appendParticle(GA_Offset pt);
160 
161  /// Delete all particles not on the dead list that reference the supplied
162  /// point.
163  void deleteParticleByPoint(GA_Offset pt);
164 
165  /// Delete the specified particle.
166  /// @pre vtx belongs to this particle primitive and is not currently on
167  /// the dead list.
168  /// @sa deadParticle()
169  void deleteParticle(GA_Offset vtxoff);
170 
171  /// Resurrect a particle or give birth to a new one.
172  GA_Offset giveBirth();
173 
174  /// Move the specified particle to the dead list.
175  /// @pre vtx belongs to this particle primitive
176  /// Does not actually remove from our vertex list!
177  /// This builds a list of all vertices that should be deleted
178  /// so deleteDead() can do a single pass over them.
179  /// vtxindex is the index into our vertex list, not a vertex offset.
180  void deadParticle(GEO_ParticleVertexIndex vtxindex);
181 
182  /// Delete all dead particles.
183  void deleteDead();
184 
185  /// Returns the number of live particles.
186  int getNumParticles() const { return myVertexList.entries(); }
187 
188 #if !GA_PRIMITIVE_VERTEXLIST
189  ///
190  // Methods to handle vertex attributes for the attribute dictionary
191  ///
192  virtual bool vertexApply(bool (*apply)(GA_Offset vtx, void *),
193  void *data = 0) const;
194 
195  /// @note getVertexCount() includes dead particles.
196  virtual GA_Size getVertexCount() const;
197 
198  /// @warning Traverses the linked list of vertices.
199  virtual GA_Offset getVertexOffset(GA_Size index) const;
200 
201  void setVertexPoint(unsigned int i, GA_Offset pt)
202  {
203  if (i < myVertexList.entries())
204  wireVertex(myVertexList(i), pt);
205  }
206 
207  virtual void beginVertex(const_iterator &i) const;
208  virtual void nextVertex(const_iterator &i) const;
209 #endif
210 
212  { deleteLists(); }
213 
214  // Have we been deactivated and stashed?
215  virtual void stashed(bool beingstashed,
217 
218  virtual const GA_PrimitiveJSON *getJSON() const;
219 
220  /// @warning vertexPoint() doesn't check the bounds. Use with caution.
222  { return getDetail().vertexPoint(myVertexList(i)); }
223 
225  { return myVertexList; }
226 
227 protected:
228 #if !GA_PRIMITIVE_VERTEXLIST
229  virtual void clearForDeletion();
230 #endif
231 
233  { return GA_FAMILY_NONE; }
234 
235  // Declare intrinsic attribute methods
237 
238 #if !GA_PRIMITIVE_VERTEXLIST
239  /// Defragmentation
240  virtual void swapVertexOffsets(const GA_Defragment &defrag);
241 #endif
242 
243  /// Resize our vertex array
244  void setSize(GA_Size sz);
245 
246  // Evaluate the position or the derivative at domain point (u,v), where
247  // u and v MUST be in [0,1]. "v" and "dv" will be ignored here. Return 0 if
248  // OK and -1 otherwise.
249  virtual bool evaluatePointRefMap(GA_Offset result_vtx,
250  GA_AttributeRefMap &hlist,
251  fpreal u, fpreal v,
252  unsigned du, unsigned dv) const;
253  virtual int evaluatePointV4( UT_Vector4 &pos,
254  float u_unit, float=0,
255  unsigned du=0, unsigned = 0) const;
256  virtual bool evaluateBaryCenterRefMap(GA_Offset result_vertex,
257  GA_AttributeRefMap &hlist) const;
258 
259  // This is called by the subclass to get the
260  // memory used by myVertexList and myDeadList
261  int64 getBaseMemoryUsage() const;
262 
263  // This is called by the subclass to count the
264  // memory used by myVertexList and myDeadList
266 
267 private:
268  void deleteLists();
269  void deleteParticleVertex(GA_Offset vtxoff)
270  {
271  destroyVertex(vtxoff);
272  }
273 
274  GEO_PartRender myRenderAttribs;
275 #if !GA_PRIMITIVE_VERTEXLIST
277 #endif
279 
280  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimParticle &d)
281  {
282  d.saveH9(os, 0,
285  return os;
286  }
288 };
290 
291 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
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:133
virtual void copyPrimitive(const GEO_Primitive *src)=0
GEO_PartRender & getRenderAttribs()
Definition: GEO_PrimPart.h:154
virtual void clearForDeletion()
Definition: GA_Primitive.h:641
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:224
void setVertexPoint(unsigned int i, GA_Offset pt)
Definition: GEO_PrimPart.h:201
const GEO_PartRender & getRenderAttribs() const
Definition: GEO_PrimPart.h:155
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:476
int getNumParticles() const
Returns the number of live particles.
Definition: GEO_PrimPart.h:186
virtual bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *P) const
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:75
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
Abstract base class for a range membership query object.
const GLdouble * v
Definition: glew.h:1391
#define GA_NO_OVERRIDE
Definition: GA_Primitive.h:76
4D Vector class.
Definition: UT_Vector4.h:163
virtual void swapVertexOffsets(const GA_Defragment &defrag)
static GA_PrimitiveFamilyMask buildFamilyMask()
Definition: GEO_PrimPart.h:232
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:231
SYS_FORCE_INLINE int64 getBaseMemoryUsage() const
Report approximate memory usage for myVertexList for subclasses.
Definition: GA_Primitive.h:796
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:674
friend std::ostream & operator<<(std::ostream &os, const GEO_PrimParticle &d)
Definition: GEO_PrimPart.h:280
GA_OffsetList myVertexList
Definition: GA_Primitive.h:837
virtual bool isDegenerate() const =0
Is the primitive degenerate.
void destroyVertex(GA_Offset vertex)
GA_Size GA_Offset
Definition: GA_Types.h:637
virtual bool enlargeBoundingSphere(UT_BoundingSphere &b, const GA_Attribute *P) const
long long int64
Definition: SYS_Types.h:111
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
virtual void reverse()=0
Reverse the order of vertices.
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 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
double fpreal
Definition: SYS_Types.h:276
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:224
void clearAndDestroy()
Definition: GEO_PrimPart.h:211
GA_Size GEO_ParticleVertexIndex
Definition: GEO_PrimPart.h:25
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:232
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:76
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:221
virtual ~GEO_PrimParticle()
Definition: GEO_PrimPart.h:66
GLintptr offset
Definition: glew.h:1682