Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_EDGE_FLIP_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_EDGE_FLIP_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_edge.h>
00013 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_halfedge.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace polymesh
00018 {
00019
00026 template<typename mesh_type>
00027 bool edge_flip(PolyMeshHalfEdge<mesh_type> & h)
00028 {
00029 typedef typename mesh_type::face_iterator face_iterator;
00030 typedef typename mesh_type::halfedge_iterator halfedge_iterator;
00031 typedef typename mesh_type::edge_iterator edge_iterator;
00032 typedef typename mesh_type::vertex_iterator vertex_iterator;
00033 typedef typename mesh_type::face_handle face_handle;
00034 typedef typename mesh_type::halfedge_handle halfedge_handle;
00035 typedef typename mesh_type::edge_handle edge_handle;
00036 typedef typename mesh_type::vertex_handle vertex_handle;
00037 typedef typename mesh_type::face_traits face_traits;
00038 typedef typename mesh_type::halfedge_traits halfedge_traits;
00039 typedef typename mesh_type::edge_traits edge_traits;
00040 typedef typename mesh_type::vertex_traits vertex_traits;
00041
00042 halfedge_iterator h1 = h.get_twin_iterator();
00043 halfedge_iterator h0 = h1->get_twin_iterator();
00044
00045 edge_iterator e = h1->get_edge_iterator();
00046
00047 face_iterator f0 = h0->get_face_iterator();
00048 face_iterator f1 = h1->get_face_iterator();
00049
00050 vertex_iterator v0 = h0->get_origin_iterator();
00051 vertex_iterator v1 = h1->get_next_iterator()->get_destination_iterator();
00052 vertex_iterator v2 = h0->get_destination_iterator();
00053 vertex_iterator v3 = h0->get_next_iterator()->get_destination_iterator();
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 if(is_boundary(*h0))
00073 {
00074 assert(!"can not flip a boundary edge");
00075 return false;
00076 }
00077 if(valency(*f0)!=3)
00078 {
00079 assert(!"face 0 was not triangular");
00080 return false;
00081 }
00082 if(valency(*f1)!=3)
00083 {
00084 assert(!"face 1 was not triangular");
00085 return false;
00086 }
00087
00088 edge_traits et = static_cast<edge_traits> (*e);
00089 halfedge_traits ht0 = static_cast<halfedge_traits> (*h0);
00090 halfedge_traits ht1 = static_cast<halfedge_traits> (*h1);
00091 face_traits ft0 = static_cast<face_traits> (*f0);
00092 face_traits ft1 = static_cast<face_traits> (*f1);
00093 mesh_type * owner = h0->get_owner();
00094 if(owner==0)
00095 {
00096 assert(!"Could not find owner mesh");
00097 return false;
00098 }
00099
00100 halfedge_handle flipped = owner->find_halfedge_handle(v1->get_handle(),v3->get_handle());
00101 if(!flipped.is_null())
00102 {
00103
00104 return false;
00105 }
00106
00107 if(!owner->remove_face(f0))
00108 {
00109 assert(!"Could not remove face 0");
00110 return false;
00111 }
00112 if(!owner->remove_face(f1))
00113 {
00114 assert(!"Could not remove face 1");
00115 return false;
00116 }
00117
00118 face_handle new_f0 = owner->add_face(v0->get_handle(),v1->get_handle(),v3->get_handle());
00119 if(new_f0.is_null())
00120 {
00121 assert(!"Could not create new face 0");
00122 return false;
00123 }
00124 face_handle new_f1 = owner->add_face(v1->get_handle(),v2->get_handle(),v3->get_handle());
00125 if(new_f1.is_null())
00126 {
00127 assert(!"Could not create new face 1");
00128 return false;
00129 }
00130 flipped = owner->find_halfedge_handle(v1->get_handle(),v3->get_handle());
00131 if(flipped.is_null())
00132 {
00133 assert(!"Could not find new flipped edge");
00134 return false;
00135 }
00136
00137
00138 h0 = owner->get_halfedge_iterator(flipped);
00139 h1 = h0->get_twin_iterator();
00140 e = h0->get_edge_iterator();
00141 f0 = h0->get_face_iterator();
00142 f1 = h1->get_face_iterator();
00143
00144 edge_traits * new_et = static_cast<edge_traits*>(& (*e));
00145 halfedge_traits * new_ht0 = static_cast<halfedge_traits*>(& (*h0));
00146 halfedge_traits * new_ht1 = static_cast<halfedge_traits*>(& (*h1));
00147 face_traits * new_ft0 = static_cast<face_traits*>(& (*f0));
00148 face_traits * new_ft1 = static_cast<face_traits*>(& (*f1));
00149
00150 *new_et = et;
00151 *new_ht0 = ht0;
00152 *new_ht1 = ht1;
00153 *new_ft0 = ft0;
00154 *new_ft1 = ft1;
00155
00156 return true;
00157 }
00158
00159 template<typename mesh_type>
00160 bool edge_flip(PolyMeshEdge<mesh_type> const & e)
00161 {
00162 typename mesh_type::halfedge_iterator h = e.get_halfedge0_iterator();
00163 return edge_flip(*h);
00164 }
00165
00166 }
00167 }
00168
00169
00170 #endif