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