Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions source/MRMesh/MRObjectMeshHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,22 @@ size_t ObjectMeshHolder::numHandles() const

void ObjectMeshHolder::setDirtyFlags( uint32_t mask, bool invalidateCaches )
{
VisualObject::setDirtyFlags( mask, invalidateCaches );
invalidateMetricsCache( mask );
setDirtyFlagsFast( mask );

if ( invalidateCaches && ( mask & DIRTY_POSITION || mask & DIRTY_FACE ) && data_.mesh )
data_.mesh->invalidateCaches();
}

void ObjectMeshHolder::setDirtyFlagsFast( uint32_t mask )
{
VisualObject::setDirtyFlags( mask );
if ( ( mask & DIRTY_POSITION || mask & DIRTY_FACE ) && data_.mesh )
meshChangedSignal( mask );
}

void ObjectMeshHolder::invalidateMetricsCache( uint32_t mask )
{
if ( mask & DIRTY_FACE )
{
numHoles_.reset();
Expand All @@ -782,16 +796,6 @@ void ObjectMeshHolder::setDirtyFlags( uint32_t mask, bool invalidateCaches )
selectedArea_.reset();
volume_.reset();
avgEdgeLen_.reset();
if ( invalidateCaches && data_.mesh )
data_.mesh->invalidateCaches();
}

if ( mask & DIRTY_POSITION || mask & DIRTY_FACE)
{
if ( data_.mesh )
{
meshChangedSignal( mask );
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions source/MRMesh/MRObjectMeshHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ class MRMESH_CLASS ObjectMeshHolder : public VisualObject

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

/// this is a faster version of setDirtyFlags(), which does not invalidate metrics cache (area, volume, ...);
/// the user is responsible for calling invalidateMetricsCache( mask ) or setDirtyFlags( mask ) at the end of mesh editing;
/// DANGER: all cached values returned until then can be outdated
MRMESH_API virtual void setDirtyFlagsFast( uint32_t mask );

/// invalidates same caches with mesh metrics (area, volume, ...) as by setDirtyFlags( mask )
MRMESH_API virtual void invalidateMetricsCache( uint32_t mask );

const FaceBitSet& getSelectedFaces() const { return data_.selectedFaces; }
MRMESH_API virtual void selectFaces( FaceBitSet newSelection );
/// returns colors of selected triangles
Expand Down
18 changes: 16 additions & 2 deletions source/MRViewer/MRSurfaceManipulationWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ bool SurfaceManipulationWidget::onMouseUp_( Viewer::MouseButton button, int /*mo
updateValueChanges_( generalEditingRegion_ );
obj_->setDirtyFlags( DIRTY_POSITION );
}
else
invalidateMetricsCache_();

generalEditingRegion_.clear();
generalEditingRegion_.resize( numV, false );
Expand Down Expand Up @@ -598,7 +600,7 @@ void SurfaceManipulationWidget::changeSurface_()
params.region = &singleEditingRegion_;
params.force = settings_.relaxForce;
relax( *obj_->varMesh(), params );
obj_->setDirtyFlags( DIRTY_POSITION );
obj_->setDirtyFlagsFast( DIRTY_POSITION );
updateValueChanges_( singleEditingRegion_ );
return;
}
Expand All @@ -610,6 +612,7 @@ void SurfaceManipulationWidget::changeSurface_()
normal += mesh.dirDblArea( v );
normal = normal.normalized();

obj_->varMesh()->invalidateCaches();
auto& points = obj_->varMesh()->points;

const float maxShift = settings_.editForce;
Expand All @@ -634,7 +637,7 @@ void SurfaceManipulationWidget::changeSurface_()
generalEditingRegion_ |= singleEditingRegion_;
changedRegion_ |= singleEditingRegion_;
updateValueChanges_( singleEditingRegion_ );
obj_->setDirtyFlags( DIRTY_POSITION );
obj_->setDirtyFlagsFast( DIRTY_POSITION );
}

void SurfaceManipulationWidget::updateUVmap_( bool set, bool wholeMesh )
Expand Down Expand Up @@ -750,12 +753,23 @@ void SurfaceManipulationWidget::updateRegion_( const Vector2f& mousePos )
singleEditingRegion_ -= unchangeableVerts_;
}

void SurfaceManipulationWidget::invalidateMetricsCache_()
{
// if not-Patch mode and some surface change was done without metrics update
if ( !appendHistoryAction_ && historyAction_ )
{
assert( settings_.workMode != WorkMode::Patch );
obj_->invalidateMetricsCache( DIRTY_POSITION );
}
}

void SurfaceManipulationWidget::abortEdit_()
{
if ( !mousePressed_ )
return;
mousePressed_ = false;
removeLastStableObjMesh_();
invalidateMetricsCache_();
appendHistoryAction_ = false;
historyAction_.reset();
generalEditingRegion_.clear();
Expand Down
1 change: 1 addition & 0 deletions source/MRViewer/MRSurfaceManipulationWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class MRVIEWER_CLASS SurfaceManipulationWidget :
void changeSurface_();
void updateUVmap_( bool set, bool wholeMesh = false );
void updateRegion_( const Vector2f& mousePos );
void invalidateMetricsCache_();
void abortEdit_();
/// Laplacian
void laplacianPickVert_( const PointOnFace& pick );
Expand Down
Loading