Generates the IV surface/lines/points with children rooted at the SoGroup [result].
{
typedef float vec3[ 3 ];
SoShapeHints *myShapeHints = new SoShapeHints;
myShapeHints->vertexOrdering = SoShapeHints::UNKNOWN_ORDERING;
myShapeHints->shapeType =
false ? SoShapeHints::SOLID : SoShapeHints::UNKNOWN_SHAPE_TYPE;
myShapeHints->faceType = SoShapeHints::CONVEX;
myShapeHints->creaseAngle = 1.0;
result->addChild( myShapeHints );
uint32 nb_vtx;
uint32 nb_cells;
vec3* coords;
vec3* xyz;
SoCoordinate3 *myCoords;
typename CellSet::const_iterator ip;
typename CellSet::const_iterator ip_end;
int32* indices;
vec3* normals;
vec3* colors;
typename ColorMapping::const_iterator itc;
typename NormalMapping::const_iterator itn;
int idx;
nb_vtx = 4 * nb_cells;
if ( nb_vtx != 0 )
{
cout << "2-cells = " << nb_vtx << endl;
SoGroup* node_squares = new SoGroup;
myCoords = new SoCoordinate3;
coords = new vec3[ nb_vtx ];
xyz = coords;
indices = new int32[ nb_cells ];
normals = new vec3[ nb_cells ];
colors = new vec3[ nb_cells ];
idx = 0;
SbVec3f uv1;
SbVec3f uv2;
SbVec3f n;
while ( ip != ip_end )
{
unsigned int d = 0;
bool orient = ip->second;
for (
Dimension i = 0; i < c.dimension; ++i )
{
if ( c[ i ] & 0x1 )
dirs[ d++ ] = i;
e[ i ] = c[ i ] >> 1;
}
uv1.setValue( *xyz );
uv2.setValue( *xyz );
++xyz;
e[ dirs[ 0 ] ] ++;
uv1 -= SbVec3f( *xyz );
++xyz;
e[ dirs[ 1 ] ] ++;
++xyz;
e[ dirs[ 0 ] ] --;
uv2 -= SbVec3f( *xyz );
++xyz;
indices[ idx ] = 4;
n = uv1.cross( uv2 );
if ( orient )
{
if ( n[ 0 ] < 0.0 ) n[ 0 ] = -n[ 0 ];
if ( n[ 1 ] < 0.0 ) n[ 1 ] = -n[ 1 ];
if ( n[ 2 ] < 0.0 ) n[ 2 ] = -n[ 2 ];
}
else
{
if ( n[ 0 ] > 0.0 ) n[ 0 ] = -n[ 0 ];
if ( n[ 1 ] > 0.0 ) n[ 1 ] = -n[ 1 ];
if ( n[ 2 ] > 0.0 ) n[ 2 ] = -n[ 2 ];
}
{
n = itn->second;
double dot = uv1[0]*n[0]+uv1[1]*n[1]+uv1[2]*n[2];
if ( dot < 0.0 )
{
vec3* xyz1 = xyz - 3;
vec3* xyz2 = xyz - 1;
std::swap( (*xyz1)[0], (*xyz2)[0] );
std::swap( (*xyz1)[1], (*xyz2)[1] );
std::swap( (*xyz1)[2], (*xyz2)[2] );
}
}
n.getValue( normals[ idx ][ 0 ],
normals[ idx ][ 1 ],
normals[ idx ][ 2 ] );
n = itc->second;
n.getValue( colors[ idx ][ 0 ],
colors[ idx ][ 1 ],
colors[ idx ][ 2 ] );
++idx;
++ip;
}
myCoords->point.setValues( 0, nb_vtx, coords );
node_squares->addChild( myCoords );
SoNormal* iNormals = new SoNormal;
iNormals->vector.setValues( 0, idx, normals );
delete[] normals;
node_squares->addChild( iNormals );
SoNormalBinding *iNormalBinding = new SoNormalBinding;
iNormalBinding->value = SoNormalBinding::PER_FACE;
node_squares->addChild( iNormalBinding );
SoMaterial* iMaterials = new SoMaterial;
iMaterials->diffuseColor.setValues( 0, idx, colors );
delete[] colors;
node_squares->addChild( iMaterials );
SoMaterialBinding* iMaterialBinding = new SoMaterialBinding;
iMaterialBinding->value = SoMaterialBinding::PER_FACE;
node_squares->addChild( iMaterialBinding );
SoFaceSet* face_set = new SoFaceSet;
face_set->numVertices.setValues( 0, idx, indices );
node_squares->addChild( face_set );
result->addChild( node_squares );
delete[] indices;
}
}