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

Quadmesh_inserter.cc

00001 #include "ObjFile_inserter.h"
00002 #include <CGAL/Point_3.h>
00003 #include "set_point.h"
00004 
00005 
00006 // Debugging aids
00007 #define CHECK_INDICES 1
00008 #define REPORT_INDICES 0
00009 
00010 
00011 
00012 void MNI::ObjFile_inserter::Quadmesh::operator() ( HDS& hds )
00013 {
00014     // A quadmesh has m_points rows and n_points columns of points.
00015 
00016     int m_points = qmesh.m;
00017     int n_points = qmesh.n;
00018     int n_vert = m_points * n_points;
00019 
00020     // There are m_patches rows and n_patches columns of patches.
00021     // (m_patches = m_points-1 (open quadmesh) or m_points (closed).
00022     // Each patch will turn into a facet of the polyhedron.
00023 
00024     int m_patches, n_patches;
00025     get_quadmesh_n_objects( &qmesh, &m_patches, &n_patches );
00026     int n_face = m_patches * n_patches;
00027 
00028     // The number of half-edges is tricky, because there may or may
00029     // not be a boundary, so we can't use 4*n_face.
00030     // Instead, count the number of edges, and double them.
00031     // For each row we have one edge for each column of patches, for 
00032     // a total of (m_points * n_patches) "horizontal" edges.
00033     // Similarly, there are (n_points * m_patches) "vertical" edges.
00034 
00035     int n_hedge = 2 * ( m_points*n_patches + n_points*m_patches);
00036 
00037     // If we are going to split each patch into two triangles,
00038     // this adds two new halfedges per patch, and doubles the
00039     // number of faces.
00040 
00041     if ( split_patches ) {
00042         n_hedge += 2 * n_face;
00043         n_face *= 2;
00044     }
00045         
00046     CGAL::Polyhedron_incremental_builder_3<HDS> B( hds, true );
00047 
00048     B.begin_surface( n_vert, n_face, n_hedge );
00049 
00050     HDS::Point p;
00051     for( int i = 0; i < n_vert; ++i ) {
00052         set_point( p, Point_x(qmesh.points[i]),
00053                       Point_y(qmesh.points[i]),
00054                       Point_z(qmesh.points[i]) );
00055         B.add_vertex( p );
00056     }
00057 
00058     int facet_index[4];
00059     for( int i = 0; i < m_patches; ++i ) {
00060         for( int j = 0; j < n_patches; ++j ) {
00061             get_quadmesh_patch_indices( &qmesh, i, j, facet_index );
00062 
00063 
00064             CGAL_assertion( facet_index[0] != facet_index[1] );
00065             CGAL_assertion( facet_index[0] != facet_index[2] );
00066             CGAL_assertion( facet_index[0] != facet_index[3] );
00067             CGAL_assertion( facet_index[1] != facet_index[2] );
00068             CGAL_assertion( facet_index[1] != facet_index[3] );
00069             CGAL_assertion( facet_index[2] != facet_index[3] );
00070 
00071             if ( split_patches ) {
00072                 B.begin_facet();
00073                 B.add_vertex_to_facet( facet_index[0] );
00074                 B.add_vertex_to_facet( facet_index[1] );
00075                 B.add_vertex_to_facet( facet_index[2] );
00076                 B.end_facet();
00077                 B.begin_facet();
00078                 B.add_vertex_to_facet( facet_index[2] );
00079                 B.add_vertex_to_facet( facet_index[3] );
00080                 B.add_vertex_to_facet( facet_index[0] );
00081                 B.end_facet();
00082             } else {
00083                 B.begin_facet();
00084                 B.add_vertex_to_facet( facet_index[0] );
00085                 B.add_vertex_to_facet( facet_index[1] );
00086                 B.add_vertex_to_facet( facet_index[2] );
00087                 B.add_vertex_to_facet( facet_index[3] );
00088                 B.end_facet();
00089 
00090             }
00091         }
00092     }
00093 
00094     B.end_surface();
00095 }

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