Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_SUBDIVIDE2_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_SUBDIVIDE2_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
00014 #include <map>
00015
00016 namespace OpenTissue
00017 {
00018 namespace polymesh
00019 {
00020
00063 template<typename mesh_type>
00064 bool face_subdivide2(PolyMeshFace<mesh_type> & f)
00065 {
00066 typedef typename mesh_type::face_vertex_circulator face_vertex_circulator;
00067 typedef typename mesh_type::face_iterator face_iterator;
00068 typedef typename mesh_type::vertex_handle vertex_handle;
00069
00070 typedef typename mesh_type::math_types math_types;
00071 typedef typename math_types::vector3_type vector3_type;
00072
00073 mesh_type * owner = f.get_owner();
00074 if(owner==0)
00075 {
00076 assert(!"face_subdivide2(): No mesh owner!");
00077 return false;
00078 }
00079 typedef typename mesh_type::face_halfedge_circulator face_halfedge_circulator;
00080
00081
00082 if(is_boundary(f)) return false;
00083 face_halfedge_circulator h0(f);
00084 face_halfedge_circulator h1(f);++h1;
00085 face_halfedge_circulator h2(f);--h2;
00086 if(is_boundary(*h0)) return false;
00087 if(is_boundary(*h1)) return false;
00088 if(is_boundary(*h2)) return false;
00089 face_iterator n0 = h0->get_twin_iterator()->get_face_iterator();
00090 face_iterator n1 = h1->get_twin_iterator()->get_face_iterator();
00091 face_iterator n2 = h2->get_twin_iterator()->get_face_iterator();
00092
00093 vertex_handle v0 = h0->get_origin_handle();
00094 vertex_handle v1 = h0->get_twin_iterator()->get_next_iterator()->get_destination_handle();
00095 vertex_handle v2 = h1->get_origin_handle();
00096 vertex_handle v3 = h1->get_twin_iterator()->get_next_iterator()->get_destination_handle();
00097 vertex_handle v4 = h2->get_origin_handle();
00098 vertex_handle v5 = h2->get_twin_iterator()->get_next_iterator()->get_destination_handle();
00099
00100 vector3_type p0 = h0->get_origin_iterator()->m_coord;
00101 vector3_type p1 = h1->get_origin_iterator()->m_coord;
00102 vector3_type p2 = h2->get_origin_iterator()->m_coord;
00103
00104 owner->remove_face( f.get_handle());
00105 owner->remove_face(n0->get_handle());
00106 owner->remove_face(n1->get_handle());
00107 owner->remove_face(n2->get_handle());
00108 vertex_handle v6 = owner->add_vertex((p0+p1)*.5);
00109 vertex_handle v7 = owner->add_vertex((p1+p2)*.5);
00110 vertex_handle v8 = owner->add_vertex((p2+p0)*.5);
00111
00112 owner->add_face( v0, v1 , v6);
00113 owner->add_face( v1, v2 , v6);
00114 owner->add_face( v2, v3 , v7);
00115 owner->add_face( v3, v4 , v7);
00116 owner->add_face( v4, v5 , v8);
00117 owner->add_face( v5, v0 , v8);
00118 owner->add_face( v0, v6 , v8);
00119 owner->add_face( v6, v2 , v7);
00120 owner->add_face( v7, v4 , v8);
00121 owner->add_face( v6, v7 , v8);
00122
00123 return true;
00124 }
00125
00126 }
00127 }
00128
00129
00130 #endif