Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_SPLIT_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_SPLIT_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/polymesh/polymesh_vertex.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace polymesh
00018 {
00019
00031 template<typename mesh_type>
00032 bool face_split(PolyMeshFace<mesh_type> & f,PolyMeshVertex<mesh_type> & v0,PolyMeshVertex<mesh_type> & v1)
00033 {
00034 typedef typename mesh_type::face_halfedge_circulator face_halfedge_circulator;
00035 typedef typename mesh_type::halfedge_type halfedge_type;
00036 typedef typename mesh_type::vertex_handle vertex_handle;
00037 typedef typename mesh_type::face_handle face_handle;
00038
00039 mesh_type * owner = f.get_owner();
00040 if(owner==0)
00041 {
00042 assert(!"face_split(): No mesh owner!");
00043 return false;
00044 }
00045 if(valency(f)==3)
00046 {
00047 assert(!"face_split(): face was a triangle");
00048 return false;
00049 }
00050 if(v0.get_handle() == v1.get_handle())
00051 {
00052 assert(!"face_split(): vertices were identical");
00053 return false;
00054 }
00055
00056 halfedge_type * h0 = 0;
00057 halfedge_type * h1 = 0;
00058 face_halfedge_circulator h(f),hend;
00059
00060 for(;h!=hend;++h)
00061 {
00062 if(h->get_origin_handle() == v0.get_handle())
00063 h0 = &(*h);
00064 if(h->get_origin_handle() == v1.get_handle())
00065 h1 = &(*h);
00066 }
00067 if( ( !h0 || !h1 ) || h1==h0 )
00068 {
00069 assert(!"face_split(): could not detect new face boundaries");
00070 return false;
00071 }
00072
00073 halfedge_type * h0_end = &(*(h1->get_prev_iterator()));
00074 halfedge_type * h1_end = &(*(h0->get_prev_iterator()));
00075
00076
00077 std::list<vertex_handle> handles0;
00078 std::list<vertex_handle> handles1;
00079
00080 halfedge_type * loop = h0;
00081 handles0.push_back(h0->get_origin_handle());
00082 while(loop!=h0_end)
00083 {
00084 handles0.push_back(loop->get_destination_handle());
00085 loop = &(*(loop->get_next_iterator()));
00086 }
00087 handles0.push_back(h0_end->get_destination_handle());
00088
00089
00090 if(handles0.size()<3)
00091 {
00092 assert(!"face_split(): split would result in degenerate face");
00093 return false;
00094 }
00095
00096 loop = h1;
00097 handles1.push_back(h1->get_origin_handle());
00098 while(loop!=h1_end)
00099 {
00100 handles1.push_back(loop->get_destination_handle());
00101 loop = &(*(loop->get_next_iterator()));
00102 }
00103 handles1.push_back(h1_end->get_destination_handle());
00104
00105 if(handles1.size()<3)
00106 {
00107 assert(!"face_split(): split would result in degenerate face");
00108 return false;
00109 }
00110
00111
00112 owner->remove_face(f.get_handle());
00113
00114 face_handle f0 = owner->add_face(handles0.begin(),handles0.end());
00115 if(f0.is_null())
00116 {
00117 assert(!"face_split(): Could create face 0");
00118 return false;
00119 }
00120
00121 face_handle f1 = owner->add_face(handles1.begin(),handles1.end());
00122 if(f1.is_null())
00123 {
00124 assert(!"face_split(): Could create face 1");
00125 return false;
00126 }
00127 return true;
00128 }
00129
00130 }
00131 }
00132
00133
00134 #endif