00001 #include "ObjFile_inserter.h"
00002 #include <CGAL/Point_3.h>
00003 #include "set_point.h"
00004
00005
00006
00007 #define CHECK_INDICES 1
00008 #define REPORT_INDICES 0
00009
00010
00011
00015 void MNI::ObjFile_inserter::Polygons::operator() ( HDS& hds )
00016 {
00017 int n_vert = poly.n_points;
00018 int n_face = poly.n_items;
00019
00020 int n_hedge = 0;
00021 for( int i = 0; i < n_face; ++i ) {
00022 n_hedge += GET_OBJECT_SIZE( poly, i );
00023 }
00024
00025
00026 CGAL::Polyhedron_incremental_builder_3<HDS> B( hds, true );
00027
00028 B.begin_surface( n_vert, n_face, n_hedge );
00029
00030 HDS::Point p;
00031 for( int i = 0; i < n_vert; ++i ) {
00032 set_point( p, Point_x(poly.points[i]),
00033 Point_y(poly.points[i]),
00034 Point_z(poly.points[i]) );
00035 B.add_vertex( p );
00036 }
00037
00038 for( int i = 0; i < n_face; ++i ) {
00039 int face_size = GET_OBJECT_SIZE( poly, i );
00040 #if REPORT_INDICES
00041 cout << "Facet " << i << " (size " << face_size << "): ";
00042 #endif
00043
00044 #if CHECK_INDICES
00045 if ( face_size == 3 ) {
00046 int v0 = poly.indices[POINT_INDEX(poly.end_indices,i,0)];
00047 int v1 = poly.indices[POINT_INDEX(poly.end_indices,i,1)];
00048 int v2 = poly.indices[POINT_INDEX(poly.end_indices,i,2)];
00049
00050 CGAL_assertion( v0 != v1 );
00051 CGAL_assertion( v1 != v2 );
00052 CGAL_assertion( v2 != v0 );
00053 }
00054 #endif
00055 B.begin_facet();
00056 for( int j = 0; j < face_size; ++j ) {
00057 int v = poly.indices[POINT_INDEX(poly.end_indices,i,j)];
00058 #if REPORT_INDICES
00059 cout << v << " ";
00060 #endif
00061 B.add_vertex_to_facet( v );
00062 }
00063 #if REPORT_INDICES
00064 cout << "." << endl;
00065 #endif
00066 B.end_facet();
00067 }
00068
00069 B.end_surface();
00070 }
00071
00072
00073
00074