mirror of https://github.com/CGAL/cgal
AABB tree: started to implement new API
CAREFUL: does not compile anymore - will fix this next week.
This commit is contained in:
parent
b75a57f5b8
commit
23f94c802b
Binary file not shown.
|
|
@ -27,15 +27,11 @@ The concept \ccRefName\ provides the geometric primitive types and methods for t
|
||||||
\ccGlue
|
\ccGlue
|
||||||
\ccNestedType{Bounding_box}{Bounding box type.}
|
\ccNestedType{Bounding_box}{Bounding box type.}
|
||||||
\ccGlue
|
\ccGlue
|
||||||
\ccNestedType{Intersection}{Type of intersection.}
|
\ccNestedType{Point_and_primitive}{Pair composed of a point and a primitive.}
|
||||||
|
|
||||||
The following types are required for projection queries.
|
The following types are required for distance queries.
|
||||||
|
|
||||||
\ccNestedType{Sphere}{Sphere type.}
|
\ccNestedType{Sphere}{Sphere type.}
|
||||||
\ccGlue
|
|
||||||
\ccNestedType{Projection_query}{Type for which projection queries are issued.}
|
|
||||||
\ccGlue
|
|
||||||
\ccNestedType{Projection}{Type of projection result.}
|
|
||||||
|
|
||||||
|
|
||||||
\ccCreation
|
\ccCreation
|
||||||
|
|
@ -69,19 +65,11 @@ for which the class \ccc{AABB_tree<Traits>} may receive a query.
|
||||||
% TODO: replace return by pair<bool,Intersection>
|
% TODO: replace return by pair<bool,Intersection>
|
||||||
\ccMethod{bool intersection(const Query & q,
|
\ccMethod{bool intersection(const Query & q,
|
||||||
const Primitive& primitive,
|
const Primitive& primitive,
|
||||||
Intersection & intersection);}
|
Point_and_primitive& result);}
|
||||||
{Returns \ccc{true} iff the query intersects the primitive. In the positive, stores the intersection in the last parameter. }
|
{Returns \ccc{true} iff the query intersects the primitive. In the positive, stores the intersection in the last parameter as a pair composed of a point and a primitive. }
|
||||||
|
|
||||||
The following members are required only if projection queries are issued.
|
% TODO: document nearest_point
|
||||||
\ccMethod{Sphere sphere_from_query_and_hint(const Projection_query & center,
|
|
||||||
const Projection & hint);}
|
|
||||||
{Returns a sphere centered at \ccc{center} and passing through \ccc{hint}.}
|
|
||||||
|
|
||||||
% TODO: replace return by pair<bool,Intersection>
|
|
||||||
\ccMethod{ bool intersection(const Sphere & sphere,
|
|
||||||
const Primitive::Object object,
|
|
||||||
const Projection & projection);}
|
|
||||||
{Returns \ccc{true} iff the primitive object is intersecting the ball defined as the interior of the sphere. In the positive, the point of the primitive closest to the center of the sphere is stored in the last parameter.}
|
|
||||||
|
|
||||||
\ccMethod{bool is_contained(const Sphere & a, const Sphere & b);}{Returns \ccc{true} iff sphere $a$ is contained in sphere $b$. Both spheres are assumed to share the same center.}
|
\ccMethod{bool is_contained(const Sphere & a, const Sphere & b);}{Returns \ccc{true} iff sphere $a$ is contained in sphere $b$. Both spheres are assumed to share the same center.}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,14 @@ The class \ccRefName\ is a static data structure for efficient intersection and
|
||||||
\ccTypedef{typedef Traits::Point_3 Point;}
|
\ccTypedef{typedef Traits::Point_3 Point;}
|
||||||
{Type of 3D point.}
|
{Type of 3D point.}
|
||||||
\ccGlue
|
\ccGlue
|
||||||
\ccNestedType{Primitive}
|
\ccTypedef{typedef Traits::Primitive Primitive;}
|
||||||
{Type of input primitives.}
|
{Type of input primitive.}
|
||||||
|
\ccGlue
|
||||||
|
\ccTypedef{typedef Traits::Bounding_box Bounding_box;}
|
||||||
|
{Type of bounding box.}
|
||||||
\ccGlue
|
\ccGlue
|
||||||
\ccNestedType{Point_and_primitive}
|
\ccNestedType{Point_and_primitive}
|
||||||
{A pair composed of a Point and a Primitive.}
|
{A pair composed of a point and a primitive.}
|
||||||
|
|
||||||
%\ccNestedType{AABB}{some nested types}
|
%\ccNestedType{AABB}{some nested types}
|
||||||
|
|
||||||
|
|
@ -45,42 +48,40 @@ The class \ccRefName\ is a static data structure for efficient intersection and
|
||||||
\ccConstructor{AABB_tree();}{Default constructor.}
|
\ccConstructor{AABB_tree();}{Default constructor.}
|
||||||
\ccConstructor{template < class ConstPrimitiveIterator>
|
\ccConstructor{template < class ConstPrimitiveIterator>
|
||||||
AABB_tree( ConstPrimitiveIterator begin,
|
AABB_tree( ConstPrimitiveIterator begin,
|
||||||
ConstPrimitiveIterator beyond,
|
ConstPrimitiveIterator beyond);}
|
||||||
const bool construct_search_tree = false);}
|
{Builds the datastructure. Type \ccc{ConstPrimitiveIterator} can be any const iterator on a container of \ccc{Primitive::Object} such that \ccc{Primitive} has a constructor taking a \ccc{ConstPrimitiveIterator} as argument.}
|
||||||
{Builds the datastructure. Type \ccc{ConstPrimitiveIterator} can be any const iterator on a container of \ccc{Primitive::Object} such that \ccc{Primitive} has a constructor taking a \ccc{ConstPrimitiveIterator} as argument. Flag \ccc{construct_search_tree} indicates if the search KD-tree used to accelerate the distance queries must be computed during the construction of the AABB tree. In the negative each distance query called without any hint takes the first primitive reference point as hint and is hence slower (the flag is a mean to trade efficiency for memory). }
|
|
||||||
|
|
||||||
\ccOperations
|
\ccOperations
|
||||||
|
|
||||||
\ccMethod{template < class ConstPrimitiveIterator>
|
\ccMethod{template < class ConstPrimitiveIterator>
|
||||||
bool clear_and_insert(ConstPrimitiveIterator begin,
|
bool clear_and_insert(ConstPrimitiveIterator begin,
|
||||||
ConstPrimitiveIterator beyond,
|
ConstPrimitiveIterator beyond);}
|
||||||
const bool construct_search_tree = false);}
|
{Clears the current tree and rebuilds it from scratch. See constructor above for the parameters. Returns \ccc{true} iff the memory allocation is successful. }
|
||||||
{Clears the current tree and rebuilds it from scratch (see constructor \ccc{AABB_tree(begin,beyond)} above for the parameters). Returns \ccc{true} iff the memory allocation was successful. }
|
|
||||||
|
|
||||||
\ccMethod{void clear(void);}
|
\ccMethod{void clear(void);}
|
||||||
{Clears the current tree. }
|
{Clears the AABB tree. }
|
||||||
|
|
||||||
% INTERSECTION TESTS
|
% INTERSECTION TESTS
|
||||||
\ccHeading{Intersection Tests}
|
\ccHeading{Intersection Tests}
|
||||||
|
|
||||||
\ccMethod{ template <class Query>
|
\ccMethod{template <class Query>
|
||||||
bool do_intersect(const Query & q);}
|
bool do_intersect(const Query& query);}
|
||||||
{ Returns \ccc{true} iff the query intersects the primitives. Type \ccc{Query} has to be a type for which \ccc{do_intersect} predicates have been defined in \ccc{Traits}.}
|
{ Returns \ccc{true} iff the query intersects the input primitives. Type \ccc{Query} must be a type for which \ccc{do_intersect} predicates are defined in the \ccc{Traits}.}
|
||||||
|
|
||||||
\ccMethod{template <class Query>
|
\ccMethod{template <class Query>
|
||||||
size_t number_of_intersections(const Query& q );}
|
size_t number_of_intersections(const Query& query);}
|
||||||
{Returns the number of primitives intersected by the query. Type \ccc{Query} has to be a type for which \ccc{do_intersect} predicates have been defined in \ccc{Traits}.}
|
{Returns the number of intersections between the query and the input primitives. Type \ccc{Query} must be a type for which \ccc{do_intersect} predicates are defined in the \ccc{Traits}.}
|
||||||
|
|
||||||
\ccMethod{template <class Query, class OutputIterator>
|
\ccMethod{template <class Query, class OutputIterator>
|
||||||
OutputIterator
|
OutputIterator
|
||||||
all_intersected_primitives(const Query& query, OutputIterator out);}
|
all_intersected_primitives(const Query& query,
|
||||||
{Outputs to the iterator the list of intersected primitives. This function does not compute the intersection points and is hence faster than the function \ccc{all_intersections}. Type \ccc{Query} must be a type for which \ccc{do_intersect} predicates have been defined in \ccc{Traits}. The value type of OutputIterator is assumed to be \ccc{Primitive}.}
|
OutputIterator out);}
|
||||||
|
{Outputs to the iterator the list of all intersected primitives. This function does not compute the intersection points and is hence faster than the function \ccc{all_intersections} function below. Type \ccc{Query} must be a type for which \ccc{do_intersect} predicates are defined in the \ccc{Traits}.}
|
||||||
|
|
||||||
|
\ccMethod{template <class Query>
|
||||||
\ccMethod{template <class Query, class OutputIterator>
|
|
||||||
bool any_intersected_primitive(const Query& query,
|
bool any_intersected_primitive(const Query& query,
|
||||||
Primitive& primitive);}
|
Primitive& primitive);}
|
||||||
{Return \ccc{true} iff the query intersects the primitive. In the positive, saves the first encountered primitive to the second parameter. Type \ccc{Query} has to be a type for which \ccc{do_intersect} and intersection predicates have been defined in \ccc{Traits}.}
|
{Return \ccc{true} iff the query intersects at least one of the input primitives. In the positive, saves the first encountered primitive to the second parameter. Type \ccc{Query} must be a type for which \ccc{do_intersect} and intersection predicates are defined in the \ccc{Traits}.}
|
||||||
|
|
||||||
% INTERSECTIONS
|
% INTERSECTIONS
|
||||||
\ccHeading{Intersections}
|
\ccHeading{Intersections}
|
||||||
|
|
@ -88,16 +89,13 @@ bool any_intersected_primitive(const Query& query,
|
||||||
\ccMethod{template <class Query, class OutputIterator>
|
\ccMethod{template <class Query, class OutputIterator>
|
||||||
OutputIterator
|
OutputIterator
|
||||||
all_intersections(const Query& query,
|
all_intersections(const Query& query,
|
||||||
OutputIterator out);}
|
OutputIterator out);}
|
||||||
{Outputs to the iterator the list of all intersections between the query and input data. Type \ccc{Query} must be a type for which \ccc{do_intersect} predicates have been defined in \ccc{Traits}. The value type of OutputIterator is assumed to be \ccc{Point_and_primitive}.}
|
{Outputs to the iterator the list of all intersections between the query and input data, as objects of type \ccc{Point_and_primitive}. Type \ccc{Query} must be a type for which \ccc{do_intersect} predicates and intersections are defined in the \ccc{Traits}.}
|
||||||
|
|
||||||
% ( Note : output iterators have "void" as value_type, so you should better write "and output them to the output iterator pts, as objects of type...".)
|
|
||||||
|
|
||||||
|
|
||||||
\ccMethod{template <class Query>
|
\ccMethod{template <class Query>
|
||||||
bool any_intersection(const Query& query,
|
bool any_intersection(const Query& query,
|
||||||
Intersection& intersection);}
|
Point_and_primitive& point_and_primitive);}
|
||||||
{Returns \ccc{true} iff the query intersects the primitives. In the positive, saves the first encountered intersection to the second parameter. Type \ccc{Query} has to be a type for which \ccc{do_intersect} and intersection predicates have been defined in \ccc{Traits}.}
|
{Returns \ccc{true} iff the query intersects at least one of the input primitives. In the positive, saves the first encountered intersection to the second parameter. Type \ccc{Query} must be a type for which \ccc{do_intersect} predicates and intersections are defined in the \ccc{Traits}.}
|
||||||
|
|
||||||
|
|
||||||
% DISTANCE QUERIES
|
% DISTANCE QUERIES
|
||||||
|
|
@ -106,7 +104,7 @@ bool any_intersection(const Query& query,
|
||||||
\ccMethod{Point
|
\ccMethod{Point
|
||||||
closest_point(const Point& query,
|
closest_point(const Point& query,
|
||||||
const Point& hint);}
|
const Point& hint);}
|
||||||
{Returns the point on all input primitives which is closest to the query. In case of several points located at the same (closest) distance one arbitrarily chosen is returned. Parameter \ccc{hint} is assumed to be any point located on the input primitives (the closer \ccc{hint} to \ccc{query}, the faster the query). Parameter \ccc{hint} can be omitted. If the internal KD-tree data structure has been constructed it is used to efficiently query the nearest hint point from the query. Otherwise a naive hint point is taken as the first primitive reference point. }
|
{Returns the point on all input primitives which is closest to the query. In case of several closest points one arbitrarily chosen point is returned. Parameter \ccc{hint} is assumed to be any point located on the input primitives (the closer \ccc{hint} to \ccc{query}, the faster). Parameter \ccc{hint} can be omitted. If the internal KD-tree data structure has been constructed using function \ccc{construct_search_tree} (see below), it is used to efficiently query the nearest hint point from the query. Otherwise a naive hint point is taken as the first primitive reference point. }
|
||||||
|
|
||||||
\ccMethod{Primitive
|
\ccMethod{Primitive
|
||||||
closest_primitive(const Point& query,
|
closest_primitive(const Point& query,
|
||||||
|
|
@ -116,24 +114,25 @@ closest_primitive(const Point& query,
|
||||||
\ccMethod{Point_and_primitive
|
\ccMethod{Point_and_primitive
|
||||||
closest_point_and_primitive(const Point& query,
|
closest_point_and_primitive(const Point& query,
|
||||||
const Point& hint);}
|
const Point& hint);}
|
||||||
{Returns a pair \ccc{<Point,Primitive>} which realizes the smallest distance between the query point and all input primitives. See \ccc{closest_point} function for the optional \ccc{hint} parameter. }
|
{Returns a \ccc{std::pair<Point,Primitive>} which realizes the smallest distance between the query point and all input primitives. See \ccc{closest_point} function for the optional \ccc{hint} parameter. }
|
||||||
|
|
||||||
\ccMethod{FT
|
\ccMethod{FT
|
||||||
squared_distance(const Point& query,
|
squared_distance(const Point& query,
|
||||||
const Point& hint);}
|
const Point& hint);}
|
||||||
{Returns the squared distance between the query point and all input primitives. See \ccc{closest_point} function for the optional \ccc{hint} parameter. }
|
{Returns the minimum squared distance between the query point and all input primitives. See \ccc{closest_point} function for the optional \ccc{hint} parameter. }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
\ccHeading{Accelerating the distance queries}
|
\ccHeading{Accelerating the distance queries}
|
||||||
|
|
||||||
\ccMethod{void construct_search_tree();}
|
\ccMethod{void construct_search_tree();}
|
||||||
{ Constructs the internal search KD-tree used to accelerate the distance queries. The points in the search tree are taken from the primitives by calling the function \ccc{point_on} from the primitive.}
|
{ Constructs the internal search KD-tree used to accelerate the distance queries. The points in the search tree are taken from the primitives by calling the member function \ccc{point_on} from the primitive.}
|
||||||
|
|
||||||
|
\begin{ccAdvanced}
|
||||||
\ccMethod{template <class ConstPointIterator>
|
\ccMethod{template <class ConstPointIterator>
|
||||||
void construct_search_tree(ConstPointIterator begin,
|
void construct_search_tree(ConstPointIterator begin,
|
||||||
ConstPointIterator beyond);}
|
ConstPointIterator beyond);}
|
||||||
{ Constructs the internal search KD-tree used to accelerate the distance queries from a specified point set. }
|
{ Constructs the internal search KD-tree used to accelerate the distance queries from a specified point set. Each point from the specified point set must be located on the input primitives. For a triangle surface mesh this point set can be provided as the vertex points or as the triangle centroids.}
|
||||||
|
\end{ccAdvanced}
|
||||||
|
|
||||||
\ccSeeAlso
|
\ccSeeAlso
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,17 +44,16 @@ public:
|
||||||
|
|
||||||
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 typename GeomTraits::Point_3 Projection;
|
|
||||||
// TOFIX: Workaround for weighted_point
|
// TOFIX: Workaround for weighted_point
|
||||||
#ifndef AABB_KERNEL_USE_WEIGHTED_POINT
|
#ifndef AABB_KERNEL_USE_WEIGHTED_POINT
|
||||||
typedef typename GeomTraits::Point_3 Intersection;
|
typedef typename GeomTraits::Point_3 Point;
|
||||||
#else
|
#else
|
||||||
typedef typename GeomTraits::Point_3::Point Intersection;
|
typedef typename GeomTraits::Point_3::Point Point;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef typename GeomTraits::Point_3 Projection_query;
|
typedef typename std::pair<typename Point, typename primitive> Point_and_primitive;
|
||||||
|
|
||||||
// types for search tree
|
// types for search tree
|
||||||
// TOFIX: how can we avoid repeating those?
|
// TOFIX: how can we avoid repeating those?
|
||||||
|
|
@ -68,7 +67,8 @@ public:
|
||||||
typedef typename GeomTraits::Construct_max_vertex_3 Construct_max_vertex_3;
|
typedef typename GeomTraits::Construct_max_vertex_3 Construct_max_vertex_3;
|
||||||
typedef typename GeomTraits::Compute_squared_radius_3 Compute_squared_radius_3;
|
typedef typename GeomTraits::Compute_squared_radius_3 Compute_squared_radius_3;
|
||||||
typedef typename GeomTraits::Cartesian_const_iterator_3 Cartesian_const_iterator_3;
|
typedef typename GeomTraits::Cartesian_const_iterator_3 Cartesian_const_iterator_3;
|
||||||
typedef typename GeomTraits::Construct_cartesian_const_iterator_3 Construct_cartesian_const_iterator_3;
|
typedef typename GeomTraits::Construct_cartesian_const_iterator_3
|
||||||
|
Construct_cartesian_const_iterator_3;
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
AABB_traits() { };
|
AABB_traits() { };
|
||||||
|
|
@ -126,22 +126,21 @@ public:
|
||||||
template<typename Query>
|
template<typename Query>
|
||||||
bool intersection(const Query& q,
|
bool intersection(const Query& q,
|
||||||
const Primitive& pr,
|
const Primitive& pr,
|
||||||
Intersection& intersection) const;
|
Point_and_primitive& result) const;
|
||||||
|
|
||||||
Sphere sphere(const Projection_query& center,
|
Sphere sphere(const Point& center,
|
||||||
const Projection& 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>
|
||||||
Projection nearest_point(const Query& q,
|
Point nearest_point(const Query& q,
|
||||||
const Primitive& pr,
|
const Primitive& pr,
|
||||||
const Projection& bound) const
|
const Point& bound) const
|
||||||
{
|
{
|
||||||
return CGAL::nearest_point_3(q, pr.datum(), bound);
|
return CGAL::nearest_point_3(q, pr.datum(), bound);
|
||||||
//return GeomTraits().nearest_point_3_object()(q, pr.datum(), bound);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -174,8 +173,8 @@ template<typename GT, typename P>
|
||||||
template<typename PrimitiveIterator>
|
template<typename PrimitiveIterator>
|
||||||
void
|
void
|
||||||
AABB_traits<GT,P>::sort_primitives(PrimitiveIterator first,
|
AABB_traits<GT,P>::sort_primitives(PrimitiveIterator first,
|
||||||
PrimitiveIterator beyond,
|
PrimitiveIterator beyond,
|
||||||
const Bounding_box& bbox) const
|
const Bounding_box& bbox) const
|
||||||
{
|
{
|
||||||
PrimitiveIterator middle = first + (beyond - first)/2;
|
PrimitiveIterator middle = first + (beyond - first)/2;
|
||||||
switch(longest_axis(bbox))
|
switch(longest_axis(bbox))
|
||||||
|
|
@ -213,8 +212,8 @@ template<typename GT, typename P>
|
||||||
template<typename Query>
|
template<typename Query>
|
||||||
bool
|
bool
|
||||||
AABB_traits<GT,P>::intersection(const Query& q,
|
AABB_traits<GT,P>::intersection(const Query& q,
|
||||||
const P& pr,
|
const P& pr,
|
||||||
Intersection& result) const
|
Point_and_primitive& result) const
|
||||||
{
|
{
|
||||||
// TODO: implement a real intersection construction method
|
// TODO: implement a real intersection construction method
|
||||||
// do_intersect is needed here because we construct intersection between
|
// do_intersect is needed here because we construct intersection between
|
||||||
|
|
@ -225,15 +224,15 @@ AABB_traits<GT,P>::intersection(const Query& q,
|
||||||
}
|
}
|
||||||
|
|
||||||
// AABB tree package call
|
// AABB tree package call
|
||||||
// TODO: extend kernel
|
|
||||||
Datum datum = pr.datum();
|
Datum datum = pr.datum();
|
||||||
CGAL::Object intersection_obj = CGAL::intersection(datum, q);
|
CGAL::Object intersection_obj = CGAL::intersection(datum, q);
|
||||||
|
Point point;
|
||||||
return CGAL::assign(result, intersection_obj);
|
if(CGAL::assign(point, intersection_obj))
|
||||||
|
result = std::pair<point,pr>;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
// Private methods
|
// Private methods
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -37,13 +37,14 @@ namespace CGAL {
|
||||||
class AABB_tree
|
class AABB_tree
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Traits types
|
/// types
|
||||||
|
typedef typename AABBTraits::FT FT;
|
||||||
|
typedef typename AABBTraits::Point Point;
|
||||||
typedef typename AABBTraits::Primitive Primitive;
|
typedef typename AABBTraits::Primitive Primitive;
|
||||||
typedef typename AABBTraits::Projection Projection;
|
|
||||||
typedef typename AABBTraits::Bounding_box Bounding_box;
|
typedef typename AABBTraits::Bounding_box Bounding_box;
|
||||||
typedef typename AABBTraits::Intersection Intersection;
|
typedef typename std::pair<typename Point,typename Primitive> Point_and_primitive;
|
||||||
typedef typename AABBTraits::Projection_query Projection_query;
|
|
||||||
private:
|
private:
|
||||||
|
// internal KD-tree used to accelerate the distance queries
|
||||||
typedef AABB_search_tree<AABBTraits> Search_tree;
|
typedef AABB_search_tree<AABBTraits> Search_tree;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -83,7 +84,8 @@ namespace CGAL {
|
||||||
template<typename ConstPointIterator>
|
template<typename ConstPointIterator>
|
||||||
void construct_search_tree(ConstPointIterator first, ConstPointIterator beyond);
|
void construct_search_tree(ConstPointIterator first, ConstPointIterator beyond);
|
||||||
|
|
||||||
/// Construct internal search tree from a point set taken on the internal primitives
|
/// Construct internal search tree from
|
||||||
|
/// a point set taken on the internal primitives
|
||||||
void construct_search_tree(void);
|
void construct_search_tree(void);
|
||||||
|
|
||||||
template<typename Query>
|
template<typename Query>
|
||||||
|
|
@ -94,25 +96,29 @@ namespace CGAL {
|
||||||
|
|
||||||
template<typename Query, typename OutputIterator>
|
template<typename Query, typename OutputIterator>
|
||||||
OutputIterator all_intersected_primitives(const Query& q,
|
OutputIterator all_intersected_primitives(const Query& q,
|
||||||
OutputIterator out) const;
|
OutputIterator out) const;
|
||||||
|
|
||||||
template<typename Query, typename OutputIterator>
|
template<typename Query, typename OutputIterator>
|
||||||
OutputIterator all_intersections(const Query& q,
|
OutputIterator all_intersections(const Query& q,
|
||||||
OutputIterator out) const;
|
OutputIterator out) const;
|
||||||
|
|
||||||
template<typename Query>
|
template<typename Query>
|
||||||
bool any_intersection(const Query& q,
|
bool any_intersection(const Query& q,
|
||||||
Intersection& intersection) const;
|
Intersection& intersection) const;
|
||||||
|
|
||||||
template<typename Query, typename OutputIterator>
|
template<typename Query, typename OutputIterator>
|
||||||
bool any_intersected_primitive(const Query& q,
|
bool any_intersected_primitive(const Query& q,
|
||||||
Primitive& pr) const;
|
Primitive& pr) const;
|
||||||
|
|
||||||
Projection closest_point(const Projection_query& q,
|
// distance queries
|
||||||
const Projection& hint) const;
|
FT squared_distance(const Point& q, const Point& hint) const;
|
||||||
|
FT squared_distance(const Point& q) const;
|
||||||
// TOFIX: make it const
|
Point closest_point(const Point& q, const Point& hint) const;
|
||||||
Projection closest_point(const Projection_query& q);
|
Point closest_point(const Point& q) const;
|
||||||
|
Primitive closest_primitive(const Point& q, const Point& hint) const;
|
||||||
|
Primitive closest_primitive(const Point& q) const;
|
||||||
|
Point_and_primitive closest_point_and_primitive(const Point& q, const Point& hint) const;
|
||||||
|
Point_and_primitive closest_point_and_primitive(const Point& q) const;
|
||||||
|
|
||||||
//////////////////////////////////////////////
|
//////////////////////////////////////////////
|
||||||
//TODO: document this
|
//TODO: document this
|
||||||
|
|
@ -158,12 +164,12 @@ namespace CGAL {
|
||||||
return AABBTraits().do_intersect(q, node.bounding_box());
|
return AABBTraits().do_intersect(q, node.bounding_box());
|
||||||
}
|
}
|
||||||
|
|
||||||
Intersection result() const { return m_result; }
|
Point_and_primitive result() const { return m_result; }
|
||||||
bool is_intersection_found() const { return m_is_found; }
|
bool is_intersection_found() const { return m_is_found; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_is_found;
|
bool m_is_found;
|
||||||
Intersection m_result;
|
Point_and_primitive m_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -175,16 +181,16 @@ namespace CGAL {
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Counting_traits()
|
Counting_traits()
|
||||||
: intersection_()
|
: m_intersection()
|
||||||
, intersection_nb_(0) {}
|
, m_nb_intersections(0) {}
|
||||||
|
|
||||||
bool go_further() const { return true; }
|
bool go_further() const { return true; }
|
||||||
|
|
||||||
void intersection(const Query& q, const Primitive& primitive)
|
void intersection(const Query& q, const Primitive& primitive)
|
||||||
{
|
{
|
||||||
if( AABBTraits().intersection(q, primitive, intersection_) )
|
if( AABBTraits().intersection(q, primitive, m_intersection) )
|
||||||
{
|
{
|
||||||
++intersection_nb_;
|
++m_nb_intersections;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,11 +199,11 @@ namespace CGAL {
|
||||||
return AABBTraits().do_intersect(q, node.bounding_box());
|
return AABBTraits().do_intersect(q, node.bounding_box());
|
||||||
}
|
}
|
||||||
|
|
||||||
int intersection_number() const { return intersection_nb_; }
|
int intersection_number() const { return m_nb_intersections; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Intersection intersection_;
|
Point_and_primitive m_intersection;
|
||||||
int intersection_nb_;
|
int m_nb_intersections;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -209,16 +215,16 @@ namespace CGAL {
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Listing_intersection_traits(Output_iterator out_it)
|
Listing_intersection_traits(Output_iterator out_it)
|
||||||
: intersection_()
|
: m_intersection()
|
||||||
, out_it_(out_it) {}
|
, m_out_it(out_it) {}
|
||||||
|
|
||||||
bool go_further() const { return true; }
|
bool go_further() const { return true; }
|
||||||
|
|
||||||
void intersection(const Query& q, const Primitive& primitive)
|
void intersection(const Query& q, const Primitive& primitive)
|
||||||
{
|
{
|
||||||
if( AABBTraits().intersection(q, primitive, intersection_) )
|
if( AABBTraits().intersection(q, primitive, m_intersection) )
|
||||||
{
|
{
|
||||||
*out_it_++ = intersection_;
|
*m_out_it++ = m_intersection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,8 +234,8 @@ namespace CGAL {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Intersection intersection_;
|
Intersection m_intersection;
|
||||||
Output_iterator out_it_;
|
Output_iterator m_out_it;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -241,7 +247,7 @@ namespace CGAL {
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Listing_primitive_traits(Output_iterator out_it)
|
Listing_primitive_traits(Output_iterator out_it)
|
||||||
: out_it_(out_it) {}
|
: m_out_it(out_it) {}
|
||||||
|
|
||||||
bool go_further() const { return true; }
|
bool go_further() const { return true; }
|
||||||
|
|
||||||
|
|
@ -249,7 +255,7 @@ namespace CGAL {
|
||||||
{
|
{
|
||||||
if( AABBTraits().do_intersect(q, primitive) )
|
if( AABBTraits().do_intersect(q, primitive) )
|
||||||
{
|
{
|
||||||
*out_it_++ = primitive;
|
*m_out_it++ = primitive;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -259,38 +265,41 @@ namespace CGAL {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Output_iterator out_it_;
|
Output_iterator m_out_it;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class Projection_traits
|
* @class Projection_traits
|
||||||
*/
|
*/
|
||||||
class Projecting_traits
|
class Distance_traits
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Projecting_traits(const Projection_query& query,
|
Distance_traits(const Point& query,
|
||||||
const Projection& hint)
|
const Point& hint)
|
||||||
: projection_(hint)
|
: m_closest_point(hint),
|
||||||
, sphere_(AABBTraits().sphere(query,hint)) { }
|
m_sphere(AABBTraits().sphere(query,hint))
|
||||||
|
{}
|
||||||
|
|
||||||
bool go_further() const { return true; }
|
bool go_further() const { return true; }
|
||||||
|
|
||||||
void intersection(const Projection_query& q, const Primitive& primitive)
|
void intersection(const Point& query, const Primitive& primitive)
|
||||||
{
|
{
|
||||||
projection_ = AABBTraits().nearest_point(q, primitive, projection_);
|
// TOFIX: update m_closest_primitive
|
||||||
sphere_ = AABBTraits().sphere(q, projection_);
|
m_closest_point = AABBTraits().nearest_point(query, primitive, m_closest_point);
|
||||||
|
m_sphere = AABBTraits().sphere(q, m_closest_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool do_intersect(const Projection_query& q, const Node& node) const
|
bool do_intersect(const Point& q, const Node& node) const
|
||||||
{
|
{
|
||||||
return AABBTraits().do_intersect(sphere_, node.bounding_box());
|
return AABBTraits().do_intersect(m_sphere, node.bounding_box());
|
||||||
}
|
}
|
||||||
|
|
||||||
Projection projection() const { return projection_; }
|
Point closest_point() const { return m_closest_point; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Projection projection_;
|
// TOFIX: add closest_primitive
|
||||||
Sphere sphere_;
|
Sphere m_sphere;
|
||||||
|
Point m_closest_point;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -373,7 +382,7 @@ namespace CGAL {
|
||||||
template<typename ConstPointIterator>
|
template<typename ConstPointIterator>
|
||||||
void
|
void
|
||||||
AABB_tree<Tr>::construct_search_tree(ConstPointIterator first,
|
AABB_tree<Tr>::construct_search_tree(ConstPointIterator first,
|
||||||
ConstPointIterator beyond)
|
ConstPointIterator beyond)
|
||||||
{
|
{
|
||||||
m_search_tree.init(first, beyond);
|
m_search_tree.init(first, beyond);
|
||||||
m_search_tree_constructed = true;
|
m_search_tree_constructed = true;
|
||||||
|
|
@ -384,7 +393,7 @@ namespace CGAL {
|
||||||
void AABB_tree<Tr>::construct_search_tree(void)
|
void AABB_tree<Tr>::construct_search_tree(void)
|
||||||
{
|
{
|
||||||
// iterate over primitives to get points on them
|
// iterate over primitives to get points on them
|
||||||
std::list<Projection_query> points;
|
std::list<Point> points;
|
||||||
typename std::vector<Primitive>::const_iterator it;
|
typename std::vector<Primitive>::const_iterator it;
|
||||||
for(it = m_data.begin(); it != m_data.end(); ++it)
|
for(it = m_data.begin(); it != m_data.end(); ++it)
|
||||||
{
|
{
|
||||||
|
|
@ -423,7 +432,7 @@ namespace CGAL {
|
||||||
template<typename Query, typename OutputIterator>
|
template<typename Query, typename OutputIterator>
|
||||||
OutputIterator
|
OutputIterator
|
||||||
AABB_tree<Tr>::all_intersected_primitives(const Query& query,
|
AABB_tree<Tr>::all_intersected_primitives(const Query& query,
|
||||||
OutputIterator out) const
|
OutputIterator out) const
|
||||||
{
|
{
|
||||||
typedef Listing_primitive_traits<Query, OutputIterator> Traversal_traits;
|
typedef Listing_primitive_traits<Query, OutputIterator> Traversal_traits;
|
||||||
Traversal_traits traversal_traits(out);
|
Traversal_traits traversal_traits(out);
|
||||||
|
|
@ -436,7 +445,7 @@ namespace CGAL {
|
||||||
template<typename Query, typename OutputIterator>
|
template<typename Query, typename OutputIterator>
|
||||||
OutputIterator
|
OutputIterator
|
||||||
AABB_tree<Tr>::all_intersections(const Query& query,
|
AABB_tree<Tr>::all_intersections(const Query& query,
|
||||||
OutputIterator out) const
|
OutputIterator out) const
|
||||||
{
|
{
|
||||||
typedef Listing_intersection_traits<Query, OutputIterator> Traversal_traits;
|
typedef Listing_intersection_traits<Query, OutputIterator> Traversal_traits;
|
||||||
Traversal_traits traversal_traits(out);
|
Traversal_traits traversal_traits(out);
|
||||||
|
|
@ -450,25 +459,44 @@ namespace CGAL {
|
||||||
template<typename Query>
|
template<typename Query>
|
||||||
bool
|
bool
|
||||||
AABB_tree<Tr>::any_intersection(const Query& query,
|
AABB_tree<Tr>::any_intersection(const Query& query,
|
||||||
Intersection& intersection) const
|
Point_and_primitive& point_and_primitive) const
|
||||||
{
|
{
|
||||||
typedef First_intersection_traits<Query> Traversal_traits;
|
typedef First_intersection_traits<Query> Traversal_traits;
|
||||||
Traversal_traits traversal_traits;
|
Traversal_traits traversal_traits;
|
||||||
|
|
||||||
this->traversal(query, traversal_traits);
|
this->traversal(query, traversal_traits);
|
||||||
|
|
||||||
intersection = traversal_traits.result();
|
point_and_primitive = traversal_traits.result();
|
||||||
return traversal_traits.is_intersection_found();
|
return traversal_traits.is_intersection_found();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// squared distance with user-specified hint
|
||||||
|
template<typename Tr>
|
||||||
|
typename AABB_tree<Tr>::FT
|
||||||
|
AABB_tree<Tr>::squared_distance(const Point& query,
|
||||||
|
const Point& hint) const
|
||||||
|
{
|
||||||
|
Point closest = closest_point(query, hint);
|
||||||
|
return CGAL::squared_distance(query, closest);
|
||||||
|
}
|
||||||
|
|
||||||
|
// squared distance without user-specified hint
|
||||||
|
template<typename Tr>
|
||||||
|
typename AABB_tree<Tr>::FT
|
||||||
|
AABB_tree<Tr>::squared_distance(const Point& query) const
|
||||||
|
{
|
||||||
|
Point closest = closest_point(query);
|
||||||
|
return CGAL::squared_distance(query, closest);
|
||||||
|
}
|
||||||
|
|
||||||
// closest point with user-specified hint
|
// closest point with user-specified hint
|
||||||
template<typename Tr>
|
template<typename Tr>
|
||||||
typename AABB_tree<Tr>::Projection
|
typename AABB_tree<Tr>::Point
|
||||||
AABB_tree<Tr>::closest_point(const Projection_query& query,
|
AABB_tree<Tr>::closest_point(const Point& query,
|
||||||
const Projection& hint) const
|
const Point& hint) const
|
||||||
{
|
{
|
||||||
Projecting_traits traversal_traits(query,hint);
|
Distance_traits traversal_traits(query,hint);
|
||||||
|
|
||||||
this->traversal(query, traversal_traits);
|
this->traversal(query, traversal_traits);
|
||||||
return traversal_traits.projection();
|
return traversal_traits.projection();
|
||||||
}
|
}
|
||||||
|
|
@ -476,11 +504,11 @@ namespace CGAL {
|
||||||
// closest point without hint, the search KD-tree is queried for the
|
// closest point without hint, the search KD-tree is queried for the
|
||||||
// first nearest neighbor point to get a hint
|
// first nearest neighbor point to get a hint
|
||||||
template<typename Tr>
|
template<typename Tr>
|
||||||
typename AABB_tree<Tr>::Projection
|
typename AABB_tree<Tr>::Point
|
||||||
AABB_tree<Tr>::closest_point(const Projection_query& query)
|
AABB_tree<Tr>::closest_point(const Point& query) const
|
||||||
{
|
{
|
||||||
// construct search KD-tree if needed
|
// construct search KD-tree if needed
|
||||||
Projection hint;
|
Point hint;
|
||||||
if(m_search_tree_constructed)
|
if(m_search_tree_constructed)
|
||||||
{
|
{
|
||||||
// pick nearest neighbor point as hint (fast)
|
// pick nearest neighbor point as hint (fast)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue