mirror of https://github.com/CGAL/cgal
update the replacement of Object_and_primitive_id ...
... to be a pair< variant<XXX>, Primitive_id > rather than pair<optional<variant<XXX> >, Primitive_id > The rational is that the optional around the variant here is not needed since there is one around the pair.
This commit is contained in:
parent
a11a5c8479
commit
75ebdeaeeb
|
|
@ -17,8 +17,8 @@ typedef CGAL::Polyhedron_3<K> Polyhedron;
|
|||
typedef CGAL::AABB_polyhedron_triangle_primitive<K,Polyhedron> Primitive;
|
||||
typedef CGAL::AABB_traits<K, Primitive> Traits;
|
||||
typedef CGAL::AABB_tree<Traits> Tree;
|
||||
typedef Tree::Intersection_and_primitive_id<Segment>::Type Segment_intersection;
|
||||
typedef Tree::Intersection_and_primitive_id<Plane>::Type Plane_intersection;
|
||||
typedef boost::optional< Tree::Intersection_and_primitive_id<Segment>::Type > Segment_intersection;
|
||||
typedef boost::optional< Tree::Intersection_and_primitive_id<Plane>::Type > Plane_intersection;
|
||||
typedef Tree::Primitive_id Primitive_id;
|
||||
|
||||
int main()
|
||||
|
|
@ -52,10 +52,10 @@ int main()
|
|||
// (generally a point)
|
||||
Segment_intersection intersection =
|
||||
tree.any_intersection(segment_query);
|
||||
if(intersection.first)
|
||||
if(intersection)
|
||||
{
|
||||
// gets intersection object
|
||||
if(boost::get<Point>(&*intersection.first))
|
||||
if(boost::get<Point>(&(intersection->first)))
|
||||
std::cout << "intersection object is a point" << std::endl;
|
||||
}
|
||||
|
||||
|
|
@ -74,10 +74,10 @@ int main()
|
|||
// computes first encountered intersection with plane query
|
||||
// (generally a segment)
|
||||
Plane_intersection plane_intersection = tree.any_intersection(plane_query);
|
||||
if(plane_intersection.first)
|
||||
if(plane_intersection)
|
||||
{
|
||||
|
||||
if(boost::get<Segment>(&*plane_intersection.first))
|
||||
if(boost::get<Segment>(&(plane_intersection->first)))
|
||||
std::cout << "intersection object is a segment" << std::endl;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,9 +71,8 @@ public:
|
|||
template<typename Query>
|
||||
struct Intersection_and_primitive_id {
|
||||
typedef std::pair<
|
||||
typename cpp11::result_of<typename GeomTraits::Intersect_3(Query, typename Primitive::Datum) >::type,
|
||||
typename IT<Query, typename Primitive::Datum>::variant_type, //using Intersection_traits to skip the optional
|
||||
typename Primitive::Id > Type;
|
||||
typedef Type type;
|
||||
};
|
||||
|
||||
// types for search tree
|
||||
|
|
@ -206,10 +205,13 @@ operator()(const Query& query, const typename AT::Primitive& primitive) const
|
|||
}
|
||||
#else
|
||||
template<typename Query>
|
||||
typename Intersection_and_primitive_id<Query>::Type
|
||||
boost::optional< typename Intersection_and_primitive_id<Query>::Type >
|
||||
operator()(const Query& query, const typename AT::Primitive& primitive) const {
|
||||
return std::make_pair(GeomTraits().intersect_3_object()(primitive.datum(),query),
|
||||
primitive.id());
|
||||
typename cpp11::result_of<typename GeomTraits::Intersect_3(Query, typename Primitive::Datum) >::type
|
||||
inter_res = GeomTraits().intersect_3_object()(primitive.datum(),query);
|
||||
if (!inter_res)
|
||||
return boost::optional<typename Intersection_and_primitive_id<Query>::Type>();
|
||||
return boost::make_optional( std::make_pair(*inter_res, primitive.id()) );
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ public:
|
|||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
boost::optional<Object_and_primitive_id>
|
||||
#else
|
||||
typename Intersection_and_primitive_id<Query>::Type
|
||||
boost::optional< typename Intersection_and_primitive_id<Query>::Type >
|
||||
#endif
|
||||
any_intersection(const Query& query) const;
|
||||
|
||||
|
|
@ -706,7 +706,7 @@ public:
|
|||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
boost::optional<typename AABB_tree<Tr>::Object_and_primitive_id>
|
||||
#else
|
||||
typename AABB_tree<Tr>::template Intersection_and_primitive_id<Query>::Type
|
||||
boost::optional< typename AABB_tree<Tr>::template Intersection_and_primitive_id<Query>::Type >
|
||||
#endif
|
||||
AABB_tree<Tr>::any_intersection(const Query& query) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -73,11 +73,11 @@ class First_intersection_traits
|
|||
typedef ::CGAL::AABB_node<AABBTraits> Node;
|
||||
|
||||
public:
|
||||
typedef typename
|
||||
typedef
|
||||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
boost::optional<Object_and_primitive_id>
|
||||
#else
|
||||
AABBTraits::template Intersection_and_primitive_id<Query>::Type
|
||||
boost::optional< typename AABBTraits::template Intersection_and_primitive_id<Query>::Type >
|
||||
#endif
|
||||
Result;
|
||||
public:
|
||||
|
|
@ -86,11 +86,7 @@ public:
|
|||
{}
|
||||
|
||||
bool go_further() const {
|
||||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
return !m_result;
|
||||
#else
|
||||
return !m_result.first;
|
||||
#endif
|
||||
}
|
||||
|
||||
void intersection(const Query& query, const Primitive& primitive)
|
||||
|
|
@ -105,11 +101,7 @@ public:
|
|||
|
||||
Result result() const { return m_result; }
|
||||
bool is_intersection_found() const {
|
||||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
return m_result;
|
||||
#else
|
||||
return m_result.first;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -143,21 +135,14 @@ public:
|
|||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
boost::optional<Object_and_primitive_id>
|
||||
#else
|
||||
typename AABBTraits::template Intersection_and_primitive_id<Query>::Type
|
||||
boost::optional< typename AABBTraits::template Intersection_and_primitive_id<Query>::Type >
|
||||
#endif
|
||||
intersection = AABBTraits().intersection_object()(query, primitive);
|
||||
|
||||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
if(intersection)
|
||||
{
|
||||
*m_out_it++ = *intersection;
|
||||
}
|
||||
#else
|
||||
if(intersection.first)
|
||||
{
|
||||
*m_out_it++ = intersection;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool do_intersect(const Query& query, const Node& node) const
|
||||
|
|
|
|||
|
|
@ -106,9 +106,9 @@ void test_all_intersection_query_types(Tree& tree)
|
|||
optional_object_and_primitive = tree.any_intersection(line);
|
||||
optional_object_and_primitive = tree.any_intersection(segment);
|
||||
#else
|
||||
typename Tree::AABB_traits::template Intersection_and_primitive_id<Ray>::type r = tree.any_intersection(ray);
|
||||
typename Tree::AABB_traits::template Intersection_and_primitive_id<Line>::type l = tree.any_intersection(line);
|
||||
typename Tree::AABB_traits::template Intersection_and_primitive_id<Segment>::type s = tree.any_intersection(segment);
|
||||
boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id<Ray>::Type > r = tree.any_intersection(ray);
|
||||
boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id<Line>::Type > l = tree.any_intersection(line);
|
||||
boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id<Segment>::Type > s = tree.any_intersection(segment);
|
||||
#endif
|
||||
|
||||
// any_intersected_primitive
|
||||
|
|
@ -124,9 +124,9 @@ void test_all_intersection_query_types(Tree& tree)
|
|||
tree.all_intersections(line,std::back_inserter(intersections));
|
||||
tree.all_intersections(segment,std::back_inserter(intersections));
|
||||
#else
|
||||
std::list<typename Tree::AABB_traits::template Intersection_and_primitive_id<Ray>::type> intersections_r;
|
||||
std::list<typename Tree::AABB_traits::template Intersection_and_primitive_id<Line>::type> intersections_l;
|
||||
std::list<typename Tree::AABB_traits::template Intersection_and_primitive_id<Segment>::type> intersections_s;
|
||||
std::list< boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id<Ray>::Type > > intersections_r;
|
||||
std::list< boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id<Line>::Type > > intersections_l;
|
||||
std::list< boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id<Segment>::Type > > intersections_s;
|
||||
tree.all_intersections(ray,std::back_inserter(intersections_r));
|
||||
tree.all_intersections(line,std::back_inserter(intersections_l));
|
||||
tree.all_intersections(segment,std::back_inserter(intersections_s));
|
||||
|
|
@ -389,14 +389,12 @@ public:
|
|||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
Intersection_result
|
||||
intersection = Traits().intersection_object()(query, Pr(it));
|
||||
#else
|
||||
boost::optional< typename Traits::template Intersection_and_primitive_id<Query>::Type >
|
||||
intersection = Traits().intersection_object()(query, Pr(it));
|
||||
#endif
|
||||
if ( intersection )
|
||||
*out++ = *intersection;
|
||||
#else
|
||||
typename Traits::template Intersection_and_primitive_id<Query>::type
|
||||
intersection = Traits().intersection_object()(query, Pr(it));
|
||||
if ( intersection.first )
|
||||
*out++ = intersection;
|
||||
#endif
|
||||
}
|
||||
|
||||
return out;
|
||||
|
|
@ -704,7 +702,7 @@ private:
|
|||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
Object_and_primitive_id
|
||||
#else
|
||||
typename Tree::AABB_traits::template Intersection_and_primitive_id<Query>::type
|
||||
typename Tree::AABB_traits::template Intersection_and_primitive_id<Query>::Type
|
||||
#endif
|
||||
Obj_type;
|
||||
|
||||
|
|
@ -746,12 +744,11 @@ private:
|
|||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
boost::optional<Object_and_primitive_id>
|
||||
#else
|
||||
typename Tree::AABB_traits::template Intersection_and_primitive_id<Query>::type
|
||||
boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id<Query>::Type >
|
||||
#endif
|
||||
intersection = tree.any_intersection(query);
|
||||
|
||||
// Check: verify we do get the result by naive method
|
||||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
if ( intersection )
|
||||
{
|
||||
assert( std::find(intersections_naive_id.begin(),
|
||||
|
|
@ -759,15 +756,6 @@ private:
|
|||
intersection->second)
|
||||
!= intersections_naive_id.end());
|
||||
}
|
||||
#else
|
||||
if ( intersection.first )
|
||||
{
|
||||
assert( std::find(intersections_naive_id.begin(),
|
||||
intersections_naive_id.end(),
|
||||
intersection.second)
|
||||
!= intersections_naive_id.end());
|
||||
}
|
||||
#endif
|
||||
else if ( intersections_naive.size() != 0 )
|
||||
assert(false);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ std::size_t intersect(ForwardIterator b, ForwardIterator e, const Tree& tree, lo
|
|||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
typename Tree::Object_and_primitive_id
|
||||
#else
|
||||
typename Tree::AABB_traits::template Intersection_and_primitive_id<typename ForwardIterator::value_type>::type
|
||||
typename Tree::AABB_traits::template Intersection_and_primitive_id<typename ForwardIterator::value_type>::Type
|
||||
#endif
|
||||
Obj_type;
|
||||
|
||||
|
|
@ -51,16 +51,9 @@ std::size_t intersect(ForwardIterator b, ForwardIterator e, const Tree& tree, lo
|
|||
v.reserve(elements);
|
||||
for(; b != e; ++b) {
|
||||
tree.all_intersections(*b, std::back_inserter(v));
|
||||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
boost::optional<Obj_type> o = tree.any_intersection(*b);
|
||||
if(o)
|
||||
++counter;
|
||||
#else
|
||||
Obj_type
|
||||
o = tree.any_intersection(*b);
|
||||
if(o.first)
|
||||
++counter;
|
||||
#endif
|
||||
}
|
||||
|
||||
return v.size();
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ int main()
|
|||
obj = CGAL::intersection(s1,s2);
|
||||
|
||||
// check the variant return type
|
||||
K::Intersect_2::Result<Triangle_2, Triangle_2>::Type o_variant = CGAL::intersection(t1,t2);
|
||||
CGAL::cpp11::result_of<K::Intersect_2(Triangle_2, Triangle_2) >::type o_variant = CGAL::intersection(t1,t2);
|
||||
if(!o_variant) {
|
||||
std::cerr << "ERROR, empty" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
|
|
@ -75,7 +75,7 @@ int main()
|
|||
}
|
||||
|
||||
// check the variant return type
|
||||
K::Intersect_3::Result<Triangle_3, Triangle_3>::Type o_variant = CGAL::intersection(t1,t2);
|
||||
CGAL::cpp11::result_of<K::Intersect_3(Triangle_3, Triangle_3)>::type o_variant = CGAL::intersection(t1,t2);
|
||||
if(!o_variant) {
|
||||
std::cerr << "ERROR, empty" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
|||
|
|
@ -402,7 +402,7 @@ public:
|
|||
Intersection>::type
|
||||
operator()(const Query& q) const
|
||||
{
|
||||
typedef typename AABB_tree_::template Intersection_and_primitive_id<Query>::Type AABB_intersection;
|
||||
typedef boost::optional< typename AABB_tree_::template Intersection_and_primitive_id<Query>::Type > AABB_intersection;
|
||||
|
||||
typedef Point_3 Bare_point;
|
||||
|
||||
|
|
@ -413,18 +413,18 @@ public:
|
|||
AABB_intersection() :
|
||||
r_domain_.bounding_tree_->any_intersection(q);
|
||||
|
||||
if(! intersection.first &&
|
||||
if(! intersection &&
|
||||
r_domain_.bounding_tree_ != &r_domain_.tree_) {
|
||||
intersection = r_domain_.tree_.any_intersection(q);
|
||||
}
|
||||
if ( intersection.first )
|
||||
if ( intersection )
|
||||
{
|
||||
// Get primitive
|
||||
AABB_primitive_id primitive_id = intersection.second;
|
||||
AABB_primitive_id primitive_id = intersection->second;
|
||||
|
||||
// intersection may be either a point or a segment
|
||||
if ( const Bare_point* p_intersect_pt =
|
||||
boost::get<Bare_point>(&*intersection.first) )
|
||||
boost::get<Bare_point>( &(intersection->first) ) )
|
||||
{
|
||||
return Intersection(*p_intersect_pt,
|
||||
r_domain_.index_from_surface_patch_index(
|
||||
|
|
@ -432,7 +432,7 @@ public:
|
|||
2);
|
||||
}
|
||||
else if ( const Segment_3* p_intersect_seg =
|
||||
boost::get<Segment_3>(&*intersection.first))
|
||||
boost::get<Segment_3>(&(intersection->first)))
|
||||
{
|
||||
return Intersection(p_intersect_seg->source(),
|
||||
r_domain_.index_from_surface_patch_index(
|
||||
|
|
|
|||
|
|
@ -94,44 +94,48 @@ namespace CGAL {
|
|||
Object operator()(const Surface_3& surface, const Segment_3& segment) const
|
||||
{
|
||||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
AABB_intersection intersection = surface.tree()->any_intersection(segment);
|
||||
|
||||
if ( intersection )
|
||||
return intersection->first;
|
||||
else
|
||||
return Object();
|
||||
AABB_intersection
|
||||
#else
|
||||
return (surface.tree()->any_intersection(segment)).first;
|
||||
boost::optional< typename AABB_traits::template Intersection_and_primitive_id<Segment_3>::Type >
|
||||
#endif
|
||||
}
|
||||
|
||||
Object operator()(const Surface_3& surface, const Ray_3& ray) const
|
||||
{
|
||||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
AABB_intersection intersection = surface.tree()->any_intersection(segment);
|
||||
intersection = surface.tree()->any_intersection(segment);
|
||||
|
||||
if ( intersection )
|
||||
return intersection->first;
|
||||
else
|
||||
return Object();
|
||||
#else
|
||||
return (surface.tree()->any_intersection(ray)).first;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Object operator()(const Surface_3& surface, const Line_3& line) const
|
||||
{
|
||||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
AABB_intersection intersection = surface.tree()->any_intersection(segment);
|
||||
AABB_intersection
|
||||
#else
|
||||
boost::optional< typename AABB_traits::template Intersection_and_primitive_id<Line_3>::Type >
|
||||
#endif
|
||||
intersection = surface.tree()->any_intersection(line);
|
||||
|
||||
if ( intersection )
|
||||
return intersection->first;
|
||||
else
|
||||
return Object();
|
||||
#else
|
||||
return (surface.tree()->any_intersection(line)).first;
|
||||
#endif
|
||||
}
|
||||
Object operator()(const Surface_3& surface, const Ray_3& ray) const
|
||||
{
|
||||
#if CGAL_INTERSECTION_VERSION < 2
|
||||
AABB_intersection
|
||||
#else
|
||||
boost::optional< typename AABB_traits::template Intersection_and_primitive_id<Ray_3>::Type >
|
||||
#endif
|
||||
intersection = surface.tree()->any_intersection(ray);
|
||||
|
||||
if ( intersection )
|
||||
return intersection->first;
|
||||
else
|
||||
return Object();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
Intersect_3 intersect_3_object() const
|
||||
|
|
|
|||
Loading…
Reference in New Issue