distance queries conform to the spec

This commit is contained in:
Camille Wormser 2009-05-09 10:22:45 +00:00
parent 33fd59e039
commit 5dc7c35be3
2 changed files with 45 additions and 14 deletions

View File

@ -39,13 +39,14 @@ template<typename GeomTraits, typename AABB_primitive>
class AABB_traits class AABB_traits
{ {
public: public:
typedef AABB_traits<GeomTraits, AABB_primitive> AT;
/// AABBTraits concept types /// AABBTraits concept types
typedef typename CGAL::Bbox_3 Bounding_box; typedef typename CGAL::Bbox_3 Bounding_box;
typedef typename CGAL::Object Object; typedef typename CGAL::Object Object;
typedef AABB_primitive Primitive; typedef AABB_primitive Primitive;
typedef typename AABB_primitive::Datum Datum; typedef typename AABB_primitive::Datum Datum;
typedef typename GeomTraits::Sphere_3 Sphere; // typedef typename GeomTraits::Sphere_3 Sphere;
typedef unsigned int Size_type; typedef unsigned int Size_type;
// TOFIX: Workaround for weighted_point // TOFIX: Workaround for weighted_point
@ -129,20 +130,52 @@ public:
boost::optional<Object_and_primitive_id> intersection(const Query& q, boost::optional<Object_and_primitive_id> intersection(const Query& q,
const Primitive& pr) const; const Primitive& pr) const;
Sphere sphere(const Point& center, /* Sphere sphere(const Point& center,
const Point& hint) const const Point& hint) const
{ {
return GeomTraits().construct_sphere_3_object() return GeomTraits().construct_sphere_3_object()
(center, GeomTraits().compute_squared_distance_3_object()(center, hint)); (center, GeomTraits().compute_squared_distance_3_object()(center, hint));
} }*/
/*
template <typename Query> template <typename Query>
Point closest_point(const Query& q, Point closest_point(const Query& q,
const Primitive& pr, const Primitive& pr,
const Point& bound) const const Point& bound) const
{ {
return CGAL::nearest_point_3(q, pr.datum(), bound); return CGAL::nearest_point_3(q, pr.datum(), bound);
} */
// This should go down to the GeomTraits, i.e. the kernel
class Closest_point_3 {
typedef typename AT::Point Point;
typedef typename AT::Primitive Primitive;
public:
Point operator()(const Point& p, const Primitive& pr, const Point& bound) const
{
return CGAL::nearest_point_3(p, pr.datum(), bound);
} }
};
// This should go down to the GeomTraits, i.e. the kernel
// and the internal implementation should change its name from
// do_intersect to something like does_contain (this is what we compute,
// this is not the same do_intersect as the spherical kernel)
class Compare_distance_3 {
typedef typename AT::Point Point;
typedef typename AT::Primitive Primitive;
public:
template <class Solid>
bool operator()(const Point& p, const Solid& pr, const Point& bound) const
{
return GeomTraits().do_intersect_3_object()
(GeomTraits().construct_sphere_3_object()
(p, GeomTraits().compute_squared_distance_3_object()(p, bound)), pr);
}
};
Closest_point_3 closest_point_3_object() {return Closest_point_3();}
Compare_distance_3 compare_distance_3_object() {return Compare_distance_3();}
private: private:
/** /**

View File

@ -154,7 +154,7 @@ namespace CGAL {
private: private:
typedef AABB_node<AABBTraits> Node; typedef AABB_node<AABBTraits> Node;
typedef typename AABBTraits::Sphere Sphere; // typedef typename AABBTraits::Sphere Sphere;
//------------------------------------------------------- //-------------------------------------------------------
// Traits classes for traversal computation // Traits classes for traversal computation
@ -338,29 +338,27 @@ namespace CGAL {
const Point& hint, const Point& hint,
const typename Primitive::Id& hint_primitive) const typename Primitive::Id& hint_primitive)
: m_closest_point(hint), : m_closest_point(hint),
m_closest_primitive(hint_primitive), m_closest_primitive(hint_primitive)
m_sphere(AABBTraits().sphere(query,hint))
{} {}
bool go_further() const { return true; } bool go_further() const { return true; }
void intersection(const Point& query, const Primitive& primitive) void intersection(const Point& query, const Primitive& primitive)
{ {
// TOFIX Point new_closest_point = AABBTraits().closest_point_3_object()
// update m_closest_primitive if needed (query, primitive, m_closest_point);
Point new_closest_point =
AABBTraits().closest_point(query, primitive, m_closest_point);
if(new_closest_point != m_closest_point) if(new_closest_point != m_closest_point)
{ {
m_closest_primitive = primitive.id(); m_closest_primitive = primitive.id();
m_closest_point = new_closest_point; m_closest_point = new_closest_point;
} }
m_sphere = AABBTraits().sphere(query, m_closest_point); // m_sphere = AABBTraits().sphere(query, m_closest_point);
} }
bool do_intersect(const Point& query, const Node& node) const bool do_intersect(const Point& query, const Node& node) const
{ {
return AABBTraits().do_intersect(m_sphere, node.bbox()); return AABBTraits().compare_distance_3_object()
(query, node.bbox(), m_closest_point);
} }
Point closest_point() const { return m_closest_point; } Point closest_point() const { return m_closest_point; }
@ -370,7 +368,7 @@ namespace CGAL {
} }
private: private:
Sphere m_sphere; // Sphere m_sphere;
Point m_closest_point; Point m_closest_point;
typename Primitive::Id m_closest_primitive; typename Primitive::Id m_closest_primitive;
}; };