KiCad PCB EDA Suite
Loading...
Searching...
No Matches
container_3d.cpp
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 <[email protected]>
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
29#include "container_3d.h"
30#include <cstdio>
31
33{
34 m_objects.clear();
35 m_bbox.Reset();
36}
37
38
40{
41 if( !m_objects.empty() )
42 {
43 for( LIST_OBJECT::iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii )
44 {
45 delete *ii;
46 *ii = nullptr;
47 }
48
49 m_objects.clear();
50 }
51
52 m_bbox.Reset();
53}
54
55
57{
58 Clear();
59}
60
61
63{
64 aOutVector.resize( m_objects.size() );
65
66 if( !m_objects.empty() )
67 {
68 unsigned int i = 0;
69
70 for( LIST_OBJECT::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii )
71 {
72 wxASSERT( (*ii) != nullptr );
73
74 aOutVector[i++] = static_cast<const OBJECT_3D*>( *ii );
75 }
76 }
77}
78
79
80bool CONTAINER_3D::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
81{
82
83 if( !m_bbox.Intersect( aRay ) )
84 return false;
85
86 bool hitted = false;
87
88 for( LIST_OBJECT::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii )
89 {
90 const OBJECT_3D *object = static_cast<const OBJECT_3D *>( *ii );
91
92 if( object->Intersect( aRay, aHitInfo) )
93 hitted = true;
94 }
95
96 return hitted;
97}
98
99
100bool CONTAINER_3D::IntersectP( const RAY &aRay, float aMaxDistance ) const
101{
102 for( LIST_OBJECT::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii )
103 {
104 const OBJECT_3D *object = static_cast<const OBJECT_3D*>( *ii );
105
106 if( object->IntersectP( aRay, aMaxDistance ) )
107 return true;
108 }
109
110 return false;
111}
void ConvertTo(CONST_VECTOR_OBJECT &aOutVector) const
LIST_OBJECT m_objects
Definition: container_3d.h:70
virtual ~CONTAINER_3D_BASE()
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
virtual bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const =0
virtual bool IntersectP(const RAY &aRay, float aMaxDistance) const =0
std::vector< const OBJECT_3D * > CONST_VECTOR_OBJECT
Definition: container_3d.h:38
bool Intersect(const RAY &aRay, float *t) const
Definition: bbox_3d_ray.cpp:46
void Reset()
Reset the bounding box to zero and de-initialize it.
Definition: bbox_3d.cpp:95
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:36
Definition: ray.h:63