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 #include <mutex>
36 
37 typedef std::list<COBJECT2D *> LIST_OBJECT2D;
38 typedef std::list<const COBJECT2D *> CONST_LIST_OBJECT2D;
39 
40 
42 {
43 protected:
46 
47 public:
48  explicit CGENERICCONTAINER2D( OBJECT2D_TYPE aObjType );
49 
50  virtual ~CGENERICCONTAINER2D();
51 
52  void Add( COBJECT2D *aObject )
53  {
54  if( aObject ) // Only add if it is a valid pointer
55  {
56  std::lock_guard<std::mutex> lock( m_lock );
57  m_objects.push_back( aObject );
58  m_bbox.Union( aObject->GetBBox() );
59  }
60  }
61 
62  void Clear();
63 
64  const LIST_OBJECT2D &GetList() const { return m_objects; }
65 
71  virtual void GetListObjectsIntersects( const CBBOX2D & aBBox,
72  CONST_LIST_OBJECT2D &aOutList ) const = 0;
73 
74 private:
75  std::mutex m_lock;
76 };
77 
78 
80 {
81 public:
82  CCONTAINER2D();
83 
84  // Imported from CGENERICCONTAINER2D
85  void GetListObjectsIntersects( const CBBOX2D & aBBox,
86  CONST_LIST_OBJECT2D &aOutList ) const override;
87 };
88 
89 
91 {
93  BVH_CONTAINER_NODE_2D *m_Children[2];
94 
97 };
98 
99 
101 {
102 public:
103  CBVHCONTAINER2D();
104  ~CBVHCONTAINER2D();
105 
106  void BuildBVH();
107 
108 private:
110  std::list<BVH_CONTAINER_NODE_2D *> m_elements_to_delete;
112 
113  void destroy();
114  void recursiveBuild_MIDDLE_SPLIT( BVH_CONTAINER_NODE_2D *aNodeParent );
115  void recursiveGetListObjectsIntersects( const BVH_CONTAINER_NODE_2D *aNode,
116  const CBBOX2D & aBBox,
117  CONST_LIST_OBJECT2D &aOutList ) const;
118 
119 public:
120 
121  // Imported from CGENERICCONTAINER2D
122  void GetListObjectsIntersects( const CBBOX2D & aBBox,
123  CONST_LIST_OBJECT2D &aOutList ) const override;
124 };
125 
126 #endif // _CCONTAINER2D_H_
CONST_LIST_OBJECT2D m_LeafList
Store the list of objects if that node is a Leaf.
Definition: ccontainer2d.h:96
const LIST_OBJECT2D & GetList() const
Definition: ccontainer2d.h:64
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:38
std::list< BVH_CONTAINER_NODE_2D * > m_elements_to_delete
Definition: ccontainer2d.h:110
virtual void GetListObjectsIntersects(const CBBOX2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const =0
GetListObjectsIntersects - Get a list of objects that intersects a bbox.
virtual ~CGENERICCONTAINER2D()
void Add(COBJECT2D *aObject)
Definition: ccontainer2d.h:52
CGENERICCONTAINER2D(OBJECT2D_TYPE aObjType)
std::list< COBJECT2D * > LIST_OBJECT2D
Definition: ccontainer2d.h:37
LIST_OBJECT2D m_objects
Definition: ccontainer2d.h:45
OBJECT2D_TYPE
Definition: cobject2d.h:46
const CBBOX2D & GetBBox() const
Definition: cobject2d.h:121
BVH_CONTAINER_NODE_2D * m_Tree
Definition: ccontainer2d.h:111