OOBB.cpp
Go to the documentation of this file.
1 // ========================================================================================
2 // ApproxMVBB
3 // Copyright (C) 2014 by Gabriel Nützi <nuetzig (at) imes (d0t) mavt (d0t) ethz (døt) ch>
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 // ========================================================================================
9 
11 #include ApproxMVBB_OOBB_INCLUDE_FILE
12 namespace ApproxMVBB{
13 OOBB::OOBB(const Vector3 & l,
14  const Vector3 & u,
15  const Matrix33 & A_IK)
16  :m_q_KI(A_IK) {
17  m_q_KI.normalize();
18  m_minPoint = Vector3(std::min(l(0),u(0)),std::min(l(1),u(1)),std::min(l(2),u(2)));
19  m_maxPoint = Vector3(std::max(l(0),u(0)),std::max(l(1),u(1)),std::max(l(2),u(2)));
20 }
21 
23 void OOBB::switchZAxis(unsigned int i) {
24  if(i > 1) {
25  return;
26  }
27  if( i == 0) {
28  // Make new x-Axis the z-Axis
29  // R_NK = Rotate around 90∞ around Y, and 90∞ around X (always in K frame) )
30  // A_IN = A_IK * A_KN = R_KI * R_NK
31  m_q_KI = m_q_KI * Quaternion(0.5 ,0.5, 0.5, 0.5);
32  // Change points Coordinates I_[x,y,z] -> K_[y,z,x]
33  std::swap(m_minPoint(0),m_minPoint(1));
34  std::swap(m_minPoint(1),m_minPoint(2));
35 
36  std::swap(m_maxPoint(0),m_maxPoint(1));
37  std::swap(m_maxPoint(1),m_maxPoint(2));
38  } else {
39  // Make new y-Axis the z-Axis
40  // R_NK = Rotate around 90∞ around -X, and 90∞ around -Y (always in K frame) )
41  // A_IN = A_IK * A_KN = R_KI * R_NK
42  m_q_KI = m_q_KI * Quaternion(0.5 ,-0.5, -0.5, -0.5);
43  // Change points Coordinates I_[x,y,z] -> K_[z,x,y]
44  std::swap(m_minPoint(0),m_minPoint(2));
45  std::swap(m_minPoint(1),m_minPoint(2));
46 
47  std::swap(m_maxPoint(0),m_maxPoint(2));
48  std::swap(m_maxPoint(1),m_maxPoint(2));
49  }
50 
51 }
52 
53 void OOBB::expandToMinExtentRelative(PREC p, PREC defaultExtent, PREC eps){
54  Array3 e = extent();
55  Vector3 c = center();
56  Array3::Index idx;
57  PREC ext = std::abs(e.maxCoeff(&idx)) * p;
58 
59  if( ext < eps ){ // extent of max axis almost zero, set all axis to defaultExtent --> cube
60  ext = defaultExtent;
61  for(int i=0;i<3;++i){
62  m_minPoint(i) = c(i) - 0.5*ext;
63  m_maxPoint(i) = c(i) + 0.5*ext;
64  }
65  }else{
66  for(int i=0;i<3;++i){
67  if(i!=idx && std::abs(e(i)) < ext){
68  m_minPoint(i) = c(i) - 0.5*ext;
69  m_maxPoint(i) = c(i) + 0.5*ext;
70  }
71  }
72  }
73 }
74 
75 void OOBB::expandToMinExtentAbsolute(PREC minExtent){
76  Array3 e = extent();
77  Vector3 c = center();
78 
79  PREC l = 0.5*minExtent;
80  for(int i=0;i<3;++i){
81  if(std::abs(e(i)) < minExtent){
82  m_minPoint(i) = c(i) - l;
83  m_maxPoint(i) = c(i) + l;
84  }
85  }
86 }
87 
88 
89 void OOBB::reset() {
90  // Violating the constraint min<max for making a completey empty box!
91  m_minPoint(0) = std::numeric_limits<PREC>::max();
92  m_maxPoint(0) = std::numeric_limits<PREC>::min();
93  m_minPoint(1) = std::numeric_limits<PREC>::max();
94  m_maxPoint(1) = std::numeric_limits<PREC>::min();
95  m_minPoint(2) = std::numeric_limits<PREC>::max();
96  m_maxPoint(2) = std::numeric_limits<PREC>::min();
97  m_q_KI.setIdentity();
98 }
99 }
Eigen::Quaternion< Scalar > Quaternion
These are some container definitions.
Vector3 m_maxPoint
in K Frame
Definition: OOBB.hpp:177
Array3 extent() const
Definition: OOBB.hpp:81
EIGEN_MAKE_ALIGNED_OPERATOR_NEW ApproxMVBB_DEFINE_MATRIX_TYPES ApproxMVBB_DEFINE_POINTS_CONFIG_TYPES OOBB()
Definition: OOBB.hpp:29
void expandToMinExtentRelative(PREC p=0.1, PREC defaultExtent=0.1, PREC eps=1e-10)
Definition: OOBB.cpp:53
void switchZAxis(unsigned int i)
Definition: OOBB.cpp:23
void expandToMinExtentAbsolute(PREC minExtent)
Definition: OOBB.cpp:75
Eigen::Matrix< Scalar, 3, 3 > Matrix33
Quaternion m_q_KI
Rotation of frame I to frame K, corresponds to a transformation A_IK;.
Definition: OOBB.hpp:175
Vector3 m_minPoint
in K Frame
Definition: OOBB.hpp:176
Eigen::Array< Scalar, 3, 1 > Array3
void reset()
Definition: OOBB.cpp:89
Eigen::Matrix< Scalar, 3, 1 > Vector3
Vector3 center()
Definition: OOBB.hpp:79


asr_approx_mvbb
Author(s): Gassner Nikolai
autogenerated on Mon Jun 10 2019 12:38:08