Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_VERTEX_EXPAND_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_VERTEX_EXPAND_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_vertex.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace polymesh
00017 {
00018
00029 template<typename mesh_type>
00030 bool vertex_expand(PolyMeshVertex<mesh_type> & v)
00031 {
00032 typedef typename mesh_type::vertex_halfedge_circulator vertex_halfedge_circulator;
00033 typedef typename mesh_type::halfedge_type halfedge_type;
00034 typedef typename mesh_type::vertex_handle vertex_handle;
00035 typedef typename mesh_type::face_handle face_handle;
00036
00037 typedef typename mesh_type::math_types math_types;
00038 typedef typename math_types::value_traits value_traits;
00039 typedef typename math_types::vector3_type vector3_type;
00040 typedef typename math_types::real_type real_type;
00041
00042 mesh_type * owner = v.get_owner();
00043 if(owner==0)
00044 {
00045 assert(!"face_collapse(): No mesh owner!");
00046 return false;
00047 }
00048 int i,j;
00049 int n = valency(v);
00050
00051 typedef std::vector<vertex_handle> boundary_container;
00052
00053
00054 boundary_container handles(n);
00055 {
00056 vertex_halfedge_circulator h(v),hend;
00057 for(i=0;h!=hend;++h,++i)
00058 {
00059 vector3_type midpoint = ( h->get_origin_iterator()->m_coord + h->get_destination_iterator()->m_coord )*.5;
00060 handles[i] = owner->add_vertex(midpoint);
00061 }
00062 }
00063
00064 std::list<face_handle> neighbors;
00065 std::vector<boundary_container> boundaries(n);
00066 {
00067 vertex_halfedge_circulator cur(v);
00068 vertex_halfedge_circulator next(v);++next;
00069 for(i=0,j=1; i<n; ++i,j=(j+1)%n,++cur,++next)
00070 {
00071 if(!cur->get_face_handle().is_null())
00072 {
00073 neighbors.push_back( cur->get_face_handle() );
00074 boundaries[i].push_back( handles[j] );
00075 halfedge_type * loop = &(*next);
00076 halfedge_type * stop = &(*cur->get_twin_iterator());
00077 do
00078 {
00079 boundaries[i].push_back( loop->get_destination_handle() );
00080 loop = &(*(loop->get_next_iterator()));
00081 }while(loop != stop );
00082 boundaries[i].push_back( handles[i] );
00083 }
00084 }
00085 }
00086
00087 {
00088 for(typename std::list<face_handle>::iterator f = neighbors.begin();f!=neighbors.end();++f)
00089 owner->remove_face( *f );
00090 owner->remove_vertex( v.get_handle() );
00091 }
00092
00093 for(i=0;i<n;++i)
00094 {
00095 if(!boundaries[i].empty())
00096 owner->add_face(boundaries[i].begin(),boundaries[i].end());
00097 }
00098
00099 owner->add_face(handles.rbegin(),handles.rend());
00100
00101 return true;
00102 }
00103
00104 }
00105 }
00106
00107
00108 #endif