Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef ApproxMVBB_OOBB_hpp
00011 #define ApproxMVBB_OOBB_hpp
00012
00013 #include "ApproxMVBB/Config/Config.hpp"
00014 #include ApproxMVBB_TypeDefs_INCLUDE_FILE
00015 #include ApproxMVBB_AABB_INCLUDE_FILE
00016 #include "ApproxMVBB/AABB.hpp"
00017
00018 namespace ApproxMVBB{
00019
00020
00021 class APPROXMVBB_EXPORT OOBB{
00022 public:
00023
00024 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00025
00026 ApproxMVBB_DEFINE_MATRIX_TYPES
00027 ApproxMVBB_DEFINE_POINTS_CONFIG_TYPES
00028
00029 OOBB() {
00030 this->reset();
00031 }
00032
00033 OOBB(const OOBB &) = default;
00034
00035 OOBB(const Vector3 & l,
00036 const Vector3 & u,
00037 const Matrix33 & A_IK);
00038
00040 OOBB(AABB3d & aabb){
00041 m_minPoint = aabb.m_minPoint;
00042 m_maxPoint = aabb.m_maxPoint;
00043 m_q_KI.setIdentity();
00044 }
00045
00047 OOBB & operator=(AABB3d & aabb){
00048 m_minPoint = aabb.m_minPoint;
00049 m_maxPoint = aabb.m_maxPoint;
00050 m_q_KI.setIdentity();
00051 return *this;
00052 }
00053
00054 inline void setZAxisLongest(){
00055 Vector3::Index i;
00056 maxExtent(i);
00057 if(i<2){
00058 switchZAxis(static_cast<unsigned int>(i));
00059 }
00060 }
00061
00063 void switchZAxis(unsigned int i);
00064
00065 void reset();
00066
00068 template<typename Derived>
00069 OOBB & unite(const MatrixBase<Derived> & p){
00070 m_maxPoint(0) = std::max(m_maxPoint(0),p(0));
00071 m_maxPoint(1) = std::max(m_maxPoint(1),p(1));
00072 m_maxPoint(2) = std::max(m_maxPoint(2),p(2));
00073 m_minPoint(0) = std::min( m_minPoint(0),p(0));
00074 m_minPoint(1) = std::min( m_minPoint(1),p(1));
00075 m_minPoint(2) = std::min( m_minPoint(2),p(2));
00076 return *this;
00077 }
00078
00079 inline Vector3 center(){ return 0.5*(m_maxPoint + m_minPoint);}
00080
00081 inline Array3 extent() const{
00082 return (m_maxPoint - m_minPoint).array();
00083 }
00084
00085 inline PREC maxExtent() const{
00086 return (m_maxPoint - m_minPoint).maxCoeff();
00087 }
00088
00089 inline PREC maxExtent(Vector3::Index & i) const{
00090 return (m_maxPoint - m_minPoint).maxCoeff(&i);
00091 }
00092
00093 inline bool isEmpty() const {
00094 return m_maxPoint(0) <= m_minPoint(0) || m_maxPoint(1) <= m_minPoint(1) || m_maxPoint(2) <= m_minPoint(2);
00095 }
00096
00103 template<typename Derived, bool coordinateSystemIsI = true>
00104 inline bool overlaps(const MatrixBase<Derived> &p) const {
00105 if(coordinateSystemIsI){
00106
00107 Vector3 t = m_q_KI.inverse() * p;
00108 return ((t.array() >= m_minPoint.array()) && (t.array() <= m_maxPoint.array())).all();
00109 }else{
00110
00111 return ((p.array() >= m_minPoint.array()) && (p.array() <= m_maxPoint.array())).all();
00112 }
00113 }
00114
00116 void expandToMinExtentRelative(PREC p = 0.1, PREC defaultExtent = 0.1, PREC eps = 1e-10);
00117
00119 void expandToMinExtentAbsolute(PREC minExtent);
00120
00121 inline void expand(PREC d) {
00122 ApproxMVBB_ASSERTMSG(d>=0,"d>=0")
00123 m_minPoint -= Vector3(d,d,d);
00124 m_maxPoint += Vector3(d,d,d);
00125 }
00126
00127 inline void expand(Vector3 d) {
00128 ApproxMVBB_ASSERTMSG(d(0)>=0 && d(1)>=0 && d(2)>=0,"d>=0")
00129 m_minPoint -= d;
00130 m_maxPoint += d;
00131 }
00132
00133 inline PREC volume() const {
00134 Vector3 d = m_maxPoint- m_minPoint;
00135 return d(0) * d(1) * d(2);
00136 }
00137
00139 inline Vector3 getDirection(unsigned int i) const{
00140 ApproxMVBB_ASSERTMSG(i<3,"Index wrong: " << i)
00141 Vector3 d = Vector3::Zero();
00142 d(i) = 1.0;
00143 return m_q_KI * d;
00144 }
00145
00152 template<bool coordinateSystemIsI = true>
00153 inline Vector3List getCornerPoints() const{
00154 Vector3List points(8);
00155 Array3 ex = extent();
00156 points[0] = m_minPoint ;
00157 points[1] = m_minPoint + (Array3(1.0, 0.0, 0.0) * ex).matrix();
00158 points[2] = m_minPoint + (Array3(0.0, 1.0, 0.0) * ex).matrix();
00159 points[3] = m_minPoint + (Array3(1.0, 1.0, 0.0) * ex).matrix();
00160
00161 points[4] = m_minPoint + (Array3(0.0, 0.0, 1.0) * ex).matrix();
00162 points[5] = m_minPoint + (Array3(1.0, 0.0, 1.0) * ex).matrix();
00163 points[6] = m_minPoint + (Array3(0.0, 1.0, 1.0) * ex).matrix();
00164 points[7] = m_maxPoint ;
00165
00166 if(coordinateSystemIsI){
00167 for(auto & p : points){
00168 p = (m_q_KI * p).eval();
00169 }
00170 }
00171
00172 return points;
00173 }
00174
00175 Quaternion m_q_KI;
00176 Vector3 m_minPoint;
00177 Vector3 m_maxPoint;
00178 };
00179
00180 }
00181
00182 #endif // OOBB_hpp