KiCad PCB EDA Suite
Loading...
Searching...
No Matches
container_2d.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-2020 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2015-2020 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
29#ifndef _CONTAINER_2D_H_
30#define _CONTAINER_2D_H_
31
32#include "../shapes2D/object_2d.h"
33#include <list>
34#include <mutex>
35
36struct RAYSEG2D;
37
38typedef std::list<OBJECT_2D*> LIST_OBJECT2D;
39typedef std::list<const OBJECT_2D*> CONST_LIST_OBJECT2D;
40
41
43{
44public:
45 explicit CONTAINER_2D_BASE( OBJECT_2D_TYPE aObjType );
46
47 virtual ~CONTAINER_2D_BASE();
48
49 void Add( OBJECT_2D* aObject )
50 {
51 if( aObject )
52 {
53 std::lock_guard<std::mutex> lock( m_lock );
54 m_objects.push_back( aObject );
55 m_bbox.Union( aObject->GetBBox() );
56 }
57 }
58
59 const BBOX_2D& GetBBox() const
60 {
61 return m_bbox;
62 }
63
64 virtual void Clear();
65
66 const LIST_OBJECT2D& GetList() const { return m_objects; }
67
74 virtual void GetIntersectingObjects( const BBOX_2D& aBBox,
75 CONST_LIST_OBJECT2D& aOutList ) const = 0;
76
83 virtual bool IntersectAny( const RAYSEG2D& aSegRay ) const = 0;
84
85protected:
88
89private:
90 std::mutex m_lock;
91};
92
93
95{
96public:
98
99 void GetIntersectingObjects( const BBOX_2D& aBBox,
100 CONST_LIST_OBJECT2D& aOutList ) const override;
101
102 bool IntersectAny( const RAYSEG2D& aSegRay ) const override;
103};
104
105
107{
110
113};
114
115
117{
118public:
121
122 void BuildBVH();
123
124 void Clear() override;
125
126 void GetIntersectingObjects( const BBOX_2D& aBBox,
127 CONST_LIST_OBJECT2D& aOutList ) const override;
128
129 bool IntersectAny( const RAYSEG2D& aSegRay ) const override;
130
131private:
132 void destroy();
135 const BBOX_2D& aBBox,
136 CONST_LIST_OBJECT2D& aOutList ) const;
138 const RAYSEG2D& aSegRay ) const;
139
141 std::list<BVH_CONTAINER_NODE_2D*> m_elementsToDelete;
143
144};
145
146#endif // _CONTAINER_2D_H_
void GetIntersectingObjects(const BBOX_2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const override
Get a list of objects that intersects a bounding box.
void Clear() override
BVH_CONTAINER_NODE_2D * m_tree
Definition: container_2d.h:142
void recursiveGetListObjectsIntersects(const BVH_CONTAINER_NODE_2D *aNode, const BBOX_2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const
void recursiveBuild_MIDDLE_SPLIT(BVH_CONTAINER_NODE_2D *aNodeParent)
bool recursiveIntersectAny(const BVH_CONTAINER_NODE_2D *aNode, const RAYSEG2D &aSegRay) const
bool IntersectAny(const RAYSEG2D &aSegRay) const override
Intersect and check if a segment ray hits a object or is inside it.
std::list< BVH_CONTAINER_NODE_2D * > m_elementsToDelete
Definition: container_2d.h:141
virtual void GetIntersectingObjects(const BBOX_2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const =0
Get a list of objects that intersects a bounding box.
virtual void Clear()
const BBOX_2D & GetBBox() const
Definition: container_2d.h:59
virtual ~CONTAINER_2D_BASE()
std::mutex m_lock
Definition: container_2d.h:90
void Add(OBJECT_2D *aObject)
Definition: container_2d.h:49
LIST_OBJECT2D m_objects
Definition: container_2d.h:87
const LIST_OBJECT2D & GetList() const
Definition: container_2d.h:66
virtual bool IntersectAny(const RAYSEG2D &aSegRay) const =0
Intersect and check if a segment ray hits a object or is inside it.
void GetIntersectingObjects(const BBOX_2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const override
Get a list of objects that intersects a bounding box.
bool IntersectAny(const RAYSEG2D &aSegRay) const override
Intersect and check if a segment ray hits a object or is inside it.
const BBOX_2D & GetBBox() const
Definition: object_2d.h:103
std::list< OBJECT_2D * > LIST_OBJECT2D
Definition: container_2d.h:38
std::list< const OBJECT_2D * > CONST_LIST_OBJECT2D
Definition: container_2d.h:39
OBJECT_2D_TYPE
Definition: object_2d.h:45
Manage a bounding box defined by two SFVEC2F min max points.
Definition: bbox_2d.h:42
void Union(const SFVEC2F &aPoint)
Recalculate the bounding box adding a point.
Definition: bbox_2d.cpp:93
CONST_LIST_OBJECT2D m_LeafList
Store the list of objects if that node is a Leaf.
Definition: container_2d.h:112
BVH_CONTAINER_NODE_2D * m_Children[2]
Definition: container_2d.h:109
Definition: ray.h:106