Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_ADD2MESH_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_ADD2MESH_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 {
00019
00020
00030 template<typename mesh_type>
00031 bool add2mesh(
00032 mesh_type const & A
00033 , mesh_type & C
00034 )
00035 {
00036 typedef typename mesh_type::vertex_handle vertex_handle;
00037 typedef typename mesh_type::face_handle face_handle;
00038 typedef typename mesh_type::vertex_iterator vertex_iterator;
00039 typedef typename mesh_type::face_iterator face_iterator;
00040 typedef typename mesh_type::const_vertex_iterator const_vertex_iterator;
00041 typedef typename mesh_type::const_face_iterator const_face_iterator;
00042 typedef typename mesh_type::const_face_vertex_circulator const_face_vertex_circulator;
00043 typedef typename mesh_type::vertex_traits vertex_traits;
00044 typedef typename mesh_type::face_traits face_traits;
00045 typedef typename mesh_type::index_type index_type;
00046
00047 typedef std::map<index_type,vertex_handle> vh_lut_type;
00048
00049 vh_lut_type vh_lut;
00050
00051 const_vertex_iterator vend = A.vertex_end();
00052 const_vertex_iterator v = A.vertex_begin();
00053 for(;v!=vend;++v)
00054 {
00055 vertex_handle h = C.add_vertex();
00056 assert(!h.is_null() || !"add2mesh(): Internal error, Could not create vertex in output mesh");
00057 vh_lut[v->get_handle().get_idx()] = h;
00058 vertex_iterator V = C.get_vertex_iterator(h);
00059
00060 vertex_traits * Vt = static_cast<vertex_traits*>(&(*V));
00061 vertex_traits const * vt = static_cast<vertex_traits const *>(&(*v));
00062 (*Vt) = (*vt);
00063 }
00064 const_face_iterator fend = A.face_end();
00065 const_face_iterator f = A.face_begin();
00066 for(;f!=fend;++f)
00067 {
00068 std::list<vertex_handle> handles;
00069 const_face_vertex_circulator vc(*f),vcend;
00070 for(;vc!=vcend;++vc)
00071 {
00072 vertex_handle h = vh_lut[vc->get_handle().get_idx()];
00073 assert(!h.is_null() || !"add2mesh(): Internal error, could not find vertices in output mesh");
00074 handles.push_back(h);
00075 }
00076 face_handle h = C.add_face(handles.begin(),handles.end());
00077 assert(!h.is_null() || !"add2mesh(): Internal error, Could not create face in output mesh");
00078 face_iterator F = C.get_face_iterator(h);
00079
00080 face_traits * Ft = static_cast<face_traits*>(&(*F));
00081 face_traits const * ft = static_cast<face_traits const *>(&(*f));
00082 (*Ft) = (*ft);
00083 }
00084 return true;
00085 }
00086
00087 }
00088 }
00089
00090
00091 #endif