HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_PrimCurveMesh.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: GT_PrimCurveMesh.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_PrimCurveMesh__
12 #define __GT_PrimCurveMesh__
13 
14 #include "GT_API.h"
15 #include "GT_Primitive.h"
16 #include "GT_CountArray.h"
17 #include "GT_FaceSetMap.h"
18 
19 class GT_DataArray;
20 class GT_AttributeList;
21 class GT_AttributeMerge;
22 class GT_PrimCurve;
23 
24 /// @brief A mesh of curves
26 {
27 public:
28  /// Default constructor
30  /// Copy c-tor
32  : GT_Primitive(src)
33  , myCurveOffsets(src.myCurveOffsets)
34  , myKnotOffsets(src.myKnotOffsets)
35  , myKnots(src.myKnots)
36  , myVertex(src.myVertex)
37  , myUniform(src.myUniform)
38  , myDetail(src.myDetail)
39  , myUMerge(NULL)
40  , myFaceSetMap(src.myFaceSetMap)
41  , myBasis(src.myBasis)
42  , myOrder(src.myOrder)
43  , myUniformOrder(src.myUniformOrder)
44  , myWrap(src.myWrap)
45  , myClosed(src.myClosed)
46  , myUseBreakpoints(src.myUseBreakpoints)
47  , myBreakpointParameterization(src.myBreakpointParameterization)
48  {
49  }
51  const GT_AttributeListHandle &vattrib,
52  const GT_AttributeListHandle &uattrib,
53  const GT_AttributeListHandle &dattrib)
54  : GT_Primitive(src)
55  , myCurveOffsets(src.myCurveOffsets)
56  , myKnotOffsets(src.myKnotOffsets)
57  , myKnots(src.myKnots)
58  , myVertex(vattrib)
59  , myUniform(uattrib)
60  , myDetail(dattrib)
61  , myUMerge(NULL)
62  , myFaceSetMap(src.myFaceSetMap)
63  , myBasis(src.myBasis)
64  , myOrder(src.myOrder)
65  , myUniformOrder(src.myUniformOrder)
66  , myWrap(src.myWrap)
67  , myClosed(src.myClosed)
68  , myUseBreakpoints(src.myUseBreakpoints)
69  , myBreakpointParameterization(src.myBreakpointParameterization)
70  {
71  }
73  GT_Basis basis,
74  const GT_CountArray &counts,
75  const GT_AttributeListHandle &vattrib,
76  const GT_AttributeListHandle &uattrib,
77  const GT_AttributeListHandle &dattrib,
78  bool wrap,
79  const GT_FaceSetMapPtr &fsets,
80  bool closed = false,
81  bool use_breakpoints = false,
82  GT_Parameterization breakpoint_parameterization = GT_PARAMETERIZATION_CHORD)
83  : GT_Primitive(src)
84  , myCurveOffsets(counts)
85  , myVertex(vattrib)
86  , myUniform(uattrib)
87  , myDetail(dattrib)
88  , myUMerge(NULL)
89  , myFaceSetMap(fsets)
90  , myBasis(basis)
91  , myUniformOrder(basis == GT_BASIS_LINEAR ? 2 : 4)
92  , myWrap(wrap)
93  , myClosed(closed)
94  , myUseBreakpoints(use_breakpoints)
95  , myBreakpointParameterization(breakpoint_parameterization)
96  {
97  }
98  /// Useful constructor
100  const GT_DataArrayHandle &vtx_counts,
101  const GT_AttributeListHandle &vertex,
102  const GT_AttributeListHandle &uniform,
103  const GT_AttributeListHandle &detail,
104  bool wrap,
106  bool closed = false,
107  bool use_breakpoints = false,
108  GT_Parameterization breakpoint_parameterization = GT_PARAMETERIZATION_CHORD)
109  : myUMerge(NULL)
110  , myKnotOffsets()
111  , myKnots()
112  , myUniformOrder(basis == GT_BASIS_LINEAR ? 2 : 4)
113  , myClosed(closed)
114  , myUseBreakpoints(use_breakpoints)
115  , myBreakpointParameterization(breakpoint_parameterization)
116  {
117  init(basis, vtx_counts, vertex, uniform, detail, wrap, indexing, closed, use_breakpoints, breakpoint_parameterization);
118  }
119  /// Construct a curve mesh from a single GT_PrimCurve
120  GT_PrimCurveMesh(const GT_PrimCurve &curve);
121 
122  /// Destructor
123  ~GT_PrimCurveMesh() override;
124 
125  const char *className() const override { return "GT_PrimCurveMesh"; }
126  bool save(UT_JSONWriter &w) const override;
127 
128  /// @{
129  /// Methods defined on GT_Primitive
130  void enlargeBounds(UT_BoundingBox boxes[], int nseg) const override;
131  void enlargeRenderBounds(UT_BoundingBox b[], int n) const override;
132  int getPrimitiveType() const override;
133  bool refine(GT_Refine &refiner,
134  const GT_RefineParms *parms) const override;
135  int getMotionSegments() const override;
136  int64 getMemoryUsage() const override;
137  const GT_ViewportRefineOptions &viewportRefineOptions() const override;
138  /// @}
139 
140  /// Initialize the mesh
141  /// - @c vtx_counts @n
142  /// An integer array, representing the number of vertices in each curve.
143  /// The length of the array determines the number of curves in the mesh.
144  /// - @c vertex @n
145  /// Unique data per vertex. The length of these attribute arrays should
146  /// be the sum of the vertex_counts array.
147  /// - @c uniform @n
148  /// Attribute per curve. There should be one entry for each entry in the
149  /// @c vtx_counts array.
150  /// - @c indexing @n
151  /// What type of indexing is required
152  void init(GT_Basis basis,
153  const GT_DataArrayHandle &vtx_counts,
154  const GT_AttributeListHandle &vertex,
155  const GT_AttributeListHandle &uniform,
156  const GT_AttributeListHandle &detail,
157  bool wrap,
159  bool closed = false,
160  bool use_breakpoint_size = false,
161  GT_Parameterization breakpoint_parameterization = GT_PARAMETERIZATION_CHORD
162  );
163 
164  /// Set knot vector. Some conditions must be met for this to work properly.
165  ///
166  /// - The basis must be GT_BASIS_BSPLINE
167  /// - The storage for the knots must be floating point
168  /// - The curve will have periodicity turned off. To create a periodic
169  /// curve, you must duplicate the first @c (order-1) vertices and adjust
170  /// the knot vector so the knot spacing for the last @c order knots
171  /// matches the spacing for the first @c order knots.
172  /// - The length of the knot vector must be @n
173  /// <tt>sum(getVertexCount(i)) + sum(getOrder(i))</tt> @n
174  /// That is, the length of the knot vector for each curve must be the
175  /// number of vertices in the curve plus its order.
176  ///
177  /// @note In Houdini curves, the first vertex is implicitly duplicated
178  /// for periodic NURBS curves. This is @b not the case for GT, where the
179  /// first vertex must be explicitly duplicated.
180  bool setKnots(const GT_DataArrayHandle &knots);
181 
182  /// @{
183  /// Set the basis & order for the curves
184  /// Basis Type Min Order Max Order
185  /// GT_BASIS_LINEAR 2 2
186  /// GT_BASIS_BEZIER 2 31
187  /// GT_BASIS_BSPLINE 2 arbitrary
188  /// GT_BASIS_CATMULLROM 4 4
189  /// GT_BASIS_HERMITE 4 4
190  /// GT_BASIS_POWER 2 arbitrary
191  /// @note Changing the order will clear the knot vector (if one exists)
192  bool setBasis(GT_Basis basis, int order=4);
193  bool setBasis(GT_Basis basis, const GT_DataArrayHandle &order);
194  /// @}
195 
196  /// @{
197  /// Set the curve order
198  bool setOrder(int order)
199  { return setBasis(getBasis(), order); }
201  { return setBasis(getBasis(), order); }
202  /// @}
203 
204 
205  /// Return the number of faces in the mesh
206  GT_Size getCurveCount() const;
207  /// Return a pointer to the individual face
208  GT_PrimitiveHandle getCurve(GT_Offset i) const;
209 
210  /// Refine to linear curves
211  GT_PrimitiveHandle refineToLinear(const GT_RefineParms *parms=NULL,
212  fpreal lod_scale = -1) const;
213 
214  /// Remove degenerate curves from the meseh
215  GT_PrimitiveHandle removeDegenerate() const;
216 
217  /// In some systems (Alembic, Usd), curve data can have a "varying" storage
218  /// specification. This stores data per curve span rather than per vertex.
219  /// This method will convert any varying or uniform storage arrays to
220  /// per-vertex data.
221  GT_PrimitiveHandle expandUniformVarying() const;
222 
223  /// Pin curves. This is only valid when the basis is one of:
224  /// - GT_BASIS_BSPLINE
225  /// - GT_BASIS_CATMULLROM
226  /// If the basis is invalid an empty primitive handle is returned.
227  ///
228  /// Pinning curves will add an extra vertex at the beginning and end of
229  /// each curve, such that: @code
230  /// P[-1] = 2*P[0] - P[1]
231  /// P[n] = 2*P[n-1] - P[n-2]
232  /// @endcode
233  GT_PrimitiveHandle pinCurves() const;
234 
235  /// Unpin curves. This method will fail if the curve mesh has an invalid
236  /// basis or if any curves don't have enough vertices.
237  GT_PrimitiveHandle unpinCurves() const;
238 
239  /// @{
240  /// Accessors
242  { return myBasis; }
244  { return myCurveOffsets; }
246  { return myVertex; }
248  { return myUniform; }
250  { return myDetail; }
251  bool getWrap() const
252  { return myWrap; }
253  bool getClosed() const
254  { return myClosed; }
255  bool getUseBreakpoints() const
256  { return myUseBreakpoints; }
258  { return myBreakpointParameterization; }
259 
260  const GT_DataArrayHandle knots() const { return myKnots; }
262  {
263  return myKnots ? myKnotOffsets.getOffset(curve) : 0;
264  }
265  /// @}
266 
267  /// Return the order for a given curve
268  int getOrder(GT_Offset curve) const
269  {
270  return (myUniformOrder > 0) ? myUniformOrder
271  : myOrder->getI32(curve);
272  }
273  /// Check to see whether all curves have the same order
274  bool isUniformOrder() const { return myUniformOrder > 0; }
275 
276  /// Return the order for all curves. If the curves have varying orders,
277  /// the uniform order will be less than zero.
278  int uniformOrder() const { return myUniformOrder; }
279 
280  /// Return the varying orders (may be NULL)
281  const GT_DataArrayHandle &varyingOrders() const { return myOrder; }
282 
283  /// Harden all attributes so there are no dangling dependencies
284  GT_PrimitiveHandle doHarden() const override;
286  { return new GT_PrimCurveMesh(*this); }
287 
288  /// The virtual implementation of attribute merging
290  const UT_StringMMPattern *vertex,
291  const UT_StringMMPattern *point,
292  const UT_StringMMPattern *uniform,
293  const UT_StringMMPattern *detail
294  ) const override;
295 
296  /// @{
297  /// Access to the face sets (curve sets)
298  const GT_FaceSetMapPtr &faceSetMap() const { return myFaceSetMap; }
300  { myFaceSetMap = v; }
301  void addFaceSet(const char *name,
302  const GT_FaceSetPtr &set);
303  /// @}
304 
305  /// @{
306  /// Access attributes
308  { return myVertex; }
310  { return myUniform; }
312  { return myDetail; }
313  /// @}
314 
315  /// Return the offset into the vertex list for the given face
317  { return myCurveOffsets.getOffset(face); }
318  /// Return the length of the vertex list for the given face
320  { return myCurveOffsets.getCount(face); }
321 
322  /// Return an array containing the face counts per-face
323  /// @warning This is expensive and will create a separate numeric array
324  const GT_DataArrayHandle
325  getCurveCounts(GT_IndexingMode mode=GT_INDEXING_QUICK) const;
326 
327  /// GEO/GU support to compute perimeter of curve
328  fpreal computePerimeter(int seg) const override;
329 
330 private:
331  void makeMerge();
332 
333  GT_CountArray myCurveOffsets;
334  GT_CountArray myKnotOffsets;
335  GT_DataArrayHandle myKnots;
337  GT_AttributeListHandle myVertex;
338  GT_AttributeListHandle myUniform;
339  GT_AttributeListHandle myDetail;
340  GT_FaceSetMapPtr myFaceSetMap;
341  GT_AttributeMerge *myUMerge;
343  int myUniformOrder;
344  /// Wrap is like closed, but really just appends the first point to the start
345  bool myWrap;
346  /// Closed will close the curve by making it into a polygon
347  bool myClosed;
348  // Number of P attributes at which to use "breakpoints" method
349  // This is required because the attribute lists must be equal to P's size for gtutil_GEORefine::makeCurveMesh(),
350  // but GU_Detail::interpCurveBreakpoint() may modify the point count.
351  // Could use some refactoring in the future because it implies you know the size of P after
352  // computing breakpoints, which can only be done if you compute the gdp twice.
353  bool myUseBreakpoints;
354 
355  GT_Parameterization myBreakpointParameterization;
356 };
357 
358 #endif
virtual int getMotionSegments() const =0
bool getUseBreakpoints() const
Keep track of merging of attribute maps.
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
const GT_FaceSetMapPtr & faceSetMap() const
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
GLuint GLdouble GLdouble GLint GLint order
Definition: glew.h:3460
virtual const GT_ViewportRefineOptions & viewportRefineOptions() const
virtual int getPrimitiveType() const
virtual fpreal computePerimeter(int seg=0) const
int myOrder
Definition: GT_CurveEval.h:263
const char * className() const override
GT_PrimCurveMesh(const GT_PrimCurveMesh &src, const GT_AttributeListHandle &vattrib, const GT_AttributeListHandle &uattrib, const GT_AttributeListHandle &dattrib)
int uniformOrder() const
GT_IndexingMode
Definition: GT_Types.h:102
#define GT_API
Definition: GT_API.h:11
GT_Size getVertexCount(GT_Offset face) const
Return the length of the vertex list for the given face.
const GT_AttributeListHandle & getUniformAttributes() const override
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
GLuint const GLchar * name
Definition: glcorearb.h:786
GLenum src
Definition: glcorearb.h:1793
A mesh of curves.
bool getWrap() const
void setFaceSetMap(const GT_FaceSetMapPtr &v)
bool isUniformOrder() const
Check to see whether all curves have the same order.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GT_PrimCurveMesh(const GT_PrimCurveMesh &src, GT_Basis basis, const GT_CountArray &counts, const GT_AttributeListHandle &vattrib, const GT_AttributeListHandle &uattrib, const GT_AttributeListHandle &dattrib, bool wrap, const GT_FaceSetMapPtr &fsets, bool closed=false, bool use_breakpoints=false, GT_Parameterization breakpoint_parameterization=GT_PARAMETERIZATION_CHORD)
bool setOrder(const GT_DataArrayHandle &order)
bool getClosed() const
GT_PrimitiveHandle doSoftCopy() const override
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
const GLdouble * v
Definition: glcorearb.h:837
virtual void enlargeRenderBounds(UT_BoundingBox boxes[], int nsegments) const
const GT_AttributeListHandle & getDetail() const
int64 GT_Offset
Definition: GT_Types.h:124
long long int64
Definition: SYS_Types.h:116
GT_Parameterization
Definition: GT_Types.h:69
GT_Offset getVertexOffset(GT_Offset face) const
Return the offset into the vertex list for the given face.
GT_PrimCurveMesh(const GT_PrimCurveMesh &src)
Copy c-tor.
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
const GT_DataArrayHandle knots() const
virtual GT_PrimitiveHandle doHarden() const
GT_Basis getBasis() const
virtual int64 getMemoryUsage() const =0
GLenum mode
Definition: glcorearb.h:99
GLdouble n
Definition: glcorearb.h:2008
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
int64 GT_Size
Definition: GT_Types.h:123
const GT_AttributeListHandle & getVertexAttributes() const override
GT_Parameterization getBreakpointsParameterization() const
GT_Basis myBasis
Definition: GT_CurveEval.h:262
const GT_CountArray & getCurveCountArray() const
const GT_AttributeListHandle & getDetailAttributes() const override
int getOrder(GT_Offset curve) const
Return the order for a given curve.
fpreal64 fpreal
Definition: SYS_Types.h:277
const GT_AttributeListHandle & getUniform() const
virtual bool save(UT_JSONWriter &w) const
GT_Offset knotOffset(GT_Offset curve) const
const GT_DataArrayHandle & varyingOrders() const
Return the varying orders (may be NULL)
GT_Basis
Definition: GT_Types.h:53
A single linear or cubic patch.
Definition: GT_PrimCurve.h:18
virtual GT_PrimitiveHandle doAttributeMerge(const GT_Primitive &src, const UT_StringMMPattern *vertex, const UT_StringMMPattern *point, const UT_StringMMPattern *uniform, const UT_StringMMPattern *detail) const
The virtual implementation of attribute merging.
virtual void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const =0
bool setOrder(int order)
const GT_AttributeListHandle & getVertex() const
GLenum GLuint GLint GLenum face
Definition: glew.h:4630
GT_PrimCurveMesh(GT_Basis basis, const GT_DataArrayHandle &vtx_counts, const GT_AttributeListHandle &vertex, const GT_AttributeListHandle &uniform, const GT_AttributeListHandle &detail, bool wrap, GT_IndexingMode indexing=GT_INDEXING_QUICK, bool closed=false, bool use_breakpoints=false, GT_Parameterization breakpoint_parameterization=GT_PARAMETERIZATION_CHORD)
Useful constructor.