mirror of https://github.com/CGAL/cgal
move alpha computation into a functor
This commit is contained in:
parent
48712f7862
commit
003bf47781
|
|
@ -34,28 +34,6 @@ namespace CGAL {
|
||||||
namespace Intersections {
|
namespace Intersections {
|
||||||
namespace internal{
|
namespace internal{
|
||||||
|
|
||||||
//TODO: move into a functor
|
|
||||||
template <class K>
|
|
||||||
typename K::FT
|
|
||||||
coplanar_segment_segment_alpha_intersection(const typename K::Point_3& p1, const typename K::Point_3& p2, // segment 1
|
|
||||||
const typename K::Point_3& p3, const typename K::Point_3& p4, // segment 2
|
|
||||||
const K& k)
|
|
||||||
{
|
|
||||||
const typename K::Vector_3 v1 = p2-p1;
|
|
||||||
const typename K::Vector_3 v2 = p4-p3;
|
|
||||||
|
|
||||||
CGAL_assertion(k.coplanar_3_object()(p1,p2,p3,p4));
|
|
||||||
|
|
||||||
const typename K::Vector_3 v3 = p3 - p1;
|
|
||||||
const typename K::Vector_3 v3v2 = cross_product(v3,v2);
|
|
||||||
const typename K::Vector_3 v1v2 = cross_product(v1,v2);
|
|
||||||
const typename K::FT sl = v1v2.squared_length();
|
|
||||||
CGAL_assertion(!certainly(is_zero(sl)));
|
|
||||||
|
|
||||||
const typename K::FT t = ((v3v2.x()*v1v2.x()) + (v3v2.y()*v1v2.y()) + (v3v2.z()*v1v2.z())) / sl;
|
|
||||||
return t; // p1 + (p2-p1) * t
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Kernel>
|
template <class Kernel>
|
||||||
struct Point_on_triangle
|
struct Point_on_triangle
|
||||||
{
|
{
|
||||||
|
|
@ -179,6 +157,8 @@ intersection(const Point_on_triangle<Kernel>& p,
|
||||||
std::cout << " (" << p.id1() << "," << p.id2() << ",[" << p.alpha << "]) -";
|
std::cout << " (" << p.id1() << "," << p.id2() << ",[" << p.alpha << "]) -";
|
||||||
std::cout << " (" << q.id1() << "," << q.id2() << ",[" << q.alpha << "]) || e" << edge_id_t1;
|
std::cout << " (" << q.id1() << "," << q.id2() << ",[" << q.alpha << "]) || e" << edge_id_t1;
|
||||||
#endif
|
#endif
|
||||||
|
typename Kernel::Compute_alpha_for_coplanar_triangle_intersection_3 compute_alpha
|
||||||
|
= k.compute_alpha_for_coplanar_triangle_intersection_3_object();
|
||||||
typedef Point_on_triangle<Kernel> Pot;
|
typedef Point_on_triangle<Kernel> Pot;
|
||||||
switch(p.id1())
|
switch(p.id1())
|
||||||
{
|
{
|
||||||
|
|
@ -193,10 +173,9 @@ intersection(const Point_on_triangle<Kernel>& p,
|
||||||
#ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION
|
#ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION
|
||||||
std::cout << " -- case 1\n";
|
std::cout << " -- case 1\n";
|
||||||
#endif
|
#endif
|
||||||
typename Kernel::FT alpha =
|
typename Kernel::FT alpha = compute_alpha(p1, q1,
|
||||||
coplanar_segment_segment_alpha_intersection(p1, q1,
|
Pot::point_from_id(p2, q2, r2, p.id2()),
|
||||||
Pot::point_from_id(p2, q2, r2, p.id2()),
|
Pot::point_from_id(p2, q2, r2, q.id2()));
|
||||||
Pot::point_from_id(p2, q2, r2, q.id2()), k);
|
|
||||||
int id2 = (p.id2()+1)%3 == q.id2() ? p.id2() : q.id2();
|
int id2 = (p.id2()+1)%3 == q.id2() ? p.id2() : q.id2();
|
||||||
return Point_on_triangle<Kernel>(edge_id_t1, id2, alpha); // intersection with an original edge of t2
|
return Point_on_triangle<Kernel>(edge_id_t1, id2, alpha); // intersection with an original edge of t2
|
||||||
}
|
}
|
||||||
|
|
@ -209,10 +188,9 @@ intersection(const Point_on_triangle<Kernel>& p,
|
||||||
std::cout << " -- case 2\n";
|
std::cout << " -- case 2\n";
|
||||||
#endif
|
#endif
|
||||||
// points are on the same edge of t2 --> we shorten an already cut edge
|
// points are on the same edge of t2 --> we shorten an already cut edge
|
||||||
typename Kernel::FT alpha =
|
typename Kernel::FT alpha = compute_alpha(p1, q1,
|
||||||
coplanar_segment_segment_alpha_intersection(p1, q1,
|
Pot::point_from_id(p2, q2, r2, q.id2()),
|
||||||
Pot::point_from_id(p2, q2, r2, q.id2()),
|
Pot::point_from_id(p2, q2, r2, (q.id2()+1)%3));
|
||||||
Pot::point_from_id(p2, q2, r2, (q.id2()+1)%3), k);
|
|
||||||
|
|
||||||
return Point_on_triangle<Kernel>(edge_id_t1, q.id2(), alpha);
|
return Point_on_triangle<Kernel>(edge_id_t1, q.id2(), alpha);
|
||||||
}
|
}
|
||||||
|
|
@ -278,10 +256,9 @@ intersection(const Point_on_triangle<Kernel>& p,
|
||||||
std::cout << " -- case 7\n";
|
std::cout << " -- case 7\n";
|
||||||
#endif
|
#endif
|
||||||
// points are on the same edge of t2 --> we shorten an already cut edge
|
// points are on the same edge of t2 --> we shorten an already cut edge
|
||||||
typename Kernel::FT alpha =
|
typename Kernel::FT alpha = compute_alpha(p1, q1,
|
||||||
coplanar_segment_segment_alpha_intersection(p1, q1,
|
Pot::point_from_id(p2, q2, r2, p.id2()),
|
||||||
Pot::point_from_id(p2, q2, r2, p.id2()),
|
Pot::point_from_id(p2, q2, r2, (p.id2()+1)%3));
|
||||||
Pot::point_from_id(p2, q2, r2, (p.id2()+1)%3), k);
|
|
||||||
|
|
||||||
return Point_on_triangle<Kernel>(edge_id_t1, p.id2(), alpha);
|
return Point_on_triangle<Kernel>(edge_id_t1, p.id2(), alpha);
|
||||||
}
|
}
|
||||||
|
|
@ -314,10 +291,9 @@ intersection(const Point_on_triangle<Kernel>& p,
|
||||||
#ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION
|
#ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION
|
||||||
std::cout << " -- case 10\n";
|
std::cout << " -- case 10\n";
|
||||||
#endif
|
#endif
|
||||||
typename Kernel::FT alpha =
|
typename Kernel::FT alpha = compute_alpha(p1, q1,
|
||||||
coplanar_segment_segment_alpha_intersection(p1, q1,
|
Pot::point_from_id(p2, q2, r2, q.id2()),
|
||||||
Pot::point_from_id(p2, q2, r2, q.id2()),
|
Pot::point_from_id(p2, q2, r2, (q.id2()+1)%3));
|
||||||
Pot::point_from_id(p2, q2, r2, (q.id2()+1)%3), k);
|
|
||||||
return Point_on_triangle<Kernel>(edge_id_t1, q.id2(), alpha);
|
return Point_on_triangle<Kernel>(edge_id_t1, q.id2(), alpha);
|
||||||
}
|
}
|
||||||
// we are intersecting an edge of t1
|
// we are intersecting an edge of t1
|
||||||
|
|
|
||||||
|
|
@ -2149,6 +2149,37 @@ namespace CommonKernelFunctors {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename K>
|
||||||
|
class Compute_alpha_for_coplanar_triangle_intersection_3
|
||||||
|
{
|
||||||
|
typedef typename K::Point_3 Point_3;
|
||||||
|
typedef typename K::Vector_3 Vector_3;
|
||||||
|
public:
|
||||||
|
typedef typename K::FT result_type;
|
||||||
|
result_type
|
||||||
|
operator()(const Point_3& p1, const Point_3& p2, // segment 1
|
||||||
|
const Point_3& p3, const Point_3& p4) const // segment 2
|
||||||
|
{
|
||||||
|
typename K::Construct_vector_3 vector = K().construct_vector_3_object();
|
||||||
|
typename K::Construct_cross_product_vector_3 cross_product =
|
||||||
|
K().construct_cross_product_vector_3_object();
|
||||||
|
|
||||||
|
const Vector_3 v1 = vector(p1, p2);
|
||||||
|
const Vector_3 v2 = vector(p3, p4);
|
||||||
|
|
||||||
|
CGAL_assertion(K().coplanar_3_object()(p1,p2,p3,p4));
|
||||||
|
|
||||||
|
const Vector_3 v3 = vector(p1, p3);
|
||||||
|
const Vector_3 v3v2 = cross_product(v3,v2);
|
||||||
|
const Vector_3 v1v2 = cross_product(v1,v2);
|
||||||
|
const typename K::FT sl = K().compute_squared_length_3_object()(v1v2);
|
||||||
|
CGAL_assertion(!certainly(is_zero(sl)));
|
||||||
|
|
||||||
|
const typename K::FT t = ((v3v2.x()*v1v2.x()) + (v3v2.y()*v1v2.y()) + (v3v2.z()*v1v2.z())) / sl;
|
||||||
|
return t; // p1 + (p2-p1) * t
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <typename K>
|
template <typename K>
|
||||||
class Construct_point_on_2
|
class Construct_point_on_2
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -396,6 +396,8 @@ CGAL_Kernel_cons(Construct_plane_3,
|
||||||
construct_plane_3_object)
|
construct_plane_3_object)
|
||||||
CGAL_Kernel_cons(Construct_plane_line_intersection_point_3,
|
CGAL_Kernel_cons(Construct_plane_line_intersection_point_3,
|
||||||
construct_plane_line_intersection_point_3_object)
|
construct_plane_line_intersection_point_3_object)
|
||||||
|
CGAL_Kernel_cons(Compute_alpha_for_coplanar_triangle_intersection_3,
|
||||||
|
compute_alpha_for_coplanar_triangle_intersection_3_object)
|
||||||
CGAL_Kernel_cons(Construct_point_on_2,
|
CGAL_Kernel_cons(Construct_point_on_2,
|
||||||
construct_point_on_2_object)
|
construct_point_on_2_object)
|
||||||
CGAL_Kernel_cons(Construct_point_on_3,
|
CGAL_Kernel_cons(Construct_point_on_3,
|
||||||
|
|
|
||||||
|
|
@ -386,7 +386,7 @@ void coplanar_intersections(const std::array<typename K::Point_3, 3>& t1,
|
||||||
|
|
||||||
//intersect t2 with the three half planes which intersection defines t1
|
//intersect t2 with the three half planes which intersection defines t1
|
||||||
K k;
|
K k;
|
||||||
intersection_coplanar_triangles_cutoff(p1,q1,r1,0,p2,q2,r2,k,l_inter_pts); //line p1q1
|
Intersections::internal::intersection_coplanar_triangles_cutoff(p1,q1,r1,0,p2,q2,r2,k,l_inter_pts); //line p1q1
|
||||||
#ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION
|
#ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION
|
||||||
std::cout << " ipts size: " << l_inter_pts.size() << "\n";
|
std::cout << " ipts size: " << l_inter_pts.size() << "\n";
|
||||||
print_points();
|
print_points();
|
||||||
|
|
@ -401,7 +401,7 @@ void coplanar_intersections(const std::array<typename K::Point_3, 3>& t1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
intersection_coplanar_triangles_cutoff(q1,r1,p1,1,p2,q2,r2,k,l_inter_pts); //line q1r1
|
Intersections::internal::intersection_coplanar_triangles_cutoff(q1,r1,p1,1,p2,q2,r2,k,l_inter_pts); //line q1r1
|
||||||
#ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION
|
#ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION
|
||||||
std::cout << " ipts size: " << l_inter_pts.size() << "\n";
|
std::cout << " ipts size: " << l_inter_pts.size() << "\n";
|
||||||
print_points();
|
print_points();
|
||||||
|
|
@ -416,7 +416,7 @@ void coplanar_intersections(const std::array<typename K::Point_3, 3>& t1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
intersection_coplanar_triangles_cutoff(r1,p1,q1,2,p2,q2,r2,k,l_inter_pts); //line r1p1
|
Intersections::internal::intersection_coplanar_triangles_cutoff(r1,p1,q1,2,p2,q2,r2,k,l_inter_pts); //line r1p1
|
||||||
#ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION
|
#ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION
|
||||||
std::cout << " ipts size: " << l_inter_pts.size() << "\n";
|
std::cout << " ipts size: " << l_inter_pts.size() << "\n";
|
||||||
print_points();
|
print_points();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue