HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  {
46  }
48  const GT_AttributeListHandle &vattrib,
49  const GT_AttributeListHandle &uattrib,
50  const GT_AttributeListHandle &dattrib)
51  : GT_Primitive(src)
52  , myCurveOffsets(src.myCurveOffsets)
53  , myKnotOffsets(src.myKnotOffsets)
54  , myKnots(src.myKnots)
55  , myVertex(vattrib)
56  , myUniform(uattrib)
57  , myDetail(dattrib)
58  , myUMerge(NULL)
59  , myFaceSetMap(src.myFaceSetMap)
60  , myBasis(src.myBasis)
61  , myOrder(src.myOrder)
62  , myUniformOrder(src.myUniformOrder)
63  , myWrap(src.myWrap)
64  {
65  }
67  GT_Basis basis,
68  const GT_CountArray &counts,
69  const GT_AttributeListHandle &vattrib,
70  const GT_AttributeListHandle &uattrib,
71  const GT_AttributeListHandle &dattrib,
72  bool wrap,
73  const GT_FaceSetMapPtr &fsets)
74  : GT_Primitive(src)
75  , myCurveOffsets(counts)
76  , myVertex(vattrib)
77  , myUniform(uattrib)
78  , myDetail(dattrib)
79  , myUMerge(NULL)
80  , myFaceSetMap(fsets)
81  , myBasis(basis)
82  , myUniformOrder(basis == GT_BASIS_LINEAR ? 2 : 4)
83  , myWrap(wrap)
84  {
85  }
86  /// Useful constructor
88  const GT_DataArrayHandle &vtx_counts,
89  const GT_AttributeListHandle &vertex,
90  const GT_AttributeListHandle &uniform,
91  const GT_AttributeListHandle &detail,
92  bool wrap,
94  : myUMerge(NULL)
95  , myKnotOffsets()
96  , myKnots()
97  , myUniformOrder(basis == GT_BASIS_LINEAR ? 2 : 4)
98  {
99  init(basis, vtx_counts, vertex, uniform, detail, wrap, indexing);
100  }
101  /// Construct a curve mesh from a single GT_PrimCurve
102  GT_PrimCurveMesh(const GT_PrimCurve &curve);
103 
104  /// Destructor
105  virtual ~GT_PrimCurveMesh();
106 
107  virtual const char *className() const { return "GT_PrimCurveMesh"; }
108  virtual bool save(UT_JSONWriter &w) const;
109 
110  /// @{
111  /// Methods defined on GT_Primitive
112  virtual void enlargeBounds(UT_BoundingBox boxes[],
113  int nseg) const;
114  virtual void enlargeRenderBounds(UT_BoundingBox b[], int n) const;
115  virtual int getPrimitiveType() const;
116  virtual bool refine(GT_Refine &refiner,
117  const GT_RefineParms *parms) const;
118  virtual int getMotionSegments() const;
119  virtual int64 getMemoryUsage() const;
120  virtual const GT_ViewportRefineOptions &viewportRefineOptions() const;
121  /// @}
122 
123  /// Initialize the mesh
124  /// - @c vtx_counts @n
125  /// An integer array, representing the number of vertices in each curve.
126  /// The length of the array determines the number of curves in the mesh.
127  /// - @c vertex @n
128  /// Unique data per vertex. The length of these attribute arrays should
129  /// be the sum of the vertex_counts array.
130  /// - @c uniform @n
131  /// Attribute per curve. There should be one entry for each entry in the
132  /// @c vtx_counts array.
133  /// - @c indexing @n
134  /// What type of indexing is required
135  void init(GT_Basis basis,
136  const GT_DataArrayHandle &vtx_counts,
137  const GT_AttributeListHandle &vertex,
138  const GT_AttributeListHandle &uniform,
139  const GT_AttributeListHandle &detail,
140  bool wrap,
142 
143  /// Set knot vector. Some conditions must be met for this to work properly.
144  ///
145  /// - The basis must be GT_BASIS_BSPLINE
146  /// - The storage for the knots must be floating point
147  /// - The curve will have periodicity turned off. To create a periodic
148  /// curve, you must duplicate the first @c (order-1) vertices and adjust
149  /// the knot vector so the knot spacing for the last @c order knots
150  /// matches the spacing for the first @c order knots.
151  /// - The length of the knot vector must be @n
152  /// <tt>sum(getVertexCount(i)) + sum(getOrder(i))</tt> @n
153  /// That is, the length of the knot vector for each curve must be the
154  /// number of vertices in the curve plus its order.
155  ///
156  /// @note In Houdini curves, the first vertex is implicitly duplicated
157  /// for periodic NURBS curves. This is @b not the case for GT, where the
158  /// first vertex must be explicitly duplicated.
159  bool setKnots(const GT_DataArrayHandle &knots);
160 
161  /// @{
162  /// Set the basis & order for the curves
163  /// Basis Type Min Order Max Order
164  /// GT_BASIS_LINEAR 2 2
165  /// GT_BASIS_BEZIER 2 31
166  /// GT_BASIS_BSPLINE 2 arbitrary
167  /// GT_BASIS_CATMULLROM 4 4
168  /// GT_BASIS_HERMITE 4 4
169  /// GT_BASIS_POWER 2 arbitrary
170  /// @note Changing the order will clear the knot vector (if one exists)
171  bool setBasis(GT_Basis basis, int order=4);
172  bool setBasis(GT_Basis basis, const GT_DataArrayHandle &order);
173  /// @}
174 
175  /// @{
176  /// Set the curve order
177  bool setOrder(int order)
178  { return setBasis(getBasis(), order); }
179  bool setOrder(const GT_DataArrayHandle &order)
180  { return setBasis(getBasis(), order); }
181  /// @}
182 
183 
184  /// Return the number of faces in the mesh
185  GT_Size getCurveCount() const;
186  /// Return a pointer to the individual face
187  GT_PrimitiveHandle getCurve(GT_Offset i) const;
188 
189  /// Refine to linear curves
190  GT_PrimitiveHandle refineToLinear(const GT_RefineParms *parms=NULL,
191  fpreal lod_scale = -1) const;
192  /// @{
193  /// Accessors
195  { return myBasis; }
197  { return myCurveOffsets; }
199  { return myVertex; }
201  { return myUniform; }
203  { return myDetail; }
204  bool getWrap() const
205  { return myWrap; }
206  const GT_DataArrayHandle knots() const { return myKnots; }
208  {
209  return myKnots ? myKnotOffsets.getOffset(curve) : 0;
210  }
211  /// @}
212 
213  /// Return the order for a given curve
214  int getOrder(GT_Offset curve) const
215  {
216  return (myUniformOrder > 0) ? myUniformOrder
217  : myOrder->getI32(curve);
218  }
219  /// Check to see whether all curves have the same order
220  bool isUniformOrder() const { return myUniformOrder > 0; }
221 
222  /// Return the order for all curves. If the curves have varying orders,
223  /// the uniform order will be less than zero.
224  int uniformOrder() const { return myUniformOrder; }
225 
226  /// Return the varying orders (may be NULL)
227  const GT_DataArrayHandle &varyingOrders() const { return myOrder; }
228 
229  /// Harden all attributes so there are no dangling dependencies
230  virtual GT_PrimitiveHandle doHarden() const;
232  { return new GT_PrimCurveMesh(*this); }
233 
234  /// The virtual implementation of attribute merging
236  const UT_StringMMPattern *vertex,
237  const UT_StringMMPattern *point,
238  const UT_StringMMPattern *uniform,
239  const UT_StringMMPattern *detail) const;
240 
241  /// @{
242  /// Access to the face sets (curve sets)
243  const GT_FaceSetMapPtr &faceSetMap() const { return myFaceSetMap; }
245  { myFaceSetMap = v; }
246  void addFaceSet(const char *name,
247  const GT_FaceSetPtr &set);
248  /// @}
249 
250  /// @{
251  /// Access attributes
253  { return myVertex; }
255  { return myUniform; }
257  { return myDetail; }
258  /// @}
259 
260  /// Return the offset into the vertex list for the given face
262  { return myCurveOffsets.getOffset(face); }
263  /// Return the length of the vertex list for the given face
265  { return myCurveOffsets.getCount(face); }
266 
267  /// Return an array containing the face counts per-face
268  /// @warning This is expensive and will create a separate numeric array
269  const GT_DataArrayHandle
270  getCurveCounts(GT_IndexingMode mode=GT_INDEXING_QUICK) const;
271 
272  /// GEO/GU support to compute perimeter of curve
273  virtual fpreal computePerimeter(int seg) const;
274 
275 private:
276  void makeMerge();
277 
278  GT_CountArray myCurveOffsets;
279  GT_CountArray myKnotOffsets;
280  GT_DataArrayHandle myKnots;
282  GT_AttributeListHandle myVertex;
283  GT_AttributeListHandle myUniform;
284  GT_AttributeListHandle myDetail;
285  GT_FaceSetMapPtr myFaceSetMap;
286  GT_AttributeMerge *myUMerge;
288  int myUniformOrder;
289  bool myWrap;
290 };
291 
292 #endif
virtual int getMotionSegments() const =0
Keep track of merging of attribute maps.
const GT_FaceSetMapPtr & faceSetMap() const
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
virtual const GT_ViewportRefineOptions & viewportRefineOptions() const
virtual const char * className() const
virtual int getPrimitiveType() const
virtual fpreal computePerimeter(int seg=0) const
int myOrder
Definition: GT_CurveEval.h:263
const GLdouble * v
Definition: glcorearb.h:836
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)
virtual const GT_AttributeListHandle & getDetailAttributes() const
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:88
#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.
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
png_uint_32 i
Definition: png.h:2877
A mesh of curves.
bool getWrap() const
virtual const GT_AttributeListHandle & getVertexAttributes() const
void setFaceSetMap(const GT_FaceSetMapPtr &v)
bool isUniformOrder() const
Check to see whether all curves have the same order.
long long int64
Definition: SYS_Types.h:106
GLdouble n
Definition: glcorearb.h:2007
bool setOrder(const GT_DataArrayHandle &order)
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:38
virtual GT_PrimitiveHandle doSoftCopy() const
virtual void enlargeRenderBounds(UT_BoundingBox boxes[], int nsegments) const
const GT_AttributeListHandle & getDetail() const
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)
Useful constructor.
virtual const GT_AttributeListHandle & getUniformAttributes() const
GLuint const GLchar * name
Definition: glcorearb.h:785
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.
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
The base class for all GT primitive types.
Definition: GT_Primitive.h:41
const GT_DataArrayHandle knots() const
virtual GT_PrimitiveHandle doHarden() const
GT_Basis getBasis() const
virtual int64 getMemoryUsage() const =0
GLenum mode
Definition: glcorearb.h:98
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
double fpreal
Definition: SYS_Types.h:269
GT_Basis myBasis
Definition: GT_CurveEval.h:262
const GT_CountArray & getCurveCountArray() const
int getOrder(GT_Offset curve) const
Return the order for a given curve.
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)
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GT_Basis
Definition: GT_Types.h:49
int64 GT_Offset
Definition: GT_Types.h:110
int64 GT_Size
Definition: GT_Types.h:109
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 src
Definition: glcorearb.h:1792