Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_AABB_TREE_POLICIES_AABB_TREE_REFITTER_POLICY_H
00002 #define OPENTISSUE_COLLISION_AABB_TREE_POLICIES_AABB_TREE_REFITTER_POLICY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace aabb_tree
00015 {
00016
00017 template<typename aabb_tree_geometry>
00018 class RefitterPolicy
00019 {
00020 public:
00021
00022 typedef typename aabb_tree_geometry::bvh_type bvh_type;
00023 typedef typename bvh_type::volume_type volume_type;
00024 typedef typename bvh_type::geometry_type geometry_type;
00025 typedef typename bvh_type::bv_ptr bv_ptr;
00026 typedef typename bvh_type::annotated_bv_ptr annotated_bv_ptr;
00027 typedef typename bvh_type::annotated_bv_type annotated_bv_type;
00028 typedef typename bvh_type::bv_iterator bv_iterator;
00029 typedef typename bvh_type::geometry_iterator geometry_iterator;
00030 typedef typename volume_type::real_type real_type;
00031 typedef typename volume_type::vector3_type vector3_type;
00032
00033 public:
00034
00035 real_type m_enlargement;
00036
00037
00038
00039 public:
00040
00041 RefitterPolicy()
00042 : m_enlargement(0)
00043 {}
00044
00045 public:
00046
00047 void refit(bv_ptr bv)
00048 {
00049 assert(bv);
00050 vector3_type & m = bv->volume().min();
00051 vector3_type & M = bv->volume().max();
00052 m = vector3_type( math::detail::highest<real_type>() );
00053 M = vector3_type( math::detail::lowest<real_type>() );
00054 if(bv->is_leaf())
00055 {
00056 annotated_bv_ptr annotated_bv = boost::static_pointer_cast<annotated_bv_type>(bv);
00057
00058 geometry_type * geometry = &(*(annotated_bv->geometry_begin()));
00059 vector3_type p0 = geometry->m_p0->position();
00060 vector3_type p1 = geometry->m_p1->position();
00061 vector3_type p2 = geometry->m_p2->position();
00062
00063 m = min(m, p0);
00064 m = min(m, p1);
00065 m = min(m, p2);
00066 M = max(M, p0);
00067 M = max(M, p1);
00068 M = max(M, p2);
00069 if(m_enlargement>0)
00070 {
00071 m -= vector3_type(m_enlargement,m_enlargement,m_enlargement);
00072 M += vector3_type(m_enlargement,m_enlargement,m_enlargement);
00073 }
00074 }
00075 else
00076 {
00077 for ( bv_iterator child = bv->child_begin();child!=bv->child_end();++child )
00078 {
00079 m = min( m, child->volume().min() );
00080 M = max( M, child->volume().max() );
00081 }
00082 }
00083 }
00084 };
00085
00086 }
00087
00088 }
00089
00090
00091 #endif