KiCad PCB EDA Suite
SHAPE_INDEX< T > Class Template Reference

#include <shape_index.h>

Classes

class  Iterator
 

Public Member Functions

 SHAPE_INDEX ()
 
 ~SHAPE_INDEX ()
 
void Add (T aShape)
 Function Add() More...
 
void Remove (T aShape)
 Function Remove() More...
 
void RemoveAll ()
 Function RemoveAll() More...
 
template<class V >
void Accept (V aVisitor)
 Function Accept() More...
 
void Reindex ()
 Function Reindex() More...
 
template<class V >
int Query (const SHAPE *aShape, int aMinDistance, V &aVisitor, bool aExact)
 Function Query() More...
 
Iterator Begin ()
 Function Begin() More...
 

Private Attributes

RTree< T, int, 2, float > * m_tree
 

Detailed Description

template<class T = SHAPE*>
class SHAPE_INDEX< T >

Definition at line 107 of file shape_index.h.

Constructor & Destructor Documentation

template<class T >
SHAPE_INDEX< T >::SHAPE_INDEX ( )

Definition at line 298 of file shape_index.h.

299 {
300  this->m_tree = new RTree<T, int, 2, float>();
301 }
RTree< T, int, 2, float > * m_tree
Definition: shape_index.h:290
template<class T >
SHAPE_INDEX< T >::~SHAPE_INDEX ( )

Definition at line 304 of file shape_index.h.

305 {
306  delete this->m_tree;
307 }
RTree< T, int, 2, float > * m_tree
Definition: shape_index.h:290

Member Function Documentation

template<class T = SHAPE*>
template<class V >
void SHAPE_INDEX< T >::Accept ( aVisitor)
inline

Function Accept()

Accepts a visitor for every SHAPE object contained in this INDEX.

Parameters
aVisitorVisitor object to be run

Definition at line 241 of file shape_index.h.

References acceptVisitor(), SHAPE_INDEX< T >::Begin(), and SHAPE_INDEX< T >::Iterator::IsNull().

242  {
243  Iterator iter = this->Begin();
244 
245  while( !iter.IsNull() )
246  {
247  T shape = *iter;
248  acceptVisitor( shape, aVisitor );
249  iter++;
250  }
251  }
T
enum T contains all this lexer's tokens.
Iterator Begin()
Function Begin()
Definition: shape_index.h:358
void acceptVisitor(T aObject, V aVisitor)
acceptVisitor template method
Definition: shape_index.h:74
template<class T >
void SHAPE_INDEX< T >::Add ( aShape)

Function Add()

Adds a SHAPE to the index.

Parameters
aShapeis the new SHAPE.

Definition at line 310 of file shape_index.h.

References boundingBox(), BOX2< Vec >::GetBottom(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), max, and min.

Referenced by PNS::INDEX::Add().

311 {
312  BOX2I box = boundingBox( aShape );
313  int min[2] = { box.GetX(), box.GetY() };
314  int max[2] = { box.GetRight(), box.GetBottom() };
315 
316  this->m_tree->Insert( min, max, aShape );
317 }
coord_type GetY() const
Definition: box2.h:179
coord_type GetRight() const
Definition: box2.h:187
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
RTree< T, int, 2, float > * m_tree
Definition: shape_index.h:290
coord_type GetBottom() const
Definition: box2.h:188
void Insert(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], const DATATYPE &a_dataId)
Insert entry.
#define max(a, b)
Definition: auxiliary.h:86
coord_type GetX() const
Definition: box2.h:178
#define min(a, b)
Definition: auxiliary.h:85
template<class T >
SHAPE_INDEX< T >::Iterator SHAPE_INDEX< T >::Begin ( )

Function Begin()

Creates an iterator for the current index object

Returns
iterator

Definition at line 358 of file shape_index.h.

Referenced by SHAPE_INDEX< T >::Accept().

359 {
360  return Iterator( this );
361 }
template<class T = SHAPE*>
template<class V >
int SHAPE_INDEX< T >::Query ( const SHAPE aShape,
int  aMinDistance,
V &  aVisitor,
bool  aExact 
)
inline

Function Query()

Runs a callback on every SHAPE object contained in the bounding box of (shape).

Parameters
aShapeshape to search against
aMinDistancedistance threshold
aVisitorobject to be invoked on every object contained in the search area.

Definition at line 270 of file shape_index.h.

References SHAPE::BBox(), BOX2< Vec >::GetBottom(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), BOX2< Vec >::Inflate(), SHAPE_INDEX< T >::m_tree, max, min, and RTree< DATATYPE, ELEMTYPE, NUMDIMS, ELEMTYPEREAL, TMAXNODES, TMINNODES >::Search().

Referenced by PNS::INDEX::querySingle().

271  {
272  BOX2I box = aShape->BBox();
273  box.Inflate( aMinDistance );
274 
275  int min[2] = { box.GetX(), box.GetY() };
276  int max[2] = { box.GetRight(), box.GetBottom() };
277 
278  return this->m_tree->Search( min, max, aVisitor );
279  }
coord_type GetY() const
Definition: box2.h:179
coord_type GetRight() const
Definition: box2.h:187
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
RTree< T, int, 2, float > * m_tree
Definition: shape_index.h:290
coord_type GetBottom() const
Definition: box2.h:188
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:266
#define max(a, b)
Definition: auxiliary.h:86
int Search(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], bool a_resultCallback(DATATYPE a_data, void *a_context), void *a_context)
Find all within search rectangle.
coord_type GetX() const
Definition: box2.h:178
#define min(a, b)
Definition: auxiliary.h:85
template<class T >
void SHAPE_INDEX< T >::Reindex ( )

Function Reindex()

Rebuilds the index. This should be used if the geometry of the objects contained by the index has changed.

Definition at line 336 of file shape_index.h.

References boundingBox(), BOX2< Vec >::GetBottom(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), RTree< DATATYPE, ELEMTYPE, NUMDIMS, ELEMTYPEREAL, TMAXNODES, TMINNODES >::Insert(), RTree< DATATYPE, ELEMTYPE, NUMDIMS, ELEMTYPEREAL, TMAXNODES, TMINNODES >::IsNull(), max, and min.

337 {
338  RTree<T, int, 2, float>* newTree;
339  newTree = new RTree<T, int, 2, float>();
340 
341  Iterator iter = this->Begin();
342 
343  while( !iter.IsNull() )
344  {
345  T shape = *iter;
346  BOX2I box = boundingBox( shape );
347  int min[2] = { box.GetX(), box.GetY() };
348  int max[2] = { box.GetRight(), box.GetBottom() };
349  newTree->Insert( min, max, shape );
350  iter++;
351  }
352 
353  delete this->m_tree;
354  this->m_tree = newTree;
355 }
coord_type GetY() const
Definition: box2.h:179
T
enum T contains all this lexer's tokens.
coord_type GetRight() const
Definition: box2.h:187
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
RTree< T, int, 2, float > * m_tree
Definition: shape_index.h:290
coord_type GetBottom() const
Definition: box2.h:188
Iterator Begin()
Function Begin()
Definition: shape_index.h:358
void Insert(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], const DATATYPE &a_dataId)
Insert entry.
bool IsNull(Iterator &a_it)
Is iterator NULL, or at end?
Definition: rtree.h:366
#define max(a, b)
Definition: auxiliary.h:86
coord_type GetX() const
Definition: box2.h:178
#define min(a, b)
Definition: auxiliary.h:85
template<class T >
void SHAPE_INDEX< T >::Remove ( aShape)

Function Remove()

Removes a SHAPE to the index.

Parameters
aShapeis the new SHAPE.

Definition at line 320 of file shape_index.h.

References boundingBox(), BOX2< Vec >::GetBottom(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), max, and min.

Referenced by PNS::INDEX::Remove().

321 {
322  BOX2I box = boundingBox( aShape );
323  int min[2] = { box.GetX(), box.GetY() };
324  int max[2] = { box.GetRight(), box.GetBottom() };
325 
326  this->m_tree->Remove( min, max, aShape );
327 }
coord_type GetY() const
Definition: box2.h:179
coord_type GetRight() const
Definition: box2.h:187
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
RTree< T, int, 2, float > * m_tree
Definition: shape_index.h:290
coord_type GetBottom() const
Definition: box2.h:188
#define max(a, b)
Definition: auxiliary.h:86
void Remove(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], const DATATYPE &a_dataId)
Remove entry.
coord_type GetX() const
Definition: box2.h:178
#define min(a, b)
Definition: auxiliary.h:85
template<class T >
void SHAPE_INDEX< T >::RemoveAll ( )

Function RemoveAll()

Removes all the contents of the index.

Definition at line 330 of file shape_index.h.

331 {
332  this->m_tree->RemoveAll();
333 }
void RemoveAll()
Remove all entries from tree.
RTree< T, int, 2, float > * m_tree
Definition: shape_index.h:290

Member Data Documentation

template<class T = SHAPE*>
RTree<T, int, 2, float>* SHAPE_INDEX< T >::m_tree
private

Definition at line 290 of file shape_index.h.

Referenced by SHAPE_INDEX< T >::Iterator::Iterator(), and SHAPE_INDEX< T >::Query().


The documentation for this class was generated from the following file: