Go to the documentation of this file.00001 #ifndef OPENTISSUE_BVH_BOTTOM_UP_CONSTRUCTOR_BVH_VOXEL2BVH_GRAPH_H
00002 #define OPENTISSUE_BVH_BOTTOM_UP_CONSTRUCTOR_BVH_VOXEL2BVH_GRAPH_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/grid/grid.h>
00013 #include <OpenTissue/core/containers/grid/util/grid_idx2coord.h>
00014 #include <OpenTissue/core/geometry/geometry_aabb.h>
00015 #include <OpenTissue/core/math/math_vector3.h>
00016 #include <vector>
00017 #include <iostream>
00018
00019 namespace OpenTissue
00020 {
00021 namespace bvh
00022 {
00023
00027 template<typename voxels_type,typename graph_type>
00028 class Voxel2BVHGraph
00029 {
00030 public:
00031
00032
00033 typedef typename graph_type::node_ptr_type node_ptr_type;
00034 typedef typename graph_type::edge_ptr_type edge_ptr_type;
00035 typedef typename graph_type::volume_type volume_type;
00036 typedef typename voxels_type::value_type voxel_type;
00037 typedef typename voxels_type::index_iterator index_iterator;
00038
00039 typedef typename volume_type::math_types math_types;
00040 typedef typename math_types::vector3_type vector3_type;
00041 typedef geometry::AABB<math_types> aabb_type;
00042 public:
00043
00044
00045 void run(voxels_type & voxels, graph_type & graph)
00046 {
00047 typedef typename voxels_type::math_types math_types;
00048 typedef OpenTissue::grid::Grid<node_ptr_type,math_types > lookup_grid_type;
00049
00050 node_ptr_type unused_value;
00051 lookup_grid_type lookup( unused_value );
00052
00053 lookup.create(voxels.min_coord(),voxels.max_coord(),voxels.I(),voxels.J(),voxels.K());
00054
00055 vector3_type ext = vector3_type(voxels.dx() /2., voxels.dy() /2., voxels.dz() /2.);
00056
00057 int cnt = 0;
00058 for( index_iterator iter = voxels.begin(); iter != voxels.end(); ++iter)
00059 {
00060 if( (*iter)==1 )
00061 {
00062 aabb_type aabb;
00063 vector3_type p;
00064 OpenTissue::grid::idx2coord(iter,p);
00065 vector3_type pmin = p - ext;
00066 vector3_type pmax = p + ext;
00067 aabb.set(pmin,pmax);
00068 node_ptr_type node = graph.insert(aabb);
00069 lookup( iter.get_index() ) = node;
00070 cnt++;
00071 }
00072 }
00073
00074 std::cout << "Voxel2BVHGraph::run(): " << cnt << " AABB nodes in graph" << std::endl;
00075 cnt = 0;
00076 for(unsigned int k=0;k<(voxels.K()-1);++k)
00077 for(unsigned int j=0;j<(voxels.J()-1);++j)
00078 for(unsigned int i=0;i<(voxels.I()-1);++i)
00079 {
00080 node_ptr_type node = lookup(i,j,k);
00081 if(!node)
00082 continue;
00083 node_ptr_type node_I = lookup(i+1,j,k);
00084 node_ptr_type node_J = lookup(i,j+1,k);
00085 node_ptr_type node_K = lookup(i,j,k+1);
00086 if(node_I)
00087 {
00088 graph.insert(node,node_I);
00089 cnt++;
00090 }
00091 if(node_J)
00092 {
00093 graph.insert(node,node_J);
00094 cnt++;
00095 }
00096 if(node_K)
00097 {
00098 graph.insert(node,node_K);
00099 cnt++;
00100 }
00101 }
00102 std::cout << "Voxel2BVHGraph::run(): Created " << cnt << " edges in graph" << std::endl;
00103 }
00104
00105 };
00106
00107
00108 }
00109
00110 }
00111
00112
00113 #endif