QCAD
Open Source 2D CAD
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 RSpatialIndex* create() = 0;
82  virtual void clear() = 0;
83 
84  virtual void bulkLoad(const QList<int>& ids, const QList<QList<RBox> >& bbs);
85 
86  virtual void bulkLoadSimple(const QList<int>& ids, const QList<RBox>& bbs);
87 
91  virtual void addToIndex(
92  int id, int pos,
93  double x1, double y1, double z1,
94  double x2, double y2, double z2
95  ) = 0;
96 
100  virtual void addToIndex(
101  int id, int pos,
102  const RBox& bb
103  );
104 
109  virtual void addToIndex(
110  int id,
111  const QList<RBox>& bbs
112  );
113 
117  //virtual void removeFromIndex(int id) = 0;
118 
123  virtual bool removeFromIndex(
124  int id, int pos,
125  double x1, double y1, double z1,
126  double x2, double y2, double z2) = 0;
127 
132  virtual bool removeFromIndex(int id, int pos, const RBox& bb);
133 
138  virtual bool removeFromIndex(int id, const QList<RBox>& bb);
139 
154  virtual QMap<int, QSet<int> > queryIntersected(
155  double x1, double y1, double z1,
156  double x2, double y2, double z2,
157  RSpatialIndexVisitor* dataVisitor=NULL
158  ) = 0;
159 
164  virtual QMap<int, QSet<int> > queryIntersected(
165  const RBox& b,
166  RSpatialIndexVisitor* dataVisitor=NULL
167  );
168 
182  virtual QMap<int, QSet<int> > queryContained(
183  double x1, double y1, double z1,
184  double x2, double y2, double z2,
185  RSpatialIndexVisitor* dataVisitor=NULL
186  ) = 0;
187 
192  virtual QMap<int, QSet<int> > queryContained(
193  const RBox& b,
194  RSpatialIndexVisitor* dataVisitor=NULL
195  );
196 
206  virtual QMap<int, QSet<int> > queryNearestNeighbor(
207  unsigned int k,
208  double x, double y, double z,
209  RSpatialIndexVisitor* dataVisitor=NULL
210  ) = 0;
211 
212  virtual QPair<int, int> queryNearestNeighbor(double x, double y, double z);
213 
214 protected:
216 };
217 
218 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RSpatialIndex& si);
219 
221 
222 #endif
Represents a box e.g.
Definition: RBox.h:43
QDebug dbg
Definition: RSpatialIndex.h:58
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RSpatialIndex.h:37
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RSpatialIndexVisitor.h:35
virtual ~RSpatialIndex()
Definition: RSpatialIndex.h:74
RSpatialIndexDebugVisitor(QDebug dbg)
Definition: RSpatialIndex.h:39
#define QCADCORE_EXPORT
Definition: core_global.h:10
virtual ~RSpatialIndexDebugVisitor()
Definition: RSpatialIndex.h:40
virtual void visitData(int id, int pos, double x1, double y1, double z1, double x2, double y2, double z2)=0
QList< QPair< int, int > > matches
Definition: RSpatialIndex.h:59
int idCounter
Definition: RSpatialIndex.h:215
Q_DECLARE_METATYPE(RMath *)
virtual void visitNode(double x1, double y1, double z1, double x2, double y2, double z2)
Definition: RSpatialIndex.h:47
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RSpatialIndex &si)
Stream operator for QDebug.
Definition: RSpatialIndex.cpp:144
int k
Definition: SelectionFilter.js:12
RSpatialIndex()
Definition: RSpatialIndex.h:71
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RRequireHeap.h:30
Abstract base class for spatial index implementations.
Definition: RSpatialIndex.h:69