00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_SUBDIVIDE_H 00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_SUBDIVIDE_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 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 00066 template<typename mesh_type> 00067 bool face_subdivide(PolyMeshFace<mesh_type> & f) 00068 { 00069 typedef typename mesh_type::face_vertex_circulator face_vertex_circulator; 00070 typedef typename mesh_type::vertex_handle vertex_handle; 00071 typedef typename mesh_type::math_types math_types; 00072 typedef typename math_types::vector3_type vector3_type; 00073 00074 mesh_type * owner = f.get_owner(); 00075 if(owner==0) 00076 { 00077 assert(!"face_subdivide(): No mesh owner!"); 00078 return false; 00079 } 00080 int i,j; 00081 int n = valency(f); 00082 std::vector<vertex_handle> boundary(n); 00083 face_vertex_circulator v(f); 00084 for(i=0;i<n;++v,++i) 00085 boundary[i] = v->get_handle(); 00086 vector3_type center(0,0,0); 00087 mesh::compute_face_center(f,center); 00088 vertex_handle k = owner->add_vertex(center); 00089 owner->remove_face(f.get_handle()); 00090 for(i=0,j=1;i<n;++i,j=(j+1)%n) 00091 { 00092 owner->add_face( boundary[i],boundary[j],k); 00093 } 00094 return true; 00095 } 00096 00097 } // namespace polymesh 00098 } // namespace OpenTissue 00099 00100 //OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_FACE_SUBDIVIDE_H 00101 #endif