Commit 3d1bf65c authored by Janis Born's avatar Janis Born

port MidpointT back to C++98 馃槩

parent 50e3887a
Pipeline #4119 failed with stage
in 40 minutes and 39 seconds
......@@ -14,55 +14,63 @@ template<typename MeshType, typename RealType = double>
class MidpointT : public SubdividerT<MeshType, RealType>
{
public:
using real_t = RealType;
using mesh_t = MeshType;
using parent_t = SubdividerT<MeshType, RealType>;
typedef RealType real_t;
typedef MeshType mesh_t;
typedef SubdividerT<MeshType, RealType> parent_t;
using parent_t::parent_t;
// Inherited constructors
MidpointT() : parent_t() {}
MidpointT(mesh_t& _m) : parent_t(_m) {}
const char* name() const { return "midpoint"; }
protected: // SubdividerT interface
bool prepare(mesh_t& _m) override
bool prepare(mesh_t& _m)
{
return true;
}
bool subdivide(mesh_t& _m, size_t _n, const bool _update_points = true) override
bool subdivide(mesh_t& _m, size_t _n, const bool _update_points = true)
{
auto edge_midpoint = makePropertyManagerFromNew<EPropHandleT<typename mesh_t::VertexHandle>>(_m, "edge_midpoint");
auto is_original_vertex = makePropertyManagerFromNew<VPropHandleT<bool>>(_m, "is_original_vertex");
PropertyManager<EPropHandleT<typename mesh_t::VertexHandle>, mesh_t> edge_midpoint(_m, "edge_midpoint");
PropertyManager<VPropHandleT<bool>, mesh_t> is_original_vertex(_m, "is_original_vertex");
for (size_t iteration = 0; iteration < _n; ++iteration) {
is_original_vertex.set_range(_m.vertices_begin(), _m.vertices_end(), true);
// Create vertices on edge midpoints
for (const auto& eh : _m.edges()) {
auto new_vh = _m.new_vertex(_m.calc_edge_midpoint(eh));
for (typename mesh_t::EdgeIter it = _m.edges_begin(), end = _m.edges_end(); it != end; ++it) {
EdgeHandle eh = *it;
VertexHandle new_vh = _m.new_vertex(_m.calc_edge_midpoint(eh));
edge_midpoint[eh] = new_vh;
is_original_vertex[new_vh] = false;
}
// Create new faces from original faces
for (const auto& fh : _m.faces()) {
for (typename mesh_t::FaceIter it = _m.faces_begin(), end = _m.faces_end(); it != end; ++it) {
FaceHandle fh = *it;
std::vector<typename mesh_t::VertexHandle> new_corners;
for (const auto& eh : _m.fe_range(fh)) {
for (typename mesh_t::FaceEdgeIter it = _m.fe_begin(fh), end = _m.fe_end(fh); it != end; ++it) {
EdgeHandle eh = *it;
new_corners.push_back(edge_midpoint[eh]);
}
_m.add_face(new_corners);
}
// Create new faces from original vertices
for (const auto& vh : _m.vertices()) {
for (typename mesh_t::VertexIter it = _m.vertices_begin(), end = _m.vertices_end(); it != end; ++it) {
VertexHandle vh = *it;
if (is_original_vertex[vh]) {
if (!_m.is_boundary(vh)) {
std::vector<typename mesh_t::VertexHandle> new_corners;
for (const auto& eh : _m.ve_range(vh)) {
for (typename mesh_t::VertexEdgeIter it = _m.ve_begin(vh), end = _m.ve_end(vh); it != end; ++it) {
EdgeHandle eh = *it;
new_corners.push_back(edge_midpoint[eh]);
}
std::reverse(begin(new_corners), end(new_corners));
std::reverse(new_corners.begin(), new_corners.end());
_m.add_face(new_corners);
}
}
}
for (const auto& vh : _m.vertices()) {
for (typename mesh_t::VertexIter it = _m.vertices_begin(), end = _m.vertices_end(); it != end; ++it) {
VertexHandle vh = *it;
if (is_original_vertex[vh]) {
_m.delete_vertex(vh);
}
......@@ -71,7 +79,7 @@ protected: // SubdividerT interface
return true;
}
bool cleanup(mesh_t& _m) override
bool cleanup(mesh_t& _m)
{
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment