OpenLexocad  27.0
RTree.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Geom/Bnd_Box.h>
4 #include <Geom/geom_defines.h>
5 
6 #include <boost/geometry.hpp>
7 #include <boost/geometry/geometries/point.hpp>
8 #include <boost/geometry/geometries/segment.hpp>
9 #include <boost/geometry/index/rtree.hpp>
10 
11 
12 namespace Geom
13 {
14 class Pnt;
15 class Pnt2d;
16 
17 namespace RTree
18 {
19  // Convenient namespaces
20  namespace bg = boost::geometry;
21  namespace bgm = boost::geometry::model;
22  namespace bgi = boost::geometry::index;
23 
24  // Convenient types 3d
25  typedef bgm::point<double, 3, bg::cs::cartesian> Point;
26  typedef bg::model::box<Point> Box;
27 
28  typedef std::pair<Point, uintptr_t> PointValue;
29  typedef bgi::rtree<PointValue, bgi::rstar<16> > PointRTree;
30 
31  typedef std::pair<Box, uintptr_t> BoxValue;
32  typedef bgi::rtree<BoxValue, bgi::rstar<16> > BoxRTree;
33 
35  GEOM_EXPORT Box getBox(const Geom::Pnt& p, const double& radius);
36  GEOM_EXPORT Box getBox(const Geom::Bnd_Box& bbox);
37 
38  GEOM_EXPORT PointValue getPointValue(const Geom::Pnt& p, uintptr_t userData);
39  GEOM_EXPORT BoxValue getBoxValue(const Bnd_Box& bbox, uintptr_t userData);
40 
41  // Convenient types 2d
42  typedef bgm::point<double, 2, bg::cs::cartesian> Point2d;
43  typedef bgm::segment<Point2d> Segment2d;
44  typedef bg::model::box<Point2d> Box2d;
45 
46  typedef std::pair<Segment2d, uintptr_t> Segment2dValue;
47  typedef bgi::rtree<Segment2dValue, bgi::rstar<16> > Segment2dRTree;
48 
49  typedef std::pair<Point2d, uintptr_t> Point2dValue;
50  typedef bgi::rtree<Point2dValue, bgi::rstar<16> > Point2dRTree;
51 
52  typedef std::pair<Box2d, uintptr_t> Box2dValue;
53  typedef bgi::rtree<Box2dValue, bgi::rstar<16> > Box2dRTree;
54 
55  GEOM_EXPORT Box2d getBox2d(const double& minx, const double& miny, const double& maxx, const double& maxy);
56  GEOM_EXPORT Box2d getBox2d(const Geom::Pnt2d& p, const double& radius);
58 
59  GEOM_EXPORT Box2dValue getBox2dValue(const double& minx, const double& miny, const double& maxx, const double& maxy, uintptr_t userData);
60  GEOM_EXPORT Box2dValue getBox2dValue(const Geom::Bnd_Box& bbox, uintptr_t userData);
61 } // namespace RTree
62 
63 
65 {
66 public:
67  struct Value
68  {
70  uintptr_t userData;
71  };
72 
73  BoxRTree();
74  BoxRTree(const std::vector<Value>& values); // building of tree is faster with this constructor
75  BoxRTree(const BoxRTree& other); // copy constructor
76  ~BoxRTree();
77 
78  void insert(const Bnd_Box& bbox, uintptr_t userData);
79  void insert(const Value& value);
80  bool remove(const Bnd_Box& bbox, uintptr_t userData); // removes only one value from the container
81  bool remove(const Value& value); // removes only one value from the container
82 
83  void queryIntersects(const Bnd_Box& bbox, std::vector<uintptr_t>& userDataVec) const;
84 
85 private:
86  RTree::BoxRTree* _tree;
87 };
88 
89 
91 {
92 public:
93  struct Value
94  {
96  uintptr_t userData;
97  };
98 
99  Box2dRTree();
100  Box2dRTree(const std::vector<Value>& values); // building of tree is faster with this constructor
101  Box2dRTree(const Box2dRTree& other); // copy constructor
102  ~Box2dRTree();
103 
104  void insert(const Bnd_Box& bbox, uintptr_t userData);
105  void insert(const Value& value);
106  bool remove(const Bnd_Box& bbox, uintptr_t userData); // removes only one value from the container
107  bool remove(const Value& value); // removes only one value from the container
108 
109  void queryIntersects(const Bnd_Box& bbox, std::vector<uintptr_t>& userDataVec) const;
110  void queryIntersects(const RTree::Box2d& bbox, std::vector<uintptr_t>& userDataVec) const;
111  bool hasIntersection(const Bnd_Box& bbox) const; // has at least one intersection
112  bool hasIntersection(const RTree::Box2d& bbox) const; // has at least one intersection
113 
114 private:
115  RTree::Box2dRTree* _tree;
116 };
117 } // namespace Geom
GEOM_EXPORT BoxValue getBoxValue(const Bnd_Box &bbox, uintptr_t userData)
bgm::point< double, 2, bg::cs::cartesian > Point2d
Definition: RTree.h:42
Definition: Rotation.h:5
std::pair< Point, uintptr_t > PointValue
Definition: RTree.h:28
Defines a non-persistent 3D Cartesian point.
Definition: Pnt.h:42
GEOM_EXPORT Box2dValue getBox2dValue(const double &minx, const double &miny, const double &maxx, const double &maxy, uintptr_t userData)
bgi::rtree< BoxValue, bgi::rstar< 16 > > BoxRTree
Definition: RTree.h:32
Definition: RTree.h:64
Definition: Bnd_Box.h:66
#define GEOM_EXPORT
Definition: geom_defines.h:8
uintptr_t userData
Definition: RTree.h:70
Definition: RTree.h:67
bgi::rtree< Box2dValue, bgi::rstar< 16 > > Box2dRTree
Definition: RTree.h:53
std::pair< Segment2d, uintptr_t > Segment2dValue
Definition: RTree.h:46
GEOM_EXPORT Box getBox(const Geom::Pnt &p, const double &radius)
uintptr_t userData
Definition: RTree.h:96
Definition: RTree.h:90
bg::model::box< Point2d > Box2d
Definition: RTree.h:44
bgi::rtree< Point2dValue, bgi::rstar< 16 > > Point2dRTree
Definition: RTree.h:50
bg::model::box< Point > Box
Definition: RTree.h:26
bgi::rtree< Segment2dValue, bgi::rstar< 16 > > Segment2dRTree
Definition: RTree.h:47
GEOM_EXPORT Point getPoint(const Geom::Pnt &p)
bgm::segment< Point2d > Segment2d
Definition: RTree.h:43
bgm::point< double, 3, bg::cs::cartesian > Point
Definition: RTree.h:25
Geom::Bnd_Box bbox
Definition: RTree.h:95
Definition: RTree.h:93
std::pair< Point2d, uintptr_t > Point2dValue
Definition: RTree.h:49
Geom::Bnd_Box bbox
Definition: RTree.h:69
Defines a non-persistent 2D cartesian point.
Definition: Pnt2d.h:33
bgi::rtree< PointValue, bgi::rstar< 16 > > PointRTree
Definition: RTree.h:29
GEOM_EXPORT Box2d getBox2d(const double &minx, const double &miny, const double &maxx, const double &maxy)
std::pair< Box2d, uintptr_t > Box2dValue
Definition: RTree.h:52
std::pair< Box, uintptr_t > BoxValue
Definition: RTree.h:31
GEOM_EXPORT PointValue getPointValue(const Geom::Pnt &p, uintptr_t userData)