Jafar
|
00001 00002 #include <geom/Point.hpp> 00003 00004 namespace jafar { 00005 namespace geom { 00006 00007 template<int dimension> 00008 BoundingBox<dimension>::BoundingBox() : m_corner1(0), m_corner2(0), m_defined(false) 00009 { 00010 } 00011 00012 template<int dimension> 00013 BoundingBox<dimension>::BoundingBox(const BoundingBox<dimension>::HomogenousVec& corner1, const BoundingBox<dimension>::HomogenousVec& corner2) 00014 : m_corner1(corner1), m_corner2(corner2), m_defined(true) 00015 { 00016 normalize(); 00017 } 00018 00019 template<int dimension> 00020 BoundingBox<dimension>::BoundingBox(const BoundingBox<dimension>& ref) 00021 : m_corner1(ref.corner1()), m_corner2(ref.corner2()), m_defined(true) 00022 { 00023 // normalize(); 00024 } 00025 00026 template<int dimension> 00027 bool BoundingBox<dimension>::operator==( const BoundingBox& _rhs ) const 00028 { 00029 for( int i = 0; i < dimension; ++i) 00030 { 00031 if( _rhs.m_corner1(i) != m_corner1(i) or _rhs.m_corner2(i) != m_corner2(i) ) 00032 { 00033 return false; 00034 } 00035 } 00036 return true; 00037 } 00038 00039 template<int dimension> 00040 inline const typename BoundingBox<dimension>::HomogenousVec& BoundingBox<dimension>::corner1() const 00041 { 00042 return m_corner1; 00043 } 00044 00045 template<int dimension> 00046 inline const typename BoundingBox<dimension>::HomogenousVec& BoundingBox<dimension>::corner2() const 00047 { 00048 return m_corner2; 00049 } 00050 00051 template<int dimension> 00052 inline void BoundingBox<dimension>::extend(double size) 00053 { 00054 HomogenousVec extensionVec = jblas::scalar_vec( dimension+1, size ); 00055 extensionVec( dimension ) = 0.0; 00056 m_corner1 -= extensionVec; 00057 m_corner2 += extensionVec; 00058 } 00059 00060 template<int dimension> 00061 inline void BoundingBox<dimension>::normalize() 00062 { 00063 for(int i = 0; i < dimension; i++) 00064 { 00065 if( m_corner1(i) > m_corner2(i) ) 00066 { 00067 double v = m_corner1(i); 00068 m_corner1(i) = m_corner2(i); 00069 m_corner2(i) = v; 00070 } 00071 } 00072 } 00073 00074 template<int dimension> 00075 inline bool BoundingBox<dimension>::isDefined() const 00076 { 00077 return m_defined; 00078 } 00079 00080 template<int dimension> 00081 inline bool BoundingBox<dimension>::contains( const typename BoundingBox<dimension>::HomogenousVec& _point) const 00082 { 00083 for( int i = 0; i < dimension; i++) 00084 { 00085 if( _point(i) > m_corner2(i) or _point(i) < m_corner1(i) ) 00086 { 00087 return false; 00088 } 00089 } 00090 return true; 00091 } 00092 00093 template<int dimension> 00094 inline bool BoundingBox<dimension>::strictContains( const typename BoundingBox<dimension>::HomogenousVec& _point) const 00095 { 00096 for( int i = 0; i < dimension; i++) 00097 { 00098 if( _point(i) >= m_corner2(i) or _point(i) <= m_corner1(i) ) 00099 { 00100 return false; 00101 } 00102 } 00103 return true; 00104 } 00105 00106 template<int _dimension_> 00107 inline bool BoundingBox<_dimension_>::overlap( const BoundingBox<_dimension_>& _bb) const 00108 { 00109 if( *this == _bb ) return true; 00110 for( int i = 0; i < _dimension_; i++) 00111 { // If both coordinate from corner1 and corner2 are out of the range, then it's over 00112 if( (_bb.corner1()(i) > m_corner2(i) or _bb.corner1()(i) < m_corner1(i) ) and 00113 (_bb.corner2()(i) > m_corner2(i) or _bb.corner2()(i) < m_corner1(i) ) and 00114 (_bb.corner2()(i) < m_corner2(i) or _bb.corner1()(i) > m_corner2(i) ) and 00115 (_bb.corner2()(i) < m_corner1(i) or _bb.corner1()(i) > m_corner1(i) ) ) 00116 { 00117 return false; 00118 } 00119 } 00120 return true; 00121 } 00122 00123 template<int _dimension_> 00124 inline bool BoundingBox<_dimension_>::strictOverlap( const BoundingBox<_dimension_>& _bb) const 00125 { 00126 if( *this == _bb ) return true; // Special case 00127 for( int i = 0; i < _dimension_; i++) 00128 { // If both coordinate from corner1 and corner2 are out of the range, then it's over 00129 if( (_bb.corner1()(i) >= m_corner2(i) or _bb.corner1()(i) <= m_corner1(i) ) and 00130 (_bb.corner2()(i) >= m_corner2(i) or _bb.corner2()(i) <= m_corner1(i) ) and 00131 (_bb.corner2()(i) <= m_corner2(i) or _bb.corner1()(i) >= m_corner2(i) ) and 00132 (_bb.corner2()(i) <= m_corner1(i) or _bb.corner1()(i) >= m_corner1(i) ) ) 00133 { 00134 return false; 00135 } 00136 } 00137 return true; 00138 } 00139 00140 template<int _dimension_> 00141 inline std::ostream& operator<<(std::ostream& _s, const BoundingBox<_dimension_>& _bb) 00142 { 00143 _s << _bb.corner1() << " " << _bb.corner2(); 00144 return _s; 00145 } 00146 00147 } 00148 }
Generated on Wed Oct 15 2014 00:37:19 for Jafar by doxygen 1.7.6.1 |