KiCad PCB EDA Suite
ccontainer2d.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) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
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 
30 #ifndef _CCONTAINER2D_H_
31 #define _CCONTAINER2D_H_
32 
33 #include "../shapes2D/cobject2d.h"
34 #include <list>
35 
36 typedef std::list<COBJECT2D *> LIST_OBJECT2D;
37 typedef std::list<const COBJECT2D *> CONST_LIST_OBJECT2D;
38 
39 
41 {
42 protected:
45 
46 public:
47  explicit CGENERICCONTAINER2D( OBJECT2D_TYPE aObjType );
48 
49  virtual ~CGENERICCONTAINER2D();
50 
51  void Add( COBJECT2D *aObject )
52  {
53  if( aObject ) // Only add if it is a valid pointer
54  {
55  m_objects.push_back( aObject );
56  m_bbox.Union( aObject->GetBBox() );
57  }
58  }
59 
60  void Clear();
61 
62  const LIST_OBJECT2D &GetList() const { return m_objects; }
63 
69  virtual void GetListObjectsIntersects( const CBBOX2D & aBBox,
70  CONST_LIST_OBJECT2D &aOutList ) const = 0;
71 
72 private:
73 };
74 
75 
77 {
78 public:
79  CCONTAINER2D();
80 
81  // Imported from CGENERICCONTAINER2D
82  void GetListObjectsIntersects( const CBBOX2D & aBBox,
83  CONST_LIST_OBJECT2D &aOutList ) const override;
84 };
85 
86 
88 {
91 
94 };
95 
96 
98 {
99 public:
100  CBVHCONTAINER2D();
102 
103  void BuildBVH();
104 
105 private:
107  std::list<BVH_CONTAINER_NODE_2D *> m_elements_to_delete;
109 
110  void destroy();
113  const CBBOX2D & aBBox,
114  CONST_LIST_OBJECT2D &aOutList ) const;
115 
116 public:
117 
118  // Imported from CGENERICCONTAINER2D
119  void GetListObjectsIntersects( const CBBOX2D & aBBox,
120  CONST_LIST_OBJECT2D &aOutList ) const override;
121 };
122 
123 #endif // _CCONTAINER2D_H_
void GetListObjectsIntersects(const CBBOX2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const override
GetListObjectsIntersects - Get a list of objects that intersects a bbox.
CONST_LIST_OBJECT2D m_LeafList
Store the list of objects if that node is a Leaf.
Definition: ccontainer2d.h:93
const LIST_OBJECT2D & GetList() const
Definition: ccontainer2d.h:62
void Union(const SFVEC2F &aPoint)
Function Union recalculate the bounding box adding a point.
Definition: cbbox2d.cpp:95
Class CBBOX manages a bounding box defined by two SFVEC2F min max points.
Definition: cbbox2d.h:40
std::list< const COBJECT2D * > CONST_LIST_OBJECT2D
Definition: ccontainer2d.h:37
std::list< BVH_CONTAINER_NODE_2D * > m_elements_to_delete
Definition: ccontainer2d.h:107
virtual void GetListObjectsIntersects(const CBBOX2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const =0
GetListObjectsIntersects - Get a list of objects that intersects a bbox.
BVH_CONTAINER_NODE_2D * m_Children[2]
Definition: ccontainer2d.h:90
void recursiveBuild_MIDDLE_SPLIT(BVH_CONTAINER_NODE_2D *aNodeParent)
virtual ~CGENERICCONTAINER2D()
void Add(COBJECT2D *aObject)
Definition: ccontainer2d.h:51
CGENERICCONTAINER2D(OBJECT2D_TYPE aObjType)
std::list< COBJECT2D * > LIST_OBJECT2D
Definition: ccontainer2d.h:36
LIST_OBJECT2D m_objects
Definition: ccontainer2d.h:44
OBJECT2D_TYPE
Definition: cobject2d.h:46
const CBBOX2D & GetBBox() const
Definition: cobject2d.h:121
BVH_CONTAINER_NODE_2D * m_Tree
Definition: ccontainer2d.h:108
void recursiveGetListObjectsIntersects(const BVH_CONTAINER_NODE_2D *aNode, const CBBOX2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const
void GetListObjectsIntersects(const CBBOX2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const override
GetListObjectsIntersects - Get a list of objects that intersects a bbox.