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 (
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;
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);
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);
84 for (
auto vh : _m.vertices())
85 if (is_original_vertex[vh])
87 _m.garbage_collection();
89 _m.release_face_status();
90 _m.release_vertex_status();
91 _m.release_edge_status();
92 _m.release_halfedge_status();
This class is intended to manage the lifecycle of properties.
Definition: PropertyManager.hh:80
bool subdivide(mesh_t &_m, size_t _n, const bool _update_points=true)
Performs one step of Midpoint subdivision.
Definition: MidpointT.hh:48
void set_range(HandleTypeIterator begin, HandleTypeIterator end, const PROP_VALUE &value)
Conveniently set the property for an entire range of values.
Definition: PropertyManager.hh:517
Handle for a vertex entity.
Definition: Handles.hh:120
bool prepare(mesh_t &_m)
Prepare mesh, e.g. add properties.
Definition: MidpointT.hh:41
Midpoint subdivision algorithm.
Definition: MidpointT.hh:27
Abstract base class for uniform subdivision algorithms.
Definition: SubdividerT.hh:88
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
const char * name() const
Return name of subdivision algorithm.
Definition: MidpointT.hh:38
bool cleanup(mesh_t &_m)
Cleanup mesh after usage, e.g. remove added properties.
Definition: MidpointT.hh:96