00001 #include "poly_iv.h"
00002 #include "display-colormap.h"
00003
00004
00005 #include <Inventor/nodes/SoIndexedFaceSet.h>
00006
00007
00008 #include <Inventor/nodes/SoBaseColor.h>
00009 #include <Inventor/nodes/SoCoordinate3.h>
00010 #include <Inventor/nodes/SoMaterial.h>
00011 #include <Inventor/nodes/SoMaterialBinding.h>
00012
00013
00014
00015
00016 #include <Inventor/nodes/SoSeparator.h>
00017
00018
00019 #include <map>
00020 #include <algorithm>
00021 #include <CGAL/Iterator_project.h>
00022 #include <CGAL/function_objects.h>
00023
00024
00025
00026
00027
00028 typedef Polyhedron::Vertex_const_iterator Vertex_iterator;
00029 typedef Polyhedron::Facet_const_iterator Facet_iterator;
00030 typedef Polyhedron::Halfedge_around_facet_const_circulator
00031 Halfedge_around_facet_circulator;
00032
00033
00037
00038 SoNode* polyhedron_to_iv( const Polyhedron& P )
00039 {
00040 SoSeparator* root = new SoSeparator;
00041
00042 SoMaterialBinding* material_binding = new SoMaterialBinding;
00043 material_binding->value = SoMaterialBinding::PER_FACE_INDEXED;
00044 root->addChild(material_binding);
00045
00046 SoBaseColor* base_color = new SoBaseColor;
00047 base_color->rgb.setValues(0,256,Display_color_map);
00048 root->addChild(base_color);
00049
00050
00051
00052
00053 SoCoordinate3* coord = new SoCoordinate3;
00054 coord->point.setNum( P.size_of_vertices() );
00055
00056 std::map<const Polyhedron::Vertex*,int> vertex_index;
00057 int i = 0;
00058 for( Vertex_iterator v = P.vertices_begin(); v != P.vertices_end(); ++v )
00059 {
00060 vertex_index[&*v] = i;
00061 coord->point.set1Value( i++, CGAL::to_double(v->point().x()),
00062 CGAL::to_double(v->point().y()),
00063 CGAL::to_double(v->point().z()) );
00064 }
00065 root->addChild(coord);
00066
00067 SoIndexedFaceSet* face_set = new SoIndexedFaceSet;
00068 i = 0;
00069 int facet_index = 0;
00070 for ( Facet_iterator f = P.facets_begin(); f != P.facets_end(); ++f)
00071 {
00072 CGAL_assertion( f->label >= 0 );
00073 CGAL_assertion( f->label < 256 );
00074 face_set->materialIndex.set1Value(facet_index, f->label);
00075
00076 Halfedge_around_facet_circulator h = f->facet_begin();
00077
00078 CGAL_assertion( CGAL::circulator_size(h) >= 3);
00079
00080
00081
00082
00083 do {
00084 face_set->coordIndex.set1Value( i++, vertex_index[&*h->vertex()] );
00085 } while ( ++h != f->facet_begin());
00086
00087 face_set->coordIndex.set1Value( i++, -1 );
00088 ++facet_index;
00089 }
00090 root->addChild(face_set);
00091 return root;
00092 }