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  // Build a trim loop (which will be open unless the face is closed). The
227  // loop is build every time you call this method, so it's expensive. You
228  // must free the loop yourself when you are done with it. The trim pieces
229  // are generated in the [ustart,ustop] or [ustop,ustart] interval, where
230  // ustart and ustop are parametric values.
231  virtual GD_TrimLoop *trimLoop(float ustart, float ustop) const = 0;
232 
233  // Intersects us with the domain boundaries. The list is sorted in t:
234  int intersectDomain(UT_Array<GD_TrimHitInfo> &hitlist,
235  float tol = 1E-4F) const;
236 
237  virtual int breakCount() const = 0;
238  // Get approximately "numdivs" number of points. if the flag "usebreak"
239  // is set, then, use the "evaluateBreakSeg" to get breakpoints along with
240  // other points. Otherwise, just get numdiv+1 points.
241  int getPoints(int numdivs, UT_Vector3Array &domain,
242  int usebreak);
243 
244  // Determine rationality of face.
245  virtual void weights(unsigned short) {}
246 
247 protected:
248  /// All subclasses should call this method to register the face intrinsics.
249  /// @see GA_AttributeIntrinsic
252  { return GD_Primitive::registerIntrinsics(definition); }
253 
254  virtual bool savePrivateH9(std::ostream &os, bool binary) const = 0;
255  virtual bool loadPrivateH9(UT_IStream &is) = 0;
256  // Methods for finding out about point references
257  GA_DereferenceStatus dereferencePoint(GA_Offset point,
258  bool dry_run=false) override;
259  GA_DereferenceStatus dereferencePoints(
260  const GA_RangeMemberQuery &pt_q,
261  bool dry_run=false) override;
262 
263  // Check the validity of the data. Meant to be called especially at loading
264  // time. The method returns 1 if OK and 0 if trouble.
265  virtual bool validate() const;
266 
267  // Insert a vertex multiple times in the list. Return the index.
268  int multipleInsert(unsigned int where,
269  unsigned int count,
270  unsigned int appendPoints = 1);
271 
272 #if !GA_PRIMITIVE_VERTEXLIST
273  /// Defragmentation
274  virtual void swapVertexOffsets(const GA_Defragment &defrag);
275 
276  /// Report approximate memory usage for myVertexList (exclusive)
277  virtual int64 getBaseMemoryUsage() const;
278 
279  // This is called by the subclasses to count the
280  // memory used by myVertexList (exclusive)
281  virtual void countBaseMemory(UT_MemoryCounter &counter) const;
282 #endif
283 
284 private:
285 #if !GA_PRIMITIVE_VERTEXLIST
287 #endif
288 
289  friend std::ostream &operator<<(std::ostream &os, const GD_Face &d)
290  {
291  d.saveH9(os, 0,
294  return os;
295  }
296 };
297 
298 #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
SYS_FORCE_INLINE GA_Detail & getDetail() const
Definition: GA_Primitive.h:141
virtual void clearForDeletion()
Definition: GA_Primitive.h:682
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:289
virtual UT_Vector3 baryCenter() const
UT_Vector2T< float > UT_Vector2
const GLdouble * v
Definition: glcorearb.h:837
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
virtual int detachPoints(GA_PointGroup &grp)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
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:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
Abstract base class for a range membership query object.
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:235
SYS_FORCE_INLINE int64 getBaseMemoryUsage() const
Report approximate memory usage for myVertexList for subclasses.
Definition: GA_Primitive.h:840
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:678
GA_OffsetList myVertexList
Definition: GA_Primitive.h:881
double fpreal64
Definition: SYS_Types.h:201
GA_Size GA_Offset
Definition: GA_Types.h:641
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
GLdouble n
Definition: glcorearb.h:2008
GLintptr offset
Definition: glcorearb.h:665
int open(float queuesize) override
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
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:529
void reverse() override
virtual void weights(unsigned short)
Definition: GD_Face.h:245
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
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
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
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)
GLuint index
Definition: glcorearb.h:786
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
void validRange(fpreal64 &ua, fpreal64 &ub) const
Definition: GD_Face.h:196
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
Definition of a geometric primitive.
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:665
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
GLint lod
Definition: glcorearb.h:2765
GLint GLsizei count
Definition: glcorearb.h:405
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &definition)
Definition: GD_Face.h:251
Definition: format.h:895
SYS_FORCE_INLINE bool isClosed() const
Definition: GD_Face.h:161
GLenum src
Definition: glcorearb.h:1793
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:663