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

hexa_poly_intersect.cc

00001 #include "hexa_poly_intersect.h"
00002 #include "oogl.h"
00003 #include "tester.h"
00004 
00005 
00006 class hexa_poly_intersect_test : public CppUnit::TestCase
00007 {
00008     typedef CGAL::Point_3<Exact_rep>   Point;
00009     typedef CGAL::Plane_3<Exact_rep>   Plane;
00010     typedef Polyhedron::Facet          Facet;
00011     typedef Polyhedron::Point          PolyPoint;
00012 
00013 
00014     Hexahedron_3* hp;
00015     Hexahedron_3* hp2;
00016 
00017     Polyhedron poly;
00018     Facet* ifp;           // initial facet pointer
00019 
00020 
00021 public:
00022 
00023     void setUp()
00024     {
00025         hp = new Hexahedron_3( Point(0,0,0),
00026                                Point(1,0,0),
00027                                Point(1,1,0),
00028                                Point(0,1,0),
00029                                Point(0,0,1),
00030                                Point(0,1,1),
00031                                Point(1,0,1),
00032                                Point(1,1,1) );
00033 
00034         // hp2 = hp translated by (0,0,1)
00035         hp2 = new Hexahedron_3( Point(0,0,1),
00036                                 Point(1,0,1),
00037                                 Point(1,1,1),
00038                                 Point(0,1,1),
00039                                 Point(0,0,2),
00040                                 Point(0,1,2),
00041                                 Point(1,0,2),
00042                                 Point(1,1,2) );
00043 
00044         poly.make_triangle( PolyPoint(50,-101,50,100),  // (0.5, -1.01, 0.5)
00045                             PolyPoint(101,50,50,100),   // (1.01, 0.5, 0.5)
00046                             PolyPoint(50,101,50,100) ); // (0.5, 1.01, 0.5)
00047 
00048         ifp = &* poly.facets_begin();
00049         ifp->label = 0;
00050     }
00051 
00052     
00053     // Add second facet, completely outside the hexahedron
00054     void add_second_facet()
00055     {
00056         poly.make_triangle( PolyPoint(100,100,100),
00057                             PolyPoint(101,101,100),
00058                             PolyPoint(101,100,101) );
00059     }
00060 
00061 
00062     void tearDown()
00063     {
00064         delete hp;
00065         poly.erase_all();
00066     }
00067 
00068 
00069     void check_fhv( int n_facets, int n_halfedges, int n_vertices )
00070     {
00071         // Cast second arg to int, to avoid matching
00072         // CppUnit::TestAsser::assertEquals(double,double,double,...)
00073         CPPUNIT_ASSERT_EQUAL( n_facets, int(poly.size_of_facets()) );
00074         CPPUNIT_ASSERT_EQUAL( n_halfedges, int(poly.size_of_halfedges()) );
00075         CPPUNIT_ASSERT_EQUAL( n_vertices, int(poly.size_of_vertices()) );
00076     }
00077 
00078     void check_fhv_before() { check_fhv(1,6,3); }
00079     void check_fhv_after() { check_fhv(4,24,9); }
00080 
00081 
00082     void t_01()
00083     {
00084         check_fhv_before();
00085         CPPUNIT_ASSERT_EQUAL( 4, slice_poly_with_hexa( poly, *ifp, *hp ));
00086         check_fhv_after();
00087     }
00088 
00089 
00090     void t_01_bis()
00091     {
00092         check_fhv_before();
00093         CPPUNIT_ASSERT_EQUAL( 4, 
00094                               slice_poly_with_hexa( poly, 
00095                                                     poly.facets_begin(),
00096                                                     poly.facets_end(),
00097                                                     *hp ));
00098         check_fhv_after();
00099         CPPUNIT_ASSERT_EQUAL( 4, 
00100                               slice_poly_with_hexa( poly, 
00101                                                     poly.facets_begin(),
00102                                                     poly.facets_end(),
00103                                                     *hp ));
00104         check_fhv_after();
00105     }
00106 
00107 
00108     void t_02()
00109     {
00110         std::list<Facet*> f_list;
00111 
00112         check_fhv_before();
00113         int n_facet = slice_poly_with_hexa( poly, *ifp, *hp,
00114                                             std::back_inserter(f_list) );
00115         CPPUNIT_ASSERT_EQUAL( 4, n_facet );
00116         CPPUNIT_ASSERT_EQUAL( 4, int(f_list.size()) );
00117         check_fhv_after();
00118     }
00119 
00120 
00121     void t_03()
00122     {
00123         check_fhv_before();
00124         label_poly_with_hexa(poly,*ifp,*hp,1);
00125         check_fhv_after();
00126 
00127         poly.normalize_border();
00128         CPPUNIT_ASSERT_EQUAL( 9, int(poly.size_of_border_halfedges()) );
00129 
00130         int label_count = 0;
00131         Polyhedron::Facet_const_iterator it;
00132         for( it = poly.facets_begin(); it != poly.facets_end(); ++it )
00133         {
00134             if ( it->label != 0 ) {
00135                 CPPUNIT_ASSERT_EQUAL( 1, it->label );
00136                 CPPUNIT_ASSERT( ++label_count == 1 );
00137             }
00138         }
00139     }
00140 
00141 
00142     void t_04()
00143     {
00144         add_second_facet();
00145         check_fhv(2,12,6);
00146         int n_facet = slice_poly_with_hexa( poly,
00147                                             poly.facets_begin(), 
00148                                             poly.facets_end(),
00149                                             *hp );
00150         CPPUNIT_ASSERT_EQUAL( 5, n_facet );
00151         check_fhv(5,30,12);
00152     }
00153 
00154 
00155     void t_05()
00156     {
00157         std::list<Facet*> f_list;
00158 
00159         add_second_facet();
00160         int n_facet = slice_poly_with_hexa( poly,
00161                                             poly.facets_begin(), 
00162                                             poly.facets_end(),
00163                                             *hp, 
00164                                             std::back_inserter(f_list) );
00165         CPPUNIT_ASSERT_EQUAL( 5, n_facet );
00166         CPPUNIT_ASSERT_EQUAL( 5, int(f_list.size()) );
00167         check_fhv(5,30,12);
00168     }
00169 
00170 
00171 
00172     void t_06()
00173     {
00174         add_second_facet();
00175         slice_poly_with_hexa( poly,
00176                               *hp );
00177         check_fhv(5,30,12);
00178     }
00179 
00180 
00181     void t_07()
00182     {
00183         std::list<Facet*> f_list;
00184 
00185         check_fhv_before();
00186 
00187         Hexahedron_3* h_list[2] = { hp, hp2 };
00188         int n_facet = slice_poly_with_hexa( poly, *ifp, 
00189                                             h_list, h_list + 2,
00190                                             std::back_inserter(f_list) );
00191         CPPUNIT_ASSERT_EQUAL( 4, n_facet );
00192         CPPUNIT_ASSERT_EQUAL( 4, int(f_list.size()) );
00193         check_fhv_after();
00194     }
00195 
00196 
00197 
00198     CPPUNIT_TEST_SUITE( hexa_poly_intersect_test );
00199     CPPUNIT_TEST( t_01 );
00200     CPPUNIT_TEST( t_01_bis );
00201     CPPUNIT_TEST( t_02 );
00202     CPPUNIT_TEST( t_03 );
00203     CPPUNIT_TEST( t_04 );
00204     CPPUNIT_TEST( t_05 );
00205     CPPUNIT_TEST( t_06 );
00206     CPPUNIT_TEST( t_07 );
00207     CPPUNIT_TEST_SUITE_END();
00208 };
00209 
00210 
00211 CPPUNIT_TEST_SUITE_REGISTRATION( hexa_poly_intersect_test );
00212 
00213 

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