KiCad PCB EDA Suite
view_rtree.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef __VIEW_RTREE_H
26 #define __VIEW_RTREE_H
27 
28 #include <math/box2.h>
29 
30 #include <geometry/rtree.h>
31 
32 namespace KIGFX
33 {
35 
41 class VIEW_RTREE : public VIEW_RTREE_BASE
42 {
43 public:
44 
49  void Insert( VIEW_ITEM* aItem )
50  {
51  const BOX2I& bbox = aItem->ViewBBox();
52  const int mmin[2] = { bbox.GetX(), bbox.GetY() };
53  const int mmax[2] = { bbox.GetRight(), bbox.GetBottom() };
54 
55  VIEW_RTREE_BASE::Insert( mmin, mmax, aItem );
56  }
57 
63  void Remove( VIEW_ITEM* aItem )
64  {
65  // const BOX2I& bbox = aItem->ViewBBox();
66 
67  // FIXME: use cached bbox or ptr_map to speed up pointer <-> node lookups.
68  const int mmin[2] = { INT_MIN, INT_MIN };
69  const int mmax[2] = { INT_MAX, INT_MAX };
70 
71  VIEW_RTREE_BASE::Remove( mmin, mmax, aItem );
72  }
73 
79  template <class Visitor>
80  void Query( const BOX2I& aBounds, Visitor& aVisitor ) // const
81  {
82  const int mmin[2] = { aBounds.GetX(), aBounds.GetY() };
83  const int mmax[2] = { aBounds.GetRight(), aBounds.GetBottom() };
84 
85  VIEW_RTREE_BASE::Search( mmin, mmax, aVisitor );
86  }
87 
88 private:
89 };
90 } // namespace KIGFX
91 
92 #endif
coord_type GetY() const
Definition: box2.h:179
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
coord_type GetRight() const
Definition: box2.h:187
RTree< VIEW_ITEM *, int, 2, float > VIEW_RTREE_BASE
Definition: view_rtree.h:34
void Remove(VIEW_ITEM *aItem)
Function Remove() Removes an item from the tree.
Definition: view_rtree.h:63
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW...
Definition: view_item.h:83
void Insert(VIEW_ITEM *aItem)
Function Insert() Inserts an item into the tree.
Definition: view_rtree.h:49
coord_type GetBottom() const
Definition: box2.h:188
Class VIEW_RTREE - Implements an R-tree for fast spatial indexing of VIEW items.
Definition: view_rtree.h:41
void Insert(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], const DATATYPE &a_dataId)
Insert entry.
void Query(const BOX2I &aBounds, Visitor &aVisitor)
Function Query() Executes a function object aVisitor for each item whose bounding box intersects with...
Definition: view_rtree.h:80
Implementation of RTree, a multidimensional bounding rectangle tree.
Definition: rtree.h:79
void Remove(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], const DATATYPE &a_dataId)
Remove entry.
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
virtual const BOX2I ViewBBox() const =0
Function ViewBBox() returns the bounding box of the item covering all its layers. ...