Skip to content

Commit 9010a2c

Browse files
authored
ObjectMeshHolder::setDirtyFlagsFast (#5694)
1 parent 9f8f6fc commit 9010a2c

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

source/MRMesh/MRObjectMeshHolder.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,22 @@ size_t ObjectMeshHolder::numHandles() const
763763

764764
void ObjectMeshHolder::setDirtyFlags( uint32_t mask, bool invalidateCaches )
765765
{
766-
VisualObject::setDirtyFlags( mask, invalidateCaches );
766+
invalidateMetricsCache( mask );
767+
setDirtyFlagsFast( mask );
767768

769+
if ( invalidateCaches && ( mask & DIRTY_POSITION || mask & DIRTY_FACE ) && data_.mesh )
770+
data_.mesh->invalidateCaches();
771+
}
772+
773+
void ObjectMeshHolder::setDirtyFlagsFast( uint32_t mask )
774+
{
775+
VisualObject::setDirtyFlags( mask );
776+
if ( ( mask & DIRTY_POSITION || mask & DIRTY_FACE ) && data_.mesh )
777+
meshChangedSignal( mask );
778+
}
779+
780+
void ObjectMeshHolder::invalidateMetricsCache( uint32_t mask )
781+
{
768782
if ( mask & DIRTY_FACE )
769783
{
770784
numHoles_.reset();
@@ -782,16 +796,6 @@ void ObjectMeshHolder::setDirtyFlags( uint32_t mask, bool invalidateCaches )
782796
selectedArea_.reset();
783797
volume_.reset();
784798
avgEdgeLen_.reset();
785-
if ( invalidateCaches && data_.mesh )
786-
data_.mesh->invalidateCaches();
787-
}
788-
789-
if ( mask & DIRTY_POSITION || mask & DIRTY_FACE)
790-
{
791-
if ( data_.mesh )
792-
{
793-
meshChangedSignal( mask );
794-
}
795799
}
796800
}
797801

source/MRMesh/MRObjectMeshHolder.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ class MRMESH_CLASS ObjectMeshHolder : public VisualObject
6464

6565
MRMESH_API virtual void setDirtyFlags( uint32_t mask, bool invalidateCaches = true ) override;
6666

67+
/// this is a faster version of setDirtyFlags(), which does not invalidate metrics cache (area, volume, ...);
68+
/// the user is responsible for calling invalidateMetricsCache( mask ) or setDirtyFlags( mask ) at the end of mesh editing;
69+
/// DANGER: all cached values returned until then can be outdated
70+
MRMESH_API virtual void setDirtyFlagsFast( uint32_t mask );
71+
72+
/// invalidates same caches with mesh metrics (area, volume, ...) as by setDirtyFlags( mask )
73+
MRMESH_API virtual void invalidateMetricsCache( uint32_t mask );
74+
6775
const FaceBitSet& getSelectedFaces() const { return data_.selectedFaces; }
6876
MRMESH_API virtual void selectFaces( FaceBitSet newSelection );
6977
/// returns colors of selected triangles

source/MRViewer/MRSurfaceManipulationWidget.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ bool SurfaceManipulationWidget::onMouseUp_( Viewer::MouseButton button, int /*mo
466466
updateValueChanges_( generalEditingRegion_ );
467467
obj_->setDirtyFlags( DIRTY_POSITION );
468468
}
469+
else
470+
invalidateMetricsCache_();
469471

470472
generalEditingRegion_.clear();
471473
generalEditingRegion_.resize( numV, false );
@@ -598,7 +600,7 @@ void SurfaceManipulationWidget::changeSurface_()
598600
params.region = &singleEditingRegion_;
599601
params.force = settings_.relaxForce;
600602
relax( *obj_->varMesh(), params );
601-
obj_->setDirtyFlags( DIRTY_POSITION );
603+
obj_->setDirtyFlagsFast( DIRTY_POSITION );
602604
updateValueChanges_( singleEditingRegion_ );
603605
return;
604606
}
@@ -610,6 +612,7 @@ void SurfaceManipulationWidget::changeSurface_()
610612
normal += mesh.dirDblArea( v );
611613
normal = normal.normalized();
612614

615+
obj_->varMesh()->invalidateCaches();
613616
auto& points = obj_->varMesh()->points;
614617

615618
const float maxShift = settings_.editForce;
@@ -634,7 +637,7 @@ void SurfaceManipulationWidget::changeSurface_()
634637
generalEditingRegion_ |= singleEditingRegion_;
635638
changedRegion_ |= singleEditingRegion_;
636639
updateValueChanges_( singleEditingRegion_ );
637-
obj_->setDirtyFlags( DIRTY_POSITION );
640+
obj_->setDirtyFlagsFast( DIRTY_POSITION );
638641
}
639642

640643
void SurfaceManipulationWidget::updateUVmap_( bool set, bool wholeMesh )
@@ -750,12 +753,23 @@ void SurfaceManipulationWidget::updateRegion_( const Vector2f& mousePos )
750753
singleEditingRegion_ -= unchangeableVerts_;
751754
}
752755

756+
void SurfaceManipulationWidget::invalidateMetricsCache_()
757+
{
758+
// if not-Patch mode and some surface change was done without metrics update
759+
if ( !appendHistoryAction_ && historyAction_ )
760+
{
761+
assert( settings_.workMode != WorkMode::Patch );
762+
obj_->invalidateMetricsCache( DIRTY_POSITION );
763+
}
764+
}
765+
753766
void SurfaceManipulationWidget::abortEdit_()
754767
{
755768
if ( !mousePressed_ )
756769
return;
757770
mousePressed_ = false;
758771
removeLastStableObjMesh_();
772+
invalidateMetricsCache_();
759773
appendHistoryAction_ = false;
760774
historyAction_.reset();
761775
generalEditingRegion_.clear();

source/MRViewer/MRSurfaceManipulationWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class MRVIEWER_CLASS SurfaceManipulationWidget :
122122
void changeSurface_();
123123
void updateUVmap_( bool set, bool wholeMesh = false );
124124
void updateRegion_( const Vector2f& mousePos );
125+
void invalidateMetricsCache_();
125126
void abortEdit_();
126127
/// Laplacian
127128
void laplacianPickVert_( const PointOnFace& pick );

0 commit comments

Comments
 (0)