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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
24#include <list>
25#include <mutex>
26
27struct RAYSEG2D;
28
29typedef std::list<OBJECT_2D*> LIST_OBJECT2D;
30typedef std::list<const OBJECT_2D*> CONST_LIST_OBJECT2D;
31
32
34{
35public:
36 explicit CONTAINER_2D_BASE( OBJECT_2D_TYPE aObjType );
37
38 virtual ~CONTAINER_2D_BASE();
39
40 void Add( OBJECT_2D* aObject )
41 {
42 if( aObject )
43 {
44 std::lock_guard<std::mutex> lock( m_lock );
45 m_objects.push_back( aObject );
46 m_bbox.Union( aObject->GetBBox() );
47 }
48 }
49
50 const BBOX_2D& GetBBox() const
51 {
52 return m_bbox;
53 }
54
55 virtual void Clear();
56
57 const LIST_OBJECT2D& GetList() const { return m_objects; }
58
65 virtual void GetIntersectingObjects( const BBOX_2D& aBBox, CONST_LIST_OBJECT2D& aOutList ) const = 0;
66
73 virtual bool IntersectAny( const RAYSEG2D& aSegRay ) const = 0;
74
75protected:
78
79private:
80 std::mutex m_lock;
81};
82
83
85{
86public:
88
89 void GetIntersectingObjects( const BBOX_2D& aBBox, CONST_LIST_OBJECT2D& aOutList ) const override;
90
91 bool IntersectAny( const RAYSEG2D& aSegRay ) const override;
92};
93
94
103
104
106{
107public:
110
111 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
112 // will only land us in trouble.
115
116 void BuildBVH();
117
118 void Clear() override;
119
120 void GetIntersectingObjects( const BBOX_2D& aBBox, CONST_LIST_OBJECT2D& aOutList ) const override;
121
122 bool IntersectAny( const RAYSEG2D& aSegRay ) const override;
123
124private:
125 void destroy();
127 void recursiveGetListObjectsIntersects( const BVH_CONTAINER_NODE_2D* aNode, const BBOX_2D& aBBox,
128 CONST_LIST_OBJECT2D& aOutList ) const;
129 bool recursiveIntersectAny( const BVH_CONTAINER_NODE_2D* aNode, const RAYSEG2D& aSegRay ) const;
130
131private:
133 std::list<BVH_CONTAINER_NODE_2D*> m_elementsToDelete;
135
136};
137
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
void recursiveGetListObjectsIntersects(const BVH_CONTAINER_NODE_2D *aNode, const BBOX_2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const
BVH_CONTAINER_2D & operator=(const BVH_CONTAINER_2D &)=delete
void recursiveBuild_MIDDLE_SPLIT(BVH_CONTAINER_NODE_2D *aNodeParent)
BVH_CONTAINER_2D(const BVH_CONTAINER_2D &)=delete
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
CONTAINER_2D_BASE(OBJECT_2D_TYPE aObjType)
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
virtual ~CONTAINER_2D_BASE()
std::mutex m_lock
void Add(OBJECT_2D *aObject)
LIST_OBJECT2D m_objects
const LIST_OBJECT2D & GetList() const
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:99
std::list< OBJECT_2D * > LIST_OBJECT2D
std::list< const OBJECT_2D * > CONST_LIST_OBJECT2D
OBJECT_2D_TYPE
Definition object_2d.h:41
Manage a bounding box defined by two SFVEC2F min max points.
Definition bbox_2d.h:38
CONST_LIST_OBJECT2D m_LeafList
Store the list of objects if that node is a Leaf.
BVH_CONTAINER_NODE_2D * m_Children[2]