From ce97cd97084feb968743b5b5231082af70ba0c78 Mon Sep 17 00:00:00 2001 From: emv Date: Fri, 10 Jul 2020 14:19:31 +0300 Subject: [PATCH] 0025113: Mesh - Progress indication and user break functionality for BRepMesh component Added Progress Indicator to BRep_Mesh --- src/BRepMesh/BRepMesh_BaseMeshAlgo.cxx | 9 +++- src/BRepMesh/BRepMesh_BaseMeshAlgo.hxx | 5 +- .../BRepMesh_ConstrainedBaseMeshAlgo.hxx | 3 +- src/BRepMesh/BRepMesh_Delaun.cxx | 17 ++++-- src/BRepMesh/BRepMesh_Delaun.hxx | 7 ++- .../BRepMesh_DelaunayBaseMeshAlgo.cxx | 8 ++- .../BRepMesh_DelaunayBaseMeshAlgo.hxx | 2 +- ...Mesh_DelaunayDeflectionControlMeshAlgo.hxx | 27 +++++++--- ...BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx | 20 +++++-- src/BRepMesh/BRepMesh_DiscretRoot.hxx | 3 +- src/BRepMesh/BRepMesh_EdgeDiscret.cxx | 4 +- src/BRepMesh/BRepMesh_EdgeDiscret.hxx | 3 +- src/BRepMesh/BRepMesh_FaceDiscret.cxx | 52 +++++++++++++++++-- src/BRepMesh/BRepMesh_FaceDiscret.hxx | 15 +++--- src/BRepMesh/BRepMesh_IncrementalMesh.cxx | 22 +++++--- src/BRepMesh/BRepMesh_IncrementalMesh.hxx | 8 +-- src/BRepMesh/BRepMesh_ModelHealer.cxx | 4 +- src/BRepMesh/BRepMesh_ModelHealer.hxx | 3 +- src/BRepMesh/BRepMesh_ModelPostProcessor.cxx | 4 +- src/BRepMesh/BRepMesh_ModelPostProcessor.hxx | 3 +- src/BRepMesh/BRepMesh_ModelPreProcessor.cxx | 4 +- src/BRepMesh/BRepMesh_ModelPreProcessor.hxx | 3 +- .../BRepMesh_NodeInsertionMeshAlgo.hxx | 9 +++- src/Draw/Draw_VariableCommands.cxx | 1 + src/IMeshData/IMeshData_Status.hxx | 19 +++---- src/IMeshTools/IMeshTools_Context.hxx | 13 ++--- src/IMeshTools/IMeshTools_MeshAlgo.hxx | 4 +- src/IMeshTools/IMeshTools_MeshBuilder.cxx | 14 +++-- src/IMeshTools/IMeshTools_MeshBuilder.hxx | 3 +- src/IMeshTools/IMeshTools_ModelAlgo.hxx | 9 ++-- src/MeshTest/MeshTest.cxx | 10 +++- tests/perf/mesh/bug25113_1 | 21 ++++++++ tests/perf/mesh/bug25113_2 | 21 ++++++++ 33 files changed, 266 insertions(+), 84 deletions(-) create mode 100644 tests/perf/mesh/bug25113_1 create mode 100644 tests/perf/mesh/bug25113_2 diff --git a/src/BRepMesh/BRepMesh_BaseMeshAlgo.cxx b/src/BRepMesh/BRepMesh_BaseMeshAlgo.cxx index dce927a2c4..a9f2a7fafc 100644 --- a/src/BRepMesh/BRepMesh_BaseMeshAlgo.cxx +++ b/src/BRepMesh/BRepMesh_BaseMeshAlgo.cxx @@ -46,7 +46,8 @@ BRepMesh_BaseMeshAlgo::~BRepMesh_BaseMeshAlgo() //======================================================================= void BRepMesh_BaseMeshAlgo::Perform( const IMeshData::IFaceHandle& theDFace, - const IMeshTools_Parameters& theParameters) + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) { try { @@ -61,7 +62,11 @@ void BRepMesh_BaseMeshAlgo::Perform( if (initDataStructure()) { - generateMesh(); + if (!theRange.More()) + { + return; + } + generateMesh(theRange); commitSurfaceTriangulation(); } } diff --git a/src/BRepMesh/BRepMesh_BaseMeshAlgo.hxx b/src/BRepMesh/BRepMesh_BaseMeshAlgo.hxx index 56c03b2e8a..1ab210fe8e 100644 --- a/src/BRepMesh/BRepMesh_BaseMeshAlgo.hxx +++ b/src/BRepMesh/BRepMesh_BaseMeshAlgo.hxx @@ -42,7 +42,8 @@ public: //! Performs processing of the given face. Standard_EXPORT virtual void Perform( const IMeshData::IFaceHandle& theDFace, - const IMeshTools_Parameters& theParameters) Standard_OVERRIDE; + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange = Message_ProgressRange()) Standard_OVERRIDE; DEFINE_STANDARD_RTTI_INLINE(BRepMesh_BaseMeshAlgo, IMeshTools_MeshAlgo) @@ -103,7 +104,7 @@ protected: Standard_EXPORT virtual Standard_Boolean initDataStructure(); //! Generates mesh for the contour stored in data structure. - Standard_EXPORT virtual void generateMesh() = 0; + Standard_EXPORT virtual void generateMesh(const Message_ProgressRange& theRange) = 0; private: diff --git a/src/BRepMesh/BRepMesh_ConstrainedBaseMeshAlgo.hxx b/src/BRepMesh/BRepMesh_ConstrainedBaseMeshAlgo.hxx index 7edd4aac23..38a63aab73 100644 --- a/src/BRepMesh/BRepMesh_ConstrainedBaseMeshAlgo.hxx +++ b/src/BRepMesh/BRepMesh_ConstrainedBaseMeshAlgo.hxx @@ -52,7 +52,8 @@ protected: //! Perfroms processing of generated mesh. //! By default does nothing. //! Expected to be called from method generateMesh() in successor classes. - virtual void postProcessMesh (BRepMesh_Delaun& /*theMesher*/) + virtual void postProcessMesh (BRepMesh_Delaun& /*theMesher*/, + const Message_ProgressRange& /*theRange*/) { } }; diff --git a/src/BRepMesh/BRepMesh_Delaun.cxx b/src/BRepMesh/BRepMesh_Delaun.cxx index f1d4792cd6..5a8d30ffe5 100644 --- a/src/BRepMesh/BRepMesh_Delaun.cxx +++ b/src/BRepMesh/BRepMesh_Delaun.cxx @@ -370,7 +370,7 @@ void BRepMesh_Delaun::compute(IMeshData::VectorOfInteger& theVertexIndexes) createTriangles( theVertexIndexes( anVertexIdx ), aLoopEdges ); // Add other nodes to the mesh - createTrianglesOnNewVertices( theVertexIndexes ); + createTrianglesOnNewVertices (theVertexIndexes, Message_ProgressRange()); } // Destruction of triangles containing a top of the super triangle @@ -523,7 +523,8 @@ void BRepMesh_Delaun::createTriangles(const Standard_Integer theVertexI //purpose : Creation of triangles from the new nodes //======================================================================= void BRepMesh_Delaun::createTrianglesOnNewVertices( - IMeshData::VectorOfInteger& theVertexIndexes) + IMeshData::VectorOfInteger& theVertexIndexes, + const Message_ProgressRange& theRange) { Handle(NCollection_IncAllocator) aAllocator = new NCollection_IncAllocator(IMeshData::MEMORY_BLOCK_SIZE_HUGE); @@ -537,8 +538,13 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices( Standard_Integer anIndex = theVertexIndexes.Lower(); Standard_Integer anUpper = theVertexIndexes.Upper(); - for( ; anIndex <= anUpper; ++anIndex ) + Message_ProgressScope aPS(theRange, "Create triangles on new vertices", anUpper); + for (; anIndex <= anUpper; ++anIndex, aPS.Next()) { + if (!aPS.More()) + { + return; + } aAllocator->Reset(Standard_False); IMeshData::MapOfIntegerInteger aLoopEdges(10, aAllocator); @@ -2207,13 +2213,14 @@ void BRepMesh_Delaun::RemoveVertex( const BRepMesh_Vertex& theVertex ) //function : AddVertices //purpose : Adds some vertices in the triangulation. //======================================================================= -void BRepMesh_Delaun::AddVertices(IMeshData::VectorOfInteger& theVertices) +void BRepMesh_Delaun::AddVertices(IMeshData::VectorOfInteger& theVertices, + const Message_ProgressRange& theRange) { ComparatorOfIndexedVertexOfDelaun aCmp(myMeshData); std::make_heap(theVertices.begin(), theVertices.end(), aCmp); std::sort_heap(theVertices.begin(), theVertices.end(), aCmp); - createTrianglesOnNewVertices(theVertices); + createTrianglesOnNewVertices(theVertices, theRange); } //======================================================================= diff --git a/src/BRepMesh/BRepMesh_Delaun.hxx b/src/BRepMesh/BRepMesh_Delaun.hxx index 5038e89bd8..d60b76dc18 100755 --- a/src/BRepMesh/BRepMesh_Delaun.hxx +++ b/src/BRepMesh/BRepMesh_Delaun.hxx @@ -29,6 +29,7 @@ #include #include #include +#include class Bnd_B2d; class Bnd_Box2d; @@ -75,7 +76,8 @@ public: Standard_EXPORT void RemoveVertex (const BRepMesh_Vertex& theVertex); //! Adds some vertices into the triangulation. - Standard_EXPORT void AddVertices (IMeshData::VectorOfInteger& theVerticesIndices); + Standard_EXPORT void AddVertices (IMeshData::VectorOfInteger& theVerticesIndices, + const Message_ProgressRange& theRange = Message_ProgressRange()); //! Modify mesh to use the edge. //! @return True if done @@ -284,7 +286,8 @@ private: IMeshData::SequenceOfBndB2d& thePolyBoxes); //! Creates the triangles on new nodes. - void createTrianglesOnNewVertices (IMeshData::VectorOfInteger& theVertexIndices); + void createTrianglesOnNewVertices (IMeshData::VectorOfInteger& theVertexIndices, + const Message_ProgressRange& theRange); //! Cleanup mesh from the free triangles. void cleanupMesh(); diff --git a/src/BRepMesh/BRepMesh_DelaunayBaseMeshAlgo.cxx b/src/BRepMesh/BRepMesh_DelaunayBaseMeshAlgo.cxx index 1394bd7a4a..33593dbccf 100644 --- a/src/BRepMesh/BRepMesh_DelaunayBaseMeshAlgo.cxx +++ b/src/BRepMesh/BRepMesh_DelaunayBaseMeshAlgo.cxx @@ -37,7 +37,7 @@ BRepMesh_DelaunayBaseMeshAlgo::~BRepMesh_DelaunayBaseMeshAlgo() //function : generateMesh //purpose : //======================================================================= -void BRepMesh_DelaunayBaseMeshAlgo::generateMesh() +void BRepMesh_DelaunayBaseMeshAlgo::generateMesh(const Message_ProgressRange& theRange) { const Handle(BRepMesh_DataStructureOfDelaun)& aStructure = getStructure(); const Handle(VectorOfPnt)& aNodesMap = getNodesMap(); @@ -53,5 +53,9 @@ void BRepMesh_DelaunayBaseMeshAlgo::generateMesh() BRepMesh_MeshTool aCleaner(aStructure); aCleaner.EraseFreeLinks(); - postProcessMesh(aMesher); + if (!theRange.More()) + { + return; + } + postProcessMesh(aMesher, theRange); } diff --git a/src/BRepMesh/BRepMesh_DelaunayBaseMeshAlgo.hxx b/src/BRepMesh/BRepMesh_DelaunayBaseMeshAlgo.hxx index 81bfdc7c9f..60793d7f4e 100644 --- a/src/BRepMesh/BRepMesh_DelaunayBaseMeshAlgo.hxx +++ b/src/BRepMesh/BRepMesh_DelaunayBaseMeshAlgo.hxx @@ -40,7 +40,7 @@ public: protected: //! Generates mesh for the contour stored in data structure. - Standard_EXPORT virtual void generateMesh() Standard_OVERRIDE; + Standard_EXPORT virtual void generateMesh (const Message_ProgressRange& theRange) Standard_OVERRIDE; }; #endif diff --git a/src/BRepMesh/BRepMesh_DelaunayDeflectionControlMeshAlgo.hxx b/src/BRepMesh/BRepMesh_DelaunayDeflectionControlMeshAlgo.hxx index 7d3fb09f28..128901f558 100644 --- a/src/BRepMesh/BRepMesh_DelaunayDeflectionControlMeshAlgo.hxx +++ b/src/BRepMesh/BRepMesh_DelaunayDeflectionControlMeshAlgo.hxx @@ -47,21 +47,32 @@ public: protected: //! Perfroms processing of generated mesh. Generates surface nodes and inserts them into structure. - virtual void postProcessMesh(BRepMesh_Delaun& theMesher) Standard_OVERRIDE + virtual void postProcessMesh (BRepMesh_Delaun& theMesher, + const Message_ProgressRange& theRange) Standard_OVERRIDE { + Message_ProgressScope aPS(theRange, "Post process mesh", 2); // Insert surface nodes. - DelaunayInsertionBaseClass::postProcessMesh(theMesher); + DelaunayInsertionBaseClass::postProcessMesh (theMesher, aPS.Next()); + if (!aPS.More()) + { + return; + } if (this->getParameters().ControlSurfaceDeflection && this->getStructure()->ElementsOfDomain().Extent() > 0) { - optimizeMesh(theMesher); + optimizeMesh(theMesher, aPS.Next()); + } + else + { + aPS.Next(); } } //! Checks deviation of a mesh from geometrical surface. //! Inserts additional nodes in case of huge deviation. - virtual void optimizeMesh(BRepMesh_Delaun& theMesher) + virtual void optimizeMesh (BRepMesh_Delaun& theMesher, + const Message_ProgressRange& theRange) { Handle(NCollection_IncAllocator) aTmpAlloc = new NCollection_IncAllocator(IMeshData::MEMORY_BLOCK_SIZE_HUGE); @@ -72,8 +83,13 @@ protected: const Standard_Integer aIterationsNb = 11; Standard_Boolean isInserted = Standard_True; + Message_ProgressScope aPS(theRange, "Iteration", aIterationsNb); for (Standard_Integer aPass = 1; aPass <= aIterationsNb && isInserted && !myIsAllDegenerated; ++aPass) { + if (!aPS.More()) + { + return; + } // Reset stop condition myMaxSqDeflection = -1.; myIsAllDegenerated = Standard_True; @@ -83,7 +99,6 @@ protected: { break; } - // Iterate on current triangles IMeshData::IteratorOfMapOfInteger aTriangleIt(this->getStructure()->ElementsOfDomain()); for (; aTriangleIt.More(); aTriangleIt.Next()) @@ -92,7 +107,7 @@ protected: splitTriangleGeometry(aTriangle); } - isInserted = this->insertNodes(myControlNodes, theMesher); + isInserted = this->insertNodes(myControlNodes, theMesher, aPS.Next()); } myCouplesMap.Nullify(); diff --git a/src/BRepMesh/BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx b/src/BRepMesh/BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx index ccbe55278e..d9f46e9c46 100644 --- a/src/BRepMesh/BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx +++ b/src/BRepMesh/BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx @@ -85,23 +85,29 @@ protected: } //! Perfroms processing of generated mesh. Generates surface nodes and inserts them into structure. - virtual void postProcessMesh(BRepMesh_Delaun& theMesher) Standard_OVERRIDE + virtual void postProcessMesh (BRepMesh_Delaun& theMesher, + const Message_ProgressRange& theRange) Standard_OVERRIDE { - InsertionBaseClass::postProcessMesh(theMesher); + if (!theRange.More()) + { + return; + } + InsertionBaseClass::postProcessMesh (theMesher, Message_ProgressRange()); // shouldn't be range passed here? if (!myIsPreProcessSurfaceNodes) { const Handle(IMeshData::ListOfPnt2d) aSurfaceNodes = this->getRangeSplitter().GenerateSurfaceNodes(this->getParameters()); - insertNodes(aSurfaceNodes, theMesher); + insertNodes(aSurfaceNodes, theMesher, theRange); } } //! Inserts nodes into mesh. Standard_Boolean insertNodes( const Handle(IMeshData::ListOfPnt2d)& theNodes, - BRepMesh_Delaun& theMesher) + BRepMesh_Delaun& theMesher, + const Message_ProgressRange& theRange) { if (theNodes.IsNull() || theNodes->IsEmpty()) { @@ -120,7 +126,11 @@ protected: } } - theMesher.AddVertices(aVertexIndexes); + theMesher.AddVertices (aVertexIndexes, theRange); + if (!theRange.More()) + { + return Standard_False; + } return !aVertexIndexes.IsEmpty(); } diff --git a/src/BRepMesh/BRepMesh_DiscretRoot.hxx b/src/BRepMesh/BRepMesh_DiscretRoot.hxx index 361cf0e242..eb549d31b3 100644 --- a/src/BRepMesh/BRepMesh_DiscretRoot.hxx +++ b/src/BRepMesh/BRepMesh_DiscretRoot.hxx @@ -18,6 +18,7 @@ #include #include #include +#include //! This is a common interface for meshing algorithms //! instantiated by Mesh Factory and implemented by plugins. @@ -46,7 +47,7 @@ public: } //! Compute triangulation for set shape. - virtual void Perform() = 0; + virtual void Perform(const Message_ProgressRange& theRange = Message_ProgressRange()) = 0; DEFINE_STANDARD_RTTIEXT(BRepMesh_DiscretRoot,Standard_Transient) diff --git a/src/BRepMesh/BRepMesh_EdgeDiscret.cxx b/src/BRepMesh/BRepMesh_EdgeDiscret.cxx index 4a305440d4..dfdc045065 100644 --- a/src/BRepMesh/BRepMesh_EdgeDiscret.cxx +++ b/src/BRepMesh/BRepMesh_EdgeDiscret.cxx @@ -85,8 +85,10 @@ Handle(IMeshTools_CurveTessellator) BRepMesh_EdgeDiscret::CreateEdgeTessellation //======================================================================= Standard_Boolean BRepMesh_EdgeDiscret::performInternal ( const Handle (IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) { + (void )theRange; myModel = theModel; myParameters = theParameters; diff --git a/src/BRepMesh/BRepMesh_EdgeDiscret.hxx b/src/BRepMesh/BRepMesh_EdgeDiscret.hxx index 82ac8e48d2..2adfc0a847 100644 --- a/src/BRepMesh/BRepMesh_EdgeDiscret.hxx +++ b/src/BRepMesh/BRepMesh_EdgeDiscret.hxx @@ -75,7 +75,8 @@ protected: //! Performs processing of edges of the given model. Standard_EXPORT virtual Standard_Boolean performInternal ( const Handle (IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) Standard_OVERRIDE; + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) Standard_OVERRIDE; private: diff --git a/src/BRepMesh/BRepMesh_FaceDiscret.cxx b/src/BRepMesh/BRepMesh_FaceDiscret.cxx index ce6db2102e..424fdd2c59 100644 --- a/src/BRepMesh/BRepMesh_FaceDiscret.cxx +++ b/src/BRepMesh/BRepMesh_FaceDiscret.cxx @@ -39,13 +39,46 @@ BRepMesh_FaceDiscret::~BRepMesh_FaceDiscret() { } +//! Auxiliary functor for parallel processing of Faces. +class BRepMesh_FaceDiscret::FaceListFunctor +{ +public: + FaceListFunctor (BRepMesh_FaceDiscret* theAlgo, + const Message_ProgressRange& theRange) + : myAlgo (theAlgo), + myScope (theRange, "Face Discret", theAlgo->myModel->FacesNb()) + { + myRanges.reserve (theAlgo->myModel->FacesNb()); + for (Standard_Integer aFaceIter = 0; aFaceIter < theAlgo->myModel->FacesNb(); ++aFaceIter) + { + myRanges.push_back (myScope.Next()); + } + } + + void operator() (const Standard_Integer theFaceIndex) const + { + if (!myScope.More()) + { + return; + } + Message_ProgressScope aFaceScope(myRanges[theFaceIndex], NULL, 1); + myAlgo->process(theFaceIndex, aFaceScope.Next()); + } + +private: + mutable BRepMesh_FaceDiscret* myAlgo; + Message_ProgressScope myScope; + std::vector myRanges; +}; + //======================================================================= // Function: Perform // Purpose : //======================================================================= Standard_Boolean BRepMesh_FaceDiscret::performInternal( const Handle(IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) { myModel = theModel; myParameters = theParameters; @@ -54,7 +87,12 @@ Standard_Boolean BRepMesh_FaceDiscret::performInternal( return Standard_False; } - OSD_Parallel::For(0, myModel->FacesNb(), *this, !(myParameters.InParallel && myModel->FacesNb() > 1)); + FaceListFunctor aFunctor(this, theRange); + OSD_Parallel::For(0, myModel->FacesNb(), aFunctor, !(myParameters.InParallel && myModel->FacesNb() > 1)); + if (!theRange.More()) + { + return Standard_False; + } myModel.Nullify(); // Do not hold link to model. return Standard_True; @@ -64,7 +102,8 @@ Standard_Boolean BRepMesh_FaceDiscret::performInternal( // Function: process // Purpose : //======================================================================= -void BRepMesh_FaceDiscret::process(const Standard_Integer theFaceIndex) const +void BRepMesh_FaceDiscret::process(const Standard_Integer theFaceIndex, + const Message_ProgressRange& theRange) const { const IMeshData::IFaceHandle& aDFace = myModel->GetFace(theFaceIndex); if (aDFace->IsSet(IMeshData_Failure) || @@ -86,7 +125,12 @@ void BRepMesh_FaceDiscret::process(const Standard_Integer theFaceIndex) const return; } - aMeshingAlgo->Perform(aDFace, myParameters); + if (!theRange.More()) + { + aDFace->SetStatus (IMeshData_UserBreak); + return; + } + aMeshingAlgo->Perform(aDFace, myParameters, theRange); } catch (Standard_Failure const&) { diff --git a/src/BRepMesh/BRepMesh_FaceDiscret.hxx b/src/BRepMesh/BRepMesh_FaceDiscret.hxx index 9ca86800b6..a7b550f1b2 100644 --- a/src/BRepMesh/BRepMesh_FaceDiscret.hxx +++ b/src/BRepMesh/BRepMesh_FaceDiscret.hxx @@ -20,6 +20,7 @@ #include #include #include +#include //! Class implements functionality starting triangulation of model's faces. //! Each face is processed separately and can be executed in parallel mode. @@ -36,11 +37,6 @@ public: //! Destructor. Standard_EXPORT virtual ~BRepMesh_FaceDiscret(); - //! Functor API to discretize the given edge. - inline void operator() (const Standard_Integer theFaceIndex) const { - process(theFaceIndex); - } - DEFINE_STANDARD_RTTI_INLINE(BRepMesh_FaceDiscret, IMeshTools_ModelAlgo) protected: @@ -48,12 +44,17 @@ protected: //! Performs processing of faces of the given model. Standard_EXPORT virtual Standard_Boolean performInternal ( const Handle(IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) Standard_OVERRIDE; + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) Standard_OVERRIDE; private: //! Checks existing discretization of the face and updates data model. - void process(const Standard_Integer theFaceIndex) const; + void process (const Standard_Integer theFaceIndex, + const Message_ProgressRange& theRange) const; + +private: + class FaceListFunctor; private: diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx index 25627edc83..cfae699e78 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx @@ -66,11 +66,12 @@ BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh( const TopoDS_Shape& theSh //======================================================================= BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh( const TopoDS_Shape& theShape, - const IMeshTools_Parameters& theParameters) + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) : myParameters(theParameters) { myShape = theShape; - Perform(); + Perform(theRange); } //======================================================================= @@ -85,17 +86,17 @@ BRepMesh_IncrementalMesh::~BRepMesh_IncrementalMesh() //function : Perform //purpose : //======================================================================= -void BRepMesh_IncrementalMesh::Perform() +void BRepMesh_IncrementalMesh::Perform(const Message_ProgressRange& theRange) { Handle(BRepMesh_Context) aContext = new BRepMesh_Context; - Perform (aContext); + Perform (aContext, theRange); } //======================================================================= //function : Perform //purpose : //======================================================================= -void BRepMesh_IncrementalMesh::Perform(const Handle(IMeshTools_Context)& theContext) +void BRepMesh_IncrementalMesh::Perform(const Handle(IMeshTools_Context)& theContext, const Message_ProgressRange& theRange) { initParameters(); @@ -103,9 +104,14 @@ void BRepMesh_IncrementalMesh::Perform(const Handle(IMeshTools_Context)& theCont theContext->ChangeParameters() = myParameters; theContext->ChangeParameters().CleanModel = Standard_False; + Message_ProgressScope aPS(theRange, "Perform incmesh", 10); IMeshTools_MeshBuilder aIncMesh(theContext); - aIncMesh.Perform(); - + aIncMesh.Perform(aPS.Next(9)); + if (!aPS.More()) + { + myStatus = IMeshData_UserBreak; + return; + } myStatus = IMeshData_NoError; const Handle(IMeshData_Model)& aModel = theContext->GetModel(); if (!aModel.IsNull()) @@ -122,7 +128,7 @@ void BRepMesh_IncrementalMesh::Perform(const Handle(IMeshTools_Context)& theCont } } } - + aPS.Next(1); setDone(); } diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx index 4831ffa434..0e64147616 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx @@ -50,13 +50,15 @@ public: //! @name mesher API //! @param theShape shape to be meshed. //! @param theParameters - parameters of meshing Standard_EXPORT BRepMesh_IncrementalMesh(const TopoDS_Shape& theShape, - const IMeshTools_Parameters& theParameters); + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange = Message_ProgressRange()); //! Performs meshing ot the shape. - Standard_EXPORT virtual void Perform() Standard_OVERRIDE; + Standard_EXPORT virtual void Perform(const Message_ProgressRange& theRange = Message_ProgressRange()) Standard_OVERRIDE; //! Performs meshing using custom context; - Standard_EXPORT void Perform(const Handle(IMeshTools_Context)& theContext); + Standard_EXPORT void Perform(const Handle(IMeshTools_Context)& theContext, + const Message_ProgressRange& theRange = Message_ProgressRange()); public: //! @name accessing to parameters. diff --git a/src/BRepMesh/BRepMesh_ModelHealer.cxx b/src/BRepMesh/BRepMesh_ModelHealer.cxx index 6ad9b83f56..8e1421cdb5 100644 --- a/src/BRepMesh/BRepMesh_ModelHealer.cxx +++ b/src/BRepMesh/BRepMesh_ModelHealer.cxx @@ -117,8 +117,10 @@ BRepMesh_ModelHealer::~BRepMesh_ModelHealer() //======================================================================= Standard_Boolean BRepMesh_ModelHealer::performInternal( const Handle(IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) { + (void )theRange; myModel = theModel; myParameters = theParameters; if (myModel.IsNull()) diff --git a/src/BRepMesh/BRepMesh_ModelHealer.hxx b/src/BRepMesh/BRepMesh_ModelHealer.hxx index 2e95c02da4..ec082c8e08 100644 --- a/src/BRepMesh/BRepMesh_ModelHealer.hxx +++ b/src/BRepMesh/BRepMesh_ModelHealer.hxx @@ -61,7 +61,8 @@ protected: //! Performs processing of edges of the given model. Standard_EXPORT virtual Standard_Boolean performInternal ( const Handle(IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) Standard_OVERRIDE; + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) Standard_OVERRIDE; private: diff --git a/src/BRepMesh/BRepMesh_ModelPostProcessor.cxx b/src/BRepMesh/BRepMesh_ModelPostProcessor.cxx index 23150517d5..6e7453fe76 100644 --- a/src/BRepMesh/BRepMesh_ModelPostProcessor.cxx +++ b/src/BRepMesh/BRepMesh_ModelPostProcessor.cxx @@ -179,8 +179,10 @@ BRepMesh_ModelPostProcessor::~BRepMesh_ModelPostProcessor() //======================================================================= Standard_Boolean BRepMesh_ModelPostProcessor::performInternal( const Handle(IMeshData_Model)& theModel, - const IMeshTools_Parameters& /*theParameters*/) + const IMeshTools_Parameters& /*theParameters*/, + const Message_ProgressRange& theRange) { + (void )theRange; if (theModel.IsNull()) { return Standard_False; diff --git a/src/BRepMesh/BRepMesh_ModelPostProcessor.hxx b/src/BRepMesh/BRepMesh_ModelPostProcessor.hxx index 129ba74b9e..f9fc631243 100644 --- a/src/BRepMesh/BRepMesh_ModelPostProcessor.hxx +++ b/src/BRepMesh/BRepMesh_ModelPostProcessor.hxx @@ -39,7 +39,8 @@ protected: //! Performs processing of edges of the given model. Standard_EXPORT virtual Standard_Boolean performInternal ( const Handle(IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) Standard_OVERRIDE; + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) Standard_OVERRIDE; }; #endif diff --git a/src/BRepMesh/BRepMesh_ModelPreProcessor.cxx b/src/BRepMesh/BRepMesh_ModelPreProcessor.cxx index df9d9e48d9..d51dd5f13c 100644 --- a/src/BRepMesh/BRepMesh_ModelPreProcessor.cxx +++ b/src/BRepMesh/BRepMesh_ModelPreProcessor.cxx @@ -250,8 +250,10 @@ BRepMesh_ModelPreProcessor::~BRepMesh_ModelPreProcessor() //======================================================================= Standard_Boolean BRepMesh_ModelPreProcessor::performInternal( const Handle(IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) { + (void )theRange; if (theModel.IsNull()) { return Standard_False; diff --git a/src/BRepMesh/BRepMesh_ModelPreProcessor.hxx b/src/BRepMesh/BRepMesh_ModelPreProcessor.hxx index 031053aa38..eb9943b55a 100644 --- a/src/BRepMesh/BRepMesh_ModelPreProcessor.hxx +++ b/src/BRepMesh/BRepMesh_ModelPreProcessor.hxx @@ -40,7 +40,8 @@ protected: //! Performs processing of edges of the given model. Standard_EXPORT virtual Standard_Boolean performInternal ( const Handle(IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) Standard_OVERRIDE; + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) Standard_OVERRIDE; }; #endif diff --git a/src/BRepMesh/BRepMesh_NodeInsertionMeshAlgo.hxx b/src/BRepMesh/BRepMesh_NodeInsertionMeshAlgo.hxx index 54f80fda62..e1f5b77286 100644 --- a/src/BRepMesh/BRepMesh_NodeInsertionMeshAlgo.hxx +++ b/src/BRepMesh/BRepMesh_NodeInsertionMeshAlgo.hxx @@ -47,11 +47,16 @@ public: //! Performs processing of the given face. virtual void Perform( const IMeshData::IFaceHandle& theDFace, - const IMeshTools_Parameters& theParameters) Standard_OVERRIDE + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) Standard_OVERRIDE { myRangeSplitter.Reset(theDFace, theParameters); myClassifier = new BRepMesh_Classifier; - BaseAlgo::Perform(theDFace, theParameters); + if (!theRange.More()) + { + return; + } + BaseAlgo::Perform(theDFace, theParameters, theRange); myClassifier.Nullify(); } diff --git a/src/Draw/Draw_VariableCommands.cxx b/src/Draw/Draw_VariableCommands.cxx index 21c0affe9b..5450d9cc2d 100644 --- a/src/Draw/Draw_VariableCommands.cxx +++ b/src/Draw/Draw_VariableCommands.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/src/IMeshData/IMeshData_Status.hxx b/src/IMeshData/IMeshData_Status.hxx index 4ba98d7daa..e8348773de 100644 --- a/src/IMeshData/IMeshData_Status.hxx +++ b/src/IMeshData/IMeshData_Status.hxx @@ -19,15 +19,16 @@ //! Enumerates statuses used to notify state of discrete model. enum IMeshData_Status { - IMeshData_NoError = 0x0, //!< Mesh generation is successful. - IMeshData_OpenWire = 0x1, //!< Notifies open wire problem, which can potentially lead to incorrect results. - IMeshData_SelfIntersectingWire = 0x2, //!< Notifies self-intersections on discretized wire, which can potentially lead to incorrect results. - IMeshData_Failure = 0x4, //!< Failed to generate mesh for some faces. - IMeshData_ReMesh = 0x8, //!< Deflection of some edges has been decreased due to interference of discrete model. - IMeshData_UnorientedWire = 0x10, //!< Notifies bad orientation of a wire, which can potentially lead to incorrect results. - IMeshData_TooFewPoints = 0x20, //!< Discrete model contains too few boundary points to generate mesh. - IMeshData_Outdated = 0x40, //!< Existing triangulation of some faces corresponds to greater deflection than specified by parameter. - IMeshData_Reused = 0x80 //!< Existing triangulation of some faces is reused as far as it fits specified deflection. + IMeshData_NoError = 0x0, //!< Mesh generation is successful. + IMeshData_OpenWire = 0x1, //!< Notifies open wire problem, which can potentially lead to incorrect results. + IMeshData_SelfIntersectingWire = 0x2, //!< Notifies self-intersections on discretized wire, which can potentially lead to incorrect results. + IMeshData_Failure = 0x4, //!< Failed to generate mesh for some faces. + IMeshData_ReMesh = 0x8, //!< Deflection of some edges has been decreased due to interference of discrete model. + IMeshData_UnorientedWire = 0x10, //!< Notifies bad orientation of a wire, which can potentially lead to incorrect results. + IMeshData_TooFewPoints = 0x20, //!< Discrete model contains too few boundary points to generate mesh. + IMeshData_Outdated = 0x40, //!< Existing triangulation of some faces corresponds to greater deflection than specified by parameter. + IMeshData_Reused = 0x80, //!< Existing triangulation of some faces is reused as far as it fits specified deflection. + IMeshData_UserBreak = 0x160 //!< User break }; #endif diff --git a/src/IMeshTools/IMeshTools_Context.hxx b/src/IMeshTools/IMeshTools_Context.hxx index fe77996c2e..804d9e272a 100644 --- a/src/IMeshTools/IMeshTools_Context.hxx +++ b/src/IMeshTools/IMeshTools_Context.hxx @@ -22,6 +22,7 @@ #include #include #include +#include //! Interface class representing context of BRepMesh algorithm. //! Intended to cache discrete model and instances of tools for @@ -64,7 +65,7 @@ public: } // Discretize edges of a model. - return myEdgeDiscret->Perform(myModel, myParameters); + return myEdgeDiscret->Perform(myModel, myParameters, Message_ProgressRange()); } //! Performs healing of discrete model built by DiscretizeEdges() method @@ -79,7 +80,7 @@ public: return myModelHealer.IsNull() ? Standard_True : - myModelHealer->Perform(myModel, myParameters); + myModelHealer->Perform (myModel, myParameters, Message_ProgressRange()); } //! Performs pre-processing of discrete model using assigned algorithm. @@ -94,12 +95,12 @@ public: return myPreProcessor.IsNull() ? Standard_True : - myPreProcessor->Perform(myModel, myParameters); + myPreProcessor->Perform (myModel, myParameters, Message_ProgressRange()); } //! Performs meshing of faces of discrete model using assigned meshing algorithm. //! @return True on success, False elsewhere. - Standard_EXPORT virtual Standard_Boolean DiscretizeFaces() + virtual Standard_Boolean DiscretizeFaces (const Message_ProgressRange& theRange) { if (myModel.IsNull() || myFaceDiscret.IsNull()) { @@ -107,7 +108,7 @@ public: } // Discretize faces of a model. - return myFaceDiscret->Perform(myModel, myParameters); + return myFaceDiscret->Perform (myModel, myParameters, theRange); } //! Performs post-processing of discrete model using assigned algorithm. @@ -121,7 +122,7 @@ public: return myPostProcessor.IsNull() ? Standard_True : - myPostProcessor->Perform(myModel, myParameters); + myPostProcessor->Perform(myModel, myParameters, Message_ProgressRange()); } //! Cleans temporary context data. diff --git a/src/IMeshTools/IMeshTools_MeshAlgo.hxx b/src/IMeshTools/IMeshTools_MeshAlgo.hxx index fb8e0b6d49..fd47075d0f 100644 --- a/src/IMeshTools/IMeshTools_MeshAlgo.hxx +++ b/src/IMeshTools/IMeshTools_MeshAlgo.hxx @@ -19,6 +19,7 @@ #include #include #include +#include struct IMeshTools_Parameters; @@ -35,7 +36,8 @@ public: //! Performs processing of the given face. Standard_EXPORT virtual void Perform( const IMeshData::IFaceHandle& theDFace, - const IMeshTools_Parameters& theParameters) = 0; + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) = 0; DEFINE_STANDARD_RTTI_INLINE(IMeshTools_MeshAlgo, Standard_Transient) diff --git a/src/IMeshTools/IMeshTools_MeshBuilder.cxx b/src/IMeshTools/IMeshTools_MeshBuilder.cxx index 3b67a6c798..8eb10b9081 100644 --- a/src/IMeshTools/IMeshTools_MeshBuilder.cxx +++ b/src/IMeshTools/IMeshTools_MeshBuilder.cxx @@ -47,7 +47,7 @@ IMeshTools_MeshBuilder::~IMeshTools_MeshBuilder () // Function: Perform // Purpose : //======================================================================= -void IMeshTools_MeshBuilder::Perform () +void IMeshTools_MeshBuilder::Perform (const Message_ProgressRange& theRange) { ClearStatus (); @@ -58,6 +58,8 @@ void IMeshTools_MeshBuilder::Perform () return; } + Message_ProgressScope aPS(theRange, "Mesh Perform", 10); + if (aContext->BuildModel ()) { if (aContext->DiscretizeEdges ()) @@ -66,7 +68,7 @@ void IMeshTools_MeshBuilder::Perform () { if (aContext->PreProcessModel()) { - if (aContext->DiscretizeFaces()) + if (aContext->DiscretizeFaces(aPS.Next(9))) { if (aContext->PostProcessModel()) { @@ -79,6 +81,12 @@ void IMeshTools_MeshBuilder::Perform () } else { + if (!aPS.More()) + { + SetStatus(Message_Fail8); + aContext->Clean(); + return; + } SetStatus(Message_Fail6); } } @@ -113,6 +121,6 @@ void IMeshTools_MeshBuilder::Perform () Message_Warn1 : Message_Fail2); } } - + aPS.Next(1); aContext->Clean (); } diff --git a/src/IMeshTools/IMeshTools_MeshBuilder.hxx b/src/IMeshTools/IMeshTools_MeshBuilder.hxx index 8c0d314224..83e41edc93 100644 --- a/src/IMeshTools/IMeshTools_MeshBuilder.hxx +++ b/src/IMeshTools/IMeshTools_MeshBuilder.hxx @@ -19,6 +19,7 @@ #include #include #include +#include //! Builds mesh for each face of shape without triangulation. //! In case if some faces of shape have already been triangulated @@ -62,7 +63,7 @@ public: } //! Performs meshing ot the shape using current context. - Standard_EXPORT virtual void Perform (); + Standard_EXPORT virtual void Perform (const Message_ProgressRange& theRange); DEFINE_STANDARD_RTTI_INLINE(IMeshTools_MeshBuilder, Message_Algorithm) diff --git a/src/IMeshTools/IMeshTools_ModelAlgo.hxx b/src/IMeshTools/IMeshTools_ModelAlgo.hxx index 963c880c75..e7e38cdd05 100644 --- a/src/IMeshTools/IMeshTools_ModelAlgo.hxx +++ b/src/IMeshTools/IMeshTools_ModelAlgo.hxx @@ -20,6 +20,7 @@ #include #include #include +#include class IMeshData_Model; struct IMeshTools_Parameters; @@ -37,13 +38,14 @@ public: //! Exceptions protected processing of the given model. Standard_Boolean Perform ( const Handle (IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) { try { OCC_CATCH_SIGNALS - return performInternal (theModel, theParameters); + return performInternal (theModel, theParameters, theRange); } catch (Standard_Failure const&) { @@ -63,7 +65,8 @@ protected: //! Performs processing of the given model. Standard_EXPORT virtual Standard_Boolean performInternal ( const Handle (IMeshData_Model)& theModel, - const IMeshTools_Parameters& theParameters) = 0; + const IMeshTools_Parameters& theParameters, + const Message_ProgressRange& theRange) = 0; }; #endif \ No newline at end of file diff --git a/src/MeshTest/MeshTest.cxx b/src/MeshTest/MeshTest.cxx index bfb0c5cd99..5d337dee44 100644 --- a/src/MeshTest/MeshTest.cxx +++ b/src/MeshTest/MeshTest.cxx @@ -32,11 +32,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -157,7 +159,8 @@ options:\n\ di << "Incremental Mesh, multi-threading " << (aMeshParams.InParallel ? "ON" : "OFF") << "\n"; - BRepMesh_IncrementalMesh aMesher (aShape, aMeshParams); + Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1); + BRepMesh_IncrementalMesh aMesher (aShape, aMeshParams, aProgress->Start()); di << "Meshing statuses: "; const Standard_Integer aStatus = aMesher.GetStatusFlags(); @@ -168,7 +171,7 @@ options:\n\ else { Standard_Integer i; - for (i = 0; i < 8; i++) + for (i = 0; i < 9; i++) { Standard_Integer aFlag = aStatus & (1 << i); if (aFlag) @@ -199,6 +202,9 @@ options:\n\ case IMeshData_Reused: di << "Reused "; break; + case IMeshData_UserBreak: + di << "User break"; + break; case IMeshData_NoError: default: break; diff --git a/tests/perf/mesh/bug25113_1 b/tests/perf/mesh/bug25113_1 new file mode 100644 index 0000000000..4d65740b87 --- /dev/null +++ b/tests/perf/mesh/bug25113_1 @@ -0,0 +1,21 @@ +puts "=========" +puts "0025113: Progress indicator in mesh" +puts "=========" +puts "" + +restore [locate_data_file bug21134_r.brep] a +tclean a +XProgress +t +set output [incmesh a 0.005] + +set ctr { "Perform incmesh" "Mesh Perform" + "Face Discret" "100%" + "Create triangles on new vertices" } + +foreach data ${ctr} { + if ![regexp $data $output] { + puts "Error: Non parallel version incmesh command: Mismatch data on '$data'" + break; + } +} + diff --git a/tests/perf/mesh/bug25113_2 b/tests/perf/mesh/bug25113_2 new file mode 100644 index 0000000000..80a197b41c --- /dev/null +++ b/tests/perf/mesh/bug25113_2 @@ -0,0 +1,21 @@ +puts "=========" +puts "0025113: Progress indicator in mesh" +puts "=========" +puts "" + +restore [locate_data_file bug21134_r.brep] a +tclean a +XProgress +t +set output [incmesh a 0.005 -parallel] + +set ctr { "Perform incmesh" "Mesh Perform" + "Face Discret" "100%" + "Create triangles on new vertices" } + +foreach data ${ctr} { + if ![regexp $data $output] { + puts "Error: Parallel version incmesh command for: Mismatch data on '$data'" + break; + } +} +