Solid* extrude( const TriangulatedSurface& g, const Kernel::Vector_3& v ) { std::auto_ptr< Solid > result( new Solid() ); //bottom and top for ( size_t i = 0; i < g.numGeometries(); i++ ) { Triangle bottomPart( g.geometryN( i ) ); force3D( bottomPart ); bottomPart.reverse() ; result->exteriorShell().addPolygon( bottomPart ); Triangle topPart( g.geometryN( i ) ); force3D( topPart ); translate( topPart, v ); result->exteriorShell().addPolygon( topPart ); } //boundary std::auto_ptr< Geometry > boundary( g.boundary() ) ; BOOST_ASSERT( boundary.get() != NULL ); // closed surface extruded if ( ! boundary->isEmpty() ) { std::auto_ptr< Geometry > extrudedBoundary( extrude( *boundary, v ) ) ; BOOST_ASSERT( extrudedBoundary->is< PolyhedralSurface >() ); result->exteriorShell().addPolygons( extrudedBoundary->as< PolyhedralSurface >() ); } return result.release() ; }
Solid * extrude( const Polygon & g, const Kernel::Vector_3 & v ) { BOOST_ASSERT( ! g.isEmpty() ); bool reverseOrientation = ( v * normal3D< Kernel >( g ) ) > 0 ; //resulting shell PolyhedralSurface polyhedralSurface ; // "bottom" Polygon bottom(g); force3D( bottom ) ; if ( reverseOrientation ){ bottom.reverse(); } polyhedralSurface.addPolygon( bottom ); // "top" Polygon top( bottom ); top.reverse() ; translate(top,v); polyhedralSurface.addPolygon( top ); // exterior ring and interior rings extruded for ( size_t i = 0; i < bottom.numRings(); i++ ){ std::auto_ptr< PolyhedralSurface > boundaryExtruded( extrude( bottom.ringN(i), v ) ); for ( size_t j = 0; j < boundaryExtruded->numPolygons(); j++ ){ boundaryExtruded->polygonN(j).reverse() ; polyhedralSurface.addPolygon( boundaryExtruded->polygonN(j) ) ; } } return new Solid( polyhedralSurface ); }