Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_BVH_BVH_GET_NODES_AT_DEPTH_H
00002 #define OPENTISSUE_COLLISION_BVH_BVH_GET_NODES_AT_DEPTH_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <boost/shared_ptr.hpp>
00013
00014 #include <list>
00015
00016 namespace OpenTissue
00017 {
00018 namespace bvh
00019 {
00020
00024 template<typename bvh_type,typename bv_ptr_container>
00025 inline void get_nodes_at_depth(bvh_type const & bvh, unsigned int const & depth, bv_ptr_container & nodes)
00026 {
00027 typedef typename bvh_type::bv_type bv_type;
00028 typedef typename bvh_type::bv_ptr bv_ptr;
00029 typedef typename bvh_type::bv_ptr_iterator bv_ptr_iterator;
00030
00031 nodes.clear();
00032 if ( !bvh.root() )
00033 return;
00034
00035 bv_ptr_container Q;
00036 std::list< unsigned int > D;
00037
00038 bv_ptr root = boost::const_pointer_cast<bv_type>( bvh.root() );
00039
00040 Q.push_back( root );
00041 unsigned int zero = 0;
00042 D.push_back( zero );
00043
00044 while ( !Q.empty() )
00045 {
00046 bv_ptr bv( Q.front() ); Q.pop_front();
00047 unsigned int bv_depth = D.front();D.pop_front();
00048
00049 if ( depth == bv_depth )
00050 nodes.push_back( bv );
00051
00052 bv_ptr_iterator child = bv->child_ptr_begin();
00053 bv_ptr_iterator end = bv->child_ptr_end();
00054 for(;child!=end;++child)
00055 {
00056 bv_ptr ptr( *child );
00057 Q.push_back( ptr );
00058 D.push_back( bv_depth + 1 );
00059 }
00060 }
00061 }
00062
00063 }
00064
00065 }
00066
00067
00068 #endif