HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEO_PrimTetra.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  * Produced by:
7  * Jeff Lait
8  * Side Effects Software Inc
9  * 477 Richmond Street West
10  * Toronto, Ontario
11  * Canada M5V 3E7
12  * 416-504-9876
13  *
14  * NAME: GEO_PrimTetra.h (HDK Sample, C++)
15  *
16  * COMMENTS: This is an HDK example for making a custom tetrahedron primitive type.
17  */
18 
19 #ifndef __HDK_GEO_PrimTetra__
20 #define __HDK_GEO_PrimTetra__
21 
22 #include <GEO/GEO_Primitive.h>
23 #include <GA/GA_Detail.h>
25 #include <GA/GA_Types.h>
26 #include <UT/UT_Interrupt.h>
27 #include <UT/UT_ParallelUtil.h>
28 #include <UT/UT_Vector3.h>
29 
30 namespace HDK_Sample {
31 
33 {
34 protected:
35  /// NOTE: The destructor should only be called from GA_PrimitiveList,
36  /// via a GA_Primitive pointer.
37  virtual ~GEO_PrimTetra();
38 public:
39  /// NOTE: To create a new primitive owned by the detail, call
40  /// GA_Detail::appendPrimitive or appendPrimitiveBlock on
41  /// the detail, not this constructor.
43 
44  /// @{
45  /// Required interface methods
46  virtual bool isDegenerate() const;
47  virtual int getBBox(UT_BoundingBox *bbox) const;
48  virtual void reverse();
49  virtual UT_Vector3 computeNormal() const;
50  virtual void copyPrimitive(const GEO_Primitive *src);
51  virtual void copyUnwiredForMerge(const GA_Primitive *src,
52  const GA_MergeMap &map);
53 
54  // Take the whole set of points into consideration when applying the
55  // point removal operation to this primitive. The method returns 0 if
56  // successful, -1 if it failed because it would have become degenerate,
57  // and -2 if it failed because it would have had to remove the primitive
58  // altogether.
59  virtual int detachPoints(GA_PointGroup &grp);
60  /// Before a point is deleted, all primitives using the point will be
61  /// notified. The method should return "false" if it's impossible to
62  /// delete the point. Otherwise, the vertices should be removed.
64  bool dry_run=false);
66  const GA_RangeMemberQuery &pt_q,
67  bool dry_run=false);
68  virtual const GA_PrimitiveJSON *getJSON() const;
69 
70  /// Evalaute a point given a u,v coordinate (with derivatives)
71  virtual bool evaluatePointRefMap(GA_Offset result_vtx,
72  GA_AttributeRefMap &hlist,
73  fpreal u, fpreal v, uint du, uint dv) const;
74  /// Evalaute position given a u,v coordinate (with derivatives)
75  virtual int evaluatePointV4( UT_Vector4 &pos, float u, float v = 0,
76  unsigned du=0, unsigned dv=0) const
77  {
78  return GEO_Primitive::evaluatePoint(pos, u, v,
79  du, dv);
80  }
81  /// @}
82 
83  /// @{
84  /// Though not strictly required (i.e. not pure virtual), these methods
85  /// should be implemented for proper behaviour.
86  virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
87 
88  // Have we been deactivated and stashed?
89  virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET);
90  /// @}
91 
92  /// @{
93  /// Optional interface methods. Though not required, implementing these
94  /// will give better behaviour for the new primitive.
95  virtual UT_Vector3 baryCenter() const;
96  virtual fpreal calcVolume(const UT_Vector3 &refpt) const;
97  virtual fpreal calcArea() const;
98  virtual fpreal calcPerimeter() const;
99  /// @}
100 
101  /// Load the order from a JSON value
102  bool loadOrder(const UT_JSONValue &p);
103 
104  /// @{
105  /// Save/Load vertex list to a JSON stream
107  const GA_SaveMap &map) const;
109  const GA_LoadMap &map);
110  /// @}
111 
112  /// Finds where the specified vertex offset is in this primitive's
113  /// vertex list.
115  {
116  for (GA_Size i = 0; i < 4; i++)
117  {
118  if (getVertexOffset(i) == vtxoff)
119  return i;
120  }
121  return -1;
122  }
123 
124  /// Finds where in this primitive's vertex list, some vertex
125  /// is wired to the specified point offset.
127  {
128  for (GA_Size i = 0; i < 4; i++)
129  {
130  if (getPointOffset(i) == ptoff)
131  return i;
132  }
133  return -1;
134  }
135 
136  /// Report approximate memory usage.
137  virtual int64 getMemoryUsage() const;
138 
139  /// Count memory usage using a UT_MemoryCounter in order to count
140  /// shared memory correctly.
141  /// NOTE: This should always include sizeof(*this).
142  virtual void countMemory(UT_MemoryCounter &counter) const;
143 
144  /// Allows you to find out what this primitive type was named.
145  static const GA_PrimitiveTypeId &theTypeId() { return theDefinition->getId(); }
146 
147  /// Must be invoked during the factory callback to add us to the
148  /// list of primitives
149  static void registerMyself(GA_PrimitiveFactory *factory);
150 
151  virtual const GA_PrimitiveDefinition &getTypeDef() const
152  { return *theDefinition; }
153 
154  /// @{
155  /// Conversion functions
156  virtual GEO_Primitive *convert(GEO_ConvertParms &parms,
157  GA_PointGroup *usedpts = 0);
158  virtual GEO_Primitive *convertNew(GEO_ConvertParms &parms);
159  /// @}
160 
161  /// Optional build function
162  static GEO_PrimTetra *build(GA_Detail *gdp, bool appendpts = true);
163 
164  /// Builds tetrahedrons using the specified range of point offsets,
165  /// as dictated by ntets and tetpointnumbers, in parallel.
166  /// tetpointnumbers lists the *offsets* of the points used by
167  /// each tetrahedron *MINUS* startpt, i.e. they are offsets relative to
168  /// startpt, *not* indices relative to startpt. The offset of the first
169  /// tetrahedron is returned, and the rest are at consecutive offsets. All
170  /// tetpointnumbers must be between 0 (inclusive) and npoints (exclusive).
171  ///
172  /// NOTE: Existing primitives *are* allowed to be using the points in
173  /// the specified range already, and the tetrahedrons being created do not
174  /// do not need to use all of the points in the range. However,
175  /// these cases may impact performance.
176  static GA_Offset buildBlock(GA_Detail *detail,
177  const GA_Offset startpt,
178  const GA_Size npoints,
179  const GA_Size ntets,
180  const int *tetpointnumbers);
181 
182  virtual void normal(NormalComp &output) const;
183 
184  virtual int intersectRay(const UT_Vector3 &o, const UT_Vector3 &d,
185  float tmax = 1E17F, float tol = 1E-12F,
186  float *distance = 0, UT_Vector3 *pos = 0,
187  UT_Vector3 *nml = 0, int accurate = 0,
188  float *u = 0, float *v = 0,
189  int ignoretrim = 1) const;
190 
191  // NOTE: This functor class must be in the scope of GEO_PrimTetra
192  // so that it can access myVertexList.
193  // It has to be public so that UTparallelForLightItems
194  // can be instantiated for GCC with it.
196  {
197  public:
199  const GA_Offset startvtx)
200  : myPrimitiveList(detail->getPrimitiveList())
201  , myStartPrim(startprim)
202  , myStartVtx(startvtx)
203  {}
204 
206  {
207  char bcnt = 0;
208  UT_Interrupt *boss = UTgetInterrupt();
209 
210  GA_Offset vtxoff = myStartVtx + 4*r.begin();
211  for (GA_Size i = r.begin(); i != r.end(); ++i)
212  {
213  if (!bcnt++ && boss->opInterrupt())
214  break;
215  GA_Offset offset = myStartPrim + i;
216  GEO_PrimTetra *tet = (GEO_PrimTetra *)myPrimitiveList.get(offset);
217  tet->myVertexList.setTrivial(vtxoff, 4);
218  vtxoff += 4;
219  }
220  }
221 
222  private:
223  GA_PrimitiveList &myPrimitiveList;
224  const GA_Offset myStartPrim;
225  const GA_Offset myStartVtx;
226  };
227 
228 protected:
229  /// Declare methods for implementing intrinsic attributes.
231 
233 private:
234  static GA_PrimitiveDefinition *theDefinition;
235 };
236 
237 }
238 
239 #endif
static void registerMyself(GA_PrimitiveFactory *factory)
GA_Size findPoint(GA_Offset ptoff) const
virtual void copyUnwiredForMerge(const GA_Primitive *src, const GA_MergeMap &map)
bool saveVertexArray(UT_JSONWriter &w, const GA_SaveMap &map) const
SYS_FORCE_INLINE GA_Offset getPointOffset(GA_Size i) const
Definition: GA_Primitive.h:249
void createVertices() const
Declare methods for implementing intrinsic attributes.
virtual const GA_PrimitiveJSON * getJSON() const
static GEO_PrimTetra * build(GA_Detail *gdp, bool appendpts=true)
Optional build function.
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
virtual fpreal calcArea() const
const GLdouble * v
Definition: glcorearb.h:836
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
void setTrivial(ToType startvalue, GA_Size size)
Makes the list a trivial list with the specified start value and size.
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
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
virtual int getBBox(UT_BoundingBox *bbox) const
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
bool loadOrder(const UT_JSONValue &p)
Load the order from a JSON value.
png_uint_32 i
Definition: png.h:2877
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
virtual bool evaluatePointRefMap(GA_Offset result_vtx, GA_AttributeRefMap &hlist, fpreal u, fpreal v, uint du, uint dv) const
Evalaute a point given a u,v coordinate (with derivatives)
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
GA_OffsetList myVertexList
Definition: GA_Primitive.h:794
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
Evalaute position given a u,v coordinate (with derivatives)
Definition: GEO_PrimTetra.h:75
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:106
int opInterrupt(int percent=-1)
static GA_Offset buildBlock(GA_Detail *detail, const GA_Offset startpt, const GA_Size npoints, const GA_Size ntets, const int *tetpointnumbers)
virtual UT_Vector3 baryCenter() const
virtual UT_Vector3 computeNormal() const
virtual fpreal calcVolume(const UT_Vector3 &refpt) const
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)
virtual void copyPrimitive(const GEO_Primitive *src)
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:634
virtual int intersectRay(const UT_Vector3 &o, const UT_Vector3 &d, float tmax=1E17F, float tol=1E-12F, float *distance=0, UT_Vector3 *pos=0, UT_Vector3 *nml=0, int accurate=0, float *u=0, float *v=0, int ignoretrim=1) const
virtual const GA_PrimitiveDefinition & getTypeDef() const
GLintptr offset
Definition: glcorearb.h:664
GEO_PrimTetra(GA_Detail &d, GA_Offset offset)
Definition: GEO_PrimTetra.C:75
Provide a JSON interface to a primitive.
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)
bool evaluatePoint(GA_Offset result_vtx, GA_AttributeRefMap &map, fpreal u, fpreal v=0, uint du=0, uint dv=0) const
A handle to simplify manipulation of multiple attributes.
virtual void normal(NormalComp &output) const
virtual int64 getMemoryUsage() const
Report approximate memory usage.
Options during loading.
Definition: GA_LoadMap.h:42
geo_SetVertexListsParallel(GA_Detail *detail, const GA_Offset startprim, const GA_Offset startvtx)
virtual fpreal calcPerimeter() const
static const GA_PrimitiveTypeId & theTypeId()
Allows you to find out what this primitive type was named.
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET)
Definition: GEO_PrimTetra.C:94
virtual int detachPoints(GA_PointGroup &grp)
unsigned int uint
Definition: SYS_Types.h:39
A list of primitives.
SYS_FORCE_INLINE const GA_PrimitiveTypeId & getId() const
The unique ID assigned by the GA_PrimitiveFactory.
double fpreal
Definition: SYS_Types.h:269
SYS_FORCE_INLINE const GA_Primitive * get(GA_Offset off) const
void operator()(const UT_BlockedRange< GA_Size > &r) const
UT_API UT_Interrupt * UTgetInterrupt()
Obtain global UT_Interrupt singleton.
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 GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q, bool dry_run=false)
Container class for all geometry.
Definition: GA_Detail.h:96
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
Definition of a geometric primitive.
GLboolean r
Definition: glcorearb.h:1221
bool loadVertexArray(UT_JSONParser &p, const GA_LoadMap &map)
#define const
Definition: zconf.h:214
Declare prior to use.
virtual void countMemory(UT_MemoryCounter &counter) const
GA_Size findVertex(GA_Offset vtxoff) const
virtual bool isDegenerate() const
virtual GA_DereferenceStatus dereferencePoint(GA_Offset point, bool dry_run=false)
GLenum src
Definition: glcorearb.h:1792