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