Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_COLLAPSE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_COLLAPSE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_face.h>
00013 #include <OpenTissue/core/containers/mesh/common/util/mesh_compute_face_center.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace polymesh
00018 {
00019
00032 template<typename mesh_type>
00033 bool face_collapse(PolyMeshFace<mesh_type> & f)
00034 {
00035 typedef typename mesh_type::face_halfedge_circulator face_halfedge_circulator;
00036 typedef typename mesh_type::halfedge_iterator halfedge_iterator;
00037 typedef typename mesh_type::halfedge_type halfedge_type;
00038 typedef typename mesh_type::vertex_handle vertex_handle;
00039 typedef typename mesh_type::face_handle face_handle;
00040
00041 typedef typename mesh_type::math_types math_types;
00042 typedef typename math_types::vector3_type vector3_type;
00043
00044 mesh_type * owner = f.get_owner();
00045 if(owner==0)
00046 {
00047 assert(!"face_collapse(): No mesh owner!");
00048 return false;
00049 }
00050 int i;
00051 int n = valency(f);
00052
00053 typedef std::vector<vertex_handle> boundary_container;
00054
00055 vector3_type center(0,0,0);
00056 mesh::compute_face_center(f,center);
00057 vertex_handle collapsed = owner->add_vertex(center);
00058
00059 std::list<face_handle> neighbors;
00060 std::vector<boundary_container> boundaries(n);
00061 {
00062 face_halfedge_circulator cur(f);
00063 for(i=0; i<n; ++i,++cur)
00064 {
00065 halfedge_iterator twin = cur->get_twin_iterator();
00066 halfedge_iterator first = twin->get_next_iterator();
00067 halfedge_iterator last = twin->get_prev_iterator();
00068 if(!twin->get_face_handle().is_null())
00069 {
00070 neighbors.push_back( twin->get_face_handle() );
00071 halfedge_type * loop = &(*first);
00072 halfedge_type * stop = &(*last);
00073 do
00074 {
00075 boundaries[i].push_back( loop->get_destination_handle() );
00076 loop = &(*(loop->get_next_iterator()));
00077 }while(loop != stop );
00078 boundaries[i].push_back( collapsed );
00079 }
00080 }
00081 }
00082
00083 for(typename std::list<face_handle>::iterator fi = neighbors.begin(); fi != neighbors.end(); ++fi)
00084 owner->remove_face( *fi );
00085
00086 for(i=0;i<n;++i)
00087 {
00088 if(boundaries[i].size()>2)
00089 owner->add_face(boundaries[i].begin(),boundaries[i].end());
00090 }
00091
00092 return true;
00093 }
00094
00095 }
00096 }
00097
00098
00099 #endif