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