Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_AABB_TREE_POLICIES_AABB_TREE_BOTTOM_UP_CONSTRUCTOR_POLICY_H
00002 #define OPENTISSUE_COLLISION_AABB_TREE_POLICIES_AABB_TREE_BOTTOM_UP_CONSTRUCTOR_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 BottomUpConstructorPolicy
00019 : public OpenTissue::bvh::BinaryMatchBottomUpPolicy<typename aabb_tree_geometry::bvh_type>
00020 {
00021 public:
00022
00023 typedef typename aabb_tree_geometry::bvh_type bvh_type;
00024 typedef OpenTissue::bvh::BVHGraph<bvh_type> graph_type;
00025 typedef typename graph_type::node_ptr_type node_ptr;
00026 typedef typename graph_type::edge_ptr_type edge_ptr;
00027 typedef typename graph_type::edge_iterator edge_iterator;
00028 typedef typename graph_type::node_iterator node_iterator;
00029 typedef typename bvh_type::bv_type bv_type;
00030 typedef typename bvh_type::bv_iterator bv_iterator;
00031 typedef typename bvh_type::annotated_bv_type annotated_bv_type;
00032 typedef typename bvh_type::volume_type volume_type;
00033 typedef typename bvh_type::geometry_type geometry_type;
00034 typedef typename bvh_type::geometry_iterator geometry_iterator;
00035 typedef typename volume_type::real_type real_type;
00036 typedef typename volume_type::vector3_type vector3_type;
00037
00038 public:
00039
00040 BottomUpConstructorPolicy() {}
00041 virtual ~BottomUpConstructorPolicy() {}
00042
00043 protected:
00044
00045 const unsigned int degree() const { return 8; }
00046
00047 public:
00048
00049 template<typename geometry_iterator,typename volume_iterator>
00050 volume_type fit(geometry_iterator g0,geometry_iterator g1,volume_iterator v0,volume_iterator v1)
00051 {
00052 unsigned int vN = std::distance(v0,v1);
00053 if(vN>1)
00054 return fit_volumes(v0,v1);
00055 return fit_geometry(g0,g1);
00056 }
00057
00058 private:
00059
00060 template<typename geometry_iterator>
00061 volume_type fit_geometry( geometry_iterator begin,geometry_iterator end )
00062 {
00063 vector3_type m = vector3_type( math::detail::highest<real_type>() );
00064 vector3_type M = vector3_type( math::detail::lowest<real_type>() );
00065 for ( geometry_iterator geometry = begin;geometry!=end;++geometry)
00066 {
00067 vector3_type p0 = geometry->m_p0->position();
00068 vector3_type p1 = geometry->m_p1->position();
00069 vector3_type p2 = geometry->m_p2->position();
00070
00071 m = min(m, p0);
00072 m = min(m, p1);
00073 m = min(m, p2);
00074 M = max(M, p0);
00075 M = max(M, p1);
00076 M = max(M, p2);
00077 }
00078 return volume_type(m,M);
00079 }
00080
00081 template<typename volume_iterator>
00082 volume_type fit_volumes( volume_iterator begin, volume_iterator end )
00083 {
00084 vector3_type m = vector3_type( math::detail::highest<real_type>() );
00085 vector3_type M = vector3_type( math::detail::lowest<real_type>() );
00086 for ( volume_iterator volume = begin;volume!=end;++volume )
00087 {
00088 m = min( m, volume->min() );
00089 M = max( M, volume->max() );
00090 }
00091 return volume_type(m,M);
00092 }
00093
00094 };
00095
00096 }
00097
00098 }
00099
00100
00101 #endif