use range based for loops in subdivision algorithms in order to skip deleted elements

This commit is contained in:
Max Lyon
2020-02-03 09:51:49 +01:00
parent 2cb82ec9b9
commit 9ae08da593
5 changed files with 58 additions and 92 deletions

View File

@@ -100,47 +100,38 @@ CatmullClarkT<MeshType,RealType>::subdivide( MeshType& _m , size_t _n , const bo
{ {
// Compute face centroid // Compute face centroid
FaceIter f_itr = _m.faces_begin(); for ( auto fh : _m.faces())
FaceIter f_end = _m.faces_end();
for ( ; f_itr != f_end; ++f_itr)
{ {
Point centroid; Point centroid;
_m.calc_face_centroid( *f_itr, centroid); _m.calc_face_centroid( fh, centroid);
_m.property( fp_pos_, *f_itr ) = centroid; _m.property( fp_pos_, fh ) = centroid;
} }
// Compute position for new (edge-) vertices and store them in the edge property // Compute position for new (edge-) vertices and store them in the edge property
EdgeIter e_itr = _m.edges_begin(); for ( auto eh : _m.edges())
EdgeIter e_end = _m.edges_end(); compute_midpoint( _m, eh, _update_points );
for ( ; e_itr != e_end; ++e_itr)
compute_midpoint( _m, *e_itr, _update_points );
// position updates activated? // position updates activated?
if(_update_points) if(_update_points)
{ {
// compute new positions for old vertices // compute new positions for old vertices
VertexIter v_itr = _m.vertices_begin(); for ( auto vh : _m.vertices())
VertexIter v_end = _m.vertices_end(); update_vertex( _m, vh );
for ( ; v_itr != v_end; ++v_itr)
update_vertex( _m, *v_itr );
// Commit changes in geometry // Commit changes in geometry
v_itr = _m.vertices_begin(); for ( auto vh : _m.vertices())
for ( ; v_itr != v_end; ++v_itr) _m.set_point(vh, _m.property( vp_pos_, vh ) );
_m.set_point(*v_itr, _m.property( vp_pos_, *v_itr ) );
} }
// Split each edge at midpoint stored in edge property ep_pos_; // Split each edge at midpoint stored in edge property ep_pos_;
// Attention! Creating new edges, hence make sure the loop ends correctly. // Attention! Creating new edges, hence make sure the loop ends correctly.
e_itr = _m.edges_begin(); for ( auto eh : _m.edges())
for ( ; e_itr != e_end; ++e_itr) split_edge( _m, eh );
split_edge( _m, *e_itr );
// Commit changes in topology and reconsitute consistency // Commit changes in topology and reconsitute consistency
// Attention! Creating new faces, hence make sure the loop ends correctly. // Attention! Creating new faces, hence make sure the loop ends correctly.
f_itr = _m.faces_begin(); for ( auto fh : _m.faces())
for ( ; f_itr != f_end; ++f_itr) split_face( _m, fh);
split_face( _m, *f_itr);
#if defined(_DEBUG) || defined(DEBUG) #if defined(_DEBUG) || defined(DEBUG)

View File

@@ -174,17 +174,15 @@ protected:
// edge property ep_pos_) in the vertex property vp_pos_; // edge property ep_pos_) in the vertex property vp_pos_;
// Attention! Creating new edges, hence make sure the loop ends correctly. // Attention! Creating new edges, hence make sure the loop ends correctly.
e_end = _m.edges_end(); for (auto eh : _m.edges())
for (eit=_m.edges_begin(); eit != e_end; ++eit) split_edge(_m, eh );
split_edge(_m, *eit );
// Commit changes in topology and reconsitute consistency // Commit changes in topology and reconsitute consistency
// Attention! Creating new faces, hence make sure the loop ends correctly. // Attention! Creating new faces, hence make sure the loop ends correctly.
f_end = _m.faces_end(); for (auto fh : _m.faces())
for (fit = _m.faces_begin(); fit != f_end; ++fit) split_face(_m, fh );
split_face(_m, *fit );
if(_update_points) { if(_update_points) {
// Commit changes in geometry // Commit changes in geometry

View File

@@ -57,43 +57,33 @@ protected: // SubdividerT interface
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 (typename mesh_t::EdgeIter it = _m.edges_begin(), end = _m.edges_end(); it != end; ++it) { for (auto eh : _m.edges()) {
EdgeHandle eh = *it;
VertexHandle new_vh = _m.new_vertex(_m.calc_edge_midpoint(eh)); 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 (typename mesh_t::FaceIter it = _m.faces_begin(), end = _m.faces_end(); it != end; ++it) { for (auto fh : _m.faces()) {
FaceHandle fh = *it;
std::vector<typename mesh_t::VertexHandle> new_corners; std::vector<typename mesh_t::VertexHandle> new_corners;
for (typename mesh_t::FaceEdgeIter it = _m.fe_begin(fh), end = _m.fe_end(fh); it != end; ++it) { for (auto eh : _m.fe_range(fh))
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 (typename mesh_t::VertexIter it = _m.vertices_begin(), end = _m.vertices_end(); it != end; ++it) { for (auto vh : _m.vertices()) {
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 (typename mesh_t::VertexEdgeIter it = _m.ve_begin(vh), end = _m.ve_end(vh); it != end; ++it) { for (auto eh : _m.ve_range(vh))
EdgeHandle eh = *it;
new_corners.push_back(edge_midpoint[eh]); new_corners.push_back(edge_midpoint[eh]);
}
std::reverse(new_corners.begin(), new_corners.end()); std::reverse(new_corners.begin(), new_corners.end());
_m.add_face(new_corners); _m.add_face(new_corners);
} }
} }
} }
for (typename mesh_t::VertexIter it = _m.vertices_begin(), end = _m.vertices_end(); it != end; ++it) { for (auto vh : _m.vertices())
VertexHandle vh = *it; if (is_original_vertex[vh])
if (is_original_vertex[vh]) {
_m.delete_vertex(vh); _m.delete_vertex(vh);
}
}
_m.garbage_collection(); _m.garbage_collection();
} }
_m.release_face_status(); _m.release_face_status();

View File

@@ -179,45 +179,38 @@ protected:
///TODO:Implement fixed positions ///TODO:Implement fixed positions
typename mesh_t::FaceIter fit, f_end;
typename mesh_t::EdgeIter eit, e_end;
typename mesh_t::VertexIter vit;
// Do _n subdivisions // Do _n subdivisions
for (size_t i=0; i < _n; ++i) for (size_t i=0; i < _n; ++i)
{ {
// This is an interpolating scheme, old vertices remain the same. // This is an interpolating scheme, old vertices remain the same.
typename mesh_t::VertexIter initialVerticesEnd = _m.vertices_end(); typename mesh_t::VertexIter initialVerticesEnd = _m.vertices_end();
for ( vit = _m.vertices_begin(); vit != initialVerticesEnd; ++vit) for ( auto vh : _m.vertices())
_m.property( vp_pos_, *vit ) = _m.point(*vit); _m.property( vp_pos_, vh ) = _m.point(vh);
// Compute position for new vertices and store them in the edge property // Compute position for new vertices and store them in the edge property
for (eit=_m.edges_begin(); eit != _m.edges_end(); ++eit) for (auto eh : _m.edges())
compute_midpoint( _m, *eit ); compute_midpoint( _m, eh);
// Split each edge at midpoint and store precomputed positions (stored in // Split each edge at midpoint and store precomputed positions (stored in
// edge property ep_pos_) in the vertex property vp_pos_; // edge property ep_pos_) in the vertex property vp_pos_;
// Attention! Creating new edges, hence make sure the loop ends correctly. // Attention! Creating new edges, hence make sure the loop ends correctly.
e_end = _m.edges_end(); for (auto eh : _m.edges())
for (eit=_m.edges_begin(); eit != e_end; ++eit) split_edge(_m, eh );
split_edge(_m, *eit );
// Commit changes in topology and reconsitute consistency // Commit changes in topology and reconsitute consistency
// Attention! Creating new faces, hence make sure the loop ends correctly. // Attention! Creating new faces, hence make sure the loop ends correctly.
f_end = _m.faces_end(); for (auto fh : _m.faces())
for (fit = _m.faces_begin(); fit != f_end; ++fit) split_face(_m, fh );
split_face(_m, *fit );
// Commit changes in geometry // Commit changes in geometry
for ( vit = /*initialVerticesEnd;*/_m.vertices_begin(); for ( auto vh : _m.vertices())
vit != _m.vertices_end(); ++vit) _m.set_point(vh, _m.property( vp_pos_, vh ) );
_m.set_point(*vit, _m.property( vp_pos_, *vit ) );
#if defined(_DEBUG) || defined(DEBUG) #if defined(_DEBUG) || defined(DEBUG)
// Now we have an consistent mesh! // Now we have an consistent mesh!

View File

@@ -162,11 +162,6 @@ protected:
///TODO:Implement fixed positions ///TODO:Implement fixed positions
typename MeshType::VertexIter vit;
typename MeshType::VertexVertexIter vvit;
typename MeshType::EdgeIter eit;
typename MeshType::FaceIter fit;
typename MeshType::FaceVertexIter fvit;
typename MeshType::VertexHandle vh; typename MeshType::VertexHandle vh;
typename MeshType::HalfedgeHandle heh; typename MeshType::HalfedgeHandle heh;
typename MeshType::Point pos(0,0,0), zero(0,0,0); typename MeshType::Point pos(0,0,0), zero(0,0,0);
@@ -175,22 +170,22 @@ protected:
for (size_t l=0; l<_n; ++l) for (size_t l=0; l<_n; ++l)
{ {
// tag existing edges // tag existing edges
for (eit=_m.edges_begin(); eit != _m.edges_end();++eit) for (auto eh : _m.edges())
{ {
_m.status( *eit ).set_tagged( true ); _m.status( eh ).set_tagged( true );
if ( (gen%2) && _m.is_boundary(*eit) ) if ( (gen%2) && _m.is_boundary(eh) )
compute_new_boundary_points( _m, *eit ); // *) creates new vertices compute_new_boundary_points( _m, eh ); // *) creates new vertices
} }
// do relaxation of old vertices, but store new pos in property vp_pos_ // do relaxation of old vertices, but store new pos in property vp_pos_
for (vit=_m.vertices_begin(); vit!=_m.vertices_end(); ++vit) for (auto vh : _m.vertices())
{ {
if ( _m.is_boundary(*vit) ) if ( _m.is_boundary(vh) )
{ {
if ( gen%2 ) if ( gen%2 )
{ {
heh = _m.halfedge_handle(*vit); heh = _m.halfedge_handle(vh);
if (heh.is_valid()) // skip isolated newly inserted vertices *) if (heh.is_valid()) // skip isolated newly inserted vertices *)
{ {
typename OpenMesh::HalfedgeHandle typename OpenMesh::HalfedgeHandle
@@ -203,60 +198,59 @@ protected:
pos += _m.point(_m.from_vertex_handle(prev_heh)); pos += _m.point(_m.from_vertex_handle(prev_heh));
pos *= real_t(4.0); pos *= real_t(4.0);
pos += real_t(19.0) * _m.point( *vit ); pos += real_t(19.0) * _m.point( vh );
pos *= _1over27; pos *= _1over27;
_m.property( vp_pos_, *vit ) = pos; _m.property( vp_pos_, vh ) = pos;
} }
} }
else else
_m.property( vp_pos_, *vit ) = _m.point( *vit ); _m.property( vp_pos_, vh ) = _m.point( vh );
} }
else else
{ {
size_t valence=0; size_t valence=0;
pos = zero; pos = zero;
for ( vvit = _m.vv_iter(*vit); vvit.is_valid(); ++vvit) for ( auto vvh : _m.vv_range(vh))
{ {
pos += _m.point( *vvit ); pos += _m.point( vvh );
++valence; ++valence;
} }
pos *= weights_[ valence ].second; pos *= weights_[ valence ].second;
pos += weights_[ valence ].first * _m.point(*vit); pos += weights_[ valence ].first * _m.point(vh);
_m.property( vp_pos_, *vit ) = pos; _m.property( vp_pos_, vh ) = pos;
} }
} }
// insert new vertices, but store pos in vp_pos_ // insert new vertices, but store pos in vp_pos_
typename MeshType::FaceIter fend = _m.faces_end(); for (auto fh : _m.faces())
for (fit = _m.faces_begin();fit != fend; ++fit)
{ {
if ( (gen%2) && _m.is_boundary(*fit)) if ( (gen%2) && _m.is_boundary(fh))
{ {
boundary_split( _m, *fit ); boundary_split( _m, fh );
} }
else else
{ {
fvit = _m.fv_iter( *fit ); auto fvit = _m.fv_iter( fh );
pos = _m.point( *fvit); pos = _m.point( *fvit);
pos += _m.point(*(++fvit)); pos += _m.point(*(++fvit));
pos += _m.point(*(++fvit)); pos += _m.point(*(++fvit));
pos *= _1over3; pos *= _1over3;
vh = _m.add_vertex( zero ); vh = _m.add_vertex( zero );
_m.property( vp_pos_, vh ) = pos; _m.property( vp_pos_, vh ) = pos;
_m.split( *fit, vh ); _m.split( fh, vh );
} }
} }
// commit new positions (now iterating over all vertices) // commit new positions (now iterating over all vertices)
for (vit=_m.vertices_begin();vit != _m.vertices_end(); ++vit) for (auto vh : _m.vertices())
_m.set_point(*vit, _m.property( vp_pos_, *vit ) ); _m.set_point(vh, _m.property( vp_pos_, vh ) );
// flip old edges // flip old edges
for (eit=_m.edges_begin(); eit != _m.edges_end(); ++eit) for (auto eh : _m.edges())
if ( _m.status( *eit ).tagged() && !_m.is_boundary( *eit ) ) if ( _m.status( eh ).tagged() && !_m.is_boundary( eh ) )
_m.flip(*eit); _m.flip(eh);
// Now we have an consistent mesh! // Now we have an consistent mesh!
ASSERT_CONSISTENCY( MeshType, _m ); ASSERT_CONSISTENCY( MeshType, _m );