• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/OpenTissue/OpenTissue/collision/bvh/bottom_up_constructor/bvh_mesh2bvh_graph.h

Go to the documentation of this file.
00001 #ifndef OPENTISSUE_BVH_BOTTOM_UP_CONSTRUCTOR_BVH_MESH2BVH_GRAPH_H
00002 #define OPENTISSUE_BVH_BOTTOM_UP_CONSTRUCTOR_BVH_MESH2BVH_GRAPH_H
00003 //
00004 // OpenTissue Template Library
00005 // - A generic toolbox for physics-based modeling and simulation.
00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen.
00007 //
00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php
00009 //
00010 #include <OpenTissue/configuration.h>
00011 
00012 #include <iostream>
00013 #include <queue>
00014 #include <map>
00015 #include <OpenTissue/core/containers/mesh/mesh.h>
00016 
00017 namespace OpenTissue
00018 {
00019   namespace bvh
00020   {
00021 
00026     template <typename graph_type>
00027     class Mesh2BVHGraph
00028     {
00029     public:
00030 
00031       //--- Convenience stuff
00032       typedef typename graph_type::volume_type                 volume_type;
00033       typedef typename graph_type::node_ptr_type               node_ptr_type;
00034       typedef typename OpenTissue::polymesh::PolyMesh<>        mesh_type;
00035       typedef typename mesh_type::halfedge_type                halfedge_type;
00036       typedef typename mesh_type::face_type                    face_type;
00037       typedef typename mesh_type::face_iterator                face_iterator;
00038 
00039     protected:
00040 
00041       typedef typename std::queue<face_type*>                 face_ptr_queue;
00042       typedef typename std::map<face_type *,node_ptr_type>    graph_node_map;
00043 
00044     protected:
00045 
00046       graph_node_map m_lookup;   
00047 
00048     public:
00049 
00056       void run(mesh_type & mesh,graph_type & graph)
00057       {
00058         m_lookup.clear();
00059 
00060         for(face_iterator face=mesh.face_begin();face!=mesh.face_end();++face)
00061         {
00062           node_ptr_type node = graph.insert(&(*face));
00063           m_lookup[&(*face)] = node;
00064         }
00065         face_ptr_queue Q;
00066 
00067         mesh::clear_face_tags(mesh);
00068         mesh::clear_halfedge_tags(mesh);
00069 
00070         Q.push( &(*mesh.face_begin()) );
00071         while(!Q.empty())
00072         {
00073           face_type * face = Q.front();
00074           Q.pop();
00075 
00076           face->m_tag = 1;
00077 
00078           mesh_type::face_halfedge_circulator h(*face),hend;
00079           for(;h!=hend;++h)
00080             visistConnection(face, &(*h), Q, graph);
00081         }
00082         std::cout << "Mesh2BVHGraph::run(): Graph with " << graph.size_nodes() << " nodes and  " << graph.size_edges() << " edges" << std::endl;
00083       }
00084 
00085     protected:
00086 
00087       void visistConnection(  face_type * face, halfedge_type * edge,  face_ptr_queue & Q, graph_type & graph  )
00088       {
00089         //--- See if we have a connection we have not yet visited
00090         if(edge->get_twin_handle().is_null())
00091           return;
00092 
00093         if(edge->m_tag==1)
00094           return;
00095 
00096         halfedge_type * twin_edge = &(*edge->get_twin_iterator());
00097 
00098         if(twin_edge->get_face_handle().is_null())
00099           return;
00100 
00101         face_type * twin_face = &(*twin_edge->get_face_iterator());
00102 
00103         node_ptr_type A = m_lookup[face];
00104         node_ptr_type B = m_lookup[twin_face];
00105 
00106         assert(A!=B);
00107 
00108         edge->m_tag = 1;
00109         twin_edge->m_tag = 1;
00110 
00111         graph.insert(A,B);
00112 
00113         if(twin_face->m_tag==0)
00114           Q.push(twin_face);
00115       }
00116 
00117     };
00118 
00119   } // namespace bvh
00120 
00121 } // namespace OpenTissue
00122 
00123 //OPENTISSUE_BVH_BOTTOM_UP_CONSTRUCTOR_BVH_MESH2BVH_GRAPH_H
00124 #endif

Generated on Thu Dec 1 2011 12:50:43 for HUMIM Tracker by  doxygen 1.7.1