KiCad PCB EDA Suite
cbbox.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 _CBBOX_H_
31 #define _CBBOX_H_
32 
33 #include "../ray.h"
34 #include <fctsys.h> // For the DBG(
35 
40 struct CBBOX
41 {
42 
43 public:
44 
49  CBBOX();
50 
56  explicit CBBOX( const SFVEC3F &aPbInit );
57 
64  CBBOX( const SFVEC3F &aPbMin, const SFVEC3F &aPbMax );
65 
66  ~CBBOX();
67 
68 
75  void Set( const SFVEC3F &aPbMin, const SFVEC3F &aPbMax );
76 
77  void Set( const CBBOX &aBBox );
78 
84  void Set( const SFVEC3F &aPoint );
85 
91  void Union( const SFVEC3F &aPoint );
92 
98  void Union( const CBBOX &aBBox );
99 
105  void Scale( float aScale );
106 
111  void ScaleNextUp();
112 
117  void ScaleNextDown();
118 
124  bool Intersects( const CBBOX &aBBox ) const;
125 
131  bool Inside( const SFVEC3F &aPoint ) const;
132 
138  void ApplyTransformation( glm::mat4 aTransformMatrix );
139 
146  void ApplyTransformationAA( glm::mat4 aTransformMatrix );
147 
153  float Volume() const;
154 
159  void debug() const;
160 
166  bool IsInitialized() const;
167 
172  void Reset();
173 
179  SFVEC3F GetCenter() const;
180 
186  float GetCenter( unsigned int aAxis ) const;
187 
192  SFVEC3F Offset( const SFVEC3F &p ) const;
193 
198  const SFVEC3F GetExtent() const;
199 
205  const SFVEC3F &Min() const { return m_min; }
206 
212  const SFVEC3F &Max() const { return m_max; }
213 
214 
219  unsigned int MaxDimension() const;
220 
225  float GetMaxDimension() const;
226 
231  float SurfaceArea() const;
232 
239  bool Intersect( const RAY &aRay, float *t ) const;
240 
241  bool Intersect( const RAY &aRay ) const;
242 
251  bool Intersect( const RAY &aRay, float *aOutHitt0, float *aOutHitt1 ) const;
252 
253 private:
254 
257 };
258 
259 #endif // CBBox_h
bool Inside(const SFVEC3F &aPoint) const
Function Inside check is a point is inside this bounding box.
Definition: cbbox.cpp:243
float SurfaceArea() const
Function SurfaceArea.
Definition: cbbox.cpp:184
void ScaleNextDown()
Function ScaleNextDown scales a bounding box to the next float representation making it smaller...
Definition: cbbox.cpp:218
const SFVEC3F & Min() const
Function Min return the minimun vertex pointer.
Definition: cbbox.h:205
SFVEC3F Offset(const SFVEC3F &p) const
Function Offset.
Definition: cbbox.cpp:263
bool Intersects(const CBBOX &aBBox) const
Function Intersects test if a bounding box intersects this box.
Definition: cbbox.cpp:230
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:87
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:255
CBBOX()
Constructor CBBOX Create with default values a bounding box (not inizialized)
Definition: cbbox.cpp:36
Definition: ray.h:43
float Volume() const
Function Volume calculate the volume of a bounding box.
Definition: cbbox.cpp:253
float GetMaxDimension() const
GetMaxDimension.
Definition: cbbox.cpp:169
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Function Set Set bounding box with new parameters.
Definition: cbbox.cpp:67
void Union(const SFVEC3F &aPoint)
Function Union recalculate the bounding box adding a point.
Definition: cbbox.cpp:105
void debug() const
Function debug output to stdout.
Definition: cbbox.cpp:396
const SFVEC3F & Max() const
Function Max return the maximum vertex pointer.
Definition: cbbox.h:212
void ScaleNextUp()
Function ScaleNextUp scales a bounding box to the next float representation making it larger...
Definition: cbbox.cpp:206
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:256
bool Intersect(const RAY &aRay, float *t) const
Function Intersect.
Definition: cbbox_ray.cpp:46
void Scale(float aScale)
Function Scale scales a bounding box by its center.
Definition: cbbox.cpp:194
SFVEC3F GetCenter() const
Function GetCenter return the center point of the bounding box.
Definition: cbbox.cpp:135
unsigned int MaxDimension() const
Function MaxDimension.
Definition: cbbox.cpp:154
~CBBOX()
Definition: cbbox.cpp:55
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
void ApplyTransformationAA(glm::mat4 aTransformMatrix)
Function ApplyTransformationAA apply a transformation matrix to the box points and recalculate it to ...
Definition: cbbox.cpp:367
const SFVEC3F GetExtent() const
Function GetExtent.
Definition: cbbox.cpp:148
Class CBBOX manages a bounding box defined by two SFVEC3F min max points.
Definition: cbbox.h:40
void Reset()
Function Reset reset the bounding box to zero and de-initialized it.
Definition: cbbox.cpp:98
void ApplyTransformation(glm::mat4 aTransformMatrix)
Function ApplyTransformation apply a transformation matrix to the box points.
Definition: cbbox.cpp:351