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, 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#pragma once
26
27#include "../shapes2D/object_2d.h"
28#include <list>
29#include <mutex>
30
31struct RAYSEG2D;
32
33typedef std::list<OBJECT_2D*> LIST_OBJECT2D;
34typedef std::list<const OBJECT_2D*> CONST_LIST_OBJECT2D;
35
36
38{
39public:
40 explicit CONTAINER_2D_BASE( OBJECT_2D_TYPE aObjType );
41
42 virtual ~CONTAINER_2D_BASE();
43
44 void Add( OBJECT_2D* aObject )
45 {
46 if( aObject )
47 {
48 std::lock_guard<std::mutex> lock( m_lock );
49 m_objects.push_back( aObject );
50 m_bbox.Union( aObject->GetBBox() );
51 }
52 }
53
54 const BBOX_2D& GetBBox() const
55 {
56 return m_bbox;
57 }
58
59 virtual void Clear();
60
61 const LIST_OBJECT2D& GetList() const { return m_objects; }
62
69 virtual void GetIntersectingObjects( const BBOX_2D& aBBox, CONST_LIST_OBJECT2D& aOutList ) const = 0;
70
77 virtual bool IntersectAny( const RAYSEG2D& aSegRay ) const = 0;
78
79protected:
82
83private:
84 std::mutex m_lock;
85};
86
87
89{
90public:
92
93 void GetIntersectingObjects( const BBOX_2D& aBBox, CONST_LIST_OBJECT2D& aOutList ) const override;
94
95 bool IntersectAny( const RAYSEG2D& aSegRay ) const override;
96};
97
98
100{
103
106};
107
108
110{
111public:
114
115 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
116 // will only land us in trouble.
119
120 void BuildBVH();
121
122 void Clear() override;
123
124 void GetIntersectingObjects( const BBOX_2D& aBBox, CONST_LIST_OBJECT2D& aOutList ) const override;
125
126 bool IntersectAny( const RAYSEG2D& aSegRay ) const override;
127
128private:
129 void destroy();
131 void recursiveGetListObjectsIntersects( const BVH_CONTAINER_NODE_2D* aNode, const BBOX_2D& aBBox,
132 CONST_LIST_OBJECT2D& aOutList ) const;
133 bool recursiveIntersectAny( const BVH_CONTAINER_NODE_2D* aNode, const RAYSEG2D& aSegRay ) const;
134
135private:
137 std::list<BVH_CONTAINER_NODE_2D*> m_elementsToDelete;
139
140};
141
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:138
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
Definition: container_2d.h:137
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:54
virtual ~CONTAINER_2D_BASE()
std::mutex m_lock
Definition: container_2d.h:84
void Add(OBJECT_2D *aObject)
Definition: container_2d.h:44
LIST_OBJECT2D m_objects
Definition: container_2d.h:81
const LIST_OBJECT2D & GetList() const
Definition: container_2d.h:61
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:33
std::list< const OBJECT_2D * > CONST_LIST_OBJECT2D
Definition: container_2d.h:34
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:105
BVH_CONTAINER_NODE_2D * m_Children[2]
Definition: container_2d.h:102
Definition: ray.h:106