mirror of https://github.com/CGAL/cgal
Merge pull request #325 from sloriot/Nef_3-add_construction_from_points-sloriot
add constructor from point, point range and segment
This commit is contained in:
commit
271325c5c3
|
|
@ -1128,6 +1128,11 @@ public:
|
|||
*/
|
||||
typedef unspecified_type Polylines_tag;
|
||||
|
||||
/*!
|
||||
tag for calling point constructor.
|
||||
*/
|
||||
typedef unspecified_type Points_tag;
|
||||
|
||||
/*!
|
||||
construction selection.
|
||||
*/
|
||||
|
|
@ -1200,7 +1205,27 @@ public:
|
|||
*/
|
||||
template <class Forward_iterator>
|
||||
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 <class Forward_iterator>
|
||||
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);
|
||||
|
||||
/// @}
|
||||
|
||||
|
|
|
|||
|
|
@ -188,6 +188,7 @@ class Nef_polyhedron_3 : public CGAL::Handle_for< Nef_polyhedron_3_rep<Kernel_,
|
|||
#endif
|
||||
|
||||
struct Polylines_tag {};
|
||||
struct Points_tag {};
|
||||
|
||||
enum Boundary { EXCLUDED=0, INCLUDED=1 };
|
||||
/*{\Menum construction selection.}*/
|
||||
|
|
@ -555,6 +556,53 @@ protected:
|
|||
simplify();
|
||||
}
|
||||
|
||||
explicit
|
||||
Nef_polyhedron_3(const Segment_3& s) {
|
||||
empty_rep();
|
||||
set_snc(snc());
|
||||
initialize_infibox_vertices(EMPTY);
|
||||
|
||||
Sphere_map_creator<Items, SNC_structure> smc;
|
||||
std::vector<Point_3> 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 <typename InputIterator>
|
||||
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 T1, class T2,
|
||||
template <class T31, class T32, class T33>
|
||||
class T3, class T4 >
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
#include <CGAL/Nef_polyhedron_3.h>
|
||||
#include <CGAL/IO/Nef_polyhedron_iostream_3.h>
|
||||
#include <vector>
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
||||
typedef Kernel::Point_3 Point_3;
|
||||
typedef Kernel::Segment_3 Segment_3;
|
||||
|
||||
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
|
||||
typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
|
||||
typedef std::vector<Point_3>::iterator point_iterator;
|
||||
|
||||
int main() {
|
||||
|
||||
std::vector<Point_3> 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;
|
||||
}
|
||||
Loading…
Reference in New Issue