HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 copyUnwiredForMerge(const GA_Primitive *src,
126  const GA_MergeMap &map);
127  virtual bool isDegenerate() const;
128 #if !GA_PRIMITIVE_VERTEXLIST
129  virtual void addPointRefToGroup(GA_PointGroup &grp) const;
130 #endif
131 
132  // Take the whole set of points into consideration when applying the
133  // point removal operation to this primitive. The method returns 0 if
134  // successful, -1 if it failed because it would have become degenerate,
135  // and -2 if it failed because it would have had to remove the primitive
136  // altogether.
137  virtual int detachPoints (GA_PointGroup &grp);
138 
139  /// Before a point is deleted, all primitives using the point will be
140  /// notified. The method should return "false" if it's impossible to
141  /// delete the point. Otherwise, the vertices should be removed.
142  virtual GA_DereferenceStatus dereferencePoint(GA_Offset point,
143  bool dry_run=false);
144  virtual GA_DereferenceStatus dereferencePoints(
145  const GA_RangeMemberQuery &pt_q,
146  bool dry_run=false);
147 
148  // The following method simply computes the bounding box. If no
149  // particles exist, returns 0, else return 1.
150  int getPointBBox(UT_BoundingBox &bbox) const;
151 
152  /// @{
153  /// Retrieve the object specifying how this particle system should be
154  /// rendered.
155  GEO_PartRender &getRenderAttribs() { return myRenderAttribs; }
156  const GEO_PartRender &getRenderAttribs() const { return myRenderAttribs; }
157  /// @}
158 
159  /// Append a new particle. @sa giveBirth()
160  GA_Offset appendParticle(GA_Offset pt);
161 
162  /// Delete all particles not on the dead list that reference the supplied
163  /// point.
164  void deleteParticleByPoint(GA_Offset pt);
165 
166  /// Delete the specified particle.
167  /// @pre vtx belongs to this particle primitive and is not currently on
168  /// the dead list.
169  /// @sa deadParticle()
170  void deleteParticle(GA_Offset vtxoff);
171 
172  /// Resurrect a particle or give birth to a new one.
173  GA_Offset giveBirth();
174 
175  /// Move the specified particle to the dead list.
176  /// @pre vtx belongs to this particle primitive
177  /// Does not actually remove from our vertex list!
178  /// This builds a list of all vertices that should be deleted
179  /// so deleteDead() can do a single pass over them.
180  /// vtxindex is the index into our vertex list, not a vertex offset.
181  void deadParticle(GEO_ParticleVertexIndex vtxindex);
182 
183  /// Delete all dead particles.
184  void deleteDead();
185 
186  /// Returns the number of live particles.
187  int getNumParticles() const { return myVertexList.entries(); }
188 
189 #if !GA_PRIMITIVE_VERTEXLIST
190  ///
191  // Methods to handle vertex attributes for the attribute dictionary
192  ///
193  virtual bool vertexApply(bool (*apply)(GA_Offset vtx, void *),
194  void *data = 0) const;
195 
196  /// @note getVertexCount() includes dead particles.
197  virtual GA_Size getVertexCount() const;
198 
199  /// @warning Traverses the linked list of vertices.
200  virtual GA_Offset getVertexOffset(GA_Size index) const;
201 
202  void setVertexPoint(unsigned int i, GA_Offset pt)
203  {
204  if (i < myVertexList.entries())
205  wireVertex(myVertexList(i), pt);
206  }
207 
208  virtual void beginVertex(const_iterator &i) const;
209  virtual void nextVertex(const_iterator &i) const;
210 #endif
211 
213  { deleteLists(); }
214 
215  // Have we been deactivated and stashed?
216  virtual void stashed(bool beingstashed,
218 
219  virtual const GA_PrimitiveJSON *getJSON() const;
220 
221  /// @warning vertexPoint() doesn't check the bounds. Use with caution.
223  { return getDetail().vertexPoint(myVertexList(i)); }
224 
226  { return myVertexList; }
227 
228 protected:
229 #if !GA_PRIMITIVE_VERTEXLIST
230  virtual void clearForDeletion();
231 #endif
232 
234  { return GA_FAMILY_NONE; }
235 
236  // Declare intrinsic attribute methods
238 
239 #if !GA_PRIMITIVE_VERTEXLIST
240  /// Defragmentation
241  virtual void swapVertexOffsets(const GA_Defragment &defrag);
242 #endif
243 
244  /// Resize our vertex array
245  void setSize(GA_Size sz);
246 
247  // Evaluate the position or the derivative at domain point (u,v), where
248  // u and v MUST be in [0,1]. "v" and "dv" will be ignored here. Return 0 if
249  // OK and -1 otherwise.
250  virtual bool evaluatePointRefMap(GA_Offset result_vtx,
251  GA_AttributeRefMap &hlist,
252  fpreal u, fpreal v,
253  unsigned du, unsigned dv) const;
254  virtual int evaluatePointV4( UT_Vector4 &pos,
255  float u_unit, float=0,
256  unsigned du=0, unsigned = 0) const;
257  virtual bool evaluateBaryCenterRefMap(GA_Offset result_vertex,
258  GA_AttributeRefMap &hlist) const;
259 
260  // This is called by the subclass to get the
261  // memory used by myVertexList and myDeadList
262  int64 getBaseMemoryUsage() const;
263 
264  // This is called by the subclass to count the
265  // memory used by myVertexList and myDeadList
266  void countBaseMemory(UT_MemoryCounter &counter) const;
267 
268 private:
269  void deleteLists();
270  void deleteParticleVertex(GA_Offset vtxoff)
271  {
272  destroyVertex(vtxoff);
273  }
274 
275  GEO_PartRender myRenderAttribs;
276 #if !GA_PRIMITIVE_VERTEXLIST
278 #endif
280 
281  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimParticle &d)
282  {
283  d.saveH9(os, 0,
286  return os;
287  }
289 };
291 
292 #endif
virtual void copyUnwiredForMerge(const GA_Primitive *src, const GA_MergeMap &map)
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
virtual UT_Vector3 baryCenter() const
SYS_FORCE_INLINE GA_Detail & getDetail() const
Definition: GA_Primitive.h:132
virtual void copyPrimitive(const GEO_Primitive *src)=0
GEO_PartRender & getRenderAttribs()
Definition: GEO_PrimPart.h:155
virtual void clearForDeletion()
Definition: GA_Primitive.h:598
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:227
void setVertexPoint(unsigned int i, GA_Offset pt)
Definition: GEO_PrimPart.h:202
const GEO_PartRender & getRenderAttribs() const
Definition: GEO_PrimPart.h:156
#define SYS_DEPRECATED_PUSH_DISABLE()
const GLdouble * v
Definition: glcorearb.h:836
#define SYS_DEPRECATED_POP_DISABLE()
int getNumParticles() const
Returns the number of live particles.
Definition: GEO_PrimPart.h:187
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
virtual bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *P) const
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:72
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:79
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
Abstract base class for a range membership query object.
#define GA_NO_OVERRIDE
Definition: GA_Primitive.h:75
3D Vector class.
png_uint_32 i
Definition: png.h:2877
virtual void swapVertexOffsets(const GA_Defragment &defrag)
static GA_PrimitiveFamilyMask buildFamilyMask()
Definition: GEO_PrimPart.h:233
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:211
SYS_FORCE_INLINE int64 getBaseMemoryUsage() const
Report approximate memory usage for myVertexList for subclasses.
Definition: GA_Primitive.h:753
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:654
friend std::ostream & operator<<(std::ostream &os, const GEO_PrimParticle &d)
Definition: GEO_PrimPart.h:281
GA_OffsetList myVertexList
Definition: GA_Primitive.h:794
virtual bool isDegenerate() const =0
Is the primitive degenerate.
void destroyVertex(GA_Offset vertex)
GA_Size GA_Offset
Definition: GA_Types.h:617
virtual bool enlargeBoundingSphere(UT_BoundingSphere &b, const GA_Attribute *P) const
long long int64
Definition: SYS_Types.h:106
virtual const GA_PrimitiveJSON * getJSON() const =0
GLintptr offset
Definition: glcorearb.h:664
Provide a JSON interface to a primitive.
#define GEO_API
Definition: GEO_API.h:10
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:469
void addPointRefToGroup(GA_PointGroup &grp) const
GLboolean * data
Definition: glcorearb.h:130
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
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
virtual bool vertexApply(bool(*apply)(GA_Offset vtx, void *), void *data=0) const
double fpreal
Definition: SYS_Types.h:269
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:225
void clearAndDestroy()
Definition: GEO_PrimPart.h:212
GA_Size GEO_ParticleVertexIndex
Definition: GEO_PrimPart.h:25
GLuint index
Definition: glcorearb.h:785
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:235
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:75
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:96
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
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:222
virtual ~GEO_PrimParticle()
Definition: GEO_PrimPart.h:66
GLenum src
Definition: glcorearb.h:1792