Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_OBB_TREE_OBB_TREE_INIT_H
00002 #define OPENTISSUE_COLLISION_OBB_TREE_OBB_TREE_INIT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/obb_tree/obb_tree_types.h>
00013
00014 #include <vector>
00015
00016 namespace OpenTissue
00017 {
00018 namespace obb_tree
00019 {
00020
00029 template<typename obb_tree_types>
00030 void init(
00031 typename obb_tree_types::mesh_type & mesh
00032 , typename obb_tree_types::bvh_type & tree
00033 , size_t const & degree = 2
00034 )
00035 {
00036 typedef typename obb_tree_types::index_type index_type;
00037 typedef typename obb_tree_types::construtor_type constructor_type;
00038 typedef typename obb_tree_types::face_ptr_type face_ptr_type;
00039
00040 typedef typename obb_tree_types::mesh_type mesh_type;
00041 typedef typename mesh_type::face_iterator face_iterator;
00042 typedef typename mesh_type::face_vertex_circulator face_vertex_circulator;
00043
00044
00045 index_type F = mesh.size_faces();
00046 std::vector<face_ptr_type> geometry(F,0);
00047
00048 face_iterator f = mesh.face_begin();
00049 face_iterator f_end = mesh.face_end();
00050
00051 for(index_type i=0; f!=f_end; ++f,++i)
00052 {
00053 geometry[i] = &(*f);
00054
00055 if(valency(*f)!=3)
00056 throw std::logic_error("Only triangle faces are supported");
00057
00058 face_vertex_circulator v(*f);
00059 f->m_v0 = &(v->m_coord);
00060 f->m_n0 = &(v->m_normal);
00061 ++v;
00062 f->m_v1 = &(v->m_coord);
00063 f->m_n1 = &(v->m_normal);
00064 ++v;
00065 f->m_v2 = &(v->m_coord);
00066 f->m_n2 = &(v->m_normal);
00067 }
00068 tree.clear();
00069 constructor_type constructor;
00070 constructor.set_degree( degree );
00071 constructor.run(geometry.begin(),geometry.end(),tree);
00072 }
00073
00074 }
00075
00076 }
00077
00078
00079 #endif