GEL
2
GEL is a library for Geometry and Linear Algebra
|
00001 #ifndef __GEOMETRY_AABOX__H 00002 #define __GEOMETRY_AABOX__H 00003 00004 #include <iostream> 00005 #include <vector> 00006 #include "Triangle.h" 00007 00008 namespace Geometry 00009 { 00010 const float DIST_THRESH = 5.0e-4f; 00011 00012 class AABox 00013 { 00014 CGLA::Vec3f pmin, pmax, interior_point; 00015 public: 00016 00017 AABox() {} 00018 00019 AABox(const CGLA::Vec3f& _pmin, const CGLA::Vec3f& _pmax, 00020 const CGLA::Vec3f& _interior_point): 00021 00022 pmin(_pmin), pmax(_pmax), interior_point(_interior_point) 00023 { 00024 for(int i=0;i<3;++i) 00025 if((pmax[i]-pmin[i]) < DIST_THRESH) 00026 { 00027 pmax[i] += DIST_THRESH/2.0f; 00028 pmin[i] -= DIST_THRESH/2.0f; 00029 } 00030 assert(pmin.all_le(interior_point)); 00031 assert(pmax.all_ge(interior_point)); 00032 } 00033 00034 const CGLA::Vec3f& get_pmin() const {return pmin;} 00035 00036 const CGLA::Vec3f& get_pmax() const {return pmax;} 00037 00038 bool intersect(const CGLA::Vec3f&, const CGLA::Vec3f&) const; 00039 00040 void minmax_sq_dist(const CGLA::Vec3f& p, float& dmin, float& dmax) const; 00041 00042 static AABox box_triangle(const Triangle&); 00043 00044 static AABox box_and_split(const std::vector<Triangle>& invec, 00045 std::vector<Triangle>& lvec, 00046 std::vector<Triangle>& rvec); 00047 00048 }; 00049 } 00050 00051 #endif