diff --git a/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp b/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp index 9d483301d30..4b615ca52f4 100644 --- a/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp @@ -17,8 +17,8 @@ typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; typedef CGAL::AABB_traits Traits; typedef CGAL::AABB_tree Tree; -typedef Tree::Intersection_and_primitive_id::Type Segment_intersection; -typedef Tree::Intersection_and_primitive_id::Type Plane_intersection; +typedef boost::optional< Tree::Intersection_and_primitive_id::Type > Segment_intersection; +typedef boost::optional< Tree::Intersection_and_primitive_id::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(&*intersection.first)) + if(boost::get(&(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(&*plane_intersection.first)) + if(boost::get(&(plane_intersection->first))) std::cout << "intersection object is a segment" << std::endl; } diff --git a/AABB_tree/include/CGAL/AABB_traits.h b/AABB_tree/include/CGAL/AABB_traits.h index 3f873a16660..d6e1f2ac335 100644 --- a/AABB_tree/include/CGAL/AABB_traits.h +++ b/AABB_tree/include/CGAL/AABB_traits.h @@ -71,9 +71,8 @@ public: template struct Intersection_and_primitive_id { typedef std::pair< - typename cpp11::result_of::type, + typename IT::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 Intersection_and_primitive_id::Type + boost::optional< typename Intersection_and_primitive_id::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::type + inter_res = GeomTraits().intersect_3_object()(primitive.datum(),query); + if (!inter_res) + return boost::optional::Type>(); + return boost::make_optional( std::make_pair(*inter_res, primitive.id()) ); } #endif }; diff --git a/AABB_tree/include/CGAL/AABB_tree.h b/AABB_tree/include/CGAL/AABB_tree.h index 62922953332..ce637c52880 100644 --- a/AABB_tree/include/CGAL/AABB_tree.h +++ b/AABB_tree/include/CGAL/AABB_tree.h @@ -262,7 +262,7 @@ public: #if CGAL_INTERSECTION_VERSION < 2 boost::optional #else - typename Intersection_and_primitive_id::Type + boost::optional< typename Intersection_and_primitive_id::Type > #endif any_intersection(const Query& query) const; @@ -706,7 +706,7 @@ public: #if CGAL_INTERSECTION_VERSION < 2 boost::optional::Object_and_primitive_id> #else - typename AABB_tree::template Intersection_and_primitive_id::Type + boost::optional< typename AABB_tree::template Intersection_and_primitive_id::Type > #endif AABB_tree::any_intersection(const Query& query) const { diff --git a/AABB_tree/include/CGAL/internal/AABB_tree/AABB_traversal_traits.h b/AABB_tree/include/CGAL/internal/AABB_tree/AABB_traversal_traits.h index 3c1fc18e58c..4cfb2926c0e 100644 --- a/AABB_tree/include/CGAL/internal/AABB_tree/AABB_traversal_traits.h +++ b/AABB_tree/include/CGAL/internal/AABB_tree/AABB_traversal_traits.h @@ -73,11 +73,11 @@ class First_intersection_traits typedef ::CGAL::AABB_node Node; public: - typedef typename + typedef #if CGAL_INTERSECTION_VERSION < 2 boost::optional #else - AABBTraits::template Intersection_and_primitive_id::Type + boost::optional< typename AABBTraits::template Intersection_and_primitive_id::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 #else - typename AABBTraits::template Intersection_and_primitive_id::Type + boost::optional< typename AABBTraits::template Intersection_and_primitive_id::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 diff --git a/AABB_tree/test/AABB_tree/AABB_test_util.h b/AABB_tree/test/AABB_tree/AABB_test_util.h index 1df1f612569..c790aa7d802 100644 --- a/AABB_tree/test/AABB_tree/AABB_test_util.h +++ b/AABB_tree/test/AABB_tree/AABB_test_util.h @@ -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::type r = tree.any_intersection(ray); - typename Tree::AABB_traits::template Intersection_and_primitive_id::type l = tree.any_intersection(line); - typename Tree::AABB_traits::template Intersection_and_primitive_id::type s = tree.any_intersection(segment); + boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id::Type > r = tree.any_intersection(ray); + boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id::Type > l = tree.any_intersection(line); + boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id::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::type> intersections_r; - std::list::type> intersections_l; - std::list::type> intersections_s; + std::list< boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id::Type > > intersections_r; + std::list< boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id::Type > > intersections_l; + std::list< boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id::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::Type > + intersection = Traits().intersection_object()(query, Pr(it)); + #endif if ( intersection ) *out++ = *intersection; - #else - typename Traits::template Intersection_and_primitive_id::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::type + typename Tree::AABB_traits::template Intersection_and_primitive_id::Type #endif Obj_type; @@ -746,12 +744,11 @@ private: #if CGAL_INTERSECTION_VERSION < 2 boost::optional #else - typename Tree::AABB_traits::template Intersection_and_primitive_id::type + boost::optional< typename Tree::AABB_traits::template Intersection_and_primitive_id::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); diff --git a/AABB_tree/test/AABB_tree/aabb_any_all_benchmark.cpp b/AABB_tree/test/AABB_tree/aabb_any_all_benchmark.cpp index 8183a054701..bf3e994aa83 100644 --- a/AABB_tree/test/AABB_tree/aabb_any_all_benchmark.cpp +++ b/AABB_tree/test/AABB_tree/aabb_any_all_benchmark.cpp @@ -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::type + typename Tree::AABB_traits::template Intersection_and_primitive_id::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 o = tree.any_intersection(*b); if(o) ++counter; -#else - Obj_type - o = tree.any_intersection(*b); - if(o.first) - ++counter; -#endif } return v.size(); diff --git a/Filtered_kernel/test/Filtered_kernel/test_lazy_vector_objects.cpp b/Filtered_kernel/test/Filtered_kernel/test_lazy_vector_objects.cpp index a634e1281cc..ad47d41b3e0 100644 --- a/Filtered_kernel/test/Filtered_kernel/test_lazy_vector_objects.cpp +++ b/Filtered_kernel/test/Filtered_kernel/test_lazy_vector_objects.cpp @@ -35,7 +35,7 @@ int main() obj = CGAL::intersection(s1,s2); // check the variant return type - K::Intersect_2::Result::Type o_variant = CGAL::intersection(t1,t2); + CGAL::cpp11::result_of::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::Type o_variant = CGAL::intersection(t1,t2); + CGAL::cpp11::result_of::type o_variant = CGAL::intersection(t1,t2); if(!o_variant) { std::cerr << "ERROR, empty" << std::endl; return EXIT_FAILURE; diff --git a/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h b/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h index 21b497fd593..be7d62af5e1 100644 --- a/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h +++ b/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h @@ -402,7 +402,7 @@ public: Intersection>::type operator()(const Query& q) const { - typedef typename AABB_tree_::template Intersection_and_primitive_id::Type AABB_intersection; + typedef boost::optional< typename AABB_tree_::template Intersection_and_primitive_id::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(&*intersection.first) ) + boost::get( &(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(&*intersection.first)) + boost::get(&(intersection->first))) { return Intersection(p_intersect_seg->source(), r_domain_.index_from_surface_patch_index( diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/AABB_polyhedral_oracle.h b/Polyhedron/demo/Polyhedron/include/CGAL/AABB_polyhedral_oracle.h index 2c4925a382e..4dfd5a0867d 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/AABB_polyhedral_oracle.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/AABB_polyhedral_oracle.h @@ -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::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::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::Type > + #endif + intersection = surface.tree()->any_intersection(ray); + + if ( intersection ) + return intersection->first; + else + return Object(); + } + + }; Intersect_3 intersect_3_object() const