OpenMesh
MidpointT.hh
1#pragma once
2
3#include <OpenMesh/Core/Mesh/BaseKernel.hh>
5#include <OpenMesh/Core/Utils/PropertyManager.hh>
6
7#include <algorithm>
8
9namespace OpenMesh {
10namespace Subdivider {
11namespace Uniform {
12
26template<typename MeshType, typename RealType = double>
27class MidpointT : public SubdividerT<MeshType, RealType>
28{
29public:
30 typedef RealType real_t;
31 typedef MeshType mesh_t;
33
34 // Inherited constructors
35 MidpointT() : parent_t() {}
36 MidpointT(mesh_t& _m) : parent_t(_m) {}
37
38 const char* name() const { return "midpoint"; }
39
40protected: // SubdividerT interface
41 bool prepare(mesh_t& _m)
42 {
43 return true;
44 }
45
48 bool subdivide(mesh_t& _m, size_t _n, const bool _update_points = true)
49 {
50 _m.request_halfedge_status();
51 _m.request_edge_status();
52 _m.request_vertex_status();
53 _m.request_face_status();
54 PropertyManager<EPropHandleT<typename mesh_t::VertexHandle>> edge_midpoint(_m, "edge_midpoint");
55 PropertyManager<VPropHandleT<bool>> is_original_vertex(_m, "is_original_vertex");
56
57 for (size_t iteration = 0; iteration < _n; ++iteration) {
58 is_original_vertex.set_range(_m.vertices_begin(), _m.vertices_end(), true);
59 // Create vertices on edge midpoints
60 for (auto eh : _m.edges()) {
61 VertexHandle new_vh = _m.new_vertex(_m.calc_edge_midpoint(eh));
62 edge_midpoint[eh] = new_vh;
63 is_original_vertex[new_vh] = false;
64 }
65 // Create new faces from original faces
66 for (auto fh : _m.faces()) {
67 std::vector<typename mesh_t::VertexHandle> new_corners;
68 for (auto eh : _m.fe_range(fh))
69 new_corners.push_back(edge_midpoint[eh]);
70 _m.add_face(new_corners);
71 }
72 // Create new faces from original vertices
73 for (auto vh : _m.vertices()) {
74 if (is_original_vertex[vh]) {
75 if (!_m.is_boundary(vh)) {
76 std::vector<typename mesh_t::VertexHandle> new_corners;
77 for (auto eh : _m.ve_range(vh))
78 new_corners.push_back(edge_midpoint[eh]);
79 std::reverse(new_corners.begin(), new_corners.end());
80 _m.add_face(new_corners);
81 }
82 }
83 }
84 for (auto vh : _m.vertices())
85 if (is_original_vertex[vh])
86 _m.delete_vertex(vh);
87 _m.garbage_collection();
88 }
89 _m.release_face_status();
90 _m.release_vertex_status();
91 _m.release_edge_status();
92 _m.release_halfedge_status();
93 return true;
94 }
95
96 bool cleanup(mesh_t& _m)
97 {
98 return true;
99 }
100};
101
102} // namespace Uniform
103} // namespace Subdivider
104} // namespace OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Handle for a vertex entity.
Definition: Handles.hh:121
This class is intended to manage the lifecycle of properties.
Definition: PropertyManager.hh:76
void set_range(HandleTypeIterator begin, HandleTypeIterator end, const PROP_VALUE &value)
Conveniently set the property for an entire range of values.
Definition: PropertyManager.hh:519
Midpoint subdivision algorithm.
Definition: MidpointT.hh:28
bool cleanup(mesh_t &_m)
Cleanup mesh after usage, e.g. remove added properties.
Definition: MidpointT.hh:96
bool subdivide(mesh_t &_m, size_t _n, const bool _update_points=true)
Performs one step of Midpoint subdivision.
Definition: MidpointT.hh:48
bool prepare(mesh_t &_m)
Prepare mesh, e.g.
Definition: MidpointT.hh:41
const char * name() const
Return name of subdivision algorithm.
Definition: MidpointT.hh:38
Abstract base class for uniform subdivision algorithms.
Definition: SubdividerT.hh:89

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .