1 // Copyright (c) 2014  GeometryFactory Sarl (France).
2 // All rights reserved.
3 //
4 // This file is part of CGAL (www.cgal.org).
5 //
6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/AABB_traversal_traits.h $
7 // $Id: AABB_traversal_traits.h 254d60f 2019-10-19T15:23:19+02:00 Sébastien Loriot
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 // Author(s)     : Ilker O. Yaz
11 
12 
13 #ifndef CGAL_INTERNAL_SURFACE_MESH_SEGMENTATION_AABB_TRAVERSAL_TRAITS_H
14 #define CGAL_INTERNAL_SURFACE_MESH_SEGMENTATION_AABB_TRAVERSAL_TRAITS_H
15 
16 #include <CGAL/license/Surface_mesh_segmentation.h>
17 
18 
19 namespace CGAL
20 {
21 
22 /// @cond CGAL_DOCUMENT_INTERNAL
23 
24 /**
25  * @class Special case for ray/segment-triangle
26  * the only difference with the offical one (Listing_intersection_traits) is that
27  * is the do_intersect which is made prior to the intersection call.
28  */
29 template<typename AABBTraits, typename Query, typename Output_iterator>
30 class Listing_intersection_traits_ray_or_segment_triangle
31 {
32   typedef typename AABBTraits::FT FT;
33   typedef typename AABBTraits::Point_3 Point;
34   typedef typename AABBTraits::Primitive Primitive;
35   typedef typename AABBTraits::Bounding_box Bounding_box;
36   typedef typename AABBTraits::Primitive::Id Primitive_id;
37   typedef typename AABBTraits::Point_and_primitive_id Point_and_primitive_id;
38   typedef ::CGAL::AABB_node<AABBTraits> Node;
39   typedef typename ::CGAL::AABB_tree<AABBTraits>::size_type size_type;
40 
41 public:
Listing_intersection_traits_ray_or_segment_triangle(Output_iterator out_it,const AABBTraits & traits)42   Listing_intersection_traits_ray_or_segment_triangle(Output_iterator out_it,
43       const AABBTraits& traits)
44     : m_out_it(out_it), m_traits(traits) {}
45 
go_further()46   bool go_further() const {
47     return true;
48   }
49 
intersection(const Query & query,const Primitive & primitive)50   void intersection(const Query& query, const Primitive& primitive) {
51     //SL: using Kernel_traits is not bad in this context cause we expect a Ray/Segment from a CGAL Kernel here
52     typedef typename Kernel_traits<Query>::Kernel GeomTraits;
53     typedef typename AABBTraits:: template Intersection_and_primitive_id<Query>::Type Intersection_and_primitive_id;
54 
55     if ( GeomTraits().do_intersect_3_object()(query,
56          primitive.datum(m_traits.shared_data())) ) {
57       boost::optional<Intersection_and_primitive_id> intersection
58         = m_traits.intersection_object()(query, primitive);
59       if(intersection) {
60         *m_out_it++ = *intersection;
61       }
62     }
63   }
64 
do_intersect(const Query & query,const Node & node)65   bool do_intersect(const Query& query, const Node& node) const {
66     return m_traits.do_intersect_object()(query, node.bbox());
67   }
68 
69 private:
70   Output_iterator m_out_it;
71   const AABBTraits& m_traits;
72 };
73 
74 /// @endcond
75 
76 } //namespace CGAL
77 #endif
78