HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_PrimPolygonMesh.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_PrimPolygonMesh.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_PrimPolygonMesh__
12 #define __GT_PrimPolygonMesh__
13 
14 #include "GT_API.h"
15 #include "GT_Primitive.h"
16 #include "GT_CountArray.h"
17 #include "GT_FaceSetMap.h"
18 #include <GA/GA_Names.h>
19 
20 class GT_DataArray;
21 class GT_PrimPolygon;
22 class GT_AttributeList;
23 class GT_AttributeMerge;
24 class UT_StringRef;
25 
26 /// @brief A mesh of polygons
28 {
29 public:
30  /// Default constructor
32  : myVMerge(NULL)
33  , myUMerge(NULL)
34  , myConvexFlag(false)
35  {
36  }
37  /// Useful constructor
39  const GT_DataArrayHandle &vtx_indices,
40  const GT_AttributeListHandle &shared,
41  const GT_AttributeListHandle &vertex,
42  const GT_AttributeListHandle &uniform,
43  const GT_AttributeListHandle &detail,
45  GT_Size min_vertex_count=0,
46  GT_Size max_vertex_count=0)
47  : myVMerge(NULL)
48  , myUMerge(NULL)
49  , myConvexFlag(false)
50  {
51  init(vtx_counts, vtx_indices, shared, vertex, uniform, detail,
52  indexing, min_vertex_count, max_vertex_count);
53  }
54 
55  GT_PrimPolygonMesh(const GT_CountArray &vtx_counts,
56  const GT_DataArrayHandle &vtx_indices,
57  const GT_AttributeListHandle &shared,
58  const GT_AttributeListHandle &vertex,
59  const GT_AttributeListHandle &uniform,
60  const GT_AttributeListHandle &detail)
61  : myVMerge(nullptr)
62  , myUMerge(nullptr)
63  , myConvexFlag(false)
64  {
65  init(vtx_counts, vtx_indices, shared, vertex, uniform, detail);
66  }
67 
68  /// Copy the topology information from the source pmesh, but use different
69  /// attribute lists.
71  const GT_AttributeListHandle &shared,
72  const GT_AttributeListHandle &vertex,
73  const GT_AttributeListHandle &uniform,
74  const GT_AttributeListHandle &detail);
75 
76  /// Create a new polygon mesh with re-mapped vertices (used by
77  /// removeUnusedPoints).
78  ///
79  /// Since the polygon faces are remapped you'll have to pass in a new face
80  /// set map.
82  const GT_DataArrayHandle &vtx_indices,
83  const GT_AttributeListHandle &shared);
84 
85  /// Copy c-tor
87 
88  /// Construct a polygon mesh from a GT_PrimPolygon
90  /// Destructor
91  virtual ~GT_PrimPolygonMesh();
92 
93  virtual const char *className() const { return "GT_PrimPolygonMesh"; }
94  virtual bool save(UT_JSONWriter &w) const;
95 
96  /// @{
97  /// Methods defined on GT_Primitive
98  virtual void enlargeBounds(UT_BoundingBox boxes[],
99  int nsegments) const;
100  virtual int getPrimitiveType() const;
101  virtual bool refine(GT_Refine &refiner,
102  const GT_RefineParms *parms) const;
103  virtual int getMotionSegments() const;
104  virtual int64 getMemoryUsage() const;
105  /// @}
106 
107  /// @{
108  /// Initialize the mesh
109  /// - @c vtx_counts @n
110  /// An integer array, representing the number of vertices in each face.
111  /// The length of the array determines the number of faces in the mesh.
112  /// - @c vtx_indices @n
113  /// An array of vertex references. There is an entry for every vertex in
114  /// every face. These indices refer to the shared attribute data.
115  /// - @c shared @n
116  /// Shared attribute data. This data is referenced by the vertex arrays.
117  /// - @c vertex @n
118  /// Unique data per vertex. The length of these attribute arrays should
119  /// be the same as the length of the vtx_indices array.
120  /// - @c uniform @n
121  /// Attribute per face. There should be one entry for each entry in the
122  /// @c vtx_counts array.
123  /// - @c detail @n
124  /// Constant attribute for all faces.
125  /// @c vtx_counts array.
126  /// - @c indexing @n
127  /// What type of indexing is required
128  void init(const GT_DataArrayHandle &vtx_counts,
129  const GT_DataArrayHandle &vtx_indices,
130  const GT_AttributeListHandle &shared,
131  const GT_AttributeListHandle &vertex,
132  const GT_AttributeListHandle &uniform,
133  const GT_AttributeListHandle &detail,
135  GT_Size min_vertex_count=0,
136  GT_Size max_vertex_count=0);
137  void init(const GT_CountArray &vtx_counts,
138  const GT_DataArrayHandle &vtx_indices,
139  const GT_AttributeListHandle &shared,
140  const GT_AttributeListHandle &vertex,
141  const GT_AttributeListHandle &uniform,
142  const GT_AttributeListHandle &detail);
143  /// @}
144 
145  /// Return the number of faces in the mesh
146  GT_Size getFaceCount() const;
147  /// Return a pointer to the individual face
148  GT_PrimitiveHandle getFace(GT_Offset i) const;
149 
150  /// @{
151  /// Query the minimum/maximum number of vertices per face
152  GT_Size getMinVertexCount() const { return myFaceOffsets.getMinCount();}
153  GT_Size getMaxVertexCount() const { return myFaceOffsets.getMaxCount();}
154  /// @}
155 
156  /// @{
157  /// Accessor
158  virtual const GT_DataArrayHandle &getVertexList() const
159  { return myVertexList; }
161  { return myFaceOffsets; }
162 #if 0
163  const GT_DataArrayHandle &getFaceOffsets() const
164  { return myFaceOffsets; }
165 #endif
167  { return myShared; }
169  { return myVertex; }
171  { return myUniform; }
173  { return myDetail; }
174  /// @}
175 
176  /// @{
177  /// Access to the face sets
178  const GT_FaceSetMapPtr &faceSetMap() const { return myFaceSetMap; }
180  { myFaceSetMap = v; }
181  void addFaceSet(const UT_StringHolder &name,
182  const GT_FaceSetPtr &set);
183  /// @}
184 
185  /// Harden all attributes so there are no dangling dependencies
186  virtual GT_PrimitiveHandle doHarden() const;
188  { return new GT_PrimPolygonMesh(*this); }
189 
190  /// The virtual implementation of attribute merging
192  const UT_StringMMPattern *vertex,
193  const UT_StringMMPattern *point,
194  const UT_StringMMPattern *uniform,
195  const UT_StringMMPattern *detail) const;
196 
197  /// @{
198  /// Access attributes
200  { return myVertex; }
202  { return myShared; }
204  { return myUniform; }
206  { return myDetail; }
207  /// @}
208 
209  /// Return the offset into the vertex list for the given face
211  { return myFaceOffsets.getOffset(face); }
212  /// Return the length of the vertex list for the given face
214  { return myFaceOffsets.getCount(face); }
215  /// For a given face, find the shared point numbers for the given vertex
216  /// and the next vertex (i.e. the edge starting from the given vertex).
217  void getEdgePoints(GT_Offset face, GT_Offset vertex,
218  GT_Offset &p0, GT_Offset &p1) const;
219 
220  /// Returns true if this mesh has been convexed
221  bool isConvexed() const { return myConvexFlag; }
222 
223  /// Set the convex flag on the mesh
224  void setConvexed(bool c) { myConvexFlag = c; }
225 
226  /// Return an array containing the face counts per-face
228  getFaceCounts(GT_IndexingMode indexing=GT_INDEXING_QUICK) const;
229 
230  /// The polygon mesh may have shared points which aren't used. That is,
231  /// there may be elements in the shared element list which aren't
232  /// referenced by any vertex. This method will build a list of indices for
233  /// all the used points.
234  ///
235  /// The list returned will be monotonically ascending.
236  const GT_DataArrayHandle
237  getUsedPointList(GT_IndexingMode idx=GT_INDEXING_QUICK) const;
238 
239  /// Ensure all polygons in the mesh are convex
240  GT_PrimitiveHandle convex(int max_points_per_poly=3,
241  bool keep_degenerate = false,
242  bool allow_interrupt = true,
243  bool allow_indirect_flattening=0) const;
244 
245  /// Using the indirect arrays and vertex list from a convexed mesh,
246  /// convex this mesh (assumes topology is the same).
247  GT_PrimitiveHandle adoptConvexing(
248  const GT_DataArrayHandle &verts,
249  const GT_DataArrayHandle &uniform_indexing,
250  const GT_DataArrayHandle &vertex_indexing,
251  const GT_DataArrayHandle &vert_info,
252  const GT_DataArrayHandle &prim_info)
253  const;
254 
255  /// Fetches the convexed arrays from the mesh, to be used by adoptConvexing
256  /// on a different mesh with the same topology.
257  void getConvexArrays(
258  GT_DataArrayHandle &verts,
259  GT_DataArrayHandle &uniform_indexing,
260  GT_DataArrayHandle &vertex_indexing,
261  GT_DataArrayHandle &vert_info,
262  GT_DataArrayHandle &prim_info) const;
263 
264  /// Remove unused points. This will collapse the varying point arrays,
265  /// leaving only the points referenced by the vertices.
266  GT_PrimitiveHandle removeUnusedPoints(const int32 *idx=NULL) const;
267 
268  /// @{
269  /// Compute face normals. This will use the shared attribute named P to
270  /// compute the normals for each face.
271  /// fpreal16 must have the proper vector length
272  bool faceNormals(UT_Vector3 *N,
273  int segment=0,
274  const UT_StringRef &P=GA_Names::P) const;
275  bool faceNormals(UT_Vector3D *N64,
276  int segment=0,
277  const UT_StringRef &P=GA_Names::P) const;
278  bool faceNormals(fpreal16 *N16,
279  int segment=0,
280  const UT_StringRef &P=GA_Names::P) const;
281  GT_DataArrayHandle faceNormals(int segment=0,
282  const UT_StringRef &P=GA_Names::P,
283  GT_Storage store=GT_STORE_REAL32) const;
284  /// @}
285 
286  /// @{
287  /// Compute shared normals. This will use the shared attribute named P to
288  /// compute the normals for each shared point.
289  bool pointNormals(UT_Vector3T<fpreal16> *N,
290  GT_Size npts,
291  int segment=0,
292  const UT_StringRef &P=GA_Names::P,
293  bool normalize=true,
294  const fpreal32 *pntdata = NULL) const;
295  bool pointNormals(UT_Vector3 *N, GT_Size npts,
296  int segment=0,
297  const UT_StringRef &P=GA_Names::P,
298  bool normalize=true,
299  const fpreal32 *pntdata = NULL) const;
300  bool pointNormals(UT_Vector3D *N, GT_Size npts,
301  int segment=0,
302  const UT_StringRef &P=GA_Names::P,
303  bool normalize=true,
304  const fpreal32 *pntdata = NULL) const;
305  virtual GT_DataArrayHandle createPointNormals(int segment=0,
306  const UT_StringRef &P=GA_Names::P,
307  bool normalize=true,
308  const fpreal32 *pntdata = NULL,
309  GT_Storage store =GT_STORE_REAL32) const;
310  /// @}
311 
312 
313  /// @brief Create point normals on a new mesh if no normals are found.
314  /// If no point or vertex normals are found, generate point normals from P
315  /// and return a new mesh. If normals are found, return NULL.
316  GT_PrimPolygonMesh *createPointNormalsIfMissing(int segment=0,
317  const UT_StringRef &P=GA_Names::P,
318  bool normalize=true) const;
319 
320  /// @brief Divide a mesh into smaller meshes if it exceeds the poly_limit.
321  /// If this mesh has more than polygon_limit polygons, this will split the
322  /// mesh into multiple sub-meshes, attempting to keep them all roughly the
323  /// same number of polygons. If this mesh has fewer than polygon_limit
324  /// polygons, it will return false and not add any meshes to split_meshes.
325  /// If remove_unused_points is true, each submesh will have unused points
326  // removed.
327  bool splitMesh(GT_Size polygon_limit,
328  UT_Array<GT_PrimitiveHandle> &split_meshes,
329  bool remove_unused_points = true) const;
330 
331  /// @{
332  /// Methods for GEO/GU support.
333  virtual fpreal computePerimeter(int seg) const;
334  virtual fpreal computeSurfaceArea(int seg) const;
335  virtual fpreal computeVolume(const UT_Vector3 &ref_P, int seg) const;
336  /// @}
337 
338  virtual bool updateGeoPrim(const GU_ConstDetailHandle &dtl,
339  const GT_RefineParms &refine);
340 
341 protected:
342  void hardenAttributes();
343 
344  // We have "clone" methods so that sub-classes (i.e.
345  // GT_PrimSubdivisionMesh) can create an appropriate clone. These are used
346  // by methods internal when duplicating the mesh (i.e. removeUnusedPoints)
347  virtual GT_PrimPolygonMesh *clone(const GT_DataArrayHandle &vtx_counts,
348  const GT_DataArrayHandle &vtx_indices,
349  const GT_AttributeListHandle &shared,
350  const GT_AttributeListHandle &vertex,
351  const GT_AttributeListHandle &uniform,
352  const GT_AttributeListHandle &detail,
354  GT_Size min_vertex_count=0,
355  GT_Size max_vertex_count=0) const
356  {
357  return new GT_PrimPolygonMesh(vtx_counts, vtx_indices,
358  shared, vertex, uniform, detail, indexing,
359  min_vertex_count, max_vertex_count);
360  }
361  virtual GT_PrimPolygonMesh *clone(const GT_CountArray &vtx_counts,
362  const GT_DataArrayHandle &vtx_indices,
363  const GT_AttributeListHandle &shared,
364  const GT_AttributeListHandle &vertex,
365  const GT_AttributeListHandle &uniform,
366  const GT_AttributeListHandle &detail) const
367  {
368  return new GT_PrimPolygonMesh(vtx_counts, vtx_indices,
369  shared, vertex, uniform, detail);
370  }
372  const GT_AttributeListHandle &vertex,
373  const GT_AttributeListHandle &uniform,
374  const GT_AttributeListHandle &detail) const
375  {
376  return new GT_PrimPolygonMesh(*this, shared, vertex, uniform, detail);
377  }
378  virtual GT_PrimPolygonMesh *clone(const GT_DataArrayHandle &vtx_indices,
379  const GT_AttributeListHandle &shared) const
380  {
381  return new GT_PrimPolygonMesh(*this, vtx_indices, shared);
382  }
383 
388 
389 private:
390  template <typename VECTOR_T>
391  bool computePointNormals(
393  GT_Size Nsize,
394  const UT_StringRef &P,
395  int segment,
396  bool normalize,
397  const fpreal32 *point_data) const;
398 
399  void makeMerge();
400 
401  GT_DataArrayHandle myVertexList;
402  GT_CountArray myFaceOffsets;
403  GT_FaceSetMapPtr myFaceSetMap;
404  GT_AttributeMerge *myVMerge, *myUMerge;
405  bool myConvexFlag;
406 };
407 
408 #endif
409 
GT_Storage
Definition: GT_Types.h:17
virtual int getMotionSegments() const =0
Keep track of merging of attribute maps.
GT_PrimPolygonMesh(const GT_CountArray &vtx_counts, const GT_DataArrayHandle &vtx_indices, const GT_AttributeListHandle &shared, const GT_AttributeListHandle &vertex, const GT_AttributeListHandle &uniform, const GT_AttributeListHandle &detail)
virtual bool updateGeoPrim(const GU_ConstDetailHandle &dtl, const GT_RefineParms &parms)
update any cached data for geometry and its attributes
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
void setFaceSetMap(const GT_FaceSetMapPtr &v)
A mesh of polygons.
virtual int getPrimitiveType() const
virtual fpreal computePerimeter(int seg=0) const
virtual fpreal computeVolume(const UT_Vector3 &ref_P, int seg=0) const
virtual GT_PrimitiveHandle doSoftCopy() const
const GLdouble * v
Definition: glcorearb.h:836
GT_Size getMinVertexCount() const
GT_Size getVertexCount(GT_Offset face) const
Return the length of the vertex list for the given face.
const GT_CountArray & getFaceCountArray() const
GT_AttributeListHandle myShared
GT_IndexingMode
Definition: GT_Types.h:91
#define GT_API
Definition: GT_API.h:11
GT_PrimPolygonMesh(const GT_DataArrayHandle &vtx_counts, const GT_DataArrayHandle &vtx_indices, const GT_AttributeListHandle &shared, const GT_AttributeListHandle &vertex, const GT_AttributeListHandle &uniform, const GT_AttributeListHandle &detail, GT_IndexingMode indexing=GT_INDEXING_QUICK, GT_Size min_vertex_count=0, GT_Size max_vertex_count=0)
Useful constructor.
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
GA_API const UT_StringHolder P
3D Vector class.
const GT_AttributeListHandle & getShared() const
png_uint_32 i
Definition: png.h:2877
bool isConvexed() const
Returns true if this mesh has been convexed.
const GT_AttributeListHandle & getVertex() const
const GT_AttributeListHandle & getUniform() const
virtual GT_PrimPolygonMesh * clone(const GT_DataArrayHandle &vtx_counts, const GT_DataArrayHandle &vtx_indices, const GT_AttributeListHandle &shared, const GT_AttributeListHandle &vertex, const GT_AttributeListHandle &uniform, const GT_AttributeListHandle &detail, GT_IndexingMode indexing=GT_INDEXING_QUICK, GT_Size min_vertex_count=0, GT_Size max_vertex_count=0) const
long long int64
Definition: SYS_Types.h:107
GT_PrimPolygonMesh()
Default constructor.
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:38
virtual fpreal computeSurfaceArea(int seg=0) const
virtual GT_PrimPolygonMesh * clone(const GT_CountArray &vtx_counts, const GT_DataArrayHandle &vtx_indices, const GT_AttributeListHandle &shared, const GT_AttributeListHandle &vertex, const GT_AttributeListHandle &uniform, const GT_AttributeListHandle &detail) const
void setConvexed(bool c)
Set the convex flag on the mesh.
GT_Size getMaxVertexCount() const
GLuint const GLchar * name
Definition: glcorearb.h:785
int int32
Definition: SYS_Types.h:35
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
virtual GT_PrimitiveHandle doHarden() const
virtual int64 getMemoryUsage() const =0
virtual const GT_DataArrayHandle & getVertexList() const
virtual GT_PrimPolygonMesh * clone(const GT_DataArrayHandle &vtx_indices, const GT_AttributeListHandle &shared) const
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
virtual const GT_AttributeListHandle & getPointAttributes() const
virtual const GT_AttributeListHandle & getDetailAttributes() const
double fpreal
Definition: SYS_Types.h:270
GT_AttributeListHandle myVertex
virtual const GT_AttributeListHandle & getVertexAttributes() const
GT_AttributeListHandle myUniform
virtual const char * className() const
virtual bool save(UT_JSONWriter &w) const
GA_API const UT_StringHolder N
virtual const GT_AttributeListHandle & getUniformAttributes() const
GT_Offset getVertexOffset(GT_Offset face) const
Return the offset into the vertex list for the given face.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
virtual GT_DataArrayHandle createPointNormals(int segment=0, const UT_StringRef &P=GA_Names::P, bool normalize=true, const fpreal32 *pntdata=NULL, GT_Storage store=GT_STORE_REAL32) const
GT_AttributeListHandle myDetail
int64 GT_Offset
Definition: GT_Types.h:113
int64 GT_Size
Definition: GT_Types.h:112
virtual GT_PrimPolygonMesh * clone(const GT_AttributeListHandle &shared, const GT_AttributeListHandle &vertex, const GT_AttributeListHandle &uniform, const GT_AttributeListHandle &detail) const
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
const GT_FaceSetMapPtr & faceSetMap() const
Single closed polygon.
const GT_AttributeListHandle & getDetail() const
float fpreal32
Definition: SYS_Types.h:191
GLenum src
Definition: glcorearb.h:1792