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