From 68c01e9caece414aa03d0973188d6f1ea3882573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 8 Sep 2015 10:45:13 +0200 Subject: [PATCH] add constructor from point, point range and segment --- Nef_3/doc/Nef_3/CGAL/Nef_polyhedron_3.h | 27 ++++++++++- Nef_3/include/CGAL/Nef_polyhedron_3.h | 48 ++++++++++++++++++++ Nef_3/test/Nef_3/nef_3_from_points.cpp | 59 +++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 Nef_3/test/Nef_3/nef_3_from_points.cpp diff --git a/Nef_3/doc/Nef_3/CGAL/Nef_polyhedron_3.h b/Nef_3/doc/Nef_3/CGAL/Nef_polyhedron_3.h index bf4cd3a6224..b4818937343 100644 --- a/Nef_3/doc/Nef_3/CGAL/Nef_polyhedron_3.h +++ b/Nef_3/doc/Nef_3/CGAL/Nef_polyhedron_3.h @@ -1128,6 +1128,11 @@ public: */ typedef unspecified_type Polylines_tag; +/*! + tag for calling point constructor. +*/ + typedef unspecified_type Points_tag; + /*! construction selection. */ @@ -1198,7 +1203,27 @@ public: */ template Nef_polyhedron_3(Forward_iterator it, Forward_iterator end, - Polylines_tag); + Polylines_tag); + +/*! + creates a Nef polyhedron that consists only of points. + The iterator range [it, end) defines a range of points. +*/ + template + Nef_polyhedron_3(Forward_iterator it, Forward_iterator end, + Points_tag); + +/*! + creates a Nef polyhedron that consists of point p. +*/ + explicit + Nef_polyhedron_3(const Point_3& p); + +/*! + creates a Nef polyhedron that consists of segment s. +*/ + explicit + Nef_polyhedron_3(const Segment_3& s); /// @} diff --git a/Nef_3/include/CGAL/Nef_polyhedron_3.h b/Nef_3/include/CGAL/Nef_polyhedron_3.h index 176de242b64..81ed498efb4 100644 --- a/Nef_3/include/CGAL/Nef_polyhedron_3.h +++ b/Nef_3/include/CGAL/Nef_polyhedron_3.h @@ -188,6 +188,7 @@ class Nef_polyhedron_3 : public CGAL::Handle_for< Nef_polyhedron_3_rep smc; + std::vector endpoints(2); + endpoints[0]=s.source(); + endpoints[1]=s.target(); + smc.create_end_sphere_map(snc(),&endpoints[0],&endpoints[1]); + smc.create_end_sphere_map(snc(),&endpoints[1],&endpoints[0]); + + build_external_structure(); + simplify(); + } + + template + Nef_polyhedron_3(InputIterator begin, InputIterator end, Points_tag) { + empty_rep(); + set_snc(snc()); + initialize_infibox_vertices(EMPTY); + + for(InputIterator it=begin; it!=end;++it) + { + Vertex_handle v(snc().new_vertex(*it, true)); + SM_decorator SM(&*v); + v->new_sface(); + } + build_external_structure(); + simplify(); + } + + explicit + Nef_polyhedron_3(const Point_3& p) { + empty_rep(); + set_snc(snc()); + initialize_infibox_vertices(EMPTY); + + Vertex_handle v(snc().new_vertex(p, true)); + SM_decorator SM(&*v); + v->new_sface(); + + build_external_structure(); + simplify(); + } + template class T3, class T4 > diff --git a/Nef_3/test/Nef_3/nef_3_from_points.cpp b/Nef_3/test/Nef_3/nef_3_from_points.cpp new file mode 100644 index 00000000000..86475cd70f9 --- /dev/null +++ b/Nef_3/test/Nef_3/nef_3_from_points.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; +typedef Kernel::Point_3 Point_3; +typedef Kernel::Segment_3 Segment_3; + +typedef CGAL::Polyhedron_3 Polyhedron; +typedef CGAL::Nef_polyhedron_3 Nef_polyhedron; +typedef std::vector::iterator point_iterator; + +int main() { + + std::vector points; + + points.push_back(Point_3(1,2,3)); + points.push_back(Point_3(1,2,5)); + + Nef_polyhedron N1(points.begin(), points.end(), Nef_polyhedron::Points_tag()); + Nef_polyhedron N2(points.begin(), points.end(), Nef_polyhedron::Points_tag()); + + Nef_polyhedron N3(Segment_3(Point_3(1,2,3),Point_3(1,2,5))); + Nef_polyhedron N4(Segment_3(Point_3(1,2,3),Point_3(1,2,-5))); + + Nef_polyhedron N5(Point_3(1,2,3)); + + // test non emptyness + assert(!N1.is_empty()); + assert(!N2.is_empty()); + assert(!N3.is_empty()); + assert(!N4.is_empty()); + assert(!N5.is_empty()); + // test validitiy + assert(N1.is_valid()); + assert(N2.is_valid()); + assert(N3.is_valid()); + assert(N4.is_valid()); + assert(N5.is_valid()); + // test points-points intersection + N1*=N2; + assert(N1.is_valid()); + assert(N1==N2); + // test segment-segment intersection + assert( N3*N4 == N5 ); + // test point-segment intersection + assert( (N1*N3).is_valid() ); + assert( N1*N3 == N1 ); + // test points-points difference + assert( (N1-N2).is_valid() ); + assert( (N1-N2).is_empty() ); + // test opening and closing segment + assert( ((N3-N4)+N5).is_valid() ); + assert( ((N3-N4)+N5)==N3 ); + assert( ((N3-N4)*N5).is_empty() ); + + return 0; +}