HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  const GA_PrimitiveDefinition &getTypeDef() const override
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  bool getBBox(UT_BoundingBox *bbox) const override;
49  void addToBSphere(UT_BoundingSphere *bsphere) const override;
50  UT_Vector3 baryCenter() const override;
51  void reverse() override;
52  UT_Vector3 computeNormal() const override;
53  UT_Vector3D computeNormalD() const override;
54 
55  fpreal calcVolume(const UT_Vector3 &refpt) const override;
56  fpreal calcArea() const override;
57  fpreal calcPerimeter() const override;
58 
59  /// Load the order from a JSON value
60  bool loadOrder(const UT_JSONValue &p);
61 
62  /// @{
63  /// Save/Load vertex list to a JSON stream
64  bool saveVertexArray(UT_JSONWriter &w,
65  const GA_SaveMap &map) const;
66  bool loadVertexArray(UT_JSONParser &p,
67  const GA_LoadMap &map);
68  /// @}
69 
70  bool saveH9(std::ostream &os, bool binary,
71  const UT_Array<GA_AttribSaveDataH9> &prim_attribs,
72  const UT_Array<GA_AttribSaveDataH9> &vtx_attribs
73  ) const override;
74  bool loadH9(UT_IStream &is,
75  const UT_Array<GA_AttribLoadDataH9> &prim_attribs,
76  const UT_Array<GA_AttribLoadDataH9> &vtx_attribs
77  ) override;
78 
79  void copyPrimitive(const GEO_Primitive *src) override;
80  GEO_Primitive *copy(int preserve_shared_pts = 0) const override;
81 
82  void copySubclassData(const GA_Primitive *source) override;
83 
84 #if !GA_PRIMITIVE_VERTEXLIST
85  virtual void addPointRefToGroup(GA_PointGroup &grp) const;
86 #endif
87 
88  bool isDegenerate() const override;
89 
90  // Adjust the order of the patch.
91  void setOrder(int order);
92  int getOrder() const { return myOrder; }
93 
94  // Take the whole set of points into consideration when applying the
95  // point removal operation to this primitive. The method returns 0 if
96  // successful, -1 if it failed because it would have become degenerate,
97  // and -2 if it failed because it would have had to remove the primitive
98  // altogether.
99  int detachPoints(GA_PointGroup &grp) override;
100 
101  /// Before a point is deleted, all primitives using the point will be
102  /// notified. The method should return "false" if it's impossible to
103  /// delete the point. Otherwise, the vertices should be removed.
104  GA_DereferenceStatus dereferencePoint(GA_Offset point,
105  bool dry_run=false) override;
106  GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q,
107  bool dry_run=false) override;
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); }
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  const GA_PrimitiveJSON *getJSON() const override;
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  int64 getMemoryUsage() const override;
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  void countMemory(UT_MemoryCounter &counter) const override;
175 
176  static GEO_PrimTriBezier *build(GA_Detail *gdp, int order,
177  bool appendPts = true);
178 
179  // Conversion Methods
181  GA_PointGroup *usedpts = nullptr) override;
182  GEO_Primitive *convertNew(GEO_ConvertParms &parms) override;
183 
184  void normal(NormalComp &output) const override;
185  void normal(NormalCompD &output) const override;
186 
187 protected:
188 #if !GA_PRIMITIVE_VERTEXLIST
189  virtual void clearForDeletion();
190 #endif
191 
193  { return GA_FAMILY_NONE; }
194 
195  template <typename T>
196  UT_Vector3T<T> internalComputeNormal() const;
197 
198  template <typename T, typename NORMALCOMP>
199  void internalComputeNormal(NORMALCOMP &output) const;
200 
201  // Declare intrinsic methods
202  GA_DECLARE_INTRINSICS(override)
203 
204  // Methods for finding out about point references
205  virtual bool savePrivateH9(std::ostream & /*os*/,int /*binary*/) const
206  {return true;}
207  virtual bool loadPrivateH9(UT_IStream &) { return true; }
208 
209  // Check the validity of the data. Meant to be called especially at loading
210  // time. The method returns 1 if OK and 0 if trouble.
211  virtual bool validate() const;
212 
213  void setSize(GA_Size sz);
214 
215  /// @warning vertexPoint() doesn't check the bounds. Use with caution.
217  { return getDetail().vertexPoint(myVertexList(i)); }
219  { return vertexPoint(getRawIndex(i, j)); }
220 
221  /// @warning swapVertices() doesn't check the bounds, nor that
222  /// (i1,j1) != (i2,j2). Use with caution.
224  GA_Size i2, GA_Size j2)
225  {
226  GA_Size i = getRawIndex(i1, j1);
227  GA_Size j = getRawIndex(i2, j2);
228  GA_Offset tmp = myVertexList(i);
229  myVertexList.set(i, myVertexList(j));
230  myVertexList.set(j, tmp);
231  }
232 
233 #if !GA_PRIMITIVE_VERTEXLIST
234  /// Defragmentation
235  virtual void swapVertexOffsets(const GA_Defragment &defrag);
236 #endif
237 
238 #if !GA_PRIMITIVE_VERTEXLIST
240 #endif
241  int myOrder;
242 
243  bool evaluatePointRefMap(
244  GA_Offset result_vtx,
245  GA_AttributeRefMap &hlist,
246  fpreal u, fpreal v,
247  uint du, uint dv) const override;
248  int evaluatePointV4(
249  UT_Vector4 &pos,
250  float u, float v = 0,
251  unsigned du=0, unsigned dv = 0) const override;
253  GA_Offset result_vertex,
254  GA_AttributeRefMap &hlist) const override;
256  UT_Array<GA_Offset> &vtxlist,
257  UT_Array<float> &weightlist,
258  fpreal u, fpreal v, fpreal w) const override;
259 
260 private:
261  static GA_PrimitiveDefinition *theDefinition;
262  friend class GU_PrimitiveFactory;
263 
264  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimTriBezier &d)
265  {
266  d.saveH9(os, 0,
269  return os;
270  }
272 };
274 
275 #endif
fpreal calcPerimeter() const override
GA_Offset vertexPoint(GA_Size i, GA_Size j) const
bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const override
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
SYS_FORCE_INLINE GA_Offset getPointOffset(GA_Size i) const
Definition: GA_Primitive.h:254
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
virtual void clearForDeletion()
Definition: GA_Primitive.h:687
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
const GA_PrimitiveDefinition & getTypeDef() const override
int myOrder
Definition: GT_CurveEval.h:263
virtual void computeInteriorPointWeights(UT_Array< GA_Offset > &vtxlist, UT_Array< float > &weightlist, fpreal u, fpreal v, fpreal w) const
virtual UT_Vector3D computeNormalD() const =0
GLint GLint GLint j1
Definition: glad.h:2730
const GLdouble * v
Definition: glcorearb.h:837
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
virtual void copySubclassData(const GA_Primitive *source)
Definition: GA_Primitive.h:508
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
fpreal calcVolume(const UT_Vector3 &) const override
GLint GLint i2
Definition: glad.h:2724
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:87
void reverse() override=0
Reverse the order of vertices.
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
Abstract base class for a range membership query object.
void swapVertices(GA_Size i1, GA_Size j1, GA_Size i2, GA_Size j2)
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:209
fpreal calcArea() const override
UT_Vector3 getPos3(GA_Size i, GA_Size j) const
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:236
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:687
virtual void normal(NormalComp &output) const =0
GA_OffsetList myVertexList
Definition: GA_Primitive.h:886
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:646
void setPos3(GA_Size i, GA_Size j, const UT_Vector3 &pos) const
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Size i) const
Definition: GA_Primitive.h:274
GLintptr offset
Definition: glcorearb.h:665
GA_Size getRawIndex(GA_Size row, GA_Size col, int order) const
virtual void countMemory(UT_MemoryCounter &counter) const
virtual const GA_PrimitiveJSON * getJSON() const =0
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
Provide a JSON interface to a primitive.
#define GEO_API
Definition: GEO_API.h:14
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
long long int64
Definition: SYS_Types.h:116
A handle to simplify manipulation of multiple attributes.
GLint i1
Definition: glad.h:2724
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:529
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
SYS_FORCE_INLINE void setPos3(GA_Size i, const UT_Vector3 &pos) const
Definition: GA_Primitive.h:286
virtual bool evaluateBaryCenterRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map) const
GA_OffsetList myVertexList
GLint j
Definition: glad.h:2733
virtual bool vertexApply(bool(*apply)(GA_Offset vtx, void *), void *data=0) const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GA_Offset getPointOffset(GA_Size i, GA_Size j) const
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().
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual bool getBBox(UT_BoundingBox *bbox) const =0
GLuint index
Definition: glcorearb.h:786
GLint GLint GLint GLint j2
Definition: glad.h:2730
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:99
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:857
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
Specialization of GA_ROGenericHandle for GA_ATTRIB_VERTEX offsets.
GLenum GLenum GLsizei void * row
Definition: glad.h:5135
Definition of a geometric primitive.
void setVertexPoint(GA_Size i, GA_Size j, GA_Offset pt)
unsigned int uint
Definition: SYS_Types.h:45
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)
Definition: format.h:895
GA_Size getRawIndex(GA_Size row, GA_Size col) const
virtual bool loadPrivateH9(UT_IStream &)
GLenum src
Definition: glcorearb.h:1793