5 #include <unordered_map>
58 if (
_nodes[0] !=
nullptr) {
71 if (
_nodes[0] !=
nullptr) {
92 if (
_nodes[0] !=
nullptr) {
95 if (entityIndex != -1) {
116 auto sentityBoundingBox = (*it)->boundingBox();
134 insert(entity, entity->boundingBox());
145 if (
_nodes[0] !=
nullptr) {
155 for (
typename std::vector<E>::iterator it =
_objects.begin(); it !=
_objects.end(); it++) {
156 if ((*it)->id() == entity->id()) {
184 std::vector<E>
retrieve(
const short maxLevel = SHRT_MAX)
const {
263 if (
_nodes[0] !=
nullptr) {
274 template<
typename U,
typename T>
void each(T func) {
275 if (
_nodes[0] !=
nullptr) {
276 _nodes[0]->template each<U>(func);
277 _nodes[1]->template each<U>(func);
278 _nodes[2]->template each<U>(func);
279 _nodes[3]->template each<U>(func);
283 std::shared_ptr<U> b = std::dynamic_pointer_cast< U >(item);
295 if (
_nodes[0] !=
nullptr) {
301 if (ret1 && ret2 && ret3 && ret4) {
326 void _retrieve(std::vector<E>& list,
const short maxLevel)
const {
366 unsigned int _size(
unsigned int c)
const {
367 if (
_nodes[0] !=
nullptr) {
387 if (!(topQuadrant || bottomQuadrant)) {
396 if (!(leftQuadrant || rightQuandrant)) {
399 else if (topQuadrant && rightQuandrant) {
402 else if (topQuadrant && leftQuadrant) {
405 else if (bottomQuadrant && leftQuadrant) {
436 if (
_nodes[0] !=
nullptr) {
510 QuadTreeSub<E>(level, pBounds, maxLevels, maxObjects) {
548 _cadentities.insert(std::make_pair(entity->id(), entity));
const Coordinate minP() const
void clear()
clear Clear the quad tree by removing all levels and removing all stored entities ...
const double _verticalMidpoint
QuadTree(int level, const geo::Area &pBounds, short maxLevels, short maxObjects)
The QuadTreeSub class each nide below QuadTree will be a QuadTreeSub type.
QuadTreeSub(const geo::Area &bounds)
bool erase(const E entity)
remove Remove entity from quad tree
std::vector< E > retrieve(const short maxLevel=SHRT_MAX) const
retrieve all object's within this QuadTree up until some level
QuadTreeSub(const QuadTreeSub &other)
short maxLevels() const
maxLevels Maximum number of level's possible This value should be copied from one level to a other le...
unsigned int size() const
size all object's that are located within a given area
double x() const
Returns x of Coordinate.
const E entityByID(ID_DATATYPE id) const
std::vector< E > _objects
void _retrieve(std::vector< E > &list, const geo::Area &area, const short maxLevel) const
retrieve all object's that are located within a given area
const unsigned short _maxLevels
double y() const
Returns y of Coordinate.
bool optimise()
optimise Optmise this tree. Current implementation will remove empty nodes up till the root node ...
const double _horizontalMidpoint
void walkQuad(const std::function< void(const QuadTreeSub< E > &)> &func)
walk Allows to walk over each node within the tree specifying a function that can be called for each ...
short level() const
level returns the current level of this QuadTree
bool includes(const geo::Area &area) const
The QuadTree class Quad tree implementation to spatially store CADEntities Useful for area selections...
void insert(const E entity)
void test() const
test validy of the tree by comparing all nodes with the std::map
void insert(const E entity, const lc::geo::Area &entityBoundingBox)
insert Insert entity into the qauad tree
bool erase(const E entity)
remove Remove entity from quad tree
geo::Area bounds() const
bounds of the root portion of the tree
QuadTreeSub(int level, const geo::Area &pBounds, short maxLevels, short maxObjects)
QuadTree(const geo::Area &bounds)
QuadTree(const QuadTree &other)
std::vector< E > retrieve(const geo::Area &area, const short maxLevel=SHRT_MAX) const
retrieve all object's that are located within a given area
void _retrieve(std::vector< E > &list, const short maxLevel) const
retrieve all object's that are located within a given area
void insert(const E entity)
insert Insert entity into the quad tree
void split()
split Create 4 new quads below the current quad
const Coordinate maxP() const
std::unordered_map< ID_DATATYPE, const E > _cadentities
unsigned int _size(unsigned int c) const
const unsigned short _maxObjects
double height() const
height Returns the height of this area
void clear()
clear Clear the quad tree by removing all levels and removing all stored entities ...
short maxObjects() const
maxObjects Maximum number of objects on this level This value should be copied one level to a other l...
double width() const
width Returns the width of this area
short quadrantIndex(const geo::Area &pRect) const
quadrantIndex located a possible quadrant index
const E entityByID(const ID_DATATYPE id) const
entityByID returns a entity by its ID