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

poly_cut.cc

00001 #include "poly_cut.h"
00002 #include "poly_intersect.h"
00003 #include "tester.h"
00004 #include "poly_assertions.h"
00005 
00006 #include <list>
00007 #include <string>
00008 
00009 
00010 
00011 class poly_cut_test : public CppUnit::TestCase
00012 {
00013     //typedef CGAL::Point_3<Exact_rep>   Point;
00014     typedef Polyhedron::Point          Point;
00015     typedef CGAL::Plane_3<Exact_rep>   Plane;
00016     typedef Polyhedron::Facet          Facet;
00017     typedef Polyhedron::Halfedge       Halfedge;
00018 
00019 
00020     // points for polyhedron definition
00021     Point a,b,c,d;
00022 
00023     Polyhedron poly;
00024 
00025     // Slicing planes
00026     Plane planeZ, planeX;
00027     Plane p_list[2];
00028 
00029     // Intersection points
00030     Point u,  // planeZ intersection with ac
00031           v,  // .. intersection with bc
00032           w;  // .. intersection with dc
00033 
00034 
00035 public:
00036     void setUp() 
00037     {
00038         a = Point(2,2,-1);
00039         b = Point(-2,-2,-1);
00040         c = Point(0,0,1);
00041         d = Point(2,-2,-1);
00042 
00043         planeZ = Plane(0,0,1,0);   // plane Z = 0, positive up
00044         planeX = Plane(1,0,0,0);   // plane X = 0
00045 
00046         p_list[0] = planeX;
00047         p_list[1] = planeZ;
00048 
00049         u = Point(1,1,0);
00050         v = Point(-1,-1,0);
00051         w = Point(1,-1,0);
00052     }
00053 
00054     void tearDown()
00055     {
00056         poly.erase_all();
00057     }
00058 
00059  
00060     void check_fhv( int n_facets, int n_halfedges, int n_vertices )
00061     {
00062         assert_poly_combinatorics( poly, n_facets, n_halfedges, n_vertices );
00063     }
00064 
00065 
00066 
00067 
00068     void cut_single_single()
00069     {
00070         poly.make_triangle(a,b,c);
00071         check_fhv(1,6,3);
00072 
00073         Polyhedron::Facet_const_handle f = check_facet(poly,a,b,c);
00074         CPPUNIT_ASSERT( do_intersect_positive(*f,planeZ) );
00075 
00076         Polyhedron::Facet* f_new = cut( poly, *(poly.facets_begin()), planeZ );
00077         CPPUNIT_ASSERT( f_new );
00078         CPPUNIT_ASSERT( f_new != &*f );
00079         check_fhv(2,12,5);
00080 
00081         poly.normalize_border();
00082         CPPUNIT_ASSERT_EQUAL( 5, int(poly.size_of_border_halfedges()) );
00083 
00084         f = check_facet(poly,a,b,v,u);
00085         CPPUNIT_ASSERT( !do_intersect_positive(*f,planeZ) );
00086         f = check_facet(poly,c,u,v);
00087         CPPUNIT_ASSERT( do_intersect_positive(*f,planeZ) );
00088     }
00089 
00090 
00091     void cut_single_multiple()
00092     {
00093         poly.make_triangle(a,b,c);
00094         CPPUNIT_ASSERT_EQUAL( 4, cut( poly, *(poly.facets_begin()), 
00095                                       &p_list[0], &p_list[2] ));
00096     }
00097 
00098 
00099     void cut_single_multiple_outlist()
00100     {
00101         poly.make_triangle(a,b,c);
00102         std::list<Facet*> f_list;
00103         
00104         int n_facets = cut( poly, *(poly.facets_begin()),
00105                             &p_list[0], &p_list[2], 
00106                            std::back_inserter(f_list) );
00107         CPPUNIT_ASSERT_EQUAL( 4, n_facets );
00108         CPPUNIT_ASSERT_EQUAL( 4, int(f_list.size()) );
00109     }
00110 
00111 
00112     void cut_multiple_single()
00113     {
00114         poly.make_tetrahedron(a,b,c,d);
00115         check_fhv(4,12,4);
00116 
00117         Polyhedron::Facet_const_handle f;
00118 
00119         f = check_facet(poly,a,b,c);
00120         CPPUNIT_ASSERT( do_intersect_positive(*f,planeZ) );
00121         f = check_facet(poly,b,d,c);
00122         CPPUNIT_ASSERT( do_intersect_positive(*f,planeZ) );
00123         f = check_facet(poly,d,a,c);
00124         CPPUNIT_ASSERT( do_intersect_positive(*f,planeZ) );
00125         f = check_facet(poly,a,d,b);
00126         CPPUNIT_ASSERT( !do_intersect_positive(*f,planeZ) );
00127 
00128         cut( poly, poly.facets_begin(), poly.facets_end(), planeZ );
00129         check_fhv(7,24,7);
00130 
00131         poly.normalize_border();
00132         CPPUNIT_ASSERT_EQUAL( 0, int(poly.size_of_border_halfedges()) );
00133 
00134         // original facet abc
00135         f = check_facet(poly,a,b,v,u);
00136         CPPUNIT_ASSERT( !do_intersect_positive(*f,planeZ) );
00137         f = check_facet(poly,c,u,v);
00138         CPPUNIT_ASSERT( do_intersect_positive(*f,planeZ) );
00139 
00140         // original facet bdc
00141         f = check_facet(poly,b,d,w,v);
00142         CPPUNIT_ASSERT( !do_intersect_positive(*f,planeZ) );
00143         f = check_facet(poly,c,v,w);
00144         CPPUNIT_ASSERT( do_intersect_positive(*f,planeZ) );
00145 
00146         // original facet dac
00147         f = check_facet(poly,d,a,u,w);
00148         CPPUNIT_ASSERT( !do_intersect_positive(*f,planeZ) );
00149         f = check_facet(poly,c,w,u);
00150         CPPUNIT_ASSERT( do_intersect_positive(*f,planeZ) );
00151 
00152         // original facet adb (not split)
00153         f = check_facet(poly,a,d,b);
00154         CPPUNIT_ASSERT( !do_intersect_positive(*f,planeZ) );
00155     }
00156 
00157 
00158     void cut_multiple_multiple()
00159     {
00160         poly.make_tetrahedron(a,b,c,d);
00161 
00162         // Tetrahedron has 4 facets, 6 edges, and 4 vertices
00163         // Cutting by planeZ cuts off the top, adding 3 facets and 3 vertices
00164         // and hence 6 edges (Euler's formula requires E = F+V-2)
00165         // Cutting by planeX will add 5 facets, 4 vertices, and 9 edges
00166         // for a total of F=12, V=11, E=21.
00167 
00168         check_fhv(4,12,4);
00169         int n = cut( poly, poly.facets_begin(), poly.facets_end(),
00170                      &p_list[0], &p_list[2] );
00171         check_fhv(12,42,11);
00172         CPPUNIT_ASSERT_EQUAL( 12, n );
00173 
00174         // TODO: a full check of the 12 facets
00175     }
00176 
00177 
00178     void cut_multiple_multiple_outlist()
00179     {
00180         poly.make_tetrahedron(a,b,c,d);
00181         std::list<Facet*> f_list;
00182         
00183         int n = cut( poly, poly.facets_begin(), poly.facets_end(),
00184                      &p_list[0], &p_list[2], 
00185                      std::back_inserter(f_list) );
00186         CPPUNIT_ASSERT_EQUAL( 12, n );
00187         CPPUNIT_ASSERT_EQUAL( 12, int(f_list.size()) );
00188     }
00189 
00190 
00191 
00192 
00193     CPPUNIT_TEST_SUITE( poly_cut_test );
00194     CPPUNIT_TEST( cut_single_single );
00195     CPPUNIT_TEST( cut_single_multiple );
00196     CPPUNIT_TEST( cut_single_multiple_outlist );
00197     CPPUNIT_TEST( cut_multiple_single );
00198     CPPUNIT_TEST( cut_multiple_multiple );
00199     CPPUNIT_TEST( cut_multiple_multiple_outlist );
00200     CPPUNIT_TEST_SUITE_END();
00201 };
00202 
00203 CPPUNIT_TEST_SUITE_REGISTRATION( poly_cut_test );
00204 
00205 

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