HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GT_PrimTetra.C
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  * Produced by:
7  * Side Effects Software Inc
8  * 123 Front Street West, Suite 1401
9  * Toronto, Ontario
10  * Canada M5J 2M2
11  * 416-504-9876
12  *
13  * NAME: GT_PrimTetra.h ( GT Library, C++)
14  *
15  * COMMENTS:
16  */
17 
18 #include "GT_PrimTetra.h"
19 #include "GEO_PrimTetra.h"
20 #include <GT/GT_GEOPrimitive.h>
21 #include <GT/GT_GEODetailList.h>
23 #include <GT/GT_Refine.h>
24 #include <GT/GT_DAConstantValue.h>
25 #include <GT/GT_PrimPolygonMesh.h>
26 
27 using namespace HDK_Sample;
28 
29 void
31 {
32  // Just construct. The constructor registers itself.
33  new GT_PrimTetraCollect(id);
34 }
35 
37  : myId(id)
38 {
39  // Bind this collector to the given primitive id. When GT refines
40  // primitives and hits the given primitive id, this collector will be
41  // invoked.
42  bind(myId);
43 }
44 
46 {
47 }
48 
51  const GT_RefineParms *parms) const
52 {
53  // Collect the tet primitive offsets in a container
54  return new GT_GEOPrimCollectOffsets();
55 }
56 
59  const GEO_Primitive *const* prim_list,
60  int nsegments,
62 {
64  list = data->asPointer<GT_GEOPrimCollectOffsets>();
65  list->append(prim_list[0]);
66  return GT_PrimitiveHandle();
67 }
68 
72 {
73  GU_ConstDetailHandle gdh = geometry->getGeometry(0);
74  GU_DetailHandleAutoReadLock rlock(gdh);
75  const GU_Detail &gdp = *rlock;
77  list = data->asPointer<GT_GEOPrimCollectOffsets>();
78 
79  const GT_GEOOffsetList &offsets = list->getPrimitives();
80  if (!offsets.entries())
81  return GT_PrimitiveHandle();
82 
83  // There have been tet's collected, so now we have to build up the
84  // appropriate structures to build the GT primitive.
85  GT_GEOOffsetList ga_faces;
86  GT_GEOOffsetList ga_vertices;
87  static const int vertex_order[] = {
88  0, 1, 2,
89  1, 3, 2,
90  1, 0, 3,
91  0, 2, 3
92  };
93 
94  // Extract two lists, the list of the primitive corresponding to each face
95  // in the polygon mesh, along with the list of all the vertices for each
96  // face in the mesh.
97  for (exint i = 0; i < offsets.entries(); ++i)
98  {
99  // Each tet has 4 faces
100  const GEO_Primitive *prim = gdp.getGEOPrimitive(offsets(i));
101  for (int face = 0; face < 4; ++face)
102  {
103  // Duplicate the primitive offset for each face
104  ga_faces.append(offsets(i));
105 
106  // And now, build a list of the vertex offsets
107  for (int voff = 0; voff < 3; ++voff)
108  {
109  int vidx = vertex_order[face*3 + voff];
110  ga_vertices.append(prim->getVertexOffset(vidx));
111  }
112  }
113  }
114 
115  // Build the data structures needed for GT_PrimPolygonMesh.
116  GT_PrimPolygonMesh *pmesh;
117  GT_DataArrayHandle counts;
118  GT_DataArrayHandle ptnums;
119  GT_AttributeListHandle shared;
120  GT_AttributeListHandle vertex;
121  GT_AttributeListHandle uniform;
122  GT_AttributeListHandle detail;
123 
124  // The attribute filter isn't used in this primitive, but it allows
125  // attributes to be excluded (i.e. spheres, might not want the "N" or the
126  // "P" attributes).
128 
129  // The "shared" attributes will contain the attributes for all the points
130  // in the geometry.
131  //
132  // The attribute list consists of GT data arrays which are filled with
133  // attribute data from the GA detail(s). Each data array stored in the
134  // attribute list will have as many entries as the gdp's point offsets.
135  // The elements should be indexed by the corresponding point offset
136  shared = geometry->getPointAttributes(filter);
137 
138  // The vertex attributes are indexed by the GA_Offset of the vertices
139  //
140  // Each array in the attribute list will be filled by the attribute data
141  // associated with the GA_Offset of the vertex in the ga_vertices array.
142  // These are indexed by @c 0 to @c ga_vertices.entries().
143  vertex = geometry->getVertexAttributes(filter, &ga_vertices);
144 
145  // Create primitive attributes.
146  //
147  // Each array item is filled with the attribute data for the corresponding
148  // face in the ga_faces array.
149  uniform = geometry->getPrimitiveAttributes(filter, &ga_faces);
150 
151  // Create detail attributes. These are common for all faces
152  detail = geometry->getDetailAttributes(filter);
153 
154  // Every face has 3 vertices, so create an array of the right size that's
155  // filled with '3'.
156  counts = GT_DataArrayHandle(new GT_IntConstant(ga_faces.entries(), 3));
157 
158  // Since the @c shared array is indexed by the point offset, there needs to
159  // be a mapping from the vertex to the point offset.
160  ptnums = ga_vertices.createVertexPointArray(gdp);
161 
162  pmesh = new GT_PrimPolygonMesh(counts, ptnums,
163  shared, vertex, uniform, detail);
164 
165  return GT_PrimitiveHandle(pmesh);
166 }
void bind(const GA_PrimitiveTypeId &id) const
GT_DataArrayHandle createVertexPointArray(const GA_Detail &gdp) const
A mesh of polygons.
Class to filter attributes when building GT_AttributeLists.
virtual GT_PrimitiveHandle collect(const GT_GEODetailListHandle &geometry, const GEO_Primitive *const *prim_list, int nsegments, GT_GEOPrimCollectData *data) const
When refining a single tet primitive, we add it to the container.
Definition: GT_PrimTetra.C:58
png_uint_32 i
Definition: png.h:2877
Collection data container.
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2620
SYS_FORCE_INLINE GEO_Primitive * getGEOPrimitive(GA_Offset primoff)
Definition: GEO_Detail.h:1089
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:30
int64 exint
Definition: SYS_Types.h:109
GT_PrimTetraCollect(const GA_PrimitiveTypeId &id)
Definition: GT_PrimTetra.C:36
GLboolean * data
Definition: glcorearb.h:130
static void registerPrimitive(const GA_PrimitiveTypeId &id)
Register the GT collector.
Definition: GT_PrimTetra.C:30
Collection data container to store primitive offsets.
void append(GA_Offset offset)
Definition: GT_GEOSupport.h:75
virtual GT_GEOPrimCollectData * beginCollecting(const GT_GEODetailListHandle &geometry, const GT_RefineParms *parms) const
Return a structure to capture all the tet primitives.
Definition: GT_PrimTetra.C:50
GT_Size entries() const
Definition: GT_GEOSupport.h:85
virtual GT_PrimitiveHandle endCollecting(const GT_GEODetailListHandle &geometry, GT_GEOPrimCollectData *data) const
At the end of collecting, the single outside skin is generated.
Definition: GT_PrimTetra.C:70
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:235
GT_DAConstantValue< int64 > GT_IntConstant
virtual ~GT_PrimTetraCollect()
Destructor.
Definition: GT_PrimTetra.C:45
virtual void append(const GA_Primitive *prim)
UT_IntrusivePtr< GT_Primitive > GT_PrimitiveHandle
Definition: GT_Handles.h:33
const GT_GEOOffsetList & getPrimitives() const
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1296