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)
 Add a SHAPE to the index. More...
 
void Add (T aShape, const BOX2I &aBbox)
 Add a shape with alternate BBox. More...
 
void Remove (T aShape)
 Remove a SHAPE from the index. More...
 
void RemoveAll ()
 Remove all the contents of the index. More...
 
template<class V >
void Accept (V aVisitor)
 Accept a visitor for every SHAPE object contained in this INDEX. More...
 
void Reindex ()
 Rebuild the index. More...
 
template<class V >
int Query (const SHAPE *aShape, int aMinDistance, V &aVisitor) const
 Run a callback on every SHAPE object contained in the bounding box of (shape). More...
 
Iterator Begin ()
 Create an iterator for the current index object. More...
 

Private Attributes

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

Detailed Description

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

Definition at line 130 of file shape_index.h.

Constructor & Destructor Documentation

◆ SHAPE_INDEX()

template<class T >
SHAPE_INDEX< T >::SHAPE_INDEX

Definition at line 309 of file shape_index.h.

310{
311 this->m_tree = new RTree<T, int, 2, double>();
312}
RTree< T, int, 2, double > * m_tree
Definition: shape_index.h:301

◆ ~SHAPE_INDEX()

template<class T >
SHAPE_INDEX< T >::~SHAPE_INDEX

Definition at line 315 of file shape_index.h.

316{
317 delete this->m_tree;
318}

Member Function Documentation

◆ Accept()

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

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

Parameters
aVisitoris the visitor object to be run.

Definition at line 255 of file shape_index.h.

256 {
257 Iterator iter = this->Begin();
258
259 while( !iter.IsNull() )
260 {
261 T shape = *iter;
262 acceptVisitor( shape, aVisitor );
263 iter++;
264 }
265 }
Iterator Begin()
Create an iterator for the current index object.
Definition: shape_index.h:378
void acceptVisitor(T aObject, V aVisitor)
Used by SHAPE_INDEX to implement Accept().
Definition: shape_index.h:97

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

◆ Add() [1/2]

template<class T >
void SHAPE_INDEX< T >::Add ( aShape)

Add a SHAPE to the index.

Parameters
aShapeis the new SHAPE.

Definition at line 330 of file shape_index.h.

331{
332 BOX2I box = boundingBox( aShape );
333 int min[2] = { box.GetX(), box.GetY() };
334 int max[2] = { box.GetRight(), box.GetBottom() };
335
336 this->m_tree->Insert( min, max, aShape );
337}
coord_type GetY() const
Definition: box2.h:181
coord_type GetX() const
Definition: box2.h:180
coord_type GetRight() const
Definition: box2.h:189
coord_type GetBottom() const
Definition: box2.h:190
BOX2I boundingBox(T aObject)
Used by SHAPE_INDEX to get the bounding box of a generic T object.
Definition: shape_index.h:77

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

◆ Add() [2/2]

template<class T >
void SHAPE_INDEX< T >::Add ( aShape,
const BOX2I aBbox 
)

Add a shape with alternate BBox.

Parameters
aShapeShape (Item) to add.
aBboxalternate bounding box. This should be a subset of the item's bbox

Definition at line 321 of file shape_index.h.

322{
323 int min[2] = { aBbox.GetX(), aBbox.GetY() };
324 int max[2] = { aBbox.GetRight(), aBbox.GetBottom() };
325
326 this->m_tree->Insert( min, max, aShape );
327}

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

◆ Begin()

template<class T >
SHAPE_INDEX< T >::Iterator SHAPE_INDEX< T >::Begin

Create an iterator for the current index object.

Returns
iterator to the first object.

Definition at line 378 of file shape_index.h.

379{
380 return Iterator( this );
381}

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

◆ Query()

template<class T = SHAPE*>
template<class V >
int SHAPE_INDEX< T >::Query ( const SHAPE aShape,
int  aMinDistance,
V &  aVisitor 
) const
inline

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

Parameters
aShapeis the shape to search against.
aMinDistanceis the distance threshold.
aVisitoris the object to be invoked on every object contained in the search area.

Definition at line 282 of file shape_index.h.

283 {
284 BOX2I box = aShape->BBox();
285 box.Inflate( aMinDistance );
286
287 int min[2] = { box.GetX(), box.GetY() };
288 int max[2] = { box.GetRight(), box.GetBottom() };
289
290 return this->m_tree->Search( min, max, aVisitor );
291 }
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506
virtual const BOX2I BBox(int aClearance=0) const =0
Compute a bounding box of the shape, with a margin of aClearance a collision.

References SHAPE::BBox(), BOX2< Vec >::GetBottom(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), BOX2< Vec >::Inflate(), and SHAPE_INDEX< T >::m_tree.

◆ Reindex()

template<class T >
void SHAPE_INDEX< T >::Reindex

Rebuild the index.

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

Definition at line 356 of file shape_index.h.

357{
358 RTree<T, int, 2, double>* newTree;
359 newTree = new RTree<T, int, 2, double>();
360
361 Iterator iter = this->Begin();
362
363 while( !iter.IsNull() )
364 {
365 T shape = *iter;
366 BOX2I box = boundingBox( shape );
367 int min[2] = { box.GetX(), box.GetY() };
368 int max[2] = { box.GetRight(), box.GetBottom() };
369 newTree->Insert( min, max, shape );
370 iter++;
371 }
372
373 delete this->m_tree;
374 this->m_tree = newTree;
375}

References boundingBox(), BOX2< Vec >::GetBottom(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetX(), BOX2< Vec >::GetY(), and SHAPE_INDEX< T >::Iterator::IsNull().

◆ Remove()

template<class T >
void SHAPE_INDEX< T >::Remove ( aShape)

Remove a SHAPE from the index.

Parameters
aShapeis the SHAPE to remove.

Definition at line 340 of file shape_index.h.

341{
342 BOX2I box = boundingBox( aShape );
343 int min[2] = { box.GetX(), box.GetY() };
344 int max[2] = { box.GetRight(), box.GetBottom() };
345
346 this->m_tree->Remove( min, max, aShape );
347}

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

◆ RemoveAll()

template<class T >
void SHAPE_INDEX< T >::RemoveAll

Remove all the contents of the index.

Definition at line 350 of file shape_index.h.

351{
352 this->m_tree->RemoveAll();
353}

Member Data Documentation

◆ m_tree

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

Definition at line 301 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: