Go to the documentation of this file.00001 #ifndef OPENTISSUE_BVH_BOTTOM_UP_CONSTRUCTOR_BVH_T4MESH2BVH_GRAPH_H
00002 #define OPENTISSUE_BVH_BOTTOM_UP_CONSTRUCTOR_BVH_T4MESH2BVH_GRAPH_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <iostream>
00013 #include <vector>
00014 #include <map>
00015 #include <queue>
00016
00017 namespace OpenTissue
00018 {
00019
00020 namespace bvh
00021 {
00022
00027 template <typename mesh_type,typename graph_type>
00028 class T4Mesh2BVHGraph
00029 {
00030 public:
00031
00032
00033 typedef typename graph_type::node_ptr_type node_ptr_type;
00034 typedef typename mesh_type::tetrahedron_type tetrahedron_type;
00035 typedef typename mesh_type::tetrahedron_iterator tetrahedron_iterator;
00036
00037 protected:
00038
00039 typedef typename std::queue<tetrahedron_type*> tetrahedron_ptr_queue;
00040 typedef typename std::map<tetrahedron_type *,node_ptr_type > graph_node_map;
00041
00042 protected:
00043
00044 graph_node_map m_lookup;
00045
00046 public:
00047
00054 void run(mesh_type & mesh,graph_type & graph)
00055 {
00056 m_lookup.clear();
00057 for(tetrahedron_iterator tetrahedron=mesh.tetrahedron_begin();tetrahedron!=mesh.tetrahedron_end();++tetrahedron)
00058 {
00059 node_ptr_type node = graph.insert(&(*tetrahedron));
00060 m_lookup[&(*tetrahedron)] = node;
00061 }
00062 tetrahedron_ptr_queue Q;
00063 std::vector<bool> visited(mesh.size_tetrahedra());
00064 std::fill(visited.begin(),visited.end(),false);
00065 Q.push(&(*(mesh.tetrahedron(0))));
00066 while(!Q.empty())
00067 {
00068 tetrahedron_type * tetrahedron = Q.front();
00069 Q.pop();
00070 visited[tetrahedron->idx()] = true;
00071
00072 tetrahedron_iterator i = tetrahedron->jkm();
00073 tetrahedron_iterator j = tetrahedron->kim();
00074 tetrahedron_iterator k = tetrahedron->ijm();
00075 tetrahedron_iterator m = tetrahedron->ikj();
00076
00077 if(i!=mesh.tetrahedron_end() && !visited[i->idx()])
00078 {
00079 node_ptr_type A = m_lookup[tetrahedron];
00080 node_ptr_type B = m_lookup[&(*i)];
00081 graph.insert(A,B);
00082 Q.push(&(*i));
00083 }
00084 if(j!=mesh.tetrahedron_end() &&!visited[j->idx()])
00085 {
00086 node_ptr_type A = m_lookup[tetrahedron];
00087 node_ptr_type B = m_lookup[&(*j)];
00088 graph.insert(A,B);
00089 Q.push(&(*j));
00090 }
00091 if(k!=mesh.tetrahedron_end() && !visited[k->idx()])
00092 {
00093 node_ptr_type A = m_lookup[tetrahedron];
00094 node_ptr_type B = m_lookup[&(*k)];
00095 graph.insert(A,B);
00096 Q.push(&(*k));
00097 }
00098 if(m!=mesh.tetrahedron_end() && !visited[m->idx()])
00099 {
00100 node_ptr_type A = m_lookup[tetrahedron];
00101 node_ptr_type B = m_lookup[&(*m)];
00102 graph.insert(A,B);
00103 Q.push(&(*m));
00104 }
00105 }
00106 std::cout << "T4Mesh2BVHGraph::run() Graph with " << graph.size_nodes() << " nodes and " << graph.size_edges() << " edges" << std::endl;
00107 }
00108
00109 };
00110
00111 }
00112
00113 }
00114
00115
00116 #endif