quadtree/NodeBase.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: index/quadtree/NodeBase.java rev 1.9 (JTS-1.10)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <array>
#include <vector>
#include <string>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
#endif
// Forward declarations
namespace geos {
namespace geom {
class Coordinate;
class Envelope;
}
namespace index {
class ItemVisitor;
namespace quadtree {
class Node;
}
}
}
namespace geos {
namespace index { // geos::index
namespace quadtree { // geos::index::quadtree
class GEOS_DLL NodeBase {
private:
void visitItems(const geom::Envelope* searchEnv,
ItemVisitor& visitor);
public:
static int getSubnodeIndex(const geom::Envelope* env,
const geom::Coordinate& centre);
NodeBase();
virtual ~NodeBase();
std::vector<void*>& getItems();
void add(void* item);
std::vector<void*>& addAllItems(std::vector<void*>& resultItems) const;
virtual void addAllItemsFromOverlapping(const geom::Envelope& searchEnv,
std::vector<void*>& resultItems) const;
unsigned int depth() const;
std::size_t size() const;
std::size_t getNodeCount() const;
virtual std::string toString() const;
virtual void visit(const geom::Envelope* searchEnv, ItemVisitor& visitor);
bool remove(const geom::Envelope* itemEnv, void* item);
bool hasItems() const;
bool hasChildren() const;
bool isPrunable() const;
protected:
std::vector<void*> items;
std::array<Node*, 4> subnodes;
virtual bool isSearchMatch(const geom::Envelope& searchEnv) const = 0;
};
// INLINES, To be moved in NodeBase.inl
inline bool
NodeBase::hasChildren() const
{
for(const auto& subnode : subnodes) {
if(subnode != nullptr) {
return true;
}
}
return false;
}
inline bool
NodeBase::isPrunable() const
{
return !(hasChildren() || hasItems());
}
inline bool
NodeBase::hasItems() const
{
return ! items.empty();
}
} // namespace geos::index::quadtree
} // namespace geos::index
} // namespace geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
geos::index::ItemVisitor
A visitor for items in an index.
Definition ItemVisitor.h:28
geos::index::quadtree::NodeBase::subnodes
std::array< Node *, 4 > subnodes
Definition quadtree/NodeBase.h:122
geos::index::quadtree::NodeBase::items
std::vector< void * > items
Actual items are NOT owned by this class.
Definition quadtree/NodeBase.h:110
geos::index::quadtree::NodeBase::remove
bool remove(const geom::Envelope *itemEnv, void *item)
geos::index::quadtree::NodeBase::addAllItems
std::vector< void * > & addAllItems(std::vector< void * > &resultItems) const
Push all node items to the given vector, return the argument.
geos::index::quadtree::NodeBase::add
void add(void *item)
geos::index::quadtree::Node
Represents a node of a Quadtree.
Definition index/quadtree/Node.h:54
geos::geom
Definition Angle.h:26
geos::index::quadtree
Contains classes that implement a Quadtree spatial index.
Definition CleanCoverage.h:40
geos::index
Provides classes for various kinds of spatial indexes.
Definition CleanCoverage.h:39
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38