From f39fa7b8d8ca01e534c2e5f5bf3a002f23759a61 Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 5 Aug 2013 12:24:30 +0000 Subject: [PATCH] progress bar --- src/NETGENPlugin/NETGENPlugin_Mesher.cxx | 114 ++++++++++++------ src/NETGENPlugin/NETGENPlugin_Mesher.hxx | 8 +- src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx | 3 +- src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx | 29 +++-- src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx | 11 +- 5 files changed, 116 insertions(+), 49 deletions(-) diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx index c848928..a15b44f 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx @@ -127,6 +127,8 @@ NETGENPlugin_Mesher::NETGENPlugin_Mesher (SMESH_Mesh* mesh, _ngMesh(NULL), _occgeom(NULL), _curShapeIndex(-1), + _progressTic(1), + _totalTime(1.0), _simpleHyp(NULL), _ptrToMe(NULL) { @@ -2081,6 +2083,13 @@ namespace str << ": " << ex.What(); return str; } + + const double edgeMeshingTime = 0.001; + const double faceMeshingTime = 0.019; + const double edgeFaceMeshingTime = edgeMeshingTime + faceMeshingTime; + const double faceOptimizTime = 0.06; + const double voluMeshingTime = 0.15; + const double volOptimizeTime = 0.77; } //============================================================================= @@ -2117,6 +2126,15 @@ bool NETGENPlugin_Mesher::Compute() NETGENPlugin_Internals internals( *_mesh, _shape, _isVolume ); PrepareOCCgeometry( occgeo, _shape, *_mesh, meshedSM, &internals ); _occgeom = &occgeo; + + _totalTime = edgeFaceMeshingTime; + if ( _optimize ) + _totalTime += faceOptimizTime; + if ( _isVolume ) + _totalTime += voluMeshingTime + ( _optimize ? volOptimizeTime : 0 ); + double doneTime = 0; + _ticTime = -1; + _progressTic = 1; _curShapeIndex = -1; // ------------------------- @@ -2321,6 +2339,9 @@ bool NETGENPlugin_Mesher::Compute() err = 1; } } + if ( _isVolume ) + _ticTime = ( doneTime += edgeMeshingTime ) / _totalTime / _progressTic; + mparams.uselocalh = true; // restore as it is used at surface optimization // --------------------- @@ -2433,6 +2454,11 @@ bool NETGENPlugin_Mesher::Compute() //err = 1; -- try to make volumes anyway } } + if ( _isVolume ) + { + doneTime += faceMeshingTime + ( _optimize ? faceOptimizTime : 0 ); + _ticTime = doneTime / _totalTime / _progressTic; + } // --------------------- // generate volume mesh // --------------------- @@ -2532,6 +2558,8 @@ bool NETGENPlugin_Mesher::Compute() comment << text(exc); err = 1; } + _ticTime = ( doneTime += voluMeshingTime ) / _totalTime / _progressTic; + // Let netgen optimize 3D mesh if ( !err && _optimize ) { @@ -2582,6 +2610,9 @@ bool NETGENPlugin_Mesher::Compute() } } } + + _ticTime = 0.98 / _progressTic; + int nbNod = _ngMesh->GetNP(); int nbSeg = _ngMesh->GetNSeg(); int nbFac = _ngMesh->GetNSE(); @@ -2932,48 +2963,63 @@ bool NETGENPlugin_Mesher::Evaluate(MapShapeNbElems& aResMap) } double NETGENPlugin_Mesher::GetProgress(const SMESH_Algo* holder, - const int * algoProgressTic ) const + const int * algoProgressTic, + const double * algoProgress) const { - double progress = holder->GetProgressByTic(); + ((int&) _progressTic ) = *algoProgressTic + 1; - if ( _ngMesh && _occgeom ) - if ( _isVolume ) + double progress = -1; + if ( !_isVolume ) + { + if ( _ticTime < 0 && netgen::multithread.task[0] == 'O'/*Optimizing surface*/ ) { - if ( _occgeom->somap.Extent() > 1 ) - { - int curShapeIndex = 0; - if ( _ngMesh->GetNE() > 0 ) - { - netgen::Element el = (*_ngMesh)[netgen::ElementIndex( _ngMesh->GetNE()-1 )]; - curShapeIndex = el.GetIndex(); - } - if ( curShapeIndex != _curShapeIndex ) - { - ((int&) * algoProgressTic ) = 1; - ((int&) _curShapeIndex ) = curShapeIndex; - } - double progressPerShape = 1./ ( _occgeom->somap.Extent() + 1 ); - progress = progressPerShape * ( _curShapeIndex + holder->GetProgressByTic() ); - } + ((double&) _ticTime ) = edgeFaceMeshingTime / _totalTime / _progressTic; } - else + else if ( !_optimize /*&& _occgeom->fmap.Extent() > 1*/ ) { - if ( _occgeom->fmap.Extent() > 1 ) + int doneShapeIndex = -1; + while ( doneShapeIndex+1 < _occgeom->facemeshstatus.Size() && + _occgeom->facemeshstatus[ doneShapeIndex+1 ]) + doneShapeIndex++; + if ( doneShapeIndex+1 != _curShapeIndex ) { - int doneShapeIndex = -1; - while ( doneShapeIndex+1 < _occgeom->facemeshstatus.Size() && - _occgeom->facemeshstatus[ doneShapeIndex+1 ]) - doneShapeIndex++; - if ( doneShapeIndex+1 != _curShapeIndex ) - { - ((int&) * algoProgressTic ) = 1; - ((int&) _curShapeIndex ) = doneShapeIndex+1; - } - double progressPerShape = 1./ ( _occgeom->fmap.Extent() + 1 ); - progress = progressPerShape * ( _curShapeIndex + holder->GetProgressByTic() ); + ((int&) _curShapeIndex) = doneShapeIndex+1; + double doneShapeRate = _curShapeIndex / double( _occgeom->fmap.Extent() ); + double doneTime = edgeMeshingTime + doneShapeRate * faceMeshingTime; + ((double&) _ticTime) = doneTime / _totalTime / _progressTic; + // cout << "shape " << _curShapeIndex << " _ticTime " << _ticTime + // << " " << doneTime / _totalTime / _progressTic << endl; } } - return Min( progress, 0.98 ); + } + else if ( !_optimize && _occgeom->somap.Extent() > 1 ) + { + int curShapeIndex = _curShapeIndex; + if ( _ngMesh->GetNE() > 0 ) + { + netgen::Element el = (*_ngMesh)[netgen::ElementIndex( _ngMesh->GetNE()-1 )]; + curShapeIndex = el.GetIndex(); + } + if ( curShapeIndex != _curShapeIndex ) + { + ((int&) _curShapeIndex) = curShapeIndex; + double doneShapeRate = _curShapeIndex / double( _occgeom->somap.Extent() ); + double doneTime = edgeFaceMeshingTime + doneShapeRate * voluMeshingTime; + ((double&) _ticTime) = doneTime / _totalTime / _progressTic; + // cout << "shape " << _curShapeIndex << " _ticTime " << _ticTime + // << " " << doneTime / _totalTime / _progressTic << endl; + } + } + if ( _ticTime > 0 ) + progress = Max( *algoProgressTic * _ticTime, *algoProgress ); + if ( progress > 0 ) + { + ((int&) *algoProgressTic )++; + ((double&) *algoProgress) = progress; + } + //cout << progress << " " << *algoProgressTic << " " << netgen::multithread.task << " "<< _ticTime << endl; + + return Min( progress, 0.99 ); } //================================================================================ diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx index b87e377..1bf8b5b 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx @@ -117,7 +117,9 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Mesher bool Evaluate(MapShapeNbElems& aResMap); - double GetProgress(const SMESH_Algo* holder, const int * algoProgressTic ) const; + double GetProgress(const SMESH_Algo* holder, + const int * algoProgressTic, + const double * algoProgress) const; static void PrepareOCCgeometry(netgen::OCCGeometry& occgeom, const TopoDS_Shape& shape, @@ -184,7 +186,11 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Mesher bool _isViscousLayers2D; netgen::Mesh* _ngMesh; netgen::OCCGeometry* _occgeom; + int _curShapeIndex; + volatile int _progressTic; + volatile double _ticTime; // normalized [0,1] compute time per a SMESH_Algo::_progressTic + volatile double _totalTime; const NETGENPlugin_SimpleHypothesis_2D * _simpleHyp; diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx index d6d1a27..a08639c 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx @@ -95,6 +95,7 @@ bool NETGENPlugin_NETGEN_2D::CheckHypothesis (SMESH_Mesh& aMesh, { _hypothesis = NULL; _isViscousLayers2D = false; + _mesher = NULL; // can work with no hypothesis aStatus = SMESH_Hypothesis::HYP_OK; @@ -155,7 +156,7 @@ void NETGENPlugin_NETGEN_2D::CancelCompute() double NETGENPlugin_NETGEN_2D::GetProgress() const { - return _mesher ? _mesher->GetProgress(this, &_progressTic) : 0; + return _mesher ? _mesher->GetProgress(this, &_progressTic, &_progress) : 0; } //============================================================================= diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx index 071100c..4b90755 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx @@ -29,7 +29,7 @@ // #include "NETGENPlugin_NETGEN_2D3D.hxx" #include "NETGENPlugin_Hypothesis.hxx" -#include "NETGENPlugin_SimpleHypothesis_2D.hxx" +#include "NETGENPlugin_SimpleHypothesis_3D.hxx" #include "NETGENPlugin_Mesher.hxx" #include @@ -40,12 +40,10 @@ #include -#ifdef WITH_SMESH_CANCEL_COMPUTE namespace nglib { #include } #include -#endif using namespace std; @@ -95,6 +93,7 @@ bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis MESSAGE("NETGENPlugin_NETGEN_2D3D::CheckHypothesis"); _hypothesis = NULL; + _mesher = NULL; const list& hyps = GetUsedHypothesis(aMesh, aShape); int nbHyp = hyps.size(); @@ -131,13 +130,12 @@ bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) { -#ifdef WITH_SMESH_CANCEL_COMPUTE netgen::multithread.terminate = 0; -#endif NETGENPlugin_Mesher mesher(&aMesh, aShape, true); mesher.SetParameters(dynamic_cast(_hypothesis)); - mesher.SetParameters(dynamic_cast(_hypothesis)); + mesher.SetParameters(dynamic_cast(_hypothesis)); + mesher.SetSelfPointer( &_mesher ); return mesher.Compute(); } @@ -147,13 +145,28 @@ bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh& aMesh, */ //============================================================================= -#ifdef WITH_SMESH_CANCEL_COMPUTE void NETGENPlugin_NETGEN_2D3D::CancelCompute() { SMESH_Algo::CancelCompute(); netgen::multithread.terminate = 1; } -#endif + +//================================================================================ +/*! + * \brief Return progress of Compute() [0.,1] + */ +//================================================================================ + +double NETGENPlugin_NETGEN_2D3D::GetProgress() const +{ + double & progress = (double &)_progress; + if ( _mesher ) + progress = _mesher->GetProgress(this, &_progressTic, &_progress); + else if ( _progress > 0.001 ) + progress = 0.99; + + return _progress; +} //============================================================================= /*! diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx index b46bb2f..1c06128 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx @@ -33,9 +33,8 @@ #include "NETGENPlugin_Defs.hxx" #include -#include -#include -#include + +class NETGENPlugin_Mesher; class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_2D3D: public SMESH_3D_Algo { @@ -50,9 +49,10 @@ public: virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); -#ifdef WITH_SMESH_CANCEL_COMPUTE virtual void CancelCompute(); -#endif + + virtual double GetProgress() const; + virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, @@ -60,6 +60,7 @@ public: protected: const SMESHDS_Hypothesis* _hypothesis; + NETGENPlugin_Mesher * _mesher; }; #endif -- 2.39.2