mirror of https://github.com/CGAL/cgal
More changes after review
This commit is contained in:
parent
a5f09f89a6
commit
9a8f26ced7
|
|
@ -47,15 +47,12 @@ intersection(const CGAL::Bbox_3& a,
|
||||||
if(!do_intersect(a,b))
|
if(!do_intersect(a,b))
|
||||||
return Result_type();
|
return Result_type();
|
||||||
|
|
||||||
double xmin, xmax, ymin, ymax, zmin, zmax;
|
double xmin = (std::max)(a.xmin(), b.xmin());
|
||||||
xmin = (std::max)(a.xmin(), b.xmin());
|
double xmax = (std::min)(a.xmax(), b.xmax());
|
||||||
xmax = (std::min)(a.xmax(), b.xmax());
|
double ymin = (std::max)(a.ymin(), b.ymin());
|
||||||
|
double ymax = (std::min)(a.ymax(), b.ymax());
|
||||||
ymin = (std::max)(a.ymin(), b.ymin());
|
double zmin = (std::max)(a.zmin(), b.zmin());
|
||||||
ymax = (std::min)(a.ymax(), b.ymax());
|
double zmax = (std::min)(a.zmax(), b.zmax());
|
||||||
|
|
||||||
zmin = (std::max)(a.zmin(), b.zmin());
|
|
||||||
zmax = (std::min)(a.zmax(), b.zmax());
|
|
||||||
|
|
||||||
return Result_type(std::forward<Bbox_3>(Bbox_3(xmin, ymin, zmin, xmax, ymax, zmax)));
|
return Result_type(std::forward<Bbox_3>(Bbox_3(xmin, ymin, zmin, xmax, ymax, zmax)));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,20 +33,17 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
||||||
namespace Intersections {
|
namespace Intersections {
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
template<typename Point>
|
template<typename Point>
|
||||||
void filter_points(const std::vector<Point>& input,
|
void filter_points(std::vector<Point>& input,
|
||||||
std::vector<Point>& output)
|
std::vector<Point>& output)
|
||||||
{
|
{
|
||||||
std::set<Point> tmp;
|
std::sort(input.begin(), input.end());
|
||||||
for( auto p : input)
|
auto last = std::unique(input.begin(), input.end());
|
||||||
tmp.insert(p);
|
input.erase(last, input.end());
|
||||||
for(auto p: tmp)
|
output = std::move(input);
|
||||||
output.push_back(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Tetrahedron_3 Line_3
|
//Tetrahedron_3 Line_3
|
||||||
|
|
@ -55,7 +52,7 @@ typename Intersection_traits<K, typename K::Iso_cuboid_3, typename K::Plane_3>::
|
||||||
intersection(
|
intersection(
|
||||||
const typename K::Iso_cuboid_3 &cub,
|
const typename K::Iso_cuboid_3 &cub,
|
||||||
const typename K::Plane_3 &pl,
|
const typename K::Plane_3 &pl,
|
||||||
const K&)
|
const K& k)
|
||||||
{
|
{
|
||||||
typedef typename K::Point_3 Point_3;
|
typedef typename K::Point_3 Point_3;
|
||||||
typedef typename K::Segment_3 Segment_3;
|
typedef typename K::Segment_3 Segment_3;
|
||||||
|
|
@ -74,11 +71,11 @@ intersection(
|
||||||
|
|
||||||
//get all edges of cub
|
//get all edges of cub
|
||||||
for(int i=0; i< 4; ++i)
|
for(int i=0; i< 4; ++i)
|
||||||
edges.push_back(Segment_3(cub.vertex(i), cub.vertex((i+1)%4)));
|
edges.emplace_back(cub.vertex(i), cub.vertex((i+1)%4));
|
||||||
for(int i=0; i < 4; ++i)
|
for(int i=0; i < 4; ++i)
|
||||||
edges.push_back(Segment_3(cub.vertex(i+4), cub.vertex((i+1)%4+4)));
|
edges.emplace_back(cub.vertex(i+4), cub.vertex((i+1)%4+4));
|
||||||
for(int i=0; i < 4; ++i)
|
for(int i=0; i < 4; ++i)
|
||||||
edges.push_back(Segment_3(cub.vertex(i), cub.vertex((i+1)%4+4)));
|
edges.emplace_back(cub.vertex(i), cub.vertex((i+1)%4+4));
|
||||||
|
|
||||||
//get all intersections between pl and cub edges
|
//get all intersections between pl and cub edges
|
||||||
std::vector<Segment_3> segments;
|
std::vector<Segment_3> segments;
|
||||||
|
|
@ -98,8 +95,14 @@ intersection(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(segments.empty() && points.empty())
|
||||||
|
return result_type();
|
||||||
|
|
||||||
switch(segments.size())
|
switch(segments.size())
|
||||||
{
|
{
|
||||||
|
case 0:
|
||||||
|
//points dealt with later
|
||||||
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
//adj to an edge
|
//adj to an edge
|
||||||
|
|
@ -107,48 +110,48 @@ intersection(
|
||||||
{
|
{
|
||||||
return result_type(std::forward<Segment_3>(segments.front()));
|
return result_type(std::forward<Segment_3>(segments.front()));
|
||||||
}
|
}
|
||||||
//through an edge not on diagonal
|
//plane intersecting through an edge (not 2)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Poly res(4);
|
Poly res(4);
|
||||||
Segment_3 front(segments.front());
|
const Segment_3& entry_seg(segments.front());
|
||||||
Point_3 p1, p2;
|
Point_3 p1, p2;
|
||||||
bool has_p1(false),
|
bool p1_found(false),
|
||||||
has_p2(false);
|
p2_found(false);
|
||||||
|
|
||||||
for(auto p : points)
|
for(const Point_3& p : points)
|
||||||
{
|
{
|
||||||
if(!front.has_on(p))
|
if(!k.equal_3_object()(entry_seg.source(), p)
|
||||||
|
&& ! k.equal_3_object()(entry_seg.target(), p))
|
||||||
{
|
{
|
||||||
if(!has_p1)
|
if(!p1_found)
|
||||||
{
|
{
|
||||||
p1 = p;
|
p1 = p;
|
||||||
has_p1 = true;
|
p1_found = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p2 = p;
|
p2 = p;
|
||||||
has_p2 = true;
|
p2_found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL_assertion(has_p1 && has_p2);
|
CGAL_assertion(p1_found && p2_found);
|
||||||
Segment_3 back(p1,p2);
|
res[0] = entry_seg.target();
|
||||||
res[0] = front.target();
|
|
||||||
|
|
||||||
if((front.target() - front.source())
|
if((entry_seg.target() - p1)
|
||||||
* (back.target() - back.source()) > 0)
|
* (p2 - p1) > 0)
|
||||||
{
|
{
|
||||||
res[1] = back.target();
|
res[1] = p2;
|
||||||
res[2] = back.source();
|
res[2] = p1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res[1] = back.source();
|
res[1] = p1;
|
||||||
res[2] = back.target();
|
res[2] = p2;
|
||||||
}
|
}
|
||||||
res[3] = front.source();
|
res[3] = entry_seg.source();
|
||||||
|
|
||||||
return result_type(std::forward<Poly>(res));
|
return result_type(std::forward<Poly>(res));
|
||||||
}
|
}
|
||||||
|
|
@ -198,16 +201,13 @@ intersection(
|
||||||
|
|
||||||
Poly filtered_points;
|
Poly filtered_points;
|
||||||
filter_points(points, filtered_points);
|
filter_points(points, filtered_points);
|
||||||
if(filtered_points.empty())
|
|
||||||
return result_type();
|
|
||||||
|
|
||||||
//adjacent to a vertex
|
//adjacent to a vertex
|
||||||
if(filtered_points.size() == 1)
|
if(filtered_points.size() == 1)
|
||||||
{
|
{
|
||||||
return result_type(std::forward<Point_3>(filtered_points.front()));
|
return result_type(std::forward<Point_3>(filtered_points.front()));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//get intersections between pl and each face -> line. Foreach line, creates segment with points. Then use helper_function to recover polygon.
|
//get intersections between pl and each face -> line. Foreach line, creates segment with points. Then use helper_function to recover polygon.
|
||||||
typedef typename Intersection_traits<K,
|
typedef typename Intersection_traits<K,
|
||||||
CGAL::Plane_3<K>,
|
CGAL::Plane_3<K>,
|
||||||
|
|
@ -289,7 +289,6 @@ intersection(
|
||||||
return result_type(std::forward<Poly>(res));
|
return result_type(std::forward<Poly>(res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
template <class K>
|
template <class K>
|
||||||
typename Intersection_traits<K, typename K::Iso_cuboid_3, typename K::Plane_3>::result_type
|
typename Intersection_traits<K, typename K::Iso_cuboid_3, typename K::Plane_3>::result_type
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,13 @@ template<class K>
|
||||||
struct Tetrahedron_Line_intersection_3
|
struct Tetrahedron_Line_intersection_3
|
||||||
:public Tetrahedron_lines_intersection_3_base<K, typename K::Line_3, Tetrahedron_Line_intersection_3<K> >
|
:public Tetrahedron_lines_intersection_3_base<K, typename K::Line_3, Tetrahedron_Line_intersection_3<K> >
|
||||||
{
|
{
|
||||||
typedef typename K::Line_3 O;
|
|
||||||
typedef Tetrahedron_lines_intersection_3_base<K, typename K::Line_3,
|
typedef Tetrahedron_lines_intersection_3_base<K, typename K::Line_3,
|
||||||
Tetrahedron_Line_intersection_3<K> > Base;
|
Tetrahedron_Line_intersection_3<K> > Base;
|
||||||
typedef typename Base::Result_type Result_type;
|
typedef typename Base::Result_type Result_type;
|
||||||
Tetrahedron_Line_intersection_3(const typename K::Tetrahedron_3& tet,
|
Tetrahedron_Line_intersection_3(
|
||||||
const O& o):Base(tet,o) {}
|
const typename K::Tetrahedron_3& tet,
|
||||||
|
const typename K::Line_3& o):Base(tet,o)
|
||||||
|
{}
|
||||||
|
|
||||||
bool all_inside_test()
|
bool all_inside_test()
|
||||||
{
|
{
|
||||||
|
|
@ -64,7 +65,7 @@ intersection(
|
||||||
const typename K::Line_3 &line,
|
const typename K::Line_3 &line,
|
||||||
const K&)
|
const K&)
|
||||||
{
|
{
|
||||||
Tetrahedron_lines_intersection_3_base<K, typename K::Line_3, Tetrahedron_Line_intersection_3<K> > solver(tet, line);
|
Tetrahedron_Line_intersection_3<K> solver(tet, line);
|
||||||
solver.do_procede();
|
solver.do_procede();
|
||||||
return solver.output;
|
return solver.output;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Intersections {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
|
||||||
//Tetrahedron_3 Segment_3
|
//Tetrahedron_3 Plane_3
|
||||||
template <class K>
|
template <class K>
|
||||||
typename Intersection_traits<K, typename K::Tetrahedron_3, typename K::Plane_3>::result_type
|
typename Intersection_traits<K, typename K::Tetrahedron_3, typename K::Plane_3>::result_type
|
||||||
intersection(
|
intersection(
|
||||||
|
|
|
||||||
|
|
@ -1215,6 +1215,5 @@ int main()
|
||||||
Test< CGAL::Homogeneous<CGAL::MP_Float> >().run();
|
Test< CGAL::Homogeneous<CGAL::MP_Float> >().run();
|
||||||
Test< CGAL::Epeck >().run(true);
|
Test< CGAL::Epeck >().run(true);
|
||||||
Test< CGAL::Homogeneous<CGAL::Epeck_ft> >().run(true);
|
Test< CGAL::Homogeneous<CGAL::Epeck_ft> >().run(true);
|
||||||
// TODO : test more kernels.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue