* Remove ad-hoc code from AABBTraits:

- add nearest_point_3(Point_3, Triangle_3, Point_3)
  - updates Projecting_traits of AABB_tree
* Fix test compilation (linux x64).
This commit is contained in:
Stéphane Tayeb 2009-04-28 15:12:51 +00:00
parent aabc226876
commit 7d85cbdd57
4 changed files with 19 additions and 120 deletions

View File

@ -14,3 +14,5 @@
#include <CGAL/Triangle_3_line_3_intersection.h>
#include <CGAL/Triangle_3_plane_3_intersection.h>
#include <CGAL/Triangle_3_segment_3_intersection.h>
#include <CGAL/Point_3_triangle_3_point_3_nearest_point_3.h>

View File

@ -134,15 +134,18 @@ public:
Sphere sphere(const Projection_query& center,
const Projection& hint) const
{
return Sphere(center, GeomTraits().compute_squared_distance_3_object()
(center, hint));
return GeomTraits().construct_sphere_3_object()
(center, GeomTraits().compute_squared_distance_3_object()(center, hint));
}
bool intersection(const Sphere& sphere,
const Primitive& pr,
Projection& projection_return) const;
bool is_contained(const Sphere& a, const Sphere& b) const;
template <typename Query>
Projection nearest_point(const Query& q,
const Primitive& pr,
const Projection& bound) const
{
return CGAL::nearest_point_3(q, pr.datum(), bound);
//return GeomTraits().nearest_point_3_object()(q, pr.datum(), bound);
}
private:
/**
@ -171,6 +174,7 @@ private:
}; // end class AABB_traits
template<typename GT, typename P>
template<typename PrimitiveIterator>
void
@ -234,50 +238,6 @@ AABB_traits<GT,P>::intersection(const Query& q,
}
// PA: CAREFUL: the ad-hoc code here must be removed.
template<typename GT, typename P>
bool
AABB_traits<GT,P>::intersection(const Sphere& sphere,
const P& pr,
Projection& projected) const
{
typedef typename P::Datum Triangle_3;
const Triangle_3 triangle = pr.datum();
projected = triangle.supporting_plane().projection(sphere.center());
// If point is projected outside sphere, return false
if ( sphere.bounded_side(projected) == CGAL::ON_UNBOUNDED_SIDE )
{
return false;
}
if( is_inside_triangle_3(projected, triangle) ) // projected is modified
{
return true;
}
if(sphere.bounded_side(projected) == CGAL::ON_UNBOUNDED_SIDE)
{
return false;
}
return true;
}
template<typename GT, typename P>
bool
AABB_traits<GT,P>::is_contained(const Sphere& a, const Sphere& b) const
{
CGAL_precondition(a.center() == b.center());
return ( GT().compute_squared_radius_3_object()(a)
< GT().compute_squared_radius_3_object()(b) );
}
//-------------------------------------------------------
// Private methods
@ -314,56 +274,6 @@ AABB_traits<GT,P>::longest_axis(const Bounding_box& bbox) const
}
}
// PA: ad-hoc code to be removed
template<typename GT, typename P>
bool
AABB_traits<GT,P>::is_inside_triangle_3(Point_3& p,
const Triangle_3& t) const
{
typedef typename GT::Vector_3 Vector;
typedef typename GT::Line_3 Line;
Vector w = CGAL::cross_product(t.vertex(1) - t.vertex(0),
t.vertex(2) - t.vertex(0));
bool out = false;
for(int i = 0; i < 3; ++i)
{
Vector v = CGAL::cross_product(t.vertex(i+1) - t.vertex(i),
p - t.vertex(i));
if(v*w < 0)
{ // p is outside, on the side of (i, i+1)
out = true;
if( (p - t.vertex(i))*(t.vertex(i+1) - t.vertex(i)) >= 0
&& (p - t.vertex(i+1))*(t.vertex(i) - t.vertex(i+1)) >= 0 )
{
p = Line(t.vertex(i), t.vertex(i+1)).projection(p);
return false;
}
}
}
if(out)
{
typename GT::Compare_distance_3 c = GT().compare_distance_3_object();
if(c(p, t.vertex(1), t.vertex(0)) == CGAL::LARGER &&
c(p, t.vertex(2), t.vertex(0)) == CGAL::LARGER)
{
p = t.vertex(0);
return false;
}
if(c(p, t.vertex(0), t.vertex(1)) == CGAL::LARGER &&
c(p, t.vertex(2), t.vertex(1)) == CGAL::LARGER)
{
p = t.vertex(1);
return false;
}
p = t.vertex(2);
return false;
}
return true;
}
} // end namespace CGAL

View File

@ -254,26 +254,14 @@ namespace CGAL {
Projecting_traits(const Projection_query& query,
const Projection& hint)
: projection_(hint)
, center_(query)
, sphere_(AABBTraits().sphere(query,hint)) { }
bool go_further() const { return true; }
void intersection(const Projection_query& q, const Primitive& primitive)
{
// We don't use q here because it is embedded in sphere_ and we don't
// want to compute sphere everytime
Projection projection;
if ( AABBTraits().intersection(sphere_, primitive, projection) )
{
const Sphere sphere = AABBTraits().sphere(center_, projection);
if ( AABBTraits().is_contained(sphere, sphere_) )
{
projection_ = projection;
sphere_ = sphere;
}
}
projection_ = AABBTraits().nearest_point(q, primitive, projection_);
sphere_ = AABBTraits().sphere(q, projection_);
}
bool do_intersect(const Projection_query& q, const Node& node) const
@ -285,7 +273,6 @@ namespace CGAL {
private:
Projection projection_;
Projection_query center_;
Sphere sphere_;
};
@ -437,7 +424,7 @@ namespace CGAL {
// first nearest neighbor point to get a hint
template<typename Tr>
typename AABB_tree<Tr>::Projection
AABB_tree<Tr>::closest_point(const Projection_query& query)
AABB_tree<Tr>::closest_point(const Projection_query& query)
{
// construct search KD-tree if needed
Projection hint;

View File

@ -97,13 +97,13 @@ double random_in(const double a,
}
template <class K>
typename K::Point_3 random_point_in(CGAL::Bbox_3& bbox)
typename K::Point_3 random_point_in(const CGAL::Bbox_3& bbox)
{
typedef typename K::FT FT;
FT x = (FT)random_in(bbox.xmin(),bbox.xmax());
FT y = (FT)random_in(bbox.ymin(),bbox.ymax());
FT z = (FT)random_in(bbox.zmin(),bbox.zmax());
return K::Point_3(x,y,z);
return typename K::Point_3(x,y,z);
}
template <class K>
@ -113,7 +113,7 @@ typename K::Vector_3 random_vector()
FT x = (FT)random_in(0.0,1.0);
FT y = (FT)random_in(0.0,1.0);
FT z = (FT)random_in(0.0,1.0);
return K::Vector_3(x,y,z);
return typename K::Vector_3(x,y,z);
}
enum Query_type {RAY_QUERY,