Enhancements after review

This commit is contained in:
Maxime Gimeno 2020-01-16 17:20:13 +01:00
parent c368b349d5
commit 0f3305f983
16 changed files with 136 additions and 82 deletions

View File

@ -42,7 +42,7 @@ inline bool do_intersect(
template <class K> template <class K>
inline bool do_intersect( inline bool do_intersect(
const Bbox_2 &box, const Bbox_2 &box,
const Segment_2<K> &seg) const Segment_2<K> &seg)
{ {
return do_intersect(seg, box); return do_intersect(seg, box);
} }

View File

@ -42,7 +42,7 @@ inline bool do_intersect(
template <class K> template <class K>
inline bool do_intersect( inline bool do_intersect(
const Bbox_2 &box, const Bbox_2 &box,
const Triangle_2<K> &tr) const Triangle_2<K> &tr)
{ {
return do_intersect(tr, box); return do_intersect(tr, box);
} }

View File

@ -33,10 +33,10 @@ intersection(const CGAL::Bbox_3& a,
const CGAL::Bbox_3& b) const CGAL::Bbox_3& b)
{ {
typedef typename boost::variant<Bbox_3> variant_type; typedef typename boost::variant<Bbox_3> variant_type;
typedef typename boost::optional<variant_type> Result_type; typedef typename boost::optional<variant_type> result_type;
if(!do_intersect(a,b)) if(!do_intersect(a,b))
return Result_type(); return result_type();
double xmin = (std::max)(a.xmin(), b.xmin()); double xmin = (std::max)(a.xmin(), b.xmin());
double xmax = (std::min)(a.xmax(), b.xmax()); double xmax = (std::min)(a.xmax(), b.xmax());
@ -45,7 +45,7 @@ intersection(const CGAL::Bbox_3& a,
double zmin = (std::max)(a.zmin(), b.zmin()); double zmin = (std::max)(a.zmin(), b.zmin());
double zmax = (std::min)(a.zmax(), b.zmax()); double 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)));
} }
} //namespace CGAL } //namespace CGAL

View File

@ -27,18 +27,18 @@ template <class K>
inline bool inline bool
do_intersect(const typename K::Point_3 &pt, do_intersect(const typename K::Point_3 &pt,
const typename K::Line_3 &line, const typename K::Line_3 &line,
const K&) const K& k)
{ {
return line.has_on(pt); return k.has_on_3_object()(line,pt);
} }
template <class K> template <class K>
inline bool inline bool
do_intersect(const typename K::Line_3 &line, do_intersect(const typename K::Line_3 &line,
const typename K::Point_3 &pt, const typename K::Point_3 &pt,
const K&) const K& k)
{ {
return line.has_on(pt); return k.has_on_3_object()(line, pt);
} }
template <class K> template <class K>

View File

@ -27,18 +27,18 @@ template <class K>
inline bool inline bool
do_intersect(const typename K::Point_3 &pt, do_intersect(const typename K::Point_3 &pt,
const typename K::Plane_3 &plane, const typename K::Plane_3 &plane,
const K&) const K& k)
{ {
return plane.has_on(pt); return k.has_on_3_object()(plane,pt);
} }
template <class K> template <class K>
inline bool inline bool
do_intersect(const typename K::Plane_3 &plane, do_intersect(const typename K::Plane_3 &plane,
const typename K::Point_3 &pt, const typename K::Point_3 &pt,
const K&) const K& k)
{ {
return plane.has_on(pt); return k.has_on_3_object()(plane,pt);
} }
template <class K> template <class K>

View File

@ -28,9 +28,9 @@ inline
bool bool
do_intersect(const typename K::Point_3 &pt, do_intersect(const typename K::Point_3 &pt,
const typename K::Ray_3 &ray, const typename K::Ray_3 &ray,
const K&) const K& k)
{ {
return ray.has_on(pt); return k.has_on_3_object()(ray,pt);
} }
@ -39,9 +39,9 @@ inline
bool bool
do_intersect(const typename K::Ray_3 &ray, do_intersect(const typename K::Ray_3 &ray,
const typename K::Point_3 &pt, const typename K::Point_3 &pt,
const K&) const K& k)
{ {
return ray.has_on(pt); return k.has_on_3_object()(ray,pt);
} }

View File

@ -28,9 +28,9 @@ inline
bool bool
do_intersect(const typename K::Point_3 &pt, do_intersect(const typename K::Point_3 &pt,
const typename K::Segment_3 &seg, const typename K::Segment_3 &seg,
const K&) const K& k)
{ {
return seg.has_on(pt); return k.has_on_3_object()(seg, pt);
} }
template <class K> template <class K>
@ -38,9 +38,9 @@ inline
bool bool
do_intersect(const typename K::Segment_3 &seg, do_intersect(const typename K::Segment_3 &seg,
const typename K::Point_3 &pt, const typename K::Point_3 &pt,
const K&) const K& k)
{ {
return seg.has_on(pt); return k.has_on_3_object()(seg, pt);
} }

View File

@ -182,13 +182,62 @@ intersection(
{ {
Poly res; Poly res;
res.reserve(4); res.reserve(4);
std::list<Point_3> tmp; typename K::Has_on_3 has_on;
std::list<Segment_3> seg_list; if(has_on(pl, cub.vertex(0))
for(auto s : segments) && has_on(pl, cub.vertex(5))
seg_list.push_back(s); && has_on(pl, cub.vertex(4)))
fill_points_list(seg_list, tmp); {
for(auto p : tmp) res.push_back(cub.vertex(0));
res.push_back(p); res.push_back(cub.vertex(5));
res.push_back(cub.vertex(4));
res.push_back(cub.vertex(3));
}
else if(has_on(pl, cub.vertex(0))
&& has_on(pl, cub.vertex(1))
&& has_on(pl, cub.vertex(6)))
{
res.push_back(cub.vertex(0));
res.push_back(cub.vertex(1));
res.push_back(cub.vertex(6));
res.push_back(cub.vertex(5));
}
else if(has_on(pl, cub.vertex(1))
&& has_on(pl, cub.vertex(2))
&& has_on(pl, cub.vertex(7)))
{
res.push_back(cub.vertex(1));
res.push_back(cub.vertex(2));
res.push_back(cub.vertex(7));
res.push_back(cub.vertex(6));
}
else if(has_on(pl, cub.vertex(2))
&& has_on(pl, cub.vertex(3))
&& has_on(pl, cub.vertex(4)))
{
res.push_back(cub.vertex(2));
res.push_back(cub.vertex(3));
res.push_back(cub.vertex(4));
res.push_back(cub.vertex(7));
}
else if(has_on(pl, cub.vertex(6))
&& has_on(pl, cub.vertex(7))
&& has_on(pl, cub.vertex(4)))
{
res.push_back(cub.vertex(6));
res.push_back(cub.vertex(7));
res.push_back(cub.vertex(4));
res.push_back(cub.vertex(5));
}
else if(has_on(pl, cub.vertex(2))
&& has_on(pl, cub.vertex(1))
&& has_on(pl, cub.vertex(0)))
{
res.push_back(cub.vertex(2));
res.push_back(cub.vertex(1));
res.push_back(cub.vertex(0));
res.push_back(cub.vertex(3));
}
return result_type(std::forward<Poly>(res)); return result_type(std::forward<Poly>(res));
} }
break; break;
@ -249,11 +298,11 @@ intersection(
} }
std::list<Segment_3> tmp_segs; std::list<Segment_3> tmp_segs;
for(auto line : plane_intersections) for(const auto& line : plane_intersections)
{ {
bool first_found = false; bool first_found = false;
Point_3 first_p; Point_3 first_p;
for(auto p : filtered_points) for(const auto &p : filtered_points)
{ {
if(line.has_on(p)) if(line.has_on(p))
{ {
@ -264,7 +313,7 @@ intersection(
} }
else else
{ {
tmp_segs.push_back(Segment_3(first_p, p)); tmp_segs.emplace_back(first_p, p);
break; break;
} }
} }
@ -275,7 +324,7 @@ intersection(
std::list<Point_3> tmp_pts; std::list<Point_3> tmp_pts;
fill_points_list(tmp_segs,tmp_pts); fill_points_list(tmp_segs,tmp_pts);
Poly res; Poly res;
for(auto p : tmp_pts) for(const auto& p : tmp_pts)
res.push_back(p); res.push_back(p);
if(res.size() == 3){ if(res.size() == 3){
typename K::Triangle_3 tr(res[0], res[1], res[2]); typename K::Triangle_3 tr(res[0], res[1], res[2]);

View File

@ -46,7 +46,7 @@ intersection(
{ {
typedef typename Intersection_traits<K, typedef typename Intersection_traits<K,
typename K::Tetrahedron_3, typename K::Tetrahedron_3,
typename K::Plane_3>::result_type Result_type; typename K::Plane_3>::result_type result_type;
typedef typename Intersection_traits<K, typedef typename Intersection_traits<K,
typename K::Triangle_3, typename K::Triangle_3,
@ -68,7 +68,7 @@ intersection(
if(const typename K::Triangle_3* tr = boost::get<typename K::Triangle_3>(&*intersections[i])) if(const typename K::Triangle_3* tr = boost::get<typename K::Triangle_3>(&*intersections[i]))
{ {
typename K::Triangle_3 res = *tr; typename K::Triangle_3 res = *tr;
return Result_type(std::forward<typename K::Triangle_3>(res)); return result_type(std::forward<typename K::Triangle_3>(res));
} }
else if( const Segment_3* s else if( const Segment_3* s
= boost::get<Segment_3>(&*intersections[i])) = boost::get<Segment_3>(&*intersections[i]))
@ -91,25 +91,25 @@ intersection(
case 0: case 0:
{ {
if(p_id == -1) if(p_id == -1)
return Result_type(); return result_type();
else else
{ {
typename K::Point_3 p typename K::Point_3 p
= *boost::get<typename K::Point_3>(&*intersections[p_id]); = *boost::get<typename K::Point_3>(&*intersections[p_id]);
return Result_type(std::forward<typename K::Point_3>(p)); return result_type(std::forward<typename K::Point_3>(p));
} }
} }
break; break;
case 2: case 2:
{ {
return Result_type(std::forward<typename K::Segment_3>(segments.back())); return result_type(std::forward<typename K::Segment_3>(segments.back()));
} }
break; break;
default: default:
{ {
std::set<typename K::Point_3> all_points; std::set<typename K::Point_3> all_points;
for (auto s : segments) for (const auto& s : segments)
{ {
all_points.insert(s.source()); all_points.insert(s.source());
all_points.insert(s.target()); all_points.insert(s.target());
@ -121,7 +121,7 @@ intersection(
typename K::Point_3 mid_point = *p_it; typename K::Point_3 mid_point = *p_it;
++p_it; ++p_it;
typename K::Triangle_3 result(*all_points.begin(), mid_point, *p_it ); typename K::Triangle_3 result(*all_points.begin(), mid_point, *p_it );
return Result_type(std::forward<typename K::Triangle_3>(result)); return result_type(std::forward<typename K::Triangle_3>(result));
} }
else //size = 4 else //size = 4
{ {
@ -129,14 +129,14 @@ intersection(
std::list<typename K::Point_3> tmp; std::list<typename K::Point_3> tmp;
fill_points_list(segs, tmp); fill_points_list(segs, tmp);
std::vector<typename K::Point_3> res; std::vector<typename K::Point_3> res;
for( auto p : tmp) for( const auto& p : tmp)
res.push_back(p); res.push_back(p);
return Result_type(std::forward<std::vector<typename K::Point_3> >(res)); return result_type(std::forward<std::vector<typename K::Point_3> >(res));
} }
} }
break; break;
} }
return Result_type(); return result_type();
} }
template <class K> template <class K>

View File

@ -41,11 +41,11 @@ typename Intersection_traits<K, typename K::Tetrahedron_3, typename K::Triangle_
intersection( intersection(
const typename K::Tetrahedron_3 &tet, const typename K::Tetrahedron_3 &tet,
const typename K::Triangle_3 &tr, const typename K::Triangle_3 &tr,
const K&) const K& k)
{ {
typedef typename Intersection_traits<K, typedef typename Intersection_traits<K,
typename K::Tetrahedron_3, typename K::Tetrahedron_3,
typename K::Triangle_3>::result_type Result_type; typename K::Triangle_3>::result_type result_type;
typedef typename Intersection_traits<K, typedef typename Intersection_traits<K,
typename K::Triangle_3, typename K::Triangle_3,
@ -83,7 +83,7 @@ intersection(
if(const Triangle_3* t = boost::get<typename K::Triangle_3>(&*intersections[i])) if(const Triangle_3* t = boost::get<typename K::Triangle_3>(&*intersections[i]))
{ {
Triangle_3 res = *t; Triangle_3 res = *t;
return Result_type(std::forward<Triangle_3>(res)); return result_type(std::forward<Triangle_3>(res));
} }
//get segs and pts to construct poly //get segs and pts to construct poly
else if( const Segment_3* s else if( const Segment_3* s
@ -102,7 +102,7 @@ intersection(
= boost::get<Poly>(&*intersections[i])) = boost::get<Poly>(&*intersections[i]))
{ {
Poly res = *p; Poly res = *p;
return Result_type(std::forward<Poly>(res)); return result_type(std::forward<Poly>(res));
} }
} }
} }
@ -119,21 +119,21 @@ intersection(
fill_segments_infos(segments,tmp, tr); fill_segments_infos(segments,tmp, tr);
Poly res; Poly res;
res.reserve(4); res.reserve(4);
for( auto p : tmp){ for( const auto& p : tmp){
res.push_back(p); res.push_back(p);
} }
return Result_type(std::forward<Poly>(res)); return result_type(std::forward<Poly>(res));
} }
//else it must be adjacent to an vertex, so we return the point //else it must be adjacent to an vertex, so we return the point
else if(segments.size() == 1) else if(segments.size() == 1)
{ {
//adjacency to an edge, return resulting segment. //adjacency to an edge, return resulting segment.
return Result_type(std::forward<Segment_3>(segments.front())); return result_type(std::forward<Segment_3>(segments.front()));
} }
else else
{ {
//no segment = adjacency to an vertex or an edge : return result point //no segment = adjacency to an vertex or an edge : return result point
return Result_type(std::forward<Point_3>(points.front())); return result_type(std::forward<Point_3>(points.front()));
} }
} }
@ -155,7 +155,7 @@ intersection(
if(const Triangle_3* t = boost::get<typename K::Triangle_3>(&*intersections[i])) if(const Triangle_3* t = boost::get<typename K::Triangle_3>(&*intersections[i]))
{ {
Triangle_3 res = *t; Triangle_3 res = *t;
return Result_type(std::forward<Triangle_3>(res)); return result_type(std::forward<Triangle_3>(res));
} }
//get segs and pts to construct poly //get segs and pts to construct poly
else if( const Segment_3* s else if( const Segment_3* s
@ -173,14 +173,14 @@ intersection(
= boost::get<Poly>(&*intersections[i])) = boost::get<Poly>(&*intersections[i]))
{ {
Poly res = *p; Poly res = *p;
return Result_type(std::forward<Poly>(res)); return result_type(std::forward<Poly>(res));
} }
} }
} }
if(segments.empty()) if(segments.empty())
{ {
//then there is only one point of contact. Return it: //then there is only one point of contact. Return it:
return Result_type(std::forward<Point_3>(points.front())); return result_type(std::forward<Point_3>(points.front()));
} }
if(segments.size() > 1) if(segments.size() > 1)
@ -197,7 +197,7 @@ intersection(
bool return_solo_seg = true; bool return_solo_seg = true;
//only one intersection, a triangle edge is one of the tet edges, and //only one intersection, a triangle edge is one of the tet edges, and
//the 3rd point is outside. This is the only intersection. //the 3rd point is outside. This is the only intersection.
for(auto p : inside_points) for(const auto& p : inside_points)
{ {
if(!tet.has_on_boundary(p)) if(!tet.has_on_boundary(p))
{ {
@ -207,14 +207,14 @@ intersection(
} }
if(return_solo_seg) if(return_solo_seg)
{ {
return Result_type(std::forward<Segment_3>(segments.front())); return result_type(std::forward<Segment_3>(segments.front()));
} }
if(inside_points.size() == 1) if(inside_points.size() == 1)
{ {
Triangle_3 res(inside_points.front(), segments.front().source(), Triangle_3 res(inside_points.front(), segments.front().source(),
segments.front().target()); segments.front().target());
return Result_type(std::forward<Triangle_3>(res)); return result_type(std::forward<Triangle_3>(res));
} }
else //size 2 else //size 2
{ {
@ -232,15 +232,14 @@ intersection(
res[3] = segments.front().target(); res[3] = segments.front().target();
res[2] = segments.front().source(); res[2] = segments.front().source();
} }
return Result_type(std::forward<Poly>(res)); return result_type(std::forward<Poly>(res));
} }
} }
break; break;
case 2: case 2:
case 3: case 3:
{ {
std::list<Segment_3> segs; std::list<Segment_3> segs(segments.begin(), segments.end());
for(auto s : segments){segs.push_back(s);}
std::list<Point_3> tmp; std::list<Point_3> tmp;
fill_points_list(segs, tmp); fill_points_list(segs, tmp);
if(inside_points.size() == 1) if(inside_points.size() == 1)
@ -248,21 +247,26 @@ intersection(
Poly res; Poly res;
res.reserve(4); res.reserve(4);
res.push_back(inside_points.front()); res.push_back(inside_points.front());
for( auto p : tmp){res.push_back(p);} for( const auto& p : tmp){res.push_back(p);}
return Result_type(std::forward<Poly>(res)); return result_type(std::forward<Poly>(res));
} }
else //size 2 else //size 2
{ {
Poly res; Poly res;
res.reserve(5); res.reserve(5);
if((inside_points.front() - inside_points.back()) * typename K::Compute_scalar_product_3 scalar =
(tmp.front() - tmp.back()) > 0) k.compute_scalar_product_3_object();
typename K::Construct_vector_3 construct_vector =
k.construct_vector_3_object();
if(scalar(construct_vector(inside_points.front(), inside_points.back()),
construct_vector(tmp.front(), tmp.back())) > 0)
{ {
res.push_back(inside_points.front()); res.push_back(inside_points.front());
} }
res.push_back(inside_points.back()); res.push_back(inside_points.back());
for( auto p : tmp){res.push_back(p);} for( const auto& p : tmp){res.push_back(p);}
return Result_type(std::forward<Poly>(res)); return result_type(std::forward<Poly>(res));
} }
} }
break; break;
@ -276,8 +280,7 @@ intersection(
case 3: case 3:
{ {
//triangle entirely inside tetra : return input triangle //triangle entirely inside tetra : return input triangle
typename K::Triangle_3 res = tr; return result_type(tr);
return Result_type(std::forward<typename K::Triangle_3>(res));
} }
break; break;
default: default:

View File

@ -128,7 +128,7 @@ struct Triangle_Line_visitor {
result_type result_type
operator()(const typename K::Point_3& p, const typename K::Segment_3& s) const { operator()(const typename K::Point_3& p, const typename K::Segment_3& s) const {
if ( s.has_on(p) ) if ( typename K::Has_on_3()(s,p) )
return intersection_return<typename K::Intersect_3, typename K::Triangle_3, typename K::Triangle_3>(p); return intersection_return<typename K::Intersect_3, typename K::Triangle_3, typename K::Triangle_3>(p);
else else
return result_type(); return result_type();

View File

@ -1249,15 +1249,11 @@ inline
typename Intersection_traits<K, Bbox_3, Bbox_3>::result_type typename Intersection_traits<K, Bbox_3, Bbox_3>::result_type
intersection(const Bbox_3 &a, intersection(const Bbox_3 &a,
const Bbox_3 &b, const Bbox_3 &b,
const K& k) const K&)
{ {
return CGAL::intersection<K>(a, b); return CGAL::intersection<K>(a, b);
} }
template <class K> template <class K>
typename Intersection_traits<K, CGAL::Bbox_3, typename K::Iso_cuboid_3>::result_type typename Intersection_traits<K, CGAL::Bbox_3, typename K::Iso_cuboid_3>::result_type
intersection(const CGAL::Bbox_3 &box, intersection(const CGAL::Bbox_3 &box,

View File

@ -75,7 +75,7 @@ void fill_segments_infos(std::vector<Segment>& segments,
std::vector<Wrapped_segment> wrapped_segments; std::vector<Wrapped_segment> wrapped_segments;
for(auto s:segments) for(const auto& s:segments)
wrapped_segments.push_back(Wrapped_segment(s)); wrapped_segments.push_back(Wrapped_segment(s));
std::vector<Segment> bis = segments; std::vector<Segment> bis = segments;

View File

@ -138,8 +138,8 @@ struct Tetrahedron_lines_intersection_3_base
for(std::size_t i = 0; i< res_points.size(); ++i) for(std::size_t i = 0; i< res_points.size(); ++i)
{ {
auto p1 = res_points[i]; const auto& p1 = res_points[i];
for(auto p2 : res_points) for(const auto& p2 : res_points)
{ {
sq_distances[i].push_back(CGAL::squared_distance(p1, p2)); sq_distances[i].push_back(CGAL::squared_distance(p1, p2));
if(sq_distances[i].back() > max_dist) if(sq_distances[i].back() > max_dist)

View File

@ -574,9 +574,16 @@ struct Test {
if(is_exact) if(is_exact)
{ {
check_no_intersection (tet, L(P(5,0,0), P(5,1,0))); check_no_intersection (tet, L(P(5,0,0), P(5,1,0)));
//on edge
check_intersection (tet, L(P(0,2,0), P(0,3,0)), S(P(0,0,0), P(0,1,0))); check_intersection (tet, L(P(0,2,0), P(0,3,0)), S(P(0,0,0), P(0,1,0)));
//through vertex and out from face
check_intersection (tet, L(P(0,1,0), P(0.25,0,0.25)), S(P(0,1,0), P(0.25,0,0.25))); check_intersection (tet, L(P(0,1,0), P(0.25,0,0.25)), S(P(0,1,0), P(0.25,0,0.25)));
//through a vertex only
check_intersection (tet, L(P(1,1,0), P(-1,1,0)), P(0,1,0)); check_intersection (tet, L(P(1,1,0), P(-1,1,0)), P(0,1,0));
//through 2 faces
check_intersection (tet, L(P(0.25,0.25,0), P(0.25,0,0.25)), S(P(0.25,0,0.25), P(0.25,0.25,0)));
//through one edge
check_intersection (tet, L(P(0.5,-0.5,0.5), P(0.5,0.5,0.5)), P(0.5,0,0.5));
} }
} }
@ -1251,7 +1258,7 @@ int main()
{ {
std::cout << " |||||||| Test Simple_cartesian<double> ||||||||" << std::endl; std::cout << " |||||||| Test Simple_cartesian<double> ||||||||" << std::endl;
Test< CGAL::Simple_cartesian<double> >().run(); Test< CGAL::Simple_cartesian<double> >().run();
/*
std::cout << " |||||||| Test CGAL::Homogeneous<CGAL::MP_Float> ||||||||" << std::endl; std::cout << " |||||||| Test CGAL::Homogeneous<CGAL::MP_Float> ||||||||" << std::endl;
Test< CGAL::Homogeneous<CGAL::MP_Float> >().run(); Test< CGAL::Homogeneous<CGAL::MP_Float> >().run();
@ -1260,5 +1267,4 @@ int main()
std::cout << " |||||||| Test CGAL::Homogeneous<CGAL::Epeck_ft> ||||||||" << std::endl; std::cout << " |||||||| Test CGAL::Homogeneous<CGAL::Epeck_ft> ||||||||" << std::endl;
Test< CGAL::Homogeneous<CGAL::Epeck_ft> >().run(true); Test< CGAL::Homogeneous<CGAL::Epeck_ft> >().run(true);
*/
} }