File: AABB_halfedge_graph_segment_primitive.h

package info (click to toggle)
cgal 6.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (211 lines) | stat: -rw-r--r-- 9,336 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// Copyright (c) 2012 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h $
// $Id: include/CGAL/AABB_halfedge_graph_segment_primitive.h 08b27d3db14 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s)     : Sebastien Loriot
//

#ifndef CGAL_AABB_HALFEDGE_GRAPH_SEGMENT_PRIMITIVE_H
#define CGAL_AABB_HALFEDGE_GRAPH_SEGMENT_PRIMITIVE_H

#include <CGAL/license/AABB_tree.h>

#include <CGAL/disable_warnings.h>

#include <CGAL/AABB_primitive.h>
#include <CGAL/boost/graph/property_maps.h>

#include <iterator>
#include <boost/mpl/and.hpp>
#include <CGAL/type_traits/is_iterator.h>

#include <CGAL/Default.h>

namespace CGAL {


/*!
 * \ingroup PkgAABBTreeRef
 * Primitive type for an edge of a polyhedral surface.
 * It wraps an `edge_descriptor` into a 3D segment.
 * The class model of `HalfedgeGraph` from which the primitive is built should not be deleted
 * while the AABB tree holding the primitive is in use.
 * The type of the 3D segment is taken from the kernel of the point type which is the value type
 * of `VertexPointPMap` (using the `Kernel_traits` mechanism).
 * The segment type of the primitive (`Datum`) is `CGAL::Kernel_traits< boost::property_traits< VertexPointPMap >::%value_type >::%Kernel::Segment_3`.
 *
 * \cgalModelsBareBegin
 * \cgalModelsBare{`AABBPrimitive` if `OneHalfedgeGraphPerTree` is `CGAL::Tag_false`}
 * \cgalModelsBare{`AABBPrimitiveWithSharedData` if `OneHalfedgeGraphPerTree` is `CGAL::Tag_true`}
 * \cgalModelsBareEnd
 *
 * \tparam HalfedgeGraph is a model of the halfedge graph concept.
 *   as key type and a \cgal Kernel `Point_3` as value type.
 * \tparam VertexPointPMap is a property map with `boost::graph_traits<HalfedgeGraph>::%vertex_descriptor`.
 *                         The default is `typename boost::property_map< HalfedgeGraph,vertex_point_t>::%const_type`.
 * \tparam OneHalfedgeGraphPerTree is either `CGAL::Tag_true` or `CGAL::Tag_false`.
 * In the former case, we guarantee that all the primitives will be from a
 * common `HalfedgeGraph` and some data will be factorized so that the size of
 * the primitive is reduced. In the latter case, the primitives can be from
 * different graphs and extra storage is required in the primitives. The default is `CGAL::Tag_true`.
 * \tparam CacheDatum is either `CGAL::Tag_true` or `CGAL::Tag_false`. In the former case, the datum is
 * stored in the primitive, while in the latter it is constructed on the fly to reduce
 * the memory footprint. The default is `CGAL::Tag_false` (datum is not stored).
 *
 * \sa `AABBPrimitive`
 * \sa `AABB_primitive<Id,ObjectPropertyMap,PointPropertyMapPolyhedron,ExternalPropertyMaps,CacheDatum>`
 * \sa `AABB_face_graph_triangle_primitive<FaceGraph,VertexPointPMap,OneFaceGraphPerTree,CacheDatum>`
 * \sa `AABB_segment_primitive_3<Iterator,CacheDatum>`
 * \sa \link BGLPolyGT `boost::graph_traits<Polyhedron>` \endlink
 */
template < class HalfedgeGraph,
           class VertexPointPMap = Default,
           class OneHalfedgeGraphPerTree = Tag_true,
           class CacheDatum = Tag_false >
class AABB_halfedge_graph_segment_primitive
#ifndef DOXYGEN_RUNNING
  : public AABB_primitive< std::conditional_t<OneHalfedgeGraphPerTree::value,
                                              typename boost::graph_traits<HalfedgeGraph>::edge_descriptor,
                                              std::pair<typename boost::graph_traits<HalfedgeGraph>::edge_descriptor, const HalfedgeGraph*> >,
                            Segment_from_edge_descriptor_map<
                              HalfedgeGraph,
                              typename Default::Get<VertexPointPMap,
                                                    typename boost::property_map< HalfedgeGraph,
                                                                                  vertex_point_t>::const_type >::type >,
                            Source_point_from_edge_descriptor_map<
                              HalfedgeGraph,
                              typename Default::Get<VertexPointPMap,
                                                    typename boost::property_map< HalfedgeGraph,
                                                                                  vertex_point_t>::const_type >::type >,
                            OneHalfedgeGraphPerTree,
                            CacheDatum >
#endif
{
  typedef typename Default::Get<VertexPointPMap,typename boost::property_map< HalfedgeGraph,vertex_point_t>::const_type >::type  VertexPointPMap_;
  typedef typename boost::graph_traits<HalfedgeGraph>::edge_descriptor ED;
  typedef std::conditional_t<OneHalfedgeGraphPerTree::value, ED, std::pair<ED, const HalfedgeGraph*> > Id_;

  typedef Segment_from_edge_descriptor_map<HalfedgeGraph,VertexPointPMap_>  Segment_property_map;
  typedef Source_point_from_edge_descriptor_map<HalfedgeGraph,VertexPointPMap_> Point_property_map;

  typedef AABB_primitive< Id_,
                          Segment_property_map,
                          Point_property_map,
                          OneHalfedgeGraphPerTree,
                          CacheDatum > Base;

  ED make_id(ED ed, const HalfedgeGraph&, Tag_true)
  {
    return ed;
  }

  std::pair<ED, const HalfedgeGraph*> make_id(ED ed, const HalfedgeGraph& fg, Tag_false)
  {
    return std::make_pair(ed, &fg);
  }

public:

#ifdef DOXYGEN_RUNNING
 /// \name Types
  /// @{
  /*!
  The point type.
  */
  typedef boost::property_traits< boost::property_map< HalfedgeGraph, vertex_point_t>::const_type >::value_type Point;
  /*!
  Geometric data type.
  */
  typedef Kernel_traits<Point>::Kernel::Segment_3 Datum;
  /*!
  Id type:
  - `boost::graph_traits<HalfedgeGraph>::%edge_descriptor` if `OneHalfedgeGraphPerTree` is `Tag_true`
  - `std::pair<boost::graph_traits<HalfedgeGraph>::%edge_descriptor, const HalfedgeGraph*>` if `OneHalfedgeGraphPerTree` is `Tag_false`
  */
  unspecified_type Id;
  /// @}

  /*!
  If `OneHalfedgeGraphPerTree` is CGAL::Tag_true, constructs a `Shared_data` object from a reference to the halfedge graph.
  */
  static unspecified_type construct_shared_data( HalfedgeGraph& graph );
#else
  typedef typename Base::Id Id;
#endif
  typedef typename boost::graph_traits<HalfedgeGraph>::edge_descriptor edge_descriptor;

#ifdef DOXYGEN_RUNNING
  /*!
  constructs a primitive.

  \tparam Iterator is an input iterator with `Id` as value type.

  This \ref AABB_tree/AABB_halfedge_graph_edge_example.cpp "example" gives a way to call this constructor
  using the insert-by-range method of the class `AABB_tree<Traits>`.
  If `VertexPointPMap` is the default of the class, an additional constructor
  is available with `vppm` set to `boost::get(vertex_point, graph)`.
  */
  template <class Iterator>
  AABB_halfedge_graph_segment_primitive(Iterator it, const HalfedgeGraph& graph, VertexPointPMap vppm);

  /*!
  constructs a primitive.
  If `VertexPointPMap` is the default of the class, an additional constructor
  is available with `vppm` set to `boost::get(vertex_point, graph)`.
  */
  AABB_halfedge_graph_segment_primitive(edge_descriptor ed, const HalfedgeGraph& graph, VertexPointPMap vppm);
#else
  template <class Iterator>
  AABB_halfedge_graph_segment_primitive(Iterator it, const HalfedgeGraph& graph, VertexPointPMap_ vppm)
    : Base( Id_(make_id(*it, graph, OneHalfedgeGraphPerTree())),
            Segment_property_map(const_cast<HalfedgeGraph*>(&graph), vppm),
            Point_property_map(const_cast<HalfedgeGraph*>(&graph), vppm) )
  {}

  AABB_halfedge_graph_segment_primitive(edge_descriptor ed, const HalfedgeGraph& graph, VertexPointPMap_ vppm)
    : Base( Id_(make_id(ed, graph, OneHalfedgeGraphPerTree())),
            Segment_property_map(const_cast<HalfedgeGraph*>(&graph), vppm),
            Point_property_map(const_cast<HalfedgeGraph*>(&graph), vppm) )
  {}

  template <class Iterator>
  AABB_halfedge_graph_segment_primitive(Iterator it, const HalfedgeGraph& graph)
    : Base( Id_(make_id(*it, graph, OneHalfedgeGraphPerTree())),
            Segment_property_map(const_cast<HalfedgeGraph*>(&graph)),
            Point_property_map(const_cast<HalfedgeGraph*>(&graph)) ){}

  AABB_halfedge_graph_segment_primitive(edge_descriptor ed, const HalfedgeGraph& graph)
    : Base( Id_(make_id(ed, graph, OneHalfedgeGraphPerTree())),
            Segment_property_map(const_cast<HalfedgeGraph*>(&graph)),
            Point_property_map(const_cast<HalfedgeGraph*>(&graph)) ){}
#endif

  /// \internal
  typedef internal::Cstr_shared_data<HalfedgeGraph, Base, Segment_property_map, Point_property_map, OneHalfedgeGraphPerTree> Cstr_shared_data;
  /// \internal
  static
  typename Cstr_shared_data::Shared_data
  construct_shared_data(const HalfedgeGraph& graph)
  {
    return Cstr_shared_data::construct_shared_data(const_cast<HalfedgeGraph&>(graph));
  }

  static
  typename Cstr_shared_data::Shared_data
  construct_shared_data(const HalfedgeGraph& graph, const VertexPointPMap_& vpm)
  {
    return Cstr_shared_data::construct_shared_data(const_cast<HalfedgeGraph&>(graph), vpm);
  }
};

}  // end namespace CGAL

#include <CGAL/enable_warnings.h>

#endif // CGAL_AABB_HALFEDGE_GRAPH_SEGMENT_PRIMITIVE_H