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