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 
222 
223 #endif
RSpatialIndex::queryNearestNeighbor
virtual QMap< int, QSet< int > > queryNearestNeighbor(unsigned int k, double x, double y, double z, RSpatialIndexVisitor *dataVisitor=NULL)=0
Queries the index for closest neighbor items.
RRequireHeap.h
RBox.h
RSpatialIndex::removeFromIndex
virtual bool removeFromIndex(int id, int pos, double x1, double y1, double z1, double x2, double y2, double z2)=0
Removes the entry with the given ID from this spatial index.
RMath.h
RSpatialIndexDebugVisitor::dbg
QDebug dbg
Definition: RSpatialIndex.h:58
RDebug.h
RSpatialIndexDebugVisitor::RSpatialIndexDebugVisitor
RSpatialIndexDebugVisitor(QDebug dbg)
Definition: RSpatialIndex.h:39
RSpatialIndexDebugVisitor::matches
QList< QPair< int, int > > matches
Definition: RSpatialIndex.h:59
RSpatialIndex::RSpatialIndex
RSpatialIndex()
Definition: RSpatialIndex.h:71
RSpatialIndex::create
virtual RSpatialIndex * create()=0
RSpatialIndex::queryIntersected
virtual QMap< int, QSet< int > > queryIntersected(double x1, double y1, double z1, double x2, double y2, double z2, RSpatialIndexVisitor *dataVisitor=NULL)=0
Queries the index for all items that are completely inside or intersect with the given box x1,...
RSpatialIndex
Abstract base class for spatial index implementations.
Definition: RSpatialIndex.h:69
RSpatialIndexDebugVisitor
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RSpatialIndex.h:37
RSpatialIndexDebugVisitor::visitNode
virtual void visitNode(double x1, double y1, double z1, double x2, double y2, double z2)
Definition: RSpatialIndex.h:47
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(RMath *)
RSpatialIndex::clear
virtual void clear()=0
core_global.h
RSpatialIndexDebugVisitor::~RSpatialIndexDebugVisitor
virtual ~RSpatialIndexDebugVisitor()
Definition: RSpatialIndex.h:40
RSpatialIndex::~RSpatialIndex
virtual ~RSpatialIndex()
Definition: RSpatialIndex.h:74
operator<<
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RSpatialIndex &si)
Stream operator for QDebug.
Definition: RSpatialIndex.cpp:144
RSpatialIndex::queryContained
virtual QMap< int, QSet< int > > queryContained(double x1, double y1, double z1, double x2, double y2, double z2, RSpatialIndexVisitor *dataVisitor=NULL)=0
Queries the index for all items that are completely inside the given box x1,y1,z1,...
RSpatialIndex::addToIndex
virtual void addToIndex(int id, int pos, double x1, double y1, double z1, double x2, double y2, double z2)=0
Adds a new entry into this spatial index.
RSpatialIndexVisitor::visitData
virtual void visitData(int id, int pos, double x1, double y1, double z1, double x2, double y2, double z2)=0
RRequireHeap
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RRequireHeap.h:30
RSpatialIndexVisitor.h
RBox
Represents a box e.g.
Definition: RBox.h:43
QCADCORE_EXPORT
#define QCADCORE_EXPORT
Definition: core_global.h:10
RSpatialIndexVisitor
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RSpatialIndexVisitor.h:35
RSpatialIndex::idCounter
int idCounter
Definition: RSpatialIndex.h:215