3 #include <OpenMesh/Core/Mesh/BaseKernel.hh> 5 #include <OpenMesh/Core/Utils/PropertyManager.hh> 10 namespace Subdivider {
26 template<
typename MeshType,
typename RealType =
double>
30 typedef RealType real_t;
31 typedef MeshType mesh_t;
38 const char*
name()
const {
return "midpoint"; }
48 bool subdivide(mesh_t& _m,
size_t _n,
const bool _update_points =
true)
50 _m.request_halfedge_status();
51 _m.request_edge_status();
52 _m.request_vertex_status();
53 _m.request_face_status();
57 for (
size_t iteration = 0; iteration < _n; ++iteration) {
58 is_original_vertex.
set_range(_m.vertices_begin(), _m.vertices_end(),
true);
60 for (
typename mesh_t::EdgeIter it = _m.edges_begin(), end = _m.edges_end(); it != end; ++it) {
62 VertexHandle new_vh = _m.new_vertex(_m.calc_edge_midpoint(eh));
63 edge_midpoint[eh] = new_vh;
64 is_original_vertex[new_vh] =
false;
67 for (
typename mesh_t::FaceIter it = _m.faces_begin(), end = _m.faces_end(); it != end; ++it) {
69 std::vector<typename mesh_t::VertexHandle> new_corners;
70 for (
typename mesh_t::FaceEdgeIter it = _m.fe_begin(fh), end = _m.fe_end(fh); it != end; ++it) {
72 new_corners.push_back(edge_midpoint[eh]);
74 _m.add_face(new_corners);
77 for (
typename mesh_t::VertexIter it = _m.vertices_begin(), end = _m.vertices_end(); it != end; ++it) {
79 if (is_original_vertex[vh]) {
80 if (!_m.is_boundary(vh)) {
81 std::vector<typename mesh_t::VertexHandle> new_corners;
82 for (
typename mesh_t::VertexEdgeIter it = _m.ve_begin(vh), end = _m.ve_end(vh); it != end; ++it) {
84 new_corners.push_back(edge_midpoint[eh]);
86 std::reverse(new_corners.begin(), new_corners.end());
87 _m.add_face(new_corners);
91 for (
typename mesh_t::VertexIter it = _m.vertices_begin(), end = _m.vertices_end(); it != end; ++it) {
93 if (is_original_vertex[vh]) {
97 _m.garbage_collection();
99 _m.release_face_status();
100 _m.release_vertex_status();
101 _m.release_edge_status();
102 _m.release_halfedge_status();
bool subdivide(mesh_t &_m, size_t _n, const bool _update_points=true)
Handle for a vertex entity.
bool prepare(mesh_t &_m)
Prepare mesh, e.g. add properties.
void set_range(HandleTypeIterator begin, HandleTypeIterator end, const PROP_VALUE &value)
Handle for a face entity.
Handle for a edge entity.
const char * name() const
Return name of subdivision algorithm.
bool cleanup(mesh_t &_m)
Cleanup mesh after usage, e.g. remove added properties.