Go to the documentation of this file.00001 #ifndef OPENTISSUE_BVH_BVH_WORLD_COLLISION_QUERY_H
00002 #define OPENTISSUE_BVH_BVH_WORLD_COLLISION_QUERY_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 {
00027 template <typename collision_policy>
00028 class WorldCollisionQuery : public collision_policy
00029 {
00030 public:
00031
00040 template<typename bvh_type, typename results_container>
00041 void run( bvh_type const & bvh_A, bvh_type const & bvh_B, results_container & results )
00042 {
00043 typedef typename bvh_type::bv_type bv_type;
00044 typedef typename bvh_type::bv_ptr bv_ptr;
00045 typedef typename bvh_type::bv_ptr_container bv_ptr_container;
00046 typedef typename bvh_type::bv_ptr_iterator bv_ptr_iterator;
00047
00048 this->reset(results);
00049
00050 bv_ptr_container Q;
00051 bv_ptr root_A = boost::const_pointer_cast<bv_type>( bvh_A.root() );
00052 bv_ptr root_B = boost::const_pointer_cast<bv_type>( bvh_B.root() );
00053
00054
00055 Q.push_back( root_A );
00056 Q.push_back( root_B );
00057 while ( !Q.empty() )
00058 {
00059 bv_ptr A( Q.front() );
00060 Q.pop_front();
00061 bv_ptr B( Q.front() );
00062 Q.pop_front();
00063 if( !this->overlap( A, B ) )
00064 continue;
00065 if ( A->is_leaf() && B->is_leaf() )
00066 {
00067 this->report(A,B,results);
00068 continue;
00069 }
00070 if ( B->is_leaf() || ( !A->is_leaf() && ( A->volume().volume() > B->volume().volume() ) ) )
00071 {
00072 bv_ptr_iterator a = A->child_ptr_begin();
00073 bv_ptr_iterator end = A->child_ptr_end();
00074 for(;a!=end;++a)
00075 {
00076 bv_ptr ptr( *a );
00077 Q.push_back( ptr );
00078 Q.push_back( B );
00079 }
00080 }
00081 else
00082 {
00083 bv_ptr_iterator b = B->child_ptr_begin();
00084 bv_ptr_iterator end = B->child_ptr_end();
00085 for(;b!=end;++b)
00086 {
00087 bv_ptr ptr( *b );
00088 Q.push_back( A );
00089 Q.push_back( ptr );
00090 }
00091 }
00092 }
00093 }
00094 };
00095
00096 }
00097
00098 }
00099
00100
00101 #endif