HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEO_PrimTriBezier.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: GEO_PrimTriBezier.h ( GEO Library, C++)
7  *
8  * COMMENTS: This is the base class for all triangle mesh types.
9  */
10 
11 #ifndef __GEO_PrimTriBezier__
12 #define __GEO_PrimTriBezier__
13 
14 #include "GEO_API.h"
15 #include "GEO_Primitive.h"
16 
17 #include <GA/GA_Defines.h>
18 #include <GA/GA_GenericHandle.h>
19 #include <UT/UT_Array.h>
20 #include <UT/UT_Vector3.h>
21 
22 class GA_AttributeRefMap;
23 class GEO_ConvertParms;
24 
26 {
27 public:
29  : GEO_Primitive(d, offset)
30  {}
31 #if !GA_PRIMITIVE_VERTEXLIST
32  virtual ~GEO_PrimTriBezier();
33 #endif
34 
35  virtual const GA_PrimitiveDefinition &getTypeDef() const
36  {
37  UT_ASSERT(theDefinition);
38  return *theDefinition;
39  }
40 
41  // This fills a plain point array with our positions.
42  // The array is a compressed array in the same format as our own
43  // native stuff.
44  void fillArray(int fakeorder, UT_Vector4 *array) const;
45  void fillArray(int fakeorder, const GA_Offset *results,
46  GA_AttributeRefMap &hlist) const;
47 
48  virtual int getBBox(UT_BoundingBox *bbox) const;
49  virtual void addToBSphere(UT_BoundingSphere *bsphere) const;
50  virtual UT_Vector3 baryCenter() const;
51  virtual void reverse();
52  virtual UT_Vector3 computeNormal() const;
53 
54  virtual fpreal calcVolume(const UT_Vector3 &refpt) const;
55  virtual fpreal calcArea() const;
56  virtual fpreal calcPerimeter() const;
57 
58  /// Load the order from a JSON value
59  bool loadOrder(const UT_JSONValue &p);
60 
61  /// @{
62  /// Save/Load vertex list to a JSON stream
63  bool saveVertexArray(UT_JSONWriter &w,
64  const GA_SaveMap &map) const;
65  bool loadVertexArray(UT_JSONParser &p,
66  const GA_LoadMap &map);
67  /// @}
68 
69  virtual bool saveH9(std::ostream &os, bool binary,
70  const UT_Array<GA_AttribSaveDataH9> &prim_attribs,
71  const UT_Array<GA_AttribSaveDataH9> &vtx_attribs)
72  const;
73  virtual bool loadH9(UT_IStream &is,
74  const UT_Array<GA_AttribLoadDataH9> &prim_attribs,
75  const UT_Array<GA_AttribLoadDataH9> &vtx_attribs);
76 
77  virtual void copyPrimitive(const GEO_Primitive *src);
78  virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
79 
80  virtual void copyUnwiredForMerge(const GA_Primitive *src,
81  const GA_MergeMap &map);
82 
83 #if !GA_PRIMITIVE_VERTEXLIST
84  virtual void addPointRefToGroup(GA_PointGroup &grp) const;
85 #endif
86 
87  virtual bool isDegenerate() const;
88 
89  // Adjust the order of the patch.
90  void setOrder(int order);
91  int getOrder() const { return myOrder; }
92 
93  // Take the whole set of points into consideration when applying the
94  // point removal operation to this primitive. The method returns 0 if
95  // successful, -1 if it failed because it would have become degenerate,
96  // and -2 if it failed because it would have had to remove the primitive
97  // altogether.
98  virtual int detachPoints(GA_PointGroup &grp);
99 
100  /// Before a point is deleted, all primitives using the point will be
101  /// notified. The method should return "false" if it's impossible to
102  /// delete the point. Otherwise, the vertices should be removed.
103  virtual GA_DereferenceStatus dereferencePoint(GA_Offset point,
104  bool dry_run=false);
105  virtual GA_DereferenceStatus dereferencePoints(
106  const GA_RangeMemberQuery &pt_q,
107  bool dry_run=false);
108 
109 #if GA_PRIMITIVE_VERTEXLIST
111 #else
112  // Query the number of vertices in the array. This number may be smaller
113  // than the actual size of the array.
114  virtual GA_Size getVertexCount() const;
115  virtual GA_Offset getVertexOffset(GA_Size index) const;
116 
117  virtual void beginVertex(const_iterator &i) const;
118  virtual void nextVertex(const_iterator &i) const;
119 #endif
120 
122  {
123  if (i < myVertexList.entries())
124  wireVertex(myVertexList(i), pt);
125  }
126 
127  // And now the operators that let you treat it like a portion of
128  // a tensor product patch:
130  { return getRawIndex(row, col, myOrder); }
131  GA_Size getRawIndex(GA_Size row, GA_Size col, int order)const
132  { return (order - row)*(order-row-1)/2 + col; }
134  { return getVertexOffset(getRawIndex(i, j)); }
136  { return GEO_Primitive::getPointOffset(getRawIndex(i, j)); }
138  { return GEO_Primitive::getPos3(getRawIndex(i, j)); }
139  void setPos3(GA_Size i, GA_Size j, const UT_Vector3 &pos) const
140  { GEO_Primitive::setPos3(getRawIndex(i, j), pos); }
142  {
143  i = getRawIndex(i, j);
144  if (i < myVertexList.entries())
145  wireVertex(myVertexList(i), pt);
146  }
147 
148 #if !GA_PRIMITIVE_VERTEXLIST
149  // Have we been deactivated and stashed?
150  virtual void stashed(bool beingstashed,
152 
153  // Methods to handle vertex attributes for the attribute dictionary
154  virtual bool vertexApply(bool (*apply)(GA_Offset vtx, void *),
155  void *data = 0) const;
156 #endif
157 
158  virtual const GA_PrimitiveJSON *getJSON() const;
159 
160  /// Fill a tesselation of the mesh for a given attribute. @c ndivs must be
161  /// greater than or equal to 2. The @c pos array should be able to hold @c
162  /// (ndivs)*(ndivs+1)/2 entries.
163  template <typename T>
164  bool evaluateMesh(int ndivs,
166  T *pos) const;
167 
168  /// Report approximate memory usage.
169  virtual int64 getMemoryUsage() const;
170 
171  /// Count memory usage using a UT_MemoryCounter in order to count
172  /// shared memory correctly.
173  /// NOTE: This should always include sizeof(*this).
174  virtual void countMemory(UT_MemoryCounter &counter) const;
175 
176  static GEO_PrimTriBezier *build(GA_Detail *gdp, int order,
177  bool appendPts = true);
178 
179  // Conversion Methods
180  virtual GEO_Primitive *convert(GEO_ConvertParms &parms,
181  GA_PointGroup *usedpts = nullptr);
182  virtual GEO_Primitive *convertNew(GEO_ConvertParms &parms);
183 
184  virtual void normal(NormalComp &output) const;
185 
186 protected:
187 #if !GA_PRIMITIVE_VERTEXLIST
188  virtual void clearForDeletion();
189 #endif
190 
192  { return GA_FAMILY_NONE; }
193 
194  // Declare intrinsic methods
196 
197  // Methods for finding out about point references
198  virtual bool savePrivateH9(std::ostream & /*os*/,int /*binary*/) const
199  {return true;}
200  virtual bool loadPrivateH9(UT_IStream &) { return true; }
201 
202  // Check the validity of the data. Meant to be called especially at loading
203  // time. The method returns 1 if OK and 0 if trouble.
204  virtual bool validate(void) const;
205 
206  void setSize(GA_Size sz);
207 
208  /// @warning vertexPoint() doesn't check the bounds. Use with caution.
210  { return getDetail().vertexPoint(myVertexList(i)); }
212  { return vertexPoint(getRawIndex(i, j)); }
213 
214  /// @warning swapVertices() doesn't check the bounds, nor that
215  /// (i1,j1) != (i2,j2). Use with caution.
217  GA_Size i2, GA_Size j2)
218  {
219  GA_Size i = getRawIndex(i1, j1);
220  GA_Size j = getRawIndex(i2, j2);
221  GA_Offset tmp = myVertexList(i);
222  myVertexList.set(i, myVertexList(j));
223  myVertexList.set(j, tmp);
224  }
225 
226 #if !GA_PRIMITIVE_VERTEXLIST
227  /// Defragmentation
228  virtual void swapVertexOffsets(const GA_Defragment &defrag);
229 #endif
230 
231 #if !GA_PRIMITIVE_VERTEXLIST
233 #endif
234  int myOrder;
235 
236  virtual bool evaluatePointRefMap(GA_Offset result_vtx,
237  GA_AttributeRefMap &hlist,
238  fpreal u, fpreal v, uint du, uint dv) const;
239  virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v = 0,
240  unsigned du=0, unsigned dv = 0) const;
241  virtual bool evaluateBaryCenterRefMap(GA_Offset result_vertex,
242  GA_AttributeRefMap &hlist) const;
243  virtual void computeInteriorPointWeights(UT_Array<GA_Offset> &vtxlist, UT_FloatArray &weightlist, fpreal u, fpreal v, fpreal w) const;
244 
245 private:
246  static GA_PrimitiveDefinition *theDefinition;
247  friend class GU_PrimitiveFactory;
248 
249  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimTriBezier &d)
250  {
251  d.saveH9(os, 0,
254  return os;
255  }
257 };
259 
260 #endif
virtual void copyUnwiredForMerge(const GA_Primitive *src, const GA_MergeMap &map)
GA_Offset vertexPoint(GA_Size i, GA_Size j) const
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
SYS_FORCE_INLINE GA_Offset getPointOffset(GA_Size i) const
Definition: GA_Primitive.h:249
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
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
int myOrder
Definition: GT_CurveEval.h:263
#define SYS_DEPRECATED_PUSH_DISABLE()
const GLdouble * v
Definition: glcorearb.h:836
#define SYS_DEPRECATED_POP_DISABLE()
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 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.
void swapVertices(GA_Size i1, GA_Size j1, GA_Size i2, GA_Size j2)
#define GA_NO_OVERRIDE
Definition: GA_Primitive.h:75
virtual const GA_PrimitiveDefinition & getTypeDef() const
3D Vector class.
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:204
UT_Vector3 getPos3(GA_Size i, GA_Size j) const
png_uint_32 i
Definition: png.h:2877
virtual void swapVertexOffsets(const GA_Defragment &defrag)
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
virtual bool loadH9(UT_IStream &is, const UT_Array< GA_AttribLoadDataH9 > &prim_attribs, const UT_Array< GA_AttribLoadDataH9 > &vtx_attribs)
int getOrder() const
GA_PrimitiveFamilyMask
virtual UT_Vector3 computeNormal() const =0
Return a normal vector for the primitive.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
virtual void normal(NormalComp &output) const =0
GA_OffsetList myVertexList
Definition: GA_Primitive.h:794
void setVertexPoint(GA_Size i, GA_Offset pt)
virtual bool isDegenerate() const =0
Is the primitive degenerate.
friend std::ostream & operator<<(std::ostream &os, const GEO_PrimTriBezier &d)
GA_Size GA_Offset
Definition: GA_Types.h:617
void setPos3(GA_Size i, GA_Size j, const UT_Vector3 &pos) const
long long int64
Definition: SYS_Types.h:106
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Size i) const
Definition: GA_Primitive.h:269
GA_Size getRawIndex(GA_Size row, GA_Size col, int order) const
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
virtual void countMemory(UT_MemoryCounter &counter) const
virtual fpreal calcArea() const
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 computeInteriorPointWeights(UT_Array< GA_Offset > &vtxlist, UT_FloatArray &weightlist, fpreal u, fpreal v, fpreal w) const
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
void fillArray(ValueType *array, const ValueType val, const size_t length)
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
png_bytepp row
Definition: png.h:1836
virtual fpreal calcPerimeter() const
virtual GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q, bool dry_run=false)=0
unsigned int uint
Definition: SYS_Types.h:39
virtual bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const
SYS_FORCE_INLINE void setPos3(GA_Size i, const UT_Vector3 &pos) const
Definition: GA_Primitive.h:275
virtual bool evaluateBaryCenterRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map) const
GA_OffsetList myVertexList
virtual bool vertexApply(bool(*apply)(GA_Offset vtx, void *), void *data=0) const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
GA_Offset getPointOffset(GA_Size i, GA_Size j) const
double fpreal
Definition: SYS_Types.h:269
GEO_PrimTriBezier(GA_Detail *d, GA_Offset offset=GA_INVALID_OFFSET)
GA_Offset getVertexOffset(GA_Size i, GA_Size j) const
virtual int detachPoints(GA_PointGroup &grp)=0
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
virtual bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const
GLuint index
Definition: glcorearb.h:785
virtual fpreal calcVolume(const UT_Vector3 &) const
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
static GA_PrimitiveFamilyMask buildFamilyMask()
virtual void addToBSphere(UT_BoundingSphere *bsphere) const
GA_Offset vertexPoint(GA_Size i) const
Container class for all geometry.
Definition: GA_Detail.h:96
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
Specialization of GA_ROGenericHandle for GA_ATTRIB_VERTEX offsets.
Definition of a geometric primitive.
void setVertexPoint(GA_Size i, GA_Size j, GA_Offset pt)
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET)
GA_Size getRawIndex(GA_Size row, GA_Size col) const
virtual bool loadPrivateH9(UT_IStream &)
GLenum src
Definition: glcorearb.h:1792