HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GD_Face.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  *
10  */
11 
12 #ifndef __GD_Face_H__
13 #define __GD_Face_H__
14 
15 #include "GD_API.h"
16 #include <UT/UT_Vector2.h>
17 #include <UT/UT_Array.h>
18 #include "GD_Primitive.h"
19 #include <iosfwd>
20 
21 class GD_Detail;
22 class GD_TrimLoop;
23 class GD_TrimHitInfo;
24 class GA_AttributeRefMap;
25 class GA_Basis;
26 class GA_LoadMap;
27 class GA_SaveMap;
28 class UT_JSONParser;
29 class UT_JSONWriter;
30 class UT_MemoryCounter;
31 
32 class GD_API GD_Face : public GD_Primitive
33 {
34 public:
36  : GD_Primitive(d, offset)
37  {}
38 #if !GA_PRIMITIVE_VERTEXLIST
39  virtual ~GD_Face();
40 #endif
41 
42  virtual int getBBox(UT_BoundingBox *bbox) const;
43  virtual void addToBSphere(UT_BoundingSphere *bsphere) const;
44  virtual void getBRect(UT_BoundingRect *brect) const;
45  virtual UT_Vector3 computeNormal() const;
46  virtual UT_Vector3 baryCenter() const;
47 
48  /// @{
49  /// Return the basis for the face (or @c NULL if there is no basis)
50  virtual GA_Basis *getFaceBasis();
51  virtual const GA_Basis *getFaceBasis() const;
52  /// @}
53 
54  /// @{
55  /// Load/Save basis from a JSON value. By default, these methods fail
56  virtual bool jsonLoadBasis(UT_JSONParser &p);
57  virtual bool jsonSaveBasis(UT_JSONWriter &w) const;
58  virtual bool jsonLoadBasis(UT_JSONParser &p,
59  const UT_JSONValue &v);
60  virtual bool jsonSaveBasis(UT_JSONValue &v) const;
61  /// @}
62 
63  virtual bool saveH9(std::ostream &os, bool binary,
64  const UT_Array<GA_AttribSaveDataH9> &prim_attribs,
65  const UT_Array<GA_AttribSaveDataH9> &vtx_attribs)
66  const;
67  virtual bool loadH9(UT_IStream &is,
68  const UT_Array<GA_AttribLoadDataH9> &prim_attribs,
69  const UT_Array<GA_AttribLoadDataH9> &vtx_attribs);
70 
71  /// @{
72  /// Save/Load the vertex lists to/from a JSON stream
73  bool saveVertexArray(UT_JSONWriter &p, const GA_SaveMap &map) const;
74  bool loadVertexArray(UT_JSONParser &p, const GA_LoadMap &map);
75  /// @}
76 
77 #if !GA_PRIMITIVE_VERTEXLIST
78  virtual void clearForDeletion();
79 #endif
80 
81  virtual GD_Primitive *copy(int preserve_shared_pts = 0) const;
82  virtual int copy(const GD_Primitive &src, int ptindexdiff);
83 
84 #if !GA_PRIMITIVE_VERTEXLIST
85  virtual void copyUnwiredForMerge(const GA_Primitive *src,
86  const GA_MergeMap &map);
87 #endif
88 
89  // Evaluate one point (when du=0), or the du-th derivative.
90  // Return 0 if successful, and -1 otherwise.
91  virtual int evaluate(float u, UT_Vector3 &pos,
92  unsigned du=0, int uOffset=-1) const = 0;
93  /// Evaluate the face at the given @c u position, storing the result in the
94  /// vertex given by @c vtx.
95  /// @param vtx - Vertex to store evaluated result
96  /// @param h - Handle of attributes to evaluate
97  /// @param u - Parametric evaluation position
98  /// @param du - Derivative
99  /// @param uoffset - Basis offset
100  virtual bool evaluate(GA_Offset vtx, GA_AttributeRefMap &h,
101  fpreal u, uint du=0, int uoffset=-1) const=0;
102 
103 #if !GA_PRIMITIVE_VERTEXLIST
104  virtual void addPointRefToGroup(GA_PointGroup &grp) const;
105 #endif
106 
107  virtual bool isDegenerate() const;
108 
109  virtual unsigned getOrder(void) const = 0;
110 
111  // Adjust the size of the vertex array.
112 #if GA_PRIMITIVE_VERTEXLIST
114  void setSize(GA_Size nvertices)
115  { setNumVertices(nvertices); }
116 #else
117  void setSize(GA_Size sz);
118 #endif
119 
120  // Take the whole set of points into consideration when applying the
121  // point removal operation to this primitive. The method returns 0 if
122  // successful, -1 if it failed because it would have become degenerate,
123  // and -2 if it failed because it would have had to remove the primitive
124  // altogether.
125  virtual int detachPoints (GA_PointGroup &grp);
126 
127 // Remove all repeated vertices - (only gets consecutive vertices)
128  virtual int removeRepeatedVertices(int check_order = 0);
129 
130  // Insert or delete vertices. The insertion methods return the index if
131  // successful and -1 otherwise. The deletion methods return 0 if ok and
132  // -1 otherwise.
133  virtual GA_Size insertVertex(GA_Offset ptoff=GA_INVALID_OFFSET, GA_Size where=0);
134  virtual GA_Size appendVertex(GA_Offset ptoff=GA_INVALID_OFFSET);
135  virtual int deleteVertex(GA_Size i);
136 
137 #if !GA_PRIMITIVE_VERTEXLIST
138  // Query the number of vertices in the array. This number may be smaller
139  // than the actual size of the array.
140  virtual GA_Size getVertexCount() const;
141 
142  virtual GA_Offset getVertexOffset(GA_Size index) const;
143 #endif
144 
146  {
147  UT_Vector3 pos = getPos3(index);
148  return UT_Vector2(pos.x(), pos.y());
149  }
150 
151  // Both methods find the index of the given vertex (vtx or the vertex
152  // that contains ppt). Return -1 if not found.
153  GA_Size findPoint(GA_Offset ptoff) const;
154 
156  {
157  if (i >= 0 && i < myVertexList.entries())
158  wireVertex(myVertexList(i), ptoff);
159  }
160  /// @warning vertexPoint() doesn't check the bounds. Use with caution.
161  GA_Offset vertexPoint(unsigned int i) const
162  { return getDetail().vertexPoint(myVertexList(i)); }
163 
165  bool isClosed() const { return myVertexList.getExtraFlag(); }
166  virtual void close(int rounded = 1, int preserveShape = 0);
167  virtual void open(int preserveShape = 0, int safe = 0);
168 
169  int isClockwise(void) const;
170 
171  // Find out if we're visible at all (ie. in the valid interval of the
172  // parent surface). Partial visibility returns 1. Full visibility
173  // returns 2. 0 is returned if the face is completely invisible.
174  virtual int isVisible() const;
175 
176  // Return the barycenter of the part that visible (inside the surf domain).
177  // 1 if found, 0 otherwise.
178  virtual int visibleBaryCenter(float &uctr, float &vctr) const;
179 
180  // Append n points equally spaced between the 1st and last vertex.
181  void sampleEnds(int n);
182 
183 #if !GA_PRIMITIVE_VERTEXLIST
184  // Methods to handle vertex properties:
185  virtual bool vertexApply(bool (*apply)(GA_Offset vtx, void *),
186  void *data = 0) const;
187 #endif
188 
189  // Shift the array of vertices by an offset and wrap around. The offset
190  // can be either negative or positive.
191  virtual int cycle(int amount, int = 1);
192 
193  // Reverses the vertices of a given face. It's virtual because some faces,
194  // such as rational splines, need to be aware of it.
195  virtual void reverse();
196 
197  // Return the bounds of the valid evaluation interval in domain space:
198  virtual void validInterval(int &a, int &b ) const;
199  void validRange (fpreal64 &ua, fpreal64 &ub) const
200  {
201  validRangeImpl(ua, ub);
202  }
203  void validRange (fpreal32 &ua, fpreal32 &ub) const
204  {
205  fpreal64 ua64, ub64;
206  validRangeImpl(ua64, ub64);
207  ua = ua64; ub = ub64;
208  }
209 private:
210  virtual void validRangeImpl(fpreal64 &ua, fpreal64 &ub) const;
211 public:
212 
213  // Find the first visible range, i.e. one that is at most as big as the
214  // valid interval and is visible on the surface. Partial visibility returns
215  // 1. Full visibility returns 2. 0 is returned if completely invisible.
216  int visibleRange(fpreal64 &ua, fpreal64 &ub,
217  fpreal64 tol=1E-4) const;
218  int visibleRange(fpreal32 &ua, fpreal32 &ub,
219  fpreal32 tol=1E-4F) const;
220 
221  /// Evaluate the face between breakpoints by taking a start/stop index in
222  /// the valid domain and a level of detail representing number of points to
223  /// be interpolated between every two breakpoints. The method @b always
224  /// interpolates the encountered breakpoints (aka "edit points").
225  /// This returns true if successful, else false.
226  virtual bool evaluateBreakSegm(int ustartidx, int ustopidx,
227  int lod, UT_Vector3Array &pos, unsigned du=0) const;
228 
229  /// Evaluate the face between breakpoints by taking a start/stop index in
230  /// the valid domand and a level of detail representing the number of
231  /// points to be interpolated between breakpoints. The method @b always
232  /// interpolates the encountered breakpoints (aka "edit points"). The
233  /// method returns the number of vertices in thelist (or -1 if
234  /// unsuccessful).
235  ///
236  /// This code assumes that the destination and source geometry is the same.
237  virtual int evaluateBreakSegment(int ustart, int uend,
238  int lod, GA_Offset *vertices,
239  GA_AttributeRefMap &h, uint du=0) const;
240 
241  // Build a trim loop (which will be open unless the face is closed). The
242  // loop is build every time you call this method, so it's expensive. You
243  // must free the loop yourself when you are done with it. The trim pieces
244  // are generated in the [ustart,ustop] or [ustop,ustart] interval, where
245  // ustart and ustop are parametric values.
246  virtual GD_TrimLoop *trimLoop(float ustart, float ustop) const = 0;
247 
248  // Intersects us with the domain boundaries. The list is sorted in t:
249  int intersectDomain(UT_Array<GD_TrimHitInfo> &hitlist,
250  float tol = 1E-4F) const;
251 
252  virtual int breakCount() const = 0;
253  // Get approximately "numdivs" number of points. if the flag "usebreak"
254  // is set, then, use the "evaluateBreakSeg" to get breakpoints along with
255  // other points. Otherwise, just get numdiv+1 points.
256  int getPoints(int numdivs, UT_Vector3Array &domain,
257  int usebreak);
258 
259  // Determine rationality of face.
260  virtual void weights(unsigned short) {}
261 
262 protected:
263  /// All subclasses should call this method to register the face intrinsics.
264  /// @see GA_AttributeIntrinsic
267  { return GD_Primitive::registerIntrinsics(definition); }
268 
269  virtual bool savePrivateH9(std::ostream &os, bool binary) const = 0;
270  virtual bool loadPrivateH9(UT_IStream &is) = 0;
271  // Methods for finding out about point references
272  virtual GA_DereferenceStatus dereferencePoint(GA_Offset point,
273  bool dry_run=false);
274  virtual GA_DereferenceStatus dereferencePoints(
275  const GA_RangeMemberQuery &pt_q,
276  bool dry_run=false);
277 
278  // Check the validity of the data. Meant to be called especially at loading
279  // time. The method returns 1 if OK and 0 if trouble.
280  virtual bool validate(void) const;
281 
282  // Insert a vertex multiple times in the list. Return the index.
283  int multipleInsert(unsigned int where,
284  unsigned int count,
285  unsigned int appendPoints = 1);
286 
287 #if !GA_PRIMITIVE_VERTEXLIST
288  /// Defragmentation
289  virtual void swapVertexOffsets(const GA_Defragment &defrag);
290 
291  /// Report approximate memory usage for myVertexList (exclusive)
292  virtual int64 getBaseMemoryUsage() const;
293 
294  // This is called by the subclasses to count the
295  // memory used by myVertexList (exclusive)
296  virtual void countBaseMemory(UT_MemoryCounter &counter) const;
297 #endif
298 
299 private:
300 #if !GA_PRIMITIVE_VERTEXLIST
302 #endif
303 
304  friend std::ostream &operator<<(std::ostream &os, const GD_Face &d)
305  {
306  d.saveH9(os, 0,
309  return os;
310  }
311 };
312 
313 #endif
virtual void copyUnwiredForMerge(const GA_Primitive *src, const GA_MergeMap &map)
virtual int getBBox(UT_BoundingBox *bbox) const
SYS_FORCE_INLINE GA_Detail & getDetail() const
Definition: GA_Primitive.h:132
virtual void clearForDeletion()
Definition: GA_Primitive.h:598
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &definition)
Definition: GD_Primitive.h:74
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
friend std::ostream & operator<<(std::ostream &os, const GD_Face &d)
Definition: GD_Face.h:304
virtual UT_Vector3 baryCenter() const
UT_Vector2T< float > UT_Vector2
const GLdouble * v
Definition: glcorearb.h:836
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
virtual int detachPoints(GA_PointGroup &grp)
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
virtual void addToBSphere(UT_BoundingSphere *bsphere) const
virtual void addPointRefToGroup(GA_PointGroup &grp) 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
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
Abstract base class for a range membership query object.
virtual GA_Size getVertexCount() const
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:581
3D Vector class.
GD_Face(GD_Detail *d, GA_Offset offset=GA_INVALID_OFFSET)
Definition: GD_Face.h:35
virtual GD_Primitive * copy(int preserve_shared_pts=0) const
png_uint_32 i
Definition: png.h:2877
void setVertexPoint(GA_Size i, GA_Offset ptoff)
Definition: GD_Face.h:155
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
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)
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
GA_OffsetList myVertexList
Definition: GA_Primitive.h:794
GA_Size GA_Offset
Definition: GA_Types.h:617
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
Definition: GD_Primitive.h:67
long long int64
Definition: SYS_Types.h:106
virtual void getBRect(UT_BoundingRect *brect) const
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Size i) const
Definition: GA_Primitive.h:269
GLdouble n
Definition: glcorearb.h:2007
double fpreal64
Definition: SYS_Types.h:191
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
virtual bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const
GLintptr offset
Definition: glcorearb.h:664
Bezier or NURBS basis classes which maintain knot vectors.
Definition: GA_Basis.h:49
A handle to simplify manipulation of multiple attributes.
virtual UT_Vector3 computeNormal() const
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:469
GLboolean * data
Definition: glcorearb.h:130
virtual void weights(unsigned short)
Definition: GD_Face.h:260
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
virtual int open(float queuesize)
UT_Vector2 getPos2(GA_Size index) const
Definition: GD_Face.h:145
virtual int isVisible() 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
virtual void reverse()
GLint GLsizei count
Definition: glcorearb.h:404
GA_Offset vertexPoint(unsigned int i) const
Definition: GD_Face.h:161
virtual int visibleBaryCenter(float &uctr, float &vctr) const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:583
double fpreal
Definition: SYS_Types.h:269
void validRange(fpreal32 &ua, fpreal32 &ub) const
Definition: GD_Face.h:203
#define GD_API
Definition: GD_API.h:10
void setNumVertices(GA_Size nvertices)
virtual void close()
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
void validRange(fpreal64 &ua, fpreal64 &ub) const
Definition: GD_Face.h:199
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
Definition of a geometric primitive.
virtual bool vertexApply(bool(*apply)(GA_Offset vtx, void *), void *data=0) const =0
virtual bool isDegenerate() const
Is the primitive degenerate.
void countBaseMemory(UT_MemoryCounter &counter) const
float fpreal32
Definition: SYS_Types.h:190
GLint lod
Definition: glcorearb.h:2764
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &definition)
Definition: GD_Face.h:266
SYS_FORCE_INLINE bool isClosed() const
Definition: GD_Face.h:165
GLenum src
Definition: glcorearb.h:1792