Go to the documentation of this file.00001 #ifndef OPENTISSUE_BVH_BVH_TOP_DOWN_CONSTRUCTOR_H
00002 #define OPENTISSUE_BVH_BVH_TOP_DOWN_CONSTRUCTOR_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/bvh/top_down_constructor/bvh_default_top_down_policy.h>
00013
00014 #include <list>
00015
00016 namespace OpenTissue
00017 {
00018 namespace bvh
00019 {
00020
00044 template <
00045 typename bvh_type,
00046 typename top_down_policy = DefaultTopDownPolicy<bvh_type>
00047 >
00048 class TopDownConstructor : public top_down_policy
00049 {
00050 public:
00051
00052 typedef top_down_policy top_down_type;
00053 typedef typename bvh_type::bv_ptr bv_ptr;
00054 typedef typename bvh_type::bv_ptr_container bv_ptr_container;
00055 typedef typename top_down_type::partition_type partition_type;
00056 typedef typename top_down_type::partition_iterator partition_iterator;
00057 typedef typename std::list<partition_type> partition_queue;
00058
00059 public:
00060
00069 template< typename iterator>
00070 void run(iterator begin, iterator end, bvh_type & bvh)
00071 {
00072 partition_queue Q;
00073 bv_ptr_container parents;
00074
00075 this->init(begin, end);
00076
00077 bvh.clear();
00078
00079 bv_ptr null_ptr;
00080
00081 parents.push_back( null_ptr );
00082
00083 partition_type all = this->all();
00084 Q.push_back( all );
00085
00086 while(!Q.empty())
00087 {
00088 partition_type partition( Q.front() );
00089 Q.pop_front();
00090 bv_ptr parent( parents.front() );
00091 parents.pop_front();
00092
00093 assert(!partition.empty() || !"TopDownConstructor::run() Empty partition encountered!");
00094
00095 bv_ptr bv = bvh.insert( parent, partition.annotated() );
00096
00097 partition.fit(bv);
00098 if(partition.size()==1)
00099 continue;
00100
00101 partition.split();
00102
00103 partition_iterator s = partition.sub_partition_begin();
00104 partition_iterator end = partition.sub_partition_end();
00105 for(;s!=end;++s)
00106 {
00107 Q.push_back( (*s) );
00108 parents.push_back(bv);
00109 }
00110
00111 }
00112 std::cout << "TopDownConstructor::run(): created " << bvh.size() << " nodes" << std::endl;
00113 }
00114 };
00115
00116 }
00117
00118 }
00119
00120
00121 #endif