Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_MERGE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_MERGE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/mesh/polymesh/util/polymesh_is_shared_edge.h>
00013 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_face.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace polymesh
00018 {
00019
00030 template<typename mesh_type>
00031 bool face_merge(PolyMeshFace<mesh_type> & f0,PolyMeshFace<mesh_type> & f1)
00032 {
00033 typedef typename mesh_type::face_halfedge_circulator face_halfedge_circulator;
00034 typedef typename mesh_type::vertex_type vertex_type;
00035 typedef typename mesh_type::vertex_handle vertex_handle;
00036 typedef typename mesh_type::face_handle face_handle;
00037 typedef typename mesh_type::halfedge_type halfedge_type;
00038
00039 mesh_type * owner = f0.get_owner();
00040 if(owner==0)
00041 {
00042 assert(!"face_merge(): No mesh owner!");
00043 return false;
00044 }
00045
00046 if(!is_neighbor(f0,f1))
00047 {
00048 assert(!"face_merge(): faces were not neighbors");
00049 return false;
00050 }
00051
00052 face_halfedge_circulator h(f0),hend;
00053
00054 bool all_shared = true;
00055 for(;h!=hend;++h)
00056 {
00057 if(!is_shared_edge(*h,f0,f1))
00058 {
00059 all_shared = false;
00060 break;
00061 }
00062 }
00063 if(all_shared)
00064 {
00065 assert(!"face_merge(): faces shares all edges");
00066 return true;
00067 }
00068
00069 while( !is_shared_edge(*h,f0,f1) ) ++h;
00070
00071 while( is_shared_edge(*h,f0,f1) ) --h;
00072
00073
00074 halfedge_type * before = &(*h);
00075 ++h;
00076
00077
00078
00079 std::list<vertex_type * > shared_vertices;
00080 shared_vertices.push_back ( &(*(h->get_origin_iterator())) );
00081 while( is_shared_edge(*h,f0,f1) )
00082 {
00083 shared_vertices.push_back ( &(*(h->get_destination_iterator())) );
00084 ++h;
00085 }
00086
00087
00088 while( h->get_handle() != before->get_handle() )
00089 {
00090 if( is_shared_edge(*h,f0,f1))
00091 {
00092 assert(!"face_merge(): illegal topology, multiple disjoint shared boundaries");
00093 return false;
00094 }
00095 ++h;
00096 }
00097
00098
00099
00100
00101 owner->remove_face(f0.get_handle());
00102 owner->remove_face(f1.get_handle());
00103
00104
00105 typename std::list<vertex_type * >::iterator v = shared_vertices.begin();
00106 typename std::list<vertex_type * >::iterator end = shared_vertices.end();
00107 for(;v!=end;++v)
00108 if((*v)->get_outgoing_halfedge_handle().is_null())
00109 owner->remove_vertex((*v)->get_handle());
00110
00111 std::list<vertex_handle> handles;
00112 halfedge_type * loop = before;
00113 do
00114 {
00115 handles.push_back(loop->get_destination_handle());
00116 loop = &(*(loop->get_next_iterator()));
00117 }while(loop!=before);
00118
00119 face_handle merged_face = owner->add_face(handles.begin(),handles.end());
00120 if(merged_face.is_null())
00121 {
00122 assert(!"face_merge(): Could create merged face");
00123 return false;
00124 }
00125 return true;
00126 }
00127
00128 }
00129 }
00130
00131
00132 #endif