OOBB.cpp
Go to the documentation of this file.
00001 // ========================================================================================
00002 //  ApproxMVBB
00003 //  Copyright (C) 2014 by Gabriel Nützi <nuetzig (at) imes (d0t) mavt (d0t) ethz (døt) ch>
00004 //
00005 //  This Source Code Form is subject to the terms of the Mozilla Public
00006 //  License, v. 2.0. If a copy of the MPL was not distributed with this
00007 //  file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008 // ========================================================================================
00009 
00010 #include "ApproxMVBB/Config/Config.hpp"
00011 #include ApproxMVBB_OOBB_INCLUDE_FILE
00012 namespace ApproxMVBB{
00013 OOBB::OOBB(const Vector3 & l,
00014            const Vector3 & u,
00015            const Matrix33 & A_IK)
00016     :m_q_KI(A_IK) {
00017     m_q_KI.normalize();
00018     m_minPoint = Vector3(std::min(l(0),u(0)),std::min(l(1),u(1)),std::min(l(2),u(2)));
00019     m_maxPoint = Vector3(std::max(l(0),u(0)),std::max(l(1),u(1)),std::max(l(2),u(2)));
00020 }
00021 
00023 void OOBB::switchZAxis(unsigned int i) {
00024     if(i > 1) {
00025         return;
00026     }
00027     if( i == 0) {
00028         // Make new x-Axis the z-Axis
00029         // R_NK = Rotate around 90∞ around Y, and 90∞ around X (always in K frame) )
00030         // A_IN = A_IK * A_KN = R_KI * R_NK
00031         m_q_KI = m_q_KI * Quaternion(0.5 ,0.5, 0.5, 0.5);
00032         // Change points  Coordinates I_[x,y,z] -> K_[y,z,x]
00033         std::swap(m_minPoint(0),m_minPoint(1));
00034         std::swap(m_minPoint(1),m_minPoint(2));
00035 
00036         std::swap(m_maxPoint(0),m_maxPoint(1));
00037         std::swap(m_maxPoint(1),m_maxPoint(2));
00038     } else {
00039         // Make new y-Axis the z-Axis
00040         // R_NK = Rotate around 90∞ around -X, and 90∞ around -Y (always in K frame) )
00041         // A_IN = A_IK * A_KN = R_KI * R_NK
00042         m_q_KI = m_q_KI * Quaternion(0.5 ,-0.5, -0.5, -0.5);
00043         // Change points  Coordinates I_[x,y,z] -> K_[z,x,y]
00044         std::swap(m_minPoint(0),m_minPoint(2));
00045         std::swap(m_minPoint(1),m_minPoint(2));
00046 
00047         std::swap(m_maxPoint(0),m_maxPoint(2));
00048         std::swap(m_maxPoint(1),m_maxPoint(2));
00049     }
00050 
00051 }
00052 
00053 void OOBB::expandToMinExtentRelative(PREC p, PREC defaultExtent, PREC eps){
00054     Array3 e = extent();
00055     Vector3 c = center();
00056     Array3::Index idx;
00057     PREC ext = std::abs(e.maxCoeff(&idx)) * p;
00058 
00059    if( ext < eps ){ // extent of max axis almost zero, set all axis to defaultExtent --> cube
00060         ext = defaultExtent;
00061         for(int i=0;i<3;++i){
00062             m_minPoint(i) = c(i) - 0.5*ext;
00063             m_maxPoint(i) = c(i) + 0.5*ext;
00064         }
00065     }else{
00066         for(int i=0;i<3;++i){
00067             if(i!=idx && std::abs(e(i)) < ext){
00068                 m_minPoint(i) = c(i) - 0.5*ext;
00069                 m_maxPoint(i) = c(i) + 0.5*ext;
00070             }
00071         }
00072     }
00073 }
00074 
00075 void OOBB::expandToMinExtentAbsolute(PREC minExtent){
00076     Array3 e = extent();
00077     Vector3 c = center();
00078 
00079     PREC l = 0.5*minExtent;
00080     for(int i=0;i<3;++i){
00081         if(std::abs(e(i)) < minExtent){
00082             m_minPoint(i) = c(i) - l;
00083             m_maxPoint(i) = c(i) + l;
00084         }
00085     }
00086 }
00087 
00088 
00089 void OOBB::reset() {
00090     // Violating the constraint min<max for making a completey empty box!
00091     m_minPoint(0) = std::numeric_limits<PREC>::max();
00092     m_maxPoint(0) = std::numeric_limits<PREC>::min();
00093     m_minPoint(1) = std::numeric_limits<PREC>::max();
00094     m_maxPoint(1) = std::numeric_limits<PREC>::min();
00095     m_minPoint(2) = std::numeric_limits<PREC>::max();
00096     m_maxPoint(2) = std::numeric_limits<PREC>::min();
00097     m_q_KI.setIdentity();
00098 }
00099 }


asr_approx_mvbb
Author(s): Gassner Nikolai
autogenerated on Sat Jun 8 2019 20:21:49