port MidpointT back to C++98 😢
This commit is contained in:
@@ -14,55 +14,63 @@ template<typename MeshType, typename RealType = double>
|
|||||||
class MidpointT : public SubdividerT<MeshType, RealType>
|
class MidpointT : public SubdividerT<MeshType, RealType>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using real_t = RealType;
|
typedef RealType real_t;
|
||||||
using mesh_t = MeshType;
|
typedef MeshType mesh_t;
|
||||||
using parent_t = SubdividerT<MeshType, RealType>;
|
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"; }
|
const char* name() const { return "midpoint"; }
|
||||||
|
|
||||||
protected: // SubdividerT interface
|
protected: // SubdividerT interface
|
||||||
bool prepare(mesh_t& _m) override
|
bool prepare(mesh_t& _m)
|
||||||
{
|
{
|
||||||
return true;
|
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");
|
PropertyManager<EPropHandleT<typename mesh_t::VertexHandle>, mesh_t> edge_midpoint(_m, "edge_midpoint");
|
||||||
auto is_original_vertex = makePropertyManagerFromNew<VPropHandleT<bool>>(_m, "is_original_vertex");
|
PropertyManager<VPropHandleT<bool>, mesh_t> is_original_vertex(_m, "is_original_vertex");
|
||||||
|
|
||||||
for (size_t iteration = 0; iteration < _n; ++iteration) {
|
for (size_t iteration = 0; iteration < _n; ++iteration) {
|
||||||
is_original_vertex.set_range(_m.vertices_begin(), _m.vertices_end(), true);
|
is_original_vertex.set_range(_m.vertices_begin(), _m.vertices_end(), true);
|
||||||
// Create vertices on edge midpoints
|
// Create vertices on edge midpoints
|
||||||
for (const auto& eh : _m.edges()) {
|
for (typename mesh_t::EdgeIter it = _m.edges_begin(), end = _m.edges_end(); it != end; ++it) {
|
||||||
auto new_vh = _m.new_vertex(_m.calc_edge_midpoint(eh));
|
EdgeHandle eh = *it;
|
||||||
|
VertexHandle new_vh = _m.new_vertex(_m.calc_edge_midpoint(eh));
|
||||||
edge_midpoint[eh] = new_vh;
|
edge_midpoint[eh] = new_vh;
|
||||||
is_original_vertex[new_vh] = false;
|
is_original_vertex[new_vh] = false;
|
||||||
}
|
}
|
||||||
// Create new faces from original faces
|
// 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;
|
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]);
|
new_corners.push_back(edge_midpoint[eh]);
|
||||||
}
|
}
|
||||||
_m.add_face(new_corners);
|
_m.add_face(new_corners);
|
||||||
}
|
}
|
||||||
// Create new faces from original vertices
|
// 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 (is_original_vertex[vh]) {
|
||||||
if (!_m.is_boundary(vh)) {
|
if (!_m.is_boundary(vh)) {
|
||||||
std::vector<typename mesh_t::VertexHandle> new_corners;
|
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]);
|
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);
|
_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]) {
|
if (is_original_vertex[vh]) {
|
||||||
_m.delete_vertex(vh);
|
_m.delete_vertex(vh);
|
||||||
}
|
}
|
||||||
@@ -71,7 +79,7 @@ protected: // SubdividerT interface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cleanup(mesh_t& _m) override
|
bool cleanup(mesh_t& _m)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user