Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_CONVERT_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_CONVERT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <map>
00013 #include <list>
00014
00015 namespace OpenTissue
00016 {
00017 namespace mesh
00018 {
00047 template<typename mesh_type_in, typename mesh_type_out>
00048 bool convert( mesh_type_in const & in , mesh_type_out & out )
00049 {
00050 typedef typename mesh_type_in::const_vertex_iterator in_vertex_iterator;
00051 typedef typename mesh_type_in::const_face_iterator in_face_iterator;
00052 typedef typename mesh_type_in::const_face_vertex_circulator in_face_vertex_circulator;
00053 typedef typename mesh_type_in::vertex_traits in_vertex_traits;
00054 typedef typename mesh_type_in::face_traits in_face_traits;
00055 typedef typename mesh_type_in::index_type in_index_type;
00056
00057 typedef typename mesh_type_out::vertex_iterator out_vertex_iterator;
00058 typedef typename mesh_type_out::vertex_handle out_vertex_handle;
00059 typedef typename mesh_type_out::vertex_traits out_vertex_traits;
00060 typedef typename mesh_type_out::face_traits out_face_traits;
00061 typedef typename mesh_type_out::face_iterator out_face_iterator;
00062 typedef typename mesh_type_out::face_handle out_face_handle;
00063
00064 typedef std::map<in_index_type,out_vertex_handle> vh_lut_type;
00065 vh_lut_type vh_lut;
00066
00067 out.clear();
00068
00069 in_vertex_iterator vend = in.vertex_end();
00070 in_vertex_iterator v = in.vertex_begin();
00071 for(;v!=vend;++v)
00072 {
00073 out_vertex_handle h = out.add_vertex();
00074 assert(!h.is_null() || !"convert(): Internal error, Could not create vertex in output mesh");
00075 vh_lut[v->get_handle().get_idx()] = h;
00076 out_vertex_iterator o = out.get_vertex_iterator(h);
00077
00078 out_vertex_traits * ot = static_cast<out_vertex_traits*>(&(*o));
00079 in_vertex_traits const * it = static_cast< in_vertex_traits const *>(&(*v));
00080 (*ot) = (*it);
00081 }
00082
00083 in_face_iterator fend = in.face_end();
00084 in_face_iterator f = in.face_begin();
00085 for(;f!=fend;++f)
00086 {
00087 std::list<out_vertex_handle> handles;
00088 in_face_vertex_circulator vc(*f),vcend;
00089 for(;vc!=vcend;++vc)
00090 {
00091 out_vertex_handle h = vh_lut[vc->get_handle().get_idx()];
00092 assert(!h.is_null() || !"convert(): Internal error, could not find vertes in output mesh");
00093 handles.push_back(h);
00094 }
00095 out_face_handle h = out.add_face(handles.begin(),handles.end());
00096 assert(!h.is_null() || !"convert(): Internal error, Could not create face in output mesh");
00097 out_face_iterator o = out.get_face_iterator(h);
00098
00099 out_face_traits * ot = static_cast<out_face_traits*>(&(*o));
00100 in_face_traits const * it = static_cast< in_face_traits const *>(&(*f));
00101 (*ot) = (*it);
00102 }
00103 return true;
00104 }
00105
00106 }
00107 }
00108
00109
00110 #endif