HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_PrimTetra.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "GT_PrimTetra.h"
27 #include "GEO_PrimTetra.h"
28 #include <GT/GT_GEOPrimitive.h>
29 #include <GT/GT_GEODetailList.h>
31 #include <GT/GT_Refine.h>
32 #include <GT/GT_DAConstantValue.h>
33 #include <GT/GT_PrimPolygonMesh.h>
34 
35 using namespace HDK_Sample;
36 
37 void
39 {
40  // Just construct. The constructor registers itself.
41  new GT_PrimTetraCollect(id);
42 }
43 
45  : myId(id)
46 {
47  // Bind this collector to the given primitive id. When GT refines
48  // primitives and hits the given primitive id, this collector will be
49  // invoked.
50  bind(myId);
51 }
52 
54 {
55 }
56 
59  const GT_RefineParms *parms) const
60 {
61  // Collect the tet primitive offsets in a container
62  return new GT_GEOPrimCollectOffsets();
63 }
64 
67  const GEO_Primitive *const* prim_list,
68  int nsegments,
70 {
72  list = data->asPointer<GT_GEOPrimCollectOffsets>();
73  list->append(prim_list[0]);
74  return GT_PrimitiveHandle();
75 }
76 
80 {
81  GU_ConstDetailHandle gdh = geometry->getGeometry(0);
82  GU_DetailHandleAutoReadLock rlock(gdh);
83  const GU_Detail &gdp = *rlock;
85  list = data->asPointer<GT_GEOPrimCollectOffsets>();
86 
87  const GT_GEOOffsetList &offsets = list->getPrimitives();
88  if (!offsets.entries())
89  return GT_PrimitiveHandle();
90 
91  // There have been tet's collected, so now we have to build up the
92  // appropriate structures to build the GT primitive.
93  GT_GEOOffsetList ga_faces;
94  GT_GEOOffsetList ga_vertices;
95  static const int vertex_order[] = {
96  0, 1, 2,
97  1, 3, 2,
98  1, 0, 3,
99  0, 2, 3
100  };
101 
102  // Extract two lists, the list of the primitive corresponding to each face
103  // in the polygon mesh, along with the list of all the vertices for each
104  // face in the mesh.
105  for (exint i = 0; i < offsets.entries(); ++i)
106  {
107  // Each tet has 4 faces
108  const GEO_Primitive *prim = gdp.getGEOPrimitive(offsets(i));
109  for (int face = 0; face < 4; ++face)
110  {
111  // Duplicate the primitive offset for each face
112  ga_faces.append(offsets(i));
113 
114  // And now, build a list of the vertex offsets
115  for (int voff = 0; voff < 3; ++voff)
116  {
117  int vidx = vertex_order[face*3 + voff];
118  ga_vertices.append(prim->getVertexOffset(vidx));
119  }
120  }
121  }
122 
123  // Build the data structures needed for GT_PrimPolygonMesh.
124  GT_PrimPolygonMesh *pmesh;
125  GT_DataArrayHandle counts;
126  GT_DataArrayHandle ptnums;
127  GT_AttributeListHandle shared;
129  GT_AttributeListHandle uniform;
130  GT_AttributeListHandle detail;
131 
132  // The attribute filter isn't used in this primitive, but it allows
133  // attributes to be excluded (i.e. spheres, might not want the "N" or the
134  // "P" attributes).
136 
137  // The "shared" attributes will contain the attributes for all the points
138  // in the geometry.
139  //
140  // The attribute list consists of GT data arrays which are filled with
141  // attribute data from the GA detail(s). Each data array stored in the
142  // attribute list will have as many entries as the gdp's point offsets.
143  // The elements should be indexed by the corresponding point offset
144  shared = geometry->getPointAttributes(filter);
145 
146  // The vertex attributes are indexed by the GA_Offset of the vertices
147  //
148  // Each array in the attribute list will be filled by the attribute data
149  // associated with the GA_Offset of the vertex in the ga_vertices array.
150  // These are indexed by @c 0 to @c ga_vertices.entries().
151  vertex = geometry->getVertexAttributes(filter, &ga_vertices);
152 
153  // Create primitive attributes.
154  //
155  // Each array item is filled with the attribute data for the corresponding
156  // face in the ga_faces array.
157  uniform = geometry->getPrimitiveAttributes(filter, &ga_faces);
158 
159  // Create detail attributes. These are common for all faces
160  detail = geometry->getDetailAttributes(filter);
161 
162  // Every face has 3 vertices, so create an array of the right size that's
163  // filled with '3'.
164  counts = GT_DataArrayHandle(new GT_IntConstant(ga_faces.entries(), 3));
165 
166  // Since the @c shared array is indexed by the point offset, there needs to
167  // be a mapping from the vertex to the point offset.
168  ptnums = ga_vertices.createVertexPointArray(gdp);
169 
170  pmesh = new GT_PrimPolygonMesh(counts, ptnums,
171  shared, vertex, uniform, detail);
172 
173  return GT_PrimitiveHandle(pmesh);
174 }
SIM_API const UT_StringHolder vertex
void bind(const GA_PrimitiveTypeId &id) const
GT_DataArrayHandle createVertexPointArray(const GA_Detail &gdp) const
A mesh of polygons.
GT_GEOPrimCollectData * beginCollecting(const GT_GEODetailListHandle &geometry, const GT_RefineParms *parms) const override
Return a structure to capture all the tet primitives.
Definition: GT_PrimTetra.C:58
Class to filter attributes when building GT_AttributeLists.
int64 exint
Definition: SYS_Types.h:125
Collection data container.
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2621
SYS_FORCE_INLINE GEO_Primitive * getGEOPrimitive(GA_Offset primoff)
Definition: GEO_Detail.h:1177
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:32
GT_PrimTetraCollect(const GA_PrimitiveTypeId &id)
Definition: GT_PrimTetra.C:44
static void registerPrimitive(const GA_PrimitiveTypeId &id)
Register the GT collector.
Definition: GT_PrimTetra.C:38
Collection data container to store primitive offsets.
void append(GA_Offset offset)
Definition: GT_GEOSupport.h:76
GT_Size entries() const
Definition: GT_GEOSupport.h:86
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:240
GT_DAConstantValue< int64 > GT_IntConstant
~GT_PrimTetraCollect() override
Destructor.
Definition: GT_PrimTetra.C:53
GT_PrimitiveHandle collect(const GT_GEODetailListHandle &geometry, const GEO_Primitive *const *prim_list, int nsegments, GT_GEOPrimCollectData *data) const override
When refining a single tet primitive, we add it to the container.
Definition: GT_PrimTetra.C:66
virtual void append(const GA_Primitive *prim)
GT_PrimitiveHandle endCollecting(const GT_GEODetailListHandle &geometry, GT_GEOPrimCollectData *data) const override
At the end of collecting, the single outside skin is generated.
Definition: GT_PrimTetra.C:78
UT_IntrusivePtr< GT_Primitive > GT_PrimitiveHandle
Definition: GT_Handles.h:34
UT_SharedPtr< GT_GEODetailList > GT_GEODetailListHandle
const GT_GEOOffsetList & getPrimitives() const
Definition: format.h:895
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297