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

check-surface-intersect.cc

00001 #include <ostream>
00002 #include <fstream>
00003 #include <iterator>
00004 #include <functional>
00005 #include <boost/iterator_adaptors.hpp>
00006 
00007 #include "poly.h"
00008 #include "ObjFile.h"
00009 #include "poly_poly_intersect.h"
00010 #include "oogl.h"
00011 
00012 #include <Inventor/nodes/SoSeparator.h>
00013 #include "poly_iv.h"
00014 #include "obj_iv.h"
00015 #include "inventor/SceneViewer.h"
00016 
00017 
00018 #include <CGAL/algorithm.h>
00019 #include <CGAL/Timer.h>
00020 #include <CGAL/Triangle_3.h>
00021 
00022 #include "ParseArgv.h"
00023 
00024 
00025 
00026 static char* output_oogl_filename = 0;
00027 static int output_inventor_display;
00028 
00029 
00030 ArgvInfo argTable[] = {
00031     { "-iv", ARGV_CONSTANT, (char*)1, (char*)&output_inventor_display,
00032       "show output in inventor window" },
00033     { "-oogl", ARGV_STRING, (char*)1, (char*)&output_oogl_filename,
00034       "write output in OOGL format" },
00035     { NULL, ARGV_END, NULL, NULL, NULL }
00036 };
00037 
00038 
00039 
00040 static inline
00041 void check_facet( const Polyhedron::Facet& f ) {
00042     Polyhedron::Halfedge_const_handle h = f.halfedge();
00043 
00044     CGAL_assertion( h->next()->next()->next() == h );
00045 
00046     typedef Polyhedron::Point Point;
00047     typedef Point::R R;
00048     typedef CGAL::Triangle_3<R> Triangle;
00049 
00050     Point a = h->opposite()->vertex()->point();
00051     Point b = h->vertex()->point();
00052     Point c = h->next()->vertex()->point();
00053     Triangle T(a,b,c);
00054 
00055     CGAL_exactness_assertion_code
00056         ( if ( T.is_degenerate() ) {
00057             std::cerr << "A degenerate: " << T << std::endl; 
00058             std::cerr << "Point a = " << a << std::endl;
00059             std::cerr << "Point b = " << b << std::endl;
00060             std::cerr << "Point c = " << c << std::endl;
00061         }
00062           );
00063 }
00064 
00065 
00066 
00067 
00068 // Reads all objects in file
00069 Polyhedron read_bicobj( char* filename )
00070 {
00071     std::cout << "Loading objects from file: " << filename << std::endl;
00072 
00073     Polyhedron mesh;
00074     MNI::Object_file objfile( filename );
00075 
00076     int n_obj = objfile.size_of_objects();
00077     if ( n_obj > 3000 )
00078         n_obj = 3;
00079 
00080     for ( int i = 0; i < n_obj; ++i ) {
00081         std::cout << "Loading object " << i << "/" << n_obj << std::endl;
00082         objfile.insert( i, true, mesh );
00083     }
00084 
00085     //mesh.normalize_border();
00086 
00087     std::for_each( mesh.facets_begin(),
00088                    mesh.facets_end(),
00089                    check_facet );
00090 
00091     std::cout << "BIC OBJ file loaded:" << std::endl
00092          << "    vertices: " << mesh.size_of_vertices() << std::endl
00093          << "    half-edges: " << mesh.size_of_halfedges() << std::endl
00094         //<< "    border edges: " << mesh.size_of_border_edges() << std::endl
00095         //<< "    border half-edges: " << mesh.size_of_border_halfedges() << std::endl
00096          << "    facets: " << mesh.size_of_facets() << std::endl;
00097 
00098     return mesh;
00099 }
00100     
00101 
00102 
00103 
00104 void usage( char* argv0 )
00105 {
00106     char* s = strrchr( argv0, '/' );
00107     if ( s ) argv0 = s+1;
00108 
00109     std::cerr << "usage: " << argv0 << " [options] mesh1 mesh2" << std::endl;
00110 }
00111 
00112 
00113 int main( int ac, char* av[] )
00114 {
00115     if ( ParseArgv( &ac, av, argTable, 0 ) ) {
00116         usage( av[0] );
00117         return 1;
00118     }
00119     if ( ac != 3 ) {
00120         usage( av[0] );
00121         return 1;
00122     }
00123     CGAL::set_pretty_mode( std::cout );
00124     CGAL::set_pretty_mode( std::cerr );
00125 
00126     Polyhedron mesh1 = read_bicobj( av[1] );
00127     Polyhedron mesh2 = read_bicobj( av[2] );
00128 
00129     typedef std::vector<Facet_pair_intersection> FPI_list;
00130     FPI_list i_list;
00131 
00132     CGAL::Timer t;
00133     t.start();
00134     poly_poly_intersect_facet( mesh1, mesh2,
00135                                std::back_inserter(i_list) );
00136     t.stop();
00137 
00138     std::cout << t.time() << " seconds, " << std::endl;
00139 
00140     typedef FPI_list::iterator It1;
00141     typedef boost::transform_iterator_generator<std::select2nd<Facet_pair_intersection>,It1>::type It2;
00142 
00143 
00144     if ( output_oogl_filename != 0 ) {
00145         std::ofstream out( output_oogl_filename );
00146 
00147         It2 begin( i_list.begin() );
00148         It2 end( i_list.end() );
00149 
00150         write_oogl_vect<Exact_rep,It2>( out, begin, end );
00151     } else {
00152         output_inventor_display = 1;
00153     }
00154 
00155     if ( output_inventor_display ) {
00156         viewer_init( "iv-surface-intersect" );
00157         SoSeparator* root = new SoSeparator;
00158 
00159         root->addChild( polyhedron_to_iv(mesh1) );
00160         root->addChild( polyhedron_to_iv(mesh2) );
00161 
00162         It2 begin( i_list.begin() );
00163         It2 end( i_list.end() );
00164         for( It2 i = begin; i != end; ++i ) {
00165             root->addChild( obj_to_iv(*i) );
00166         }
00167  
00168         viewer_main( root );
00169     }
00170 
00171     return 0;
00172 }

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