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;
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;
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 cleanup(mesh_t &_m)
Cleanup mesh after usage, e.g. remove added properties.
Definition: MidpointT.hh:106
bool prepare(mesh_t &_m)
Prepare mesh, e.g. add properties.
Definition: MidpointT.hh:41
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
Definition: PolyMeshT.hh:169
This class is intended to manage the lifecycle of properties.
Definition: PropertyManager.hh:77
Handle for a vertex entity.
Definition: Handles.hh:120
const char * name() const
Return name of subdivision algorithm.
Definition: MidpointT.hh:38
Handle for a edge entity.
Definition: Handles.hh:134
void set_range(HandleTypeIterator begin, HandleTypeIterator end, const PROP_VALUE &value)
Conveniently set the property for an entire range of values.
Definition: PropertyManager.hh:390
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Midpoint subdivision algorithm.
Definition: MidpointT.hh:27
Handle for a face entity.
Definition: Handles.hh:141
Abstract base class for uniform subdivision algorithms.
Definition: SubdividerT.hh:88
Kernel::VertexEdgeIter VertexEdgeIter
Circulator.
Definition: PolyMeshT.hh:165
bool subdivide(mesh_t &_m, size_t _n, const bool _update_points=true)
Performs one step of Midpoint subdivision.
Definition: MidpointT.hh:48