QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RSpatialIndex.h
Go to the documentation of this file.
1 
20 #ifndef RSPATIALINDEX_H
21 #define RSPATIALINDEX_H
22 
23 #include "core_global.h"
24 
25 // MSVC <= 2008 does not have this:
26 //#include <stdint.h>
27 
28 #include <QSet>
29 #include <QList>
30 
31 #include "RBox.h"
32 #include "RDebug.h"
33 #include "RMath.h"
34 #include "RRequireHeap.h"
35 #include "RSpatialIndexVisitor.h"
36 
38 public:
39  RSpatialIndexDebugVisitor(QDebug dbg) : dbg(dbg) {}
41  virtual void visitData(
42  int id,
43  int pos,
44  double x1, double y1, double z1,
45  double x2, double y2, double z2);
46 
47  virtual void visitNode(
48  double x1, double y1, double z1,
49  double x2, double y2, double z2) {
50  Q_UNUSED(x1)
51  Q_UNUSED(y1)
52  Q_UNUSED(z1)
53  Q_UNUSED(x2)
54  Q_UNUSED(y2)
55  Q_UNUSED(z2)
56  }
57 
58  QDebug dbg;
59  QList<QPair<int, int> > matches;
60 };
61 
62 
70 public:
72  }
73 
74  virtual ~RSpatialIndex() {
75  }
76 
77  static qint64 getSIId(int id, int pos);
78  static int getId(qint64 siid);
79  static int getPos(qint64 siid);
80 
81  virtual void clear() = 0;
82 
86  virtual void addToIndex(
87  int id, int pos,
88  double x1, double y1, double z1,
89  double x2, double y2, double z2
90  ) = 0;
91 
95  virtual void addToIndex(
96  int id, int pos,
97  const RBox& bb
98  );
99 
104  virtual void addToIndex(
105  int id,
106  const QList<RBox>& bbs
107  );
108 
112  //virtual void removeFromIndex(int id) = 0;
113 
118  virtual bool removeFromIndex(
119  int id, int pos,
120  double x1, double y1, double z1,
121  double x2, double y2, double z2) = 0;
122 
127  virtual bool removeFromIndex(int id, int pos, const RBox& bb);
128 
133  virtual bool removeFromIndex(int id, const QList<RBox>& bb);
134 
149  virtual QMap<int, QSet<int> > queryIntersected(
150  double x1, double y1, double z1,
151  double x2, double y2, double z2,
152  RSpatialIndexVisitor* dataVisitor=NULL
153  ) = 0;
154 
159  virtual QMap<int, QSet<int> > queryIntersected(
160  const RBox& b,
161  RSpatialIndexVisitor* dataVisitor=NULL
162  );
163 
177  virtual QMap<int, QSet<int> > queryContained(
178  double x1, double y1, double z1,
179  double x2, double y2, double z2,
180  RSpatialIndexVisitor* dataVisitor=NULL
181  ) = 0;
182 
187  virtual QMap<int, QSet<int> > queryContained(
188  const RBox& b,
189  RSpatialIndexVisitor* dataVisitor=NULL
190  );
191 
201  virtual QMap<int, QSet<int> > queryNearestNeighbor(
202  unsigned int k,
203  double x, double y, double z,
204  RSpatialIndexVisitor* dataVisitor=NULL
205  ) = 0;
206 
207  virtual QPair<int, int> queryNearestNeighbor(double x, double y, double z);
208 
209 protected:
211 };
212 
213 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RSpatialIndex& si);
214 
216 
217 #endif