Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
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
00029
00030
00031 m_q_KI = m_q_KI * Quaternion(0.5 ,0.5, 0.5, 0.5);
00032
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
00040
00041
00042 m_q_KI = m_q_KI * Quaternion(0.5 ,-0.5, -0.5, -0.5);
00043
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 ){
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
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 }