Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_OBB_AABB_H
00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_OBB_AABB_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/geometry/geometry_aabb.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace geometry
00017 {
00028 template<typename vector3_type,typename matrix3x3_type>
00029 void compute_obb_aabb(
00030 vector3_type const & position
00031 , matrix3x3_type const & R
00032 , vector3_type const & ext
00033 , vector3_type & min_coord
00034 , vector3_type & max_coord
00035 )
00036 {
00037 using std::fabs;
00038
00039 typedef typename vector3_type::value_type real_type;
00040
00041
00042
00043
00044 real_type xrange = fabs(ext(0)*R(0,0)) + fabs(ext(1)*R(0,1)) + fabs(ext(2)*R(0,2)) ;
00045 real_type yrange = fabs(ext(0)*R(1,0)) + fabs(ext(1)*R(1,1)) + fabs(ext(2)*R(1,2)) ;
00046 real_type zrange = fabs(ext(0)*R(2,0)) + fabs(ext(1)*R(2,1)) + fabs(ext(2)*R(2,2)) ;
00047 min_coord(0) = position(0) - xrange;
00048 min_coord(1) = position(1) - yrange;
00049 min_coord(2) = position(2) - zrange;
00050 max_coord(0) = position(0) + xrange;
00051 max_coord(1) = position(1) + yrange;
00052 max_coord(2) = position(2) + zrange;
00053 }
00054
00063 template<typename obb_type,typename aabb_type>
00064 void compute_obb_aabb(obb_type const & obb,aabb_type & aabb)
00065 {
00066 compute_obb_aabb(obb.center(),obb.orientation(),obb.ext(),aabb.min(),aabb.max());
00067 }
00068
00077 template<typename obb_type>
00078 geometry::AABB<typename obb_type::math_types> compute_obb_aabb(obb_type const & obb)
00079 {
00080 geometry::AABB<typename obb_type::math_types> aabb;
00081 compute_obb_aabb(obb,aabb);
00082 return aabb;
00083 }
00084
00085 }
00086 }
00087
00088
00089 #endif