From cc510502f3fef4332f3ab36200c94b15af150647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Fri, 19 Jun 2020 12:07:57 +0200 Subject: [PATCH 1/5] Decimate only on selected vertices --- src/OpenMesh/Tools/Decimater/DecimaterT.hh | 11 ++-- .../Tools/Decimater/DecimaterT_impl.hh | 28 +++++---- src/OpenMesh/Tools/Decimater/McDecimaterT.hh | 51 ++++++++++++---- .../Tools/Decimater/McDecimaterT_impl.hh | 17 +++--- .../Tools/Decimater/MixedDecimaterT.hh | 60 +++++++++++++++---- .../Tools/Decimater/MixedDecimaterT_impl.hh | 14 ++--- 6 files changed, 129 insertions(+), 52 deletions(-) diff --git a/src/OpenMesh/Tools/Decimater/DecimaterT.hh b/src/OpenMesh/Tools/Decimater/DecimaterT.hh index 6fe852cd..920a1bbe 100644 --- a/src/OpenMesh/Tools/Decimater/DecimaterT.hh +++ b/src/OpenMesh/Tools/Decimater/DecimaterT.hh @@ -100,26 +100,28 @@ public: * @brief Perform a number of collapses on the mesh. * @param _n_collapses Desired number of collapses. If zero (default), attempt * to do as many collapses as possible. + * @param _only_selected Only consider vertices which are selected for decimation * @return Number of collapses that were actually performed. * @note This operation only marks the removed mesh elements for deletion. In * order to actually remove the decimated elements from the mesh, a * subsequent call to ArrayKernel::garbage_collection() is required. */ - size_t decimate( size_t _n_collapses = 0 ); + size_t decimate( size_t _n_collapses = 0 , bool _only_selected = false); /** * @brief Decimate the mesh to a desired target vertex complexity. * @param _n_vertices Target complexity, i.e. desired number of remaining * vertices after decimation. + * @param _only_selected Only consider vertices which are selected for decimation * @return Number of collapses that were actually performed. * @note This operation only marks the removed mesh elements for deletion. In * order to actually remove the decimated elements from the mesh, a * subsequent call to ArrayKernel::garbage_collection() is required. */ - size_t decimate_to( size_t _n_vertices ) + size_t decimate_to( size_t _n_vertices , bool _only_selected = false) { return ( (_n_vertices < this->mesh().n_vertices()) ? - decimate( this->mesh().n_vertices() - _n_vertices ) : 0 ); + decimate( this->mesh().n_vertices() - _n_vertices ) : 0 , _only_selected); } /** @@ -127,6 +129,7 @@ public: * complexity is achieved. * @param _n_vertices Target vertex complexity. * @param _n_faces Target face complexity. + * @param _only_selected Only consider vertices which are selected for decimation * @return Number of collapses that were actually performed. * @note Decimation stops as soon as either one of the two complexity bounds * is satisfied. @@ -134,7 +137,7 @@ public: * order to actually remove the decimated elements from the mesh, a * subsequent call to ArrayKernel::garbage_collection() is required. */ - size_t decimate_to_faces( size_t _n_vertices=0, size_t _n_faces=0 ); + size_t decimate_to_faces( size_t _n_vertices=0, size_t _n_faces=0 , bool _only_selected = false); public: diff --git a/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh b/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh index e7211a0c..4b1425a8 100644 --- a/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh +++ b/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh @@ -147,7 +147,7 @@ void DecimaterT::heap_vertex(VertexHandle _vh) { //----------------------------------------------------------------------------- template -size_t DecimaterT::decimate(size_t _n_collapses) { +size_t DecimaterT::decimate(size_t _n_collapses, bool _only_selected) { if (!this->is_initialized()) return 0; @@ -181,10 +181,15 @@ size_t DecimaterT::decimate(size_t _n_collapses) { heap_->reserve(mesh_.n_vertices()); - for (v_it = mesh_.vertices_begin(); v_it != v_end; ++v_it) { - heap_->reset_heap_position(*v_it); - if (!mesh_.status(*v_it).deleted()) - heap_vertex(*v_it); + for ( auto v_it : mesh_.vertices() ) { + heap_->reset_heap_position(v_it); + + if (!mesh_.status(v_it).deleted()) { + if (!_only_selected || mesh_.status(v_it).selected() ) { + heap_vertex(v_it); + } + } + } const bool update_normals = mesh_.has_face_normals(); @@ -251,7 +256,7 @@ size_t DecimaterT::decimate(size_t _n_collapses) { //----------------------------------------------------------------------------- template -size_t DecimaterT::decimate_to_faces(size_t _nv, size_t _nf) { +size_t DecimaterT::decimate_to_faces(size_t _nv, size_t _nf, bool _only_selected) { if (!this->is_initialized()) return 0; @@ -283,10 +288,13 @@ size_t DecimaterT::decimate_to_faces(size_t _nv, size_t _nf) { #endif heap_->reserve(mesh_.n_vertices()); - for (v_it = mesh_.vertices_begin(); v_it != v_end; ++v_it) { - heap_->reset_heap_position(*v_it); - if (!mesh_.status(*v_it).deleted()) - heap_vertex(*v_it); + for ( auto v_it : mesh_.vertices() ) { + heap_->reset_heap_position(v_it); + if (!mesh_.status(v_it).deleted()) { + if (!_only_selected || mesh_.status(v_it).selected() ) { + heap_vertex(v_it); + } + } } const bool update_normals = mesh_.has_face_normals(); diff --git a/src/OpenMesh/Tools/Decimater/McDecimaterT.hh b/src/OpenMesh/Tools/Decimater/McDecimaterT.hh index 9b38a383..238c9d46 100644 --- a/src/OpenMesh/Tools/Decimater/McDecimaterT.hh +++ b/src/OpenMesh/Tools/Decimater/McDecimaterT.hh @@ -95,29 +95,56 @@ public: //------------------------------------------------------ public methods public: - /** Decimate (perform _n_collapses collapses). Return number of - performed collapses. If _n_collapses is not given reduce as - much as possible */ - size_t decimate( size_t _n_collapses ); + /** + * @brief Decimate (perform _n_collapses collapses). Return number of + * performed collapses. If _n_collapses is not given reduce as + * much as possible + * @param _n_collapses Desired number of collapses. If zero (default), attempt + * to do as many collapses as possible. + * @param _only_selected Only consider vertices which are selected for decimation + * @return Number of collapses that were actually performed. + * @note This operation only marks the removed mesh elements for deletion. In + * order to actually remove the decimated elements from the mesh, a + * subsequent call to ArrayKernel::garbage_collection() is required. + */ + size_t decimate( size_t _n_collapses , bool _only_selected = false); - /// Decimate to target complexity, returns number of collapses - size_t decimate_to( size_t _n_vertices ) + /** + * @brief Decimate the mesh to a desired target vertex complexity. + * @param _n_vertices Target complexity, i.e. desired number of remaining + * vertices after decimation. + * @param _only_selected Only consider vertices which are selected for decimation + * @return Number of collapses that were actually performed. + * @note This operation only marks the removed mesh elements for deletion. In + * order to actually remove the decimated elements from the mesh, a + * subsequent call to ArrayKernel::garbage_collection() is required. + */ + size_t decimate_to( size_t _n_vertices , bool _only_selected = false) { return ( (_n_vertices < this->mesh().n_vertices()) ? - decimate( this->mesh().n_vertices() - _n_vertices ) : 0 ); + decimate( this->mesh().n_vertices() - _n_vertices ) : 0 , _only_selected); } - /** Decimate to target complexity (vertices and faces). - * Stops when the number of vertices or the number of faces is reached. - * Returns number of performed collapses. + /** + * @brief Attempts to decimate the mesh until a desired vertex or face + * complexity is achieved. + * @param _n_vertices Target vertex complexity. + * @param _n_faces Target face complexity. + * @param _only_selected Only consider vertices which are selected for decimation + * @return Number of collapses that were actually performed. + * @note Decimation stops as soon as either one of the two complexity bounds + * is satisfied. + * @note This operation only marks the removed mesh elements for deletion. In + * order to actually remove the decimated elements from the mesh, a + * subsequent call to ArrayKernel::garbage_collection() is required. */ - size_t decimate_to_faces( size_t _n_vertices=0, size_t _n_faces=0 ); + size_t decimate_to_faces( size_t _n_vertices=0, size_t _n_faces=0 , bool _only_selected = false); /** * Decimate only with constraints, while _factor gives the * percentage of the constraints that should be used */ - size_t decimate_constraints_only(float _factor); + size_t decimate_constraints_only(float _factor, bool _only_selected = false); size_t samples(){return randomSamples_;} void set_samples(const size_t _value){randomSamples_ = _value;} diff --git a/src/OpenMesh/Tools/Decimater/McDecimaterT_impl.hh b/src/OpenMesh/Tools/Decimater/McDecimaterT_impl.hh index f0edc676..59b4fdf2 100644 --- a/src/OpenMesh/Tools/Decimater/McDecimaterT_impl.hh +++ b/src/OpenMesh/Tools/Decimater/McDecimaterT_impl.hh @@ -99,7 +99,7 @@ McDecimaterT::~McDecimaterT() { //----------------------------------------------------------------------------- template -size_t McDecimaterT::decimate(size_t _n_collapses) { +size_t McDecimaterT::decimate(size_t _n_collapses, bool _only_selected) { if (!this->is_initialized()) return 0; @@ -142,8 +142,8 @@ size_t McDecimaterT::decimate(size_t _n_collapses) { tmpHandle = typename Mesh::HalfedgeHandle( (double(rand()) / double(RAND_MAX) ) * double(mesh_.n_halfedges()-1) ); #endif - // if it is not deleted, we analyse it - if ( ! mesh_.status(tmpHandle).deleted() ) { + // if it is not deleted, we analyze it + if ( ! mesh_.status(tmpHandle).deleted() && (!_only_selected || mesh_.status(tmpHandle).selected() ) ) { CollapseInfo ci(mesh_, tmpHandle); @@ -223,7 +223,7 @@ size_t McDecimaterT::decimate(size_t _n_collapses) { //----------------------------------------------------------------------------- template -size_t McDecimaterT::decimate_to_faces(size_t _nv, size_t _nf) { +size_t McDecimaterT::decimate_to_faces(size_t _nv, size_t _nf, bool _only_selected) { if (!this->is_initialized()) return 0; @@ -273,8 +273,8 @@ size_t McDecimaterT::decimate_to_faces(size_t _nv, size_t _nf) { tmpHandle = typename Mesh::HalfedgeHandle( ( double(rand()) / double(RAND_MAX) ) * double(mesh_.n_halfedges() - 1)); #endif - // if it is not deleted, we analyse it - if (!mesh_.status(tmpHandle).deleted()) { + // if it is not deleted, we analyze it + if ( ! mesh_.status(tmpHandle).deleted() && (!_only_selected || mesh_.status(tmpHandle).selected() ) ) { CollapseInfo ci(mesh_, tmpHandle); @@ -366,7 +366,7 @@ size_t McDecimaterT::decimate_to_faces(size_t _nv, size_t _nf) { //----------------------------------------------------------------------------- template -size_t McDecimaterT::decimate_constraints_only(float _factor) { +size_t McDecimaterT::decimate_constraints_only(float _factor, bool _only_selected) { if (!this->is_initialized()) return 0; @@ -419,7 +419,8 @@ size_t McDecimaterT::decimate_constraints_only(float _factor) { #endif // if it is not deleted, we analyze it - if (!mesh_.status(mesh_.edge_handle(tmpHandle)).deleted()) { + if (!mesh_.status(mesh_.edge_handle(tmpHandle)).deleted() && + (!_only_selected || ( mesh_.status(mesh_.to_vertex_handle(tmpHandle)).selected() && mesh_.status(mesh_.from_vertex_handle(tmpHandle)).selected() ) ) ) { CollapseInfo ci(mesh_, tmpHandle); diff --git a/src/OpenMesh/Tools/Decimater/MixedDecimaterT.hh b/src/OpenMesh/Tools/Decimater/MixedDecimaterT.hh index 24dc94f1..7e3bbdbb 100644 --- a/src/OpenMesh/Tools/Decimater/MixedDecimaterT.hh +++ b/src/OpenMesh/Tools/Decimater/MixedDecimaterT.hh @@ -95,23 +95,61 @@ public: //------------------------------------------------------ public methods public: - /** Decimate (perform _n_collapses collapses). Return number of - performed collapses. If _n_collapses is not given reduce as - much as possible */ - size_t decimate( const size_t _n_collapses, const float _mc_factor ); + /** + * @brief Decimate (perform _n_collapses collapses). Return number of + * performed collapses. If _n_collapses is not given reduce as + * much as possible + * @param _n_collapses Desired number of collapses. If zero (default), attempt + * to do as many collapses as possible. + * @param _mc_factor Number between 0 and one defining how much percent of the + * collapses should be performed by MC Decimater before switching to + * Fixed decimation + * @param _only_selected Only consider vertices which are selected for decimation + * @return Number of collapses that were actually performed. + * @note This operation only marks the removed mesh elements for deletion. In + * order to actually remove the decimated elements from the mesh, a + * subsequent call to ArrayKernel::garbage_collection() is required. + */ + size_t decimate( const size_t _n_collapses, const float _mc_factor , bool _only_selected = false); - /// Decimate to target complexity, returns number of collapses - size_t decimate_to( size_t _n_vertices, const float _mc_factor ) + /** + * @brief Decimate the mesh to a desired target vertex complexity. + * @param _n_vertices Target complexity, i.e. desired number of remaining + * vertices after decimation. + + * @param _only_selected Only consider vertices which are selected for decimation + * @param _mc_factor Number between 0 and one defining how much percent of the + * collapses should be performed by MC Decimater before switching to + * Fixed decimation + * @return Number of collapses that were actually performed. + * @note This operation only marks the removed mesh elements for deletion. In + * order to actually remove the decimated elements from the mesh, a + * subsequent call to ArrayKernel::garbage_collection() is required. + */ + size_t decimate_to( size_t _n_vertices, const float _mc_factor , bool _only_selected = false) { return ( (_n_vertices < this->mesh().n_vertices()) ? - decimate( this->mesh().n_vertices() - _n_vertices, _mc_factor ) : 0 ); + decimate( this->mesh().n_vertices() - _n_vertices, _mc_factor , _only_selected) : 0 ); } - /** Decimate to target complexity (vertices and faces). - * Stops when the number of vertices or the number of faces is reached. - * Returns number of performed collapses. + /** + * @brief Attempts to decimate the mesh until a desired vertex or face + * complexity is achieved. + * @param _n_vertices Target vertex complexity. + * @param _n_faces Target face complexity. + * @param _mc_factor Number between 0 and one defining how much percent of the + * collapses should be performed by MC Decimater before switching to + * Fixed decimation + * @param _only_selected Only consider vertices which are selected for decimation + * @return Number of collapses that were actually performed. + * @note Decimation stops as soon as either one of the two complexity bounds + * is satisfied. + * @note This operation only marks the removed mesh elements for deletion. In + * order to actually remove the decimated elements from the mesh, a + * subsequent call to ArrayKernel::garbage_collection() is required. */ - size_t decimate_to_faces( const size_t _n_vertices=0, const size_t _n_faces=0 , const float _mc_factor = 0.8); + + size_t decimate_to_faces( const size_t _n_vertices=0, const size_t _n_faces=0 , const float _mc_factor = 0.8 , bool _only_selected = false); private: //------------------------------------------------------- private data diff --git a/src/OpenMesh/Tools/Decimater/MixedDecimaterT_impl.hh b/src/OpenMesh/Tools/Decimater/MixedDecimaterT_impl.hh index 6b86b8d1..e17882a6 100644 --- a/src/OpenMesh/Tools/Decimater/MixedDecimaterT_impl.hh +++ b/src/OpenMesh/Tools/Decimater/MixedDecimaterT_impl.hh @@ -82,7 +82,7 @@ MixedDecimaterT::~MixedDecimaterT() { //----------------------------------------------------------------------------- template -size_t MixedDecimaterT::decimate(const size_t _n_collapses, const float _mc_factor) { +size_t MixedDecimaterT::decimate(const size_t _n_collapses, const float _mc_factor, bool _only_selected) { if (_mc_factor > 1.0) return 0; @@ -92,21 +92,21 @@ size_t MixedDecimaterT::decimate(const size_t _n_collapses, const float _m size_t r_collapses = 0; if (_mc_factor > 0.0) - r_collapses = McDecimaterT::decimate(n_collapses_mc); + r_collapses = McDecimaterT::decimate(n_collapses_mc,_only_selected); // returns, if the previous steps were aborted by the observer if (this->observer() && this->observer()->abort()) return r_collapses; if (_mc_factor < 1.0) - r_collapses += DecimaterT::decimate(n_collapses_inc); + r_collapses += DecimaterT::decimate(n_collapses_inc,_only_selected); return r_collapses; } template -size_t MixedDecimaterT::decimate_to_faces(const size_t _n_vertices,const size_t _n_faces, const float _mc_factor ){ +size_t MixedDecimaterT::decimate_to_faces(const size_t _n_vertices,const size_t _n_faces, const float _mc_factor , bool _only_selected){ if (_mc_factor > 1.0) return 0; @@ -122,7 +122,7 @@ size_t MixedDecimaterT::decimate_to_faces(const size_t _n_vertices,const size_t n_vertices_mc = static_cast(mesh_vertices - _mc_factor * (mesh_vertices - _n_vertices)); size_t n_faces_mc = static_cast(mesh_faces - _mc_factor * (mesh_faces - _n_faces)); - r_collapses = McDecimaterT::decimate_to_faces(n_vertices_mc, n_faces_mc); + r_collapses = McDecimaterT::decimate_to_faces(n_vertices_mc, n_faces_mc,_only_selected); } else { const size_t samples = this->samples(); @@ -145,7 +145,7 @@ size_t MixedDecimaterT::decimate_to_faces(const size_t _n_vertices,const float decimaterLevel = (float(i + 1)) * _mc_factor / (float(steps) ); this->set_samples(samples); - r_collapses += McDecimaterT::decimate_constraints_only(decimaterLevel); + r_collapses += McDecimaterT::decimate_constraints_only(decimaterLevel,_only_selected); } } } @@ -159,7 +159,7 @@ size_t MixedDecimaterT::decimate_to_faces(const size_t _n_vertices,const //reduce the rest of the mesh if (_mc_factor < 1.0) { - r_collapses += DecimaterT::decimate_to_faces(_n_vertices,_n_faces); + r_collapses += DecimaterT::decimate_to_faces(_n_vertices,_n_faces,_only_selected); } From ddf15b3bf4db0960ed8721b00b1f7ff4db0224cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Fri, 19 Jun 2020 13:54:45 +0200 Subject: [PATCH 2/5] Decimate only on selected vertices, Fixed ugly typo --- src/OpenMesh/Tools/Decimater/DecimaterT.hh | 2 +- src/OpenMesh/Tools/Decimater/McDecimaterT.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenMesh/Tools/Decimater/DecimaterT.hh b/src/OpenMesh/Tools/Decimater/DecimaterT.hh index 920a1bbe..6d0b3b4d 100644 --- a/src/OpenMesh/Tools/Decimater/DecimaterT.hh +++ b/src/OpenMesh/Tools/Decimater/DecimaterT.hh @@ -121,7 +121,7 @@ public: size_t decimate_to( size_t _n_vertices , bool _only_selected = false) { return ( (_n_vertices < this->mesh().n_vertices()) ? - decimate( this->mesh().n_vertices() - _n_vertices ) : 0 , _only_selected); + decimate( this->mesh().n_vertices() - _n_vertices , _only_selected ) : 0 ); } /** diff --git a/src/OpenMesh/Tools/Decimater/McDecimaterT.hh b/src/OpenMesh/Tools/Decimater/McDecimaterT.hh index 238c9d46..553e311d 100644 --- a/src/OpenMesh/Tools/Decimater/McDecimaterT.hh +++ b/src/OpenMesh/Tools/Decimater/McDecimaterT.hh @@ -122,7 +122,7 @@ public: size_t decimate_to( size_t _n_vertices , bool _only_selected = false) { return ( (_n_vertices < this->mesh().n_vertices()) ? - decimate( this->mesh().n_vertices() - _n_vertices ) : 0 , _only_selected); + decimate( this->mesh().n_vertices() - _n_vertices , _only_selected ) : 0 ); } /** From 2d90392e0c715e3e7e65a918186e4051f8c43fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Fri, 19 Jun 2020 14:45:45 +0200 Subject: [PATCH 3/5] Fixed cppcheck issue --- src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh b/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh index 4b1425a8..48033a92 100644 --- a/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh +++ b/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh @@ -152,7 +152,6 @@ size_t DecimaterT::decimate(size_t _n_collapses, bool _only_selected) { if (!this->is_initialized()) return 0; - typename Mesh::VertexIter v_it, v_end(mesh_.vertices_end()); typename Mesh::VertexHandle vp; typename Mesh::HalfedgeHandle v0v1; typename Mesh::VertexVertexIter vv_it; @@ -264,7 +263,6 @@ size_t DecimaterT::decimate_to_faces(size_t _nv, size_t _nf, bool _only_se if (_nv >= mesh_.n_vertices() || _nf >= mesh_.n_faces()) return 0; - typename Mesh::VertexIter v_it, v_end(mesh_.vertices_end()); typename Mesh::VertexHandle vp; typename Mesh::HalfedgeHandle v0v1; typename Mesh::VertexVertexIter vv_it; From cfb9af64f7d19ca9d4ffb1e1198f253a906abe07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Fri, 19 Jun 2020 15:54:39 +0200 Subject: [PATCH 4/5] Fixed runaway selection --- .../Tools/Decimater/DecimaterT_impl.hh | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh b/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh index 48033a92..ff5e7f6e 100644 --- a/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh +++ b/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh @@ -144,13 +144,13 @@ void DecimaterT::heap_vertex(VertexHandle _vh) { mesh_.property(priority_, _vh) = -1; } } - -//----------------------------------------------------------------------------- -template -size_t DecimaterT::decimate(size_t _n_collapses, bool _only_selected) { - - if (!this->is_initialized()) - return 0; + +//----------------------------------------------------------------------------- +template +size_t DecimaterT::decimate(size_t _n_collapses, bool _only_selected) { + + if (!this->is_initialized()) + return 0; typename Mesh::VertexHandle vp; typename Mesh::HalfedgeHandle v0v1; @@ -234,16 +234,17 @@ size_t DecimaterT::decimate(size_t _n_collapses, bool _only_selected) { // update heap (former one ring of decimated vertex) for (s_it = support.begin(), s_end = support.end(); s_it != s_end; ++s_it) { - assert(!mesh_.status(*s_it).deleted()); - heap_vertex(*s_it); - } - - // notify observer and stop if the observer requests it - if (!this->notify_observer(n_collapses)) - return n_collapses; - } - - // delete heap + assert(!mesh_.status(*s_it).deleted()); + if (!_only_selected || mesh_.status(*s_it).selected() ) + heap_vertex(*s_it); + } + + // notify observer and stop if the observer requests it + if (!this->notify_observer(n_collapses)) + return n_collapses; + } + + // delete heap heap_.reset(); @@ -252,13 +253,13 @@ size_t DecimaterT::decimate(size_t _n_collapses, bool _only_selected) { return n_collapses; } -//----------------------------------------------------------------------------- - -template -size_t DecimaterT::decimate_to_faces(size_t _nv, size_t _nf, bool _only_selected) { - - if (!this->is_initialized()) - return 0; +//----------------------------------------------------------------------------- + +template +size_t DecimaterT::decimate_to_faces(size_t _nv, size_t _nf, bool _only_selected) { + + if (!this->is_initialized()) + return 0; if (_nv >= mesh_.n_vertices() || _nf >= mesh_.n_faces()) return 0; @@ -345,16 +346,16 @@ size_t DecimaterT::decimate_to_faces(size_t _nv, size_t _nf, bool _only_se // update heap (former one ring of decimated vertex) for (s_it = support.begin(), s_end = support.end(); s_it != s_end; ++s_it) { - assert(!mesh_.status(*s_it).deleted()); - heap_vertex(*s_it); - } - - // notify observer and stop if the observer requests it - if (!this->notify_observer(n_collapses)) - return n_collapses; - } - - // delete heap + assert(!mesh_.status(*s_it).deleted()); + heap_vertex(*s_it); + } + + // notify observer and stop if the observer requests it + if (!this->notify_observer(n_collapses)) + return n_collapses; + } + + // delete heap heap_.reset(); From 044454188ef0c6ca4d373739e9bb60fa143d38a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Fri, 19 Jun 2020 16:03:22 +0200 Subject: [PATCH 5/5] Fixed runaway selection --- src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh b/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh index ff5e7f6e..c38d4272 100644 --- a/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh +++ b/src/OpenMesh/Tools/Decimater/DecimaterT_impl.hh @@ -347,7 +347,8 @@ size_t DecimaterT::decimate_to_faces(size_t _nv, size_t _nf, bool _only_se // update heap (former one ring of decimated vertex) for (s_it = support.begin(), s_end = support.end(); s_it != s_end; ++s_it) { assert(!mesh_.status(*s_it).deleted()); - heap_vertex(*s_it); + if (!_only_selected || mesh_.status(*s_it).selected() ) + heap_vertex(*s_it); } // notify observer and stop if the observer requests it