Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_BVH_BVH_GET_NODES_AT_HEIGHT_H
00002 #define OPENTISSUE_COLLISION_BVH_BVH_GET_NODES_AT_HEIGHT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <boost/shared_ptr.hpp>
00013
00014 #include <map>
00015 #include <list>
00016
00017 namespace OpenTissue
00018 {
00019 namespace bvh
00020 {
00021
00022 namespace detail
00023 {
00024
00025 template<typename bvh_type, typename bv_ptr_type, typename bv_ptr_container>
00026 inline unsigned int visit(bvh_type const & bvh, bv_ptr_type bv, unsigned int const & height, bv_ptr_container & nodes )
00027 {
00028 typedef typename bvh_type::bv_ptr_iterator bv_ptr_iterator;
00029
00030 using std::max;
00031
00032 unsigned int bv_height = 0;
00033
00034 bv_ptr_iterator child = bv->child_ptr_begin();
00035 bv_ptr_iterator end = bv->child_ptr_end();
00036 for(;child!=end;++child)
00037 {
00038 bv_ptr_type ptr( *child );
00039 bv_height = max( bv_height, visit(bvh, ptr, height, nodes ) );
00040 }
00041 bv_height = bv_height + 1;
00042 if ( bv_height == height )
00043 {
00044 nodes.push_back( bv );
00045 }
00046 return bv_height;
00047 }
00048
00049 }
00050
00054 template<typename bvh_type,typename bv_ptr_container>
00055 inline void get_nodes_at_height(bvh_type const & bvh,unsigned int const & height,bv_ptr_container & nodes)
00056 {
00057 typedef typename bvh_type::bv_ptr bv_ptr;
00058 typedef typename bvh_type::bv_type bv_type;
00059
00060 nodes.clear();
00061 if(!bvh.root())
00062 return;
00063 bv_ptr root = boost::const_pointer_cast<bv_type>( bvh.root() );
00064
00065 detail::visit( bvh, root, height, nodes );
00066 }
00067
00068 }
00069
00070
00071 }
00072
00073
00074 #endif