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 Add (T aShape, const BOX2I &aBbox)
 Adds a shape with alternate BBox. 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) const
 Function Query() More...
 
Iterator Begin ()
 Function Begin() More...
 

Private Attributes

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

Detailed Description

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

Definition at line 108 of file shape_index.h.

Constructor & Destructor Documentation

◆ SHAPE_INDEX()

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

Definition at line 306 of file shape_index.h.

307 {
308  this->m_tree = new RTree<T, int, 2, double>();
309 }
RTree< T, int, 2, double > * m_tree
Definition: shape_index.h:298

◆ ~SHAPE_INDEX()

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

Definition at line 312 of file shape_index.h.

313 {
314  delete this->m_tree;
315 }
RTree< T, int, 2, double > * m_tree
Definition: shape_index.h:298

Member Function Documentation

◆ Accept()

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 249 of file shape_index.h.

250  {
251  Iterator iter = this->Begin();
252 
253  while( !iter.IsNull() )
254  {
255  T shape = *iter;
256  acceptVisitor( shape, aVisitor );
257  iter++;
258  }
259  }
Iterator Begin()
Function Begin()
Definition: shape_index.h:375
void acceptVisitor(T aObject, V aVisitor)
acceptVisitor template method
Definition: shape_index.h:75

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

◆ Add() [1/2]

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 327 of file shape_index.h.

328 {
329  BOX2I box = boundingBox( aShape );
330  int min[2] = { box.GetX(), box.GetY() };
331  int max[2] = { box.GetRight(), box.GetBottom() };
332 
333  this->m_tree->Insert( min, max, aShape );
334 }
coord_type GetX() const
Definition: box2.h:190
coord_type GetRight() const
Definition: box2.h:199
coord_type GetBottom() const
Definition: box2.h:200
BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated c...
Definition: box2.h:43
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:60
coord_type GetY() const
Definition: box2.h:191
RTree< T, int, 2, double > * m_tree
Definition: shape_index.h:298

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 
)

Adds 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 318 of file shape_index.h.

319 {
320  int min[2] = { aBbox.GetX(), aBbox.GetY() };
321  int max[2] = { aBbox.GetRight(), aBbox.GetBottom() };
322 
323  this->m_tree->Insert( min, max, aShape );
324 }
coord_type GetX() const
Definition: box2.h:190
coord_type GetRight() const
Definition: box2.h:199
coord_type GetBottom() const
Definition: box2.h:200
coord_type GetY() const
Definition: box2.h:191
RTree< T, int, 2, double > * m_tree
Definition: shape_index.h:298

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 ( )

Function Begin()

Creates an iterator for the current index object

Returns
iterator

Definition at line 375 of file shape_index.h.

376 {
377  return Iterator( this );
378 }

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

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 278 of file shape_index.h.

279  {
280  BOX2I box = aShape->BBox();
281  box.Inflate( aMinDistance );
282 
283  int min[2] = { box.GetX(), box.GetY() };
284  int max[2] = { box.GetRight(), box.GetBottom() };
285 
286  return this->m_tree->Search( min, max, aVisitor );
287  }
coord_type GetX() const
Definition: box2.h:190
coord_type GetRight() const
Definition: box2.h:199
coord_type GetBottom() const
Definition: box2.h:200
BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated c...
Definition: box2.h:43
virtual const BOX2I BBox(int aClearance=0) const =0
Compute a bounding box of the shape, with a margin of aClearance a collision.
coord_type GetY() const
Definition: box2.h:191
RTree< T, int, 2, double > * m_tree
Definition: shape_index.h:298
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:302

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 ( )

Function Reindex()

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

Definition at line 353 of file shape_index.h.

354 {
355  RTree<T, int, 2, double>* newTree;
356  newTree = new RTree<T, int, 2, double>();
357 
358  Iterator iter = this->Begin();
359 
360  while( !iter.IsNull() )
361  {
362  T shape = *iter;
363  BOX2I box = boundingBox( shape );
364  int min[2] = { box.GetX(), box.GetY() };
365  int max[2] = { box.GetRight(), box.GetBottom() };
366  newTree->Insert( min, max, shape );
367  iter++;
368  }
369 
370  delete this->m_tree;
371  this->m_tree = newTree;
372 }
coord_type GetX() const
Definition: box2.h:190
coord_type GetRight() const
Definition: box2.h:199
coord_type GetBottom() const
Definition: box2.h:200
BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated c...
Definition: box2.h:43
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:60
Iterator Begin()
Function Begin()
Definition: shape_index.h:375
coord_type GetY() const
Definition: box2.h:191
RTree< T, int, 2, double > * m_tree
Definition: shape_index.h:298

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)

Function Remove()

Removes a SHAPE to the index.

Parameters
aShapeis the new SHAPE.

Definition at line 337 of file shape_index.h.

338 {
339  BOX2I box = boundingBox( aShape );
340  int min[2] = { box.GetX(), box.GetY() };
341  int max[2] = { box.GetRight(), box.GetBottom() };
342 
343  this->m_tree->Remove( min, max, aShape );
344 }
coord_type GetX() const
Definition: box2.h:190
coord_type GetRight() const
Definition: box2.h:199
coord_type GetBottom() const
Definition: box2.h:200
BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated c...
Definition: box2.h:43
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:60
coord_type GetY() const
Definition: box2.h:191
RTree< T, int, 2, double > * m_tree
Definition: shape_index.h:298

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

◆ RemoveAll()

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

Function RemoveAll()

Removes all the contents of the index.

Definition at line 347 of file shape_index.h.

348 {
349  this->m_tree->RemoveAll();
350 }
RTree< T, int, 2, double > * m_tree
Definition: shape_index.h:298

Member Data Documentation

◆ m_tree

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

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