Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

oogl.cc

00001 #include <algorithm>
00002 #include <ostream>
00003 #include "oogl.h"
00004 
00005 #include <CGAL/Iterator_project.h>
00006 #include <CGAL/function_objects.h>
00007 
00008 
00009 typedef Polyhedron::Vertex_const_iterator                    Vertex_iterator;
00010 typedef Polyhedron::Facet_const_iterator                     Facet_iterator;
00011 typedef Polyhedron::Halfedge_around_facet_const_circulator
00012                                             Halfedge_around_facet_circulator;
00013 
00014 
00015 
00016 oogl_traits::oogl_traits( bool has_vertex_color, 
00017                           bool has_facet_color )
00018 {
00019     v_color = has_vertex_color;
00020     f_color = has_facet_color;
00021 }
00022 
00023 
00024 
00025 CGAL::Color 
00026 oogl_traits::vertex_color( const Polyhedron::Vertex& v )
00027 {
00028     CGAL_assertion_msg( false, "Need to override oogl_traits::vertex_color" );
00029 }
00030 
00031 CGAL::Color 
00032 oogl_traits::facet_color( const Polyhedron::Facet& f )
00033 {
00034     CGAL_assertion_msg( false, "Need to override oogl_traits::facet_color" );
00035 }
00036 
00037 
00038 std::string
00039 oogl_traits::OFF_header( const Polyhedron& P ) const
00040 {
00041     std::string header = "OFF";
00042 
00043     if ( has_vertex_color() )
00044         header = "C" + header;
00045 
00046     return header;
00047 }
00048 
00049 
00050 
00051 // Write polyhedron on Object File Format (OFF).
00052 // FIXME: should be const Polyhedron&.  The typedefs need adjusting, it seems.
00053 void 
00054 write_oogl_off( std::ostream& os, const Polyhedron& P,
00055                 oogl_traits traits )
00056 {
00057     CGAL::set_ascii_mode( os );
00058 
00059     os << traits.OFF_header(P) << std::endl;
00060     os << P.size_of_vertices()                // vertices
00061        << ' ' << P.size_of_facets()           // facets
00062        << " 0"                                // edges (not used)
00063        << std::endl;
00064 
00065     
00066     for( Vertex_iterator v = P.vertices_begin(); v != P.vertices_end(); ++v ) 
00067     {
00068         write_oogl_point( os, v->point() );
00069         if ( traits.has_vertex_color() )
00070             CGAL_assertion_msg( false, "unimplemented" );
00071         os << std::endl;
00072     }
00073 
00074 
00075     for ( Facet_iterator f = P.facets_begin(); f != P.facets_end(); ++f) 
00076     {
00077         Halfedge_around_facet_circulator h = f->facet_begin();
00078         // Facets in polyhedral surfaces are at least triangles.
00079         CGAL_assertion( CGAL::circulator_size(h) >= 3);
00080 
00081         os << CGAL::circulator_size(h) << " ";
00082         do {
00083             os << " " << std::distance(P.vertices_begin(), h->vertex());
00084         } while ( ++h != f->facet_begin());
00085 
00086         if (traits.has_facet_color()) {
00087             CGAL::Color col = traits.facet_color(*f);
00088             os << col;
00089         }
00090         os << std::endl;
00091     }
00092 
00093 }

Generated on Fri Oct 26 23:38:10 2001 for bicobj-intersection by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001