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