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