44 template <
typename TSpace>
53 template <
typename TSpace>
65 template <
typename TSpace>
70 ModeMapping::const_iterator itm = myModes.find( objectName );
71 return itm == myModes.end() ?
"" : itm->second;
81 template <
typename TSpace>
86 ASSERT( l.
n() == Space::dimension );
95 template <
typename TSpace>
100 myCells[ 0 ].
clear();
101 myCells[ 1 ].clear();
102 myCells[ 2 ].clear();
110 template <
typename TSpace>
115 myDiffuseColor =
Color( color );
121 template <
typename TSpace>
126 myDiffuseColor = color;
137 template <
typename TSpace>
141 (
const Point & c,
bool orient,
const float* n )
145 for (
typename Point::ConstIterator it = c.begin(); it != c.end(); ++it )
146 if ( *it & 0x1 ) ++cdim;
150 for (
typename Point::Iterator it = p.begin(); it != p.end(); ++it )
154 drawCell( p,
false, n );
156 drawCell( p,
true, n );
162 myCells[ cdim ].insert( std::make_pair( c, orient ) );
163 myColors[ c ] = myDiffuseColor;
164 if ( n != 0 ) myNormals[ c ] = n;
174 template <
typename TSpace>
180 for (
Dimension i = 0; i < c.dimension; ++i )
181 q[ i ] = 2*c[ i ] + 1;
192 template <
typename TSpace>
197 out <<
"[DGtalInventor]";
204 template <
typename TSpace>
223 template <
typename TSpace>
227 typedef float vec3[ 3 ];
231 SoShapeHints *myShapeHints =
new SoShapeHints;
232 myShapeHints->vertexOrdering = SoShapeHints::UNKNOWN_ORDERING;
233 myShapeHints->shapeType =
234 false ? SoShapeHints::SOLID : SoShapeHints::UNKNOWN_SHAPE_TYPE;
235 myShapeHints->faceType = SoShapeHints::CONVEX;
236 myShapeHints->creaseAngle = 1.0;
237 result->addChild( myShapeHints );
244 SoCoordinate3 *myCoords;
245 typename CellSet::const_iterator ip;
246 typename CellSet::const_iterator ip_end;
250 typename ColorMapping::const_iterator itc;
251 typename NormalMapping::const_iterator itn;
255 nb_cells = myCells[ 2 ].size();
256 nb_vtx = 4 * nb_cells;
259 cout <<
"2-cells = " << nb_vtx << endl;
260 SoGroup* node_squares =
new SoGroup;
261 myCoords =
new SoCoordinate3;
262 coords =
new vec3[ nb_vtx ];
263 ip = myCells[ 2 ].begin();
264 ip_end = myCells[ 2 ].end();
266 indices =
new int32[ nb_cells ];
267 normals =
new vec3[ nb_cells ];
268 colors =
new vec3[ nb_cells ];
273 while ( ip != ip_end )
277 bool orient = ip->second;
280 for (
Dimension i = 0; i < c.dimension; ++i )
284 e[ i ] = c[ i ] >> 1;
288 myLattice.immerse( e, *xyz );
289 uv1.setValue( *xyz );
290 uv2.setValue( *xyz );
293 myLattice.immerse( e, *xyz );
294 uv1 -= SbVec3f( *xyz );
297 myLattice.immerse( e, *xyz );
300 myLattice.immerse( e, *xyz );
301 uv2 -= SbVec3f( *xyz );
308 itn = myNormals.find( c );
309 n = uv1.cross( uv2 );
312 if ( n[ 0 ] < 0.0 ) n[ 0 ] = -n[ 0 ];
313 if ( n[ 1 ] < 0.0 ) n[ 1 ] = -n[ 1 ];
314 if ( n[ 2 ] < 0.0 ) n[ 2 ] = -n[ 2 ];
318 if ( n[ 0 ] > 0.0 ) n[ 0 ] = -n[ 0 ];
319 if ( n[ 1 ] > 0.0 ) n[ 1 ] = -n[ 1 ];
320 if ( n[ 2 ] > 0.0 ) n[ 2 ] = -n[ 2 ];
322 if ( itn != myNormals.end() )
325 double dot = uv1[0]*n[0]+uv1[1]*n[1]+uv1[2]*n[2];
328 vec3* xyz1 = xyz - 3;
329 vec3* xyz2 = xyz - 1;
330 std::swap( (*xyz1)[0], (*xyz2)[0] );
331 std::swap( (*xyz1)[1], (*xyz2)[1] );
332 std::swap( (*xyz1)[2], (*xyz2)[2] );
335 n.getValue( normals[ idx ][ 0 ],
337 normals[ idx ][ 2 ] );
340 itc = myColors.find( c );
341 if ( itc != myColors.end() )
343 n.getValue( colors[ idx ][ 0 ],
345 colors[ idx ][ 2 ] );
351 myCoords->point.setValues( 0, nb_vtx, coords );
352 node_squares->addChild( myCoords );
355 SoNormal* iNormals =
new SoNormal;
356 iNormals->vector.setValues( 0, idx, normals );
358 node_squares->addChild( iNormals );
359 SoNormalBinding *iNormalBinding =
new SoNormalBinding;
360 iNormalBinding->value = SoNormalBinding::PER_FACE;
362 node_squares->addChild( iNormalBinding );
365 SoMaterial* iMaterials =
new SoMaterial;
366 iMaterials->diffuseColor.setValues( 0, idx, colors );
368 node_squares->addChild( iMaterials );
369 SoMaterialBinding* iMaterialBinding =
new SoMaterialBinding;
370 iMaterialBinding->value = SoMaterialBinding::PER_FACE;
371 node_squares->addChild( iMaterialBinding );
374 SoFaceSet* face_set =
new SoFaceSet;
375 face_set->numVertices.setValues( 0, idx, indices );
376 node_squares->addChild( face_set );
377 result->addChild( node_squares );
386 template <
typename TSpace>
392 object.selfDisplay( out );