HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tetprim/GT_PrimTetra.C
/*
* Copyright (c) 2024
* Side Effects Software Inc. All rights reserved.
*
* Redistribution and use of Houdini Development Kit samples in source and
* binary forms, with or without modification, are permitted provided that the
* following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. The name of Side Effects Software may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "GT_PrimTetra.h"
#include "GEO_PrimTetra.h"
#include <GT/GT_Refine.h>
using namespace HDK_Sample;
void
{
// Just construct. The constructor registers itself.
}
: myId(id)
{
// Bind this collector to the given primitive id. When GT refines
// primitives and hits the given primitive id, this collector will be
// invoked.
bind(myId);
}
GT_PrimTetraCollect::~GT_PrimTetraCollect()
{
}
const GT_RefineParms *parms) const
{
// Collect the tet primitive offsets in a container
}
const GEO_Primitive *const* prim_list,
int nsegments,
{
list->append(prim_list[0]);
}
GT_GEOPrimCollectData *data) const
{
GU_ConstDetailHandle gdh = geometry->getGeometry(0);
const GU_Detail &gdp = *rlock;
if (!offsets.entries())
// There have been tet's collected, so now we have to build up the
// appropriate structures to build the GT primitive.
GT_GEOOffsetList ga_faces;
GT_GEOOffsetList ga_vertices;
static const int vertex_order[] = {
0, 1, 2,
1, 3, 2,
1, 0, 3,
0, 2, 3
};
// Extract two lists, the list of the primitive corresponding to each face
// in the polygon mesh, along with the list of all the vertices for each
// face in the mesh.
for (exint i = 0; i < offsets.entries(); ++i)
{
// Each tet has 4 faces
const GEO_Primitive *prim = gdp.getGEOPrimitive(offsets(i));
for (int face = 0; face < 4; ++face)
{
// Duplicate the primitive offset for each face
ga_faces.append(offsets(i));
// And now, build a list of the vertex offsets
for (int voff = 0; voff < 3; ++voff)
{
int vidx = vertex_order[face*3 + voff];
ga_vertices.append(prim->getVertexOffset(vidx));
}
}
}
// Build the data structures needed for GT_PrimPolygonMesh.
// The attribute filter isn't used in this primitive, but it allows
// attributes to be excluded (i.e. spheres, might not want the "N" or the
// "P" attributes).
// The "shared" attributes will contain the attributes for all the points
// in the geometry.
//
// The attribute list consists of GT data arrays which are filled with
// attribute data from the GA detail(s). Each data array stored in the
// attribute list will have as many entries as the gdp's point offsets.
// The elements should be indexed by the corresponding point offset
shared = geometry->getPointAttributes(filter);
// The vertex attributes are indexed by the GA_Offset of the vertices
//
// Each array in the attribute list will be filled by the attribute data
// associated with the GA_Offset of the vertex in the ga_vertices array.
// These are indexed by @c 0 to @c ga_vertices.entries().
vertex = geometry->getVertexAttributes(filter, &ga_vertices);
// Create primitive attributes.
//
// Each array item is filled with the attribute data for the corresponding
// face in the ga_faces array.
uniform = geometry->getPrimitiveAttributes(filter, &ga_faces);
// Create detail attributes. These are common for all faces
detail = geometry->getDetailAttributes(filter);
// Every face has 3 vertices, so create an array of the right size that's
// filled with '3'.
counts = GT_DataArrayHandle(new GT_IntConstant(ga_faces.entries(), 3));
// Since the @c shared array is indexed by the point offset, there needs to
// be a mapping from the vertex to the point offset.
ptnums = ga_vertices.createVertexPointArray(gdp);
pmesh = new GT_PrimPolygonMesh(counts, ptnums,
shared, vertex, uniform, detail);
return GT_PrimitiveHandle(pmesh);
}