00001 #ifndef OPENTISSUE_COLLISION_GJK_GJK_SUPPORT_FUNCTORS_BOX_H 00002 #define OPENTISSUE_COLLISION_GJK_GJK_SUPPORT_FUNCTORS_BOX_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/core/math/math_is_number.h> 00013 00014 #include <cassert> 00015 00016 namespace OpenTissue 00017 { 00018 namespace gjk 00019 { 00023 template<typename math_types> 00024 class Box 00025 { 00026 protected: 00027 00028 typedef typename math_types::real_type T; 00029 typedef typename math_types::vector3_type V; 00030 typedef typename math_types::value_traits value_traits; 00031 00032 V m_half_extent; 00033 00034 public: 00035 00041 V const & half_extent() const { return this->m_half_extent; } 00042 V & half_extent() { return this->m_half_extent; } 00043 00044 public: 00045 00046 Box() 00047 : m_half_extent( value_traits::one(), value_traits::one(), value_traits::one() ) 00048 {} 00049 00050 public: 00051 00052 V operator()(V const & v) const 00053 { 00054 assert( this->m_half_extent(0) >= value_traits::zero() || !"Box::operator(): Negative half extent encountered"); 00055 assert( this->m_half_extent(1) >= value_traits::zero() || !"Box::operator(): Negative half extent encountered"); 00056 assert( this->m_half_extent(2) >= value_traits::zero() || !"Box::operator(): Negative half extent encountered"); 00057 00058 T const vv = dot(v,v); 00059 assert( is_number(vv) || !"Box::operator(): NaN encountered"); 00060 00061 if (vv > value_traits::zero() ) 00062 { 00063 00064 T const c0 = v(0)>value_traits::zero() ? this->m_half_extent(0) : -this->m_half_extent(0); 00065 T const c1 = v(1)>value_traits::zero() ? this->m_half_extent(1) : -this->m_half_extent(1); 00066 T const c2 = v(2)>value_traits::zero() ? this->m_half_extent(2) : -this->m_half_extent(2); 00067 00068 assert( is_number(c0) || !"Box::operator(): NaN encountered"); 00069 assert( is_number(c1) || !"Box::operator(): NaN encountered"); 00070 assert( is_number(c2) || !"Box::operator(): NaN encountered"); 00071 00072 return V(c0,c1,c2); 00073 } 00074 return (this->m_half_extent); 00075 } 00076 00077 }; 00078 00079 } // namespace gjk 00080 00081 } // namespace OpenTissue 00082 00083 // OPENTISSUE_COLLISION_GJK_GJK_SUPPORT_FUNCTORS_BOX_H 00084 #endif