From 88fc047ff042f8b82e8356ccfc8f77c677d0d8d3 Mon Sep 17 00:00:00 2001 From: akaftasev Date: Wed, 15 Jul 2020 17:23:32 +0300 Subject: [PATCH] 0025113: Added progress indicator to BRepMesh_IncrementalMesh [backport for OCCT 7.2.0] --- src/BOPAlgo/BOPAlgo_BOPAlgo_msg.pxx | 5 +- src/BRepMesh/BRepMesh_Delaun.cxx | 49 +++++--- src/BRepMesh/BRepMesh_Delaun.hxx | 17 ++- src/BRepMesh/BRepMesh_DiscretRoot.hxx | 3 - src/BRepMesh/BRepMesh_FaceSentry.hxx | 64 ----------- src/BRepMesh/BRepMesh_FastDiscret.cxx | 17 ++- src/BRepMesh/BRepMesh_FastDiscret.hxx | 29 ++--- src/BRepMesh/BRepMesh_FastDiscretFace.cxx | 45 +++++--- src/BRepMesh/BRepMesh_FastDiscretFace.hxx | 19 +-- src/BRepMesh/BRepMesh_IncrementalMesh.cxx | 134 ++++++++++++++-------- src/BRepMesh/BRepMesh_IncrementalMesh.hxx | 26 ++--- src/BRepMesh/FILES | 1 - src/MeshTest/MeshTest.cxx | 5 +- src/Message/Message_ProgressSentry.cxx | 6 +- src/Message/Message_ProgressSentry.hxx | 5 - src/Message/Message_ProgressSentry.lxx | 20 +--- 16 files changed, 215 insertions(+), 230 deletions(-) delete mode 100644 src/BRepMesh/BRepMesh_FaceSentry.hxx diff --git a/src/BOPAlgo/BOPAlgo_BOPAlgo_msg.pxx b/src/BOPAlgo/BOPAlgo_BOPAlgo_msg.pxx index c63a53875c..6e8a00b3d5 100644 --- a/src/BOPAlgo/BOPAlgo_BOPAlgo_msg.pxx +++ b/src/BOPAlgo/BOPAlgo_BOPAlgo_msg.pxx @@ -69,4 +69,7 @@ static const char BOPAlgo_BOPAlgo_msg[] = "Warning: Removal of internal boundaries among Faces has failed\n" "\n" ".BOPAlgo_AlertRemovalOfIBForEdgesFailed\n" - "Warning: Removal of internal boundaries among Edges has failed\n"; + "Warning: Removal of internal boundaries among Edges has failed\n" + "\n" + ".BOPAlgo_AlertSolidBuilderUnusedFaces\n" + "Warning: Some of the faces passed to the Solid Builder algorithm have not been classified and not used for solids creation\n"; diff --git a/src/BRepMesh/BRepMesh_Delaun.cxx b/src/BRepMesh/BRepMesh_Delaun.cxx index 72cf0bc962..26d3fce6ea 100644 --- a/src/BRepMesh/BRepMesh_Delaun.cxx +++ b/src/BRepMesh/BRepMesh_Delaun.cxx @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -305,8 +306,7 @@ void BRepMesh_Delaun::compute(BRepMesh::Array1OfInteger& theVertexIndexes) void BRepMesh_Delaun::createTriangles(const Standard_Integer theVertexIndex, BRepMesh::MapOfIntegerInteger& thePoly) { - Message_ProgressSentry aSentry(NULL, "", 0, 100, 1); - createTriangles(theVertexIndex, thePoly, aSentry); + createTriangles (theVertexIndex, thePoly, NULL); } //======================================================================= @@ -315,7 +315,7 @@ void BRepMesh_Delaun::createTriangles(const Standard_Integer theVertexIn //======================================================================= void BRepMesh_Delaun::createTriangles(const Standard_Integer theVertexIndex, BRepMesh::MapOfIntegerInteger& thePoly, - Message_ProgressSentry& theProgressEntry) + Message_ProgressSentry* theProgressEntry) { BRepMesh::ListOfInteger aLoopEdges, anExternalEdges; const gp_XY& aVertexCoord = myMeshData->GetNode( theVertexIndex ).Coord(); @@ -323,7 +323,7 @@ void BRepMesh_Delaun::createTriangles(const Standard_Integer theVertexIn BRepMesh::MapOfIntegerInteger::Iterator anEdges( thePoly ); for ( ; anEdges.More(); anEdges.Next() ) { - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } @@ -424,7 +424,7 @@ void BRepMesh_Delaun::createTriangles(const Standard_Integer theVertexIn while ( !aLoopEdges.IsEmpty() ) { - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } @@ -446,8 +446,7 @@ void BRepMesh_Delaun::createTriangles(const Standard_Integer theVertexIn void BRepMesh_Delaun::createTrianglesOnNewVertices( BRepMesh::Array1OfInteger& theVertexIndexes) { - Message_ProgressSentry aSentry(NULL, "", 0, 100, 1); - createTrianglesOnNewVertices(theVertexIndexes, aSentry); + createTrianglesOnNewVertices (theVertexIndexes, NULL); } //======================================================================= @@ -456,7 +455,7 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices( //======================================================================= void BRepMesh_Delaun::createTrianglesOnNewVertices( BRepMesh::Array1OfInteger& theVertexIndexes, - Message_ProgressSentry& theProgressEntry) + Message_ProgressSentry* theProgressEntry) { Handle(NCollection_IncAllocator) aAllocator = new NCollection_IncAllocator(BRepMesh::MEMORY_BLOCK_SIZE_HUGE); @@ -472,10 +471,11 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices( Standard_Integer anUpper = theVertexIndexes.Upper(); for( ; anIndex <= anUpper; ++anIndex ) { - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } + aAllocator->Reset(Standard_False); BRepMesh::MapOfIntegerInteger aLoopEdges(10, aAllocator); @@ -519,10 +519,11 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices( isModify = Standard_True; while ( isModify && !aCirclesList.IsEmpty() ) { - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } + isModify = Standard_False; BRepMesh::ListOfInteger::Iterator aCircleIt1( aCirclesList ); for ( ; aCircleIt1.More(); aCircleIt1.Next() ) @@ -543,7 +544,7 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices( } } - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } @@ -552,15 +553,17 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices( createTriangles( aVertexIdx, aLoopEdges, theProgressEntry ); } } - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } - insertInternalEdges(theProgressEntry); - if (!theProgressEntry.More()) + + insertInternalEdges (theProgressEntry); + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } + // Adjustment of meshes to boundary edges frontierAdjust(); } @@ -571,15 +574,14 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices( //======================================================================= void BRepMesh_Delaun::insertInternalEdges() { - Message_ProgressSentry aSentry(NULL, "", 0, 100, 1); - insertInternalEdges(aSentry); + insertInternalEdges (NULL); } //======================================================================= //function : insertInternalEdges //purpose : //======================================================================= -void BRepMesh_Delaun::insertInternalEdges(Message_ProgressSentry& theProgressEntry) +void BRepMesh_Delaun::insertInternalEdges (Message_ProgressSentry* theProgressEntry) { BRepMesh::HMapOfInteger anInternalEdges = InternalEdges(); @@ -590,10 +592,11 @@ void BRepMesh_Delaun::insertInternalEdges(Message_ProgressSentry& theProgressEnt BRepMesh::MapOfInteger::Iterator anInernalEdgesIt( *anInternalEdges ); for ( ; anInernalEdgesIt.More(); anInernalEdgesIt.Next() ) { - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } + const Standard_Integer aLinkIndex = anInernalEdgesIt.Key(); const BRepMesh_PairOfIndex& aPair = myMeshData->ElementsConnectedTo(aLinkIndex); @@ -2158,13 +2161,21 @@ void BRepMesh_Delaun::RemoveVertex( const BRepMesh_Vertex& theVertex ) } } +//======================================================================= +//function : AddVertices +//purpose : Adds some vertices in the triangulation. +//======================================================================= +void BRepMesh_Delaun::AddVertices(BRepMesh::Array1OfVertexOfDelaun& theVertices) +{ + AddVertices (theVertices, NULL); +} //======================================================================= //function : AddVertices //purpose : Adds some vertices in the triangulation. //======================================================================= void BRepMesh_Delaun::AddVertices(BRepMesh::Array1OfVertexOfDelaun& theVertices, - Message_ProgressSentry& theProgressEntry) + Message_ProgressSentry* theProgressEntry) { std::make_heap(theVertices.begin(), theVertices.end(), ComparatorOfVertexOfDelaun()); std::sort_heap(theVertices.begin(), theVertices.end(), ComparatorOfVertexOfDelaun()); diff --git a/src/BRepMesh/BRepMesh_Delaun.hxx b/src/BRepMesh/BRepMesh_Delaun.hxx index 33f564780b..18f1339c11 100755 --- a/src/BRepMesh/BRepMesh_Delaun.hxx +++ b/src/BRepMesh/BRepMesh_Delaun.hxx @@ -29,11 +29,11 @@ #include #include #include -#include class Bnd_B2d; class Bnd_Box2d; class BRepMesh_Vertex; +class Message_ProgressSentry; //! Compute the Delaunay's triangulation with the algorithm of Watson. class BRepMesh_Delaun @@ -60,8 +60,11 @@ public: Standard_EXPORT void RemoveVertex (const BRepMesh_Vertex& theVertex); //! Adds some vertices into the triangulation. - Standard_EXPORT void AddVertices (BRepMesh::Array1OfVertexOfDelaun& theVertices, - Message_ProgressSentry& theProgressEntry); + Standard_EXPORT void AddVertices (BRepMesh::Array1OfVertexOfDelaun& theVertices); + + //! Adds some vertices into the triangulation. + Standard_EXPORT void AddVertices (BRepMesh::Array1OfVertexOfDelaun& theVertices, + Message_ProgressSentry* theProgressEntry); //! Modify mesh to use the edge. //! @return True if done @@ -223,9 +226,10 @@ private: //! Creates the triangles beetween the given node and the given polyline. void createTriangles (const Standard_Integer theVertexIndex, BRepMesh::MapOfIntegerInteger& thePoly); + void createTriangles (const Standard_Integer theVertexIndex, BRepMesh::MapOfIntegerInteger& thePoly, - Message_ProgressSentry& theProgressEntry); + Message_ProgressSentry* theProgressEntry); //! Add a triangle based on the given oriented edges into mesh void addTriangle (const Standard_Integer (&theEdgesId)[3], @@ -259,7 +263,8 @@ private: //! Creates the triangles on new nodes. void createTrianglesOnNewVertices (BRepMesh::Array1OfInteger& theVertexIndices, - Message_ProgressSentry& theProgressEntry); + Message_ProgressSentry* theProgressEntry); + //! Creates the triangles on new nodes. void createTrianglesOnNewVertices (BRepMesh::Array1OfInteger& theVertexIndices); @@ -332,7 +337,7 @@ private: void insertInternalEdges(); //! Performs insertion of internal edges into mesh. - void insertInternalEdges(Message_ProgressSentry& theProgressEntry); + void insertInternalEdges (Message_ProgressSentry* theProgressEntry); private: diff --git a/src/BRepMesh/BRepMesh_DiscretRoot.hxx b/src/BRepMesh/BRepMesh_DiscretRoot.hxx index a2aed351f6..7abcb4cabe 100644 --- a/src/BRepMesh/BRepMesh_DiscretRoot.hxx +++ b/src/BRepMesh/BRepMesh_DiscretRoot.hxx @@ -18,7 +18,6 @@ #include #include #include -#include //! This is a common interface for meshing algorithms //! instantiated by Mesh Factory and implemented by plugins. @@ -50,8 +49,6 @@ public: Standard_EXPORT virtual void Perform () =0; - - DEFINE_STANDARD_RTTIEXT(BRepMesh_DiscretRoot,Standard_Transient) protected: diff --git a/src/BRepMesh/BRepMesh_FaceSentry.hxx b/src/BRepMesh/BRepMesh_FaceSentry.hxx deleted file mode 100644 index 6674785f5c..0000000000 --- a/src/BRepMesh/BRepMesh_FaceSentry.hxx +++ /dev/null @@ -1,64 +0,0 @@ -// Created: 2020-07-27 -// -// Copyright (c) 2020 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef BRepMesh_FaceSentry_HeaderFile -#define BRepMesh_FaceSentry_HeaderFile - -#include - -class Message_ProgressSentry; - -class BRepMesh_FaceSentry -{ -public: - BRepMesh_FaceSentry() - :mySentry(0L), isParallel(Standard_False) - { - } - - BRepMesh_FaceSentry (const TopoDS_Face& theFace, - Message_ProgressSentry* theSentry = 0L, - Standard_Boolean theParallel = Standard_False) - :myFace(theFace), mySentry(theSentry), - isParallel(theParallel) - { - } - - //! Get progress sentry - Message_ProgressSentry* GetProgressEntry() const - { - return mySentry; - } - - //! Return reference on TopoDS_Face - const TopoDS_Face& GetFace() const - { - return myFace; - } - - //! Returns isParallel - Standard_Boolean IsParallel() const - { - return isParallel; - } - - -private: - TopoDS_Face myFace; - Message_ProgressSentry* mySentry; - Standard_Boolean isParallel; -}; - -#endif \ No newline at end of file diff --git a/src/BRepMesh/BRepMesh_FastDiscret.cxx b/src/BRepMesh/BRepMesh_FastDiscret.cxx index 3f0de78944..f64de14122 100644 --- a/src/BRepMesh/BRepMesh_FastDiscret.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscret.cxx @@ -68,6 +68,7 @@ #include #include +#include #include #include @@ -123,15 +124,25 @@ void BRepMesh_FastDiscret::Perform(const TopoDS_Shape& theShape) OSD_Parallel::ForEach(aFaces.begin(), aFaces.end(), *this, !myParameters.InParallel); } +//======================================================================= +//function : Process +//purpose : +//======================================================================= +void BRepMesh_FastDiscret::Process(const TopoDS_Face& theFace) const +{ + Process (theFace, NULL); +} //======================================================================= //function : Process //purpose : //======================================================================= -void BRepMesh_FastDiscret::Process(const TopoDS_Face& theFace, Message_ProgressSentry& theProgrEntry) const +void BRepMesh_FastDiscret::Process (const TopoDS_Face& theFace, + Message_ProgressSentry* theProgrEntry) const { Handle(BRepMesh_FaceAttribute) anAttribute; - if (GetFaceAttribute(theFace, anAttribute) && theProgrEntry.More()) + if (GetFaceAttribute(theFace, anAttribute) + && (theProgrEntry == NULL || theProgrEntry->More())) { try { @@ -139,7 +150,7 @@ void BRepMesh_FastDiscret::Process(const TopoDS_Face& theFace, Message_ProgressS BRepMesh_FastDiscretFace aTool(myParameters.Angle, myParameters.MinSize, myParameters.InternalVerticesMode, myParameters.ControlSurfaceDeflection); - aTool.Perform(anAttribute, theProgrEntry); + aTool.Perform (anAttribute, theProgrEntry); } catch (Standard_Failure) { diff --git a/src/BRepMesh/BRepMesh_FastDiscret.hxx b/src/BRepMesh/BRepMesh_FastDiscret.hxx index b7691afd76..87cc55587d 100644 --- a/src/BRepMesh/BRepMesh_FastDiscret.hxx +++ b/src/BRepMesh/BRepMesh_FastDiscret.hxx @@ -34,9 +34,6 @@ #include #include #include -#include -#include -#include class BRepMesh_DataStructureOfDelaun; class Bnd_Box; @@ -49,6 +46,7 @@ class BRepMesh_Edge; class BRepMesh_Vertex; class gp_Pnt; class BRepMesh_FaceAttribute; +class Message_ProgressSentry; //! Algorithm to mesh a shape with respect of the
//! frontier the deflection and by option the shared
@@ -130,24 +128,17 @@ public: //! Triangulate a face previously recorded for //! processing by call to Add(). Can be executed in //! parallel threads. - Standard_EXPORT void Process(const TopoDS_Face& theFace, Message_ProgressSentry& theProgrEntry) const; + Standard_EXPORT void Process(const TopoDS_Face& face) const; - void operator () (const BRepMesh_FaceSentry& aFaceSentry) const + //! Triangulate a face previously recorded for + //! processing by call to Add(). Can be executed in + //! parallel threads. + Standard_EXPORT void Process (const TopoDS_Face& theFace, + Message_ProgressSentry* theProgrEntry) const; + + void operator () (const TopoDS_Face& face) const { - if (!aFaceSentry.GetProgressEntry()->More()) - { - return; - } - Process(aFaceSentry.GetFace(), *aFaceSentry.GetProgressEntry()); - - if (aFaceSentry.IsParallel()) - { - aFaceSentry.GetProgressEntry()->Next(OSD_Parallel::NbLogicalProcessors()); - } - else - { - aFaceSentry.GetProgressEntry()->Next(); - } + Process(face); } //! Returns parameters of meshing diff --git a/src/BRepMesh/BRepMesh_FastDiscretFace.cxx b/src/BRepMesh/BRepMesh_FastDiscretFace.cxx index ef2011f9fc..ed13287b4a 100644 --- a/src/BRepMesh/BRepMesh_FastDiscretFace.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscretFace.cxx @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -185,11 +186,20 @@ BRepMesh_FastDiscretFace::BRepMesh_FastDiscretFace( //function : Perform //purpose : //======================================================================= +void BRepMesh_FastDiscretFace::Perform(const Handle(BRepMesh_FaceAttribute)& theAttribute) +{ + Perform (theAttribute, NULL); +} + +//======================================================================= +//function : Perform +//purpose : +//======================================================================= void BRepMesh_FastDiscretFace::Perform (const Handle(BRepMesh_FaceAttribute)& theAttribute, - Message_ProgressSentry& theProgressEntry) + Message_ProgressSentry* theProgressEntry) { add(theAttribute, theProgressEntry); - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } @@ -351,7 +361,7 @@ void BRepMesh_FastDiscretFace::addLinkToMesh( //purpose : //======================================================================= void BRepMesh_FastDiscretFace::add (const Handle(BRepMesh_FaceAttribute)& theAttribute, - Message_ProgressSentry& theProgressEntry) + Message_ProgressSentry* theProgressEntry) { if (!theAttribute->IsValid() || theAttribute->ChangeMeshNodes()->IsEmpty()) return; @@ -403,20 +413,22 @@ void BRepMesh_FastDiscretFace::add (const Handle(BRepMesh_FaceAttribute)& theAtt (vmax - vmin) < Precision::PConfusion()); Standard_Real aDef = -1; - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } + if ( !isaline && myStructure->ElementsOfDomain().Extent() > 0 ) { if (!rajout) { // compute maximal deflection aDef = control(trigu, Standard_True, theProgressEntry); - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } + rajout = (aDef > myAttribute->GetDefFace() || aDef < 0.); } if (thetype != GeomAbs_Plane) @@ -430,7 +442,7 @@ void BRepMesh_FastDiscretFace::add (const Handle(BRepMesh_FaceAttribute)& theAtt if (rajout) { insertInternalVertices(trigu, theProgressEntry); - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } @@ -439,7 +451,7 @@ void BRepMesh_FastDiscretFace::add (const Handle(BRepMesh_FaceAttribute)& theAtt if (myIsControlSurfaceDeflection) { aDef = control(trigu, Standard_False, theProgressEntry); - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return; } @@ -472,7 +484,7 @@ void BRepMesh_FastDiscretFace::add (const Handle(BRepMesh_FaceAttribute)& theAtt Standard_Boolean BRepMesh_FastDiscretFace::addVerticesToMesh( const BRepMesh::ListOfVertex& theVertices, BRepMesh_Delaun& theMeshBuilder, - Message_ProgressSentry& theProgressEntry) + Message_ProgressSentry* theProgressEntry) { if (theVertices.IsEmpty()) return Standard_False; @@ -483,7 +495,7 @@ Standard_Boolean BRepMesh_FastDiscretFace::addVerticesToMesh( aArrayOfNewVertices(++aVertexId) = aVertexIt.Value(); theMeshBuilder.AddVertices(aArrayOfNewVertices, theProgressEntry); - return theProgressEntry.More(); + return theProgressEntry == NULL || theProgressEntry->More(); } //======================================================================= @@ -553,7 +565,7 @@ static void filterParameters(const BRepMesh::IMapOfReal& theParams, //purpose : //======================================================================= void BRepMesh_FastDiscretFace::insertInternalVertices (BRepMesh_Delaun& theMeshBuilder, - Message_ProgressSentry& theProgressEntry) + Message_ProgressSentry* theProgressEntry) { Handle(NCollection_IncAllocator) anAlloc = new NCollection_IncAllocator; BRepMesh::ListOfVertex aNewVertices(anAlloc); @@ -1209,7 +1221,7 @@ Standard_Boolean BRepMesh_FastDiscretFace::checkDeflectionAndInsert( Standard_Real BRepMesh_FastDiscretFace::control( BRepMesh_Delaun& theTrigu, const Standard_Boolean theIsFirst, - Message_ProgressSentry& theProgressEntry) + Message_ProgressSentry* theProgressEntry) { Standard_Integer aTrianglesNb = myStructure->ElementsOfDomain().Extent(); if (aTrianglesNb < 1) @@ -1246,10 +1258,11 @@ Standard_Real BRepMesh_FastDiscretFace::control( new NCollection_IncAllocator(BRepMesh::MEMORY_BLOCK_SIZE_HUGE); for (; aPass <= aPassesNb && aInsertedNb && !isAllDegenerated; ++aPass) { - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return 0; } + aTempAlloc->Reset(Standard_False); BRepMesh::ListOfVertex aNewVertices(aTempAlloc); @@ -1267,10 +1280,11 @@ Standard_Real BRepMesh_FastDiscretFace::control( BRepMesh::MapOfInteger::Iterator aTriangleIt(aTriangles); for (; aTriangleIt.More(); aTriangleIt.Next()) { - if (!theProgressEntry.More()) + if (theProgressEntry != NULL && !theProgressEntry->More()) { return 0; } + const Standard_Integer aTriangleId = aTriangleIt.Key(); const BRepMesh_Triangle& aCurrentTriangle = myStructure->GetElement(aTriangleId); @@ -1432,11 +1446,12 @@ Standard_Real BRepMesh_FastDiscretFace::control( ftt << "vertex vt" << aPass << "_" << i << " " << aP.X() << " " << aP.Y() << " " << aP.Z() << endl; } -#endif - if (!theProgressEntry.More()) +#endif + if (theProgressEntry != NULL && !theProgressEntry->More()) { return 0; } + if (addVerticesToMesh(aNewVertices, theTrigu, theProgressEntry)) ++aInsertedNb; } diff --git a/src/BRepMesh/BRepMesh_FastDiscretFace.hxx b/src/BRepMesh/BRepMesh_FastDiscretFace.hxx index a3a111be18..dbf301965f 100644 --- a/src/BRepMesh/BRepMesh_FastDiscretFace.hxx +++ b/src/BRepMesh/BRepMesh_FastDiscretFace.hxx @@ -27,7 +27,6 @@ #include #include #include -#include class BRepMesh_DataStructureOfDelaun; class BRepMesh_FaceAttribute; @@ -42,6 +41,7 @@ class gp_Pnt2d; class BRepMesh_Edge; class BRepMesh_Vertex; class gp_Pnt; +class Message_ProgressSentry; //! Algorithm to mesh a face with respect of the frontier //! the deflection and by option the shared components. @@ -61,18 +61,21 @@ public: const Standard_Boolean isInternalVerticesMode, const Standard_Boolean isControlSurfaceDeflection); - Standard_EXPORT void Perform(const Handle(BRepMesh_FaceAttribute)& theAttribute, Message_ProgressSentry& theProgressEntry); - + Standard_EXPORT void Perform(const Handle(BRepMesh_FaceAttribute)& theAttribute); + + Standard_EXPORT void Perform (const Handle(BRepMesh_FaceAttribute)& theAttribute, + Message_ProgressSentry* theProgressEntry); + DEFINE_STANDARD_RTTIEXT(BRepMesh_FastDiscretFace,Standard_Transient) private: - void add(const Handle(BRepMesh_FaceAttribute)& theAttribute, Message_ProgressSentry& theProgressEntry); + void add(const Handle(BRepMesh_FaceAttribute)& theAttribute, Message_ProgressSentry* theProgressEntry); void add(const TopoDS_Vertex& theVertex); Standard_Real control(BRepMesh_Delaun& theMeshBuilder, const Standard_Boolean theIsFirst, - Message_ProgressSentry& theProgressEntry); + Message_ProgressSentry* theProgressEntry); //! Registers the given nodes in mesh data structure and //! performs refinement of existing mesh. @@ -83,13 +86,13 @@ private: Standard_Boolean addVerticesToMesh( const BRepMesh::ListOfVertex& theVertices, BRepMesh_Delaun& theMeshBuilder, - Message_ProgressSentry& theProgressEntry); + Message_ProgressSentry* theProgressEntry); //! Calculates nodes lying on face's surface and inserts them to a mesh. //! @param theMeshBuilder initialized tool refining mesh //! in respect to inserting nodes. - void insertInternalVertices(BRepMesh_Delaun& theMeshBuilder, - Message_ProgressSentry& theProgressEntry); + void insertInternalVertices(BRepMesh_Delaun& theMeshBuilder, + Message_ProgressSentry* theProgressEntry); //! Calculates nodes lying on spherical surface. //! @param theNewVertices list of vertices to be extended and added to mesh. diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx index 7d73621446..e44d979ffb 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx @@ -55,8 +55,6 @@ #include #include -#include - IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_IncrementalMesh,BRepMesh_DiscretRoot) @@ -67,6 +65,51 @@ namespace static Standard_Boolean IS_IN_PARALLEL = Standard_False; } +class BRepMesh_IncrementalMesh::FaceListFunctor +{ +public: + FaceListFunctor (BRepMesh_IncrementalMesh* theAlgo, + const Handle(Message_ProgressIndicator)& theProgress, + Standard_Boolean theParallel) + : myAlgo (theAlgo), + mySentry (theProgress, "Mesh faces", 0, theAlgo->myFaces.Size(), 1), + myThreadId (OSD_Thread::Current()), + myIsParallel (theParallel), + myHasProgress (!theProgress.IsNull()) + { + } + + void operator() (const Standard_Integer theFaceIndex) const + { + if (!mySentry.More()) + { + return; + } + + TopoDS_Face& aFace = myAlgo->myFaces.ChangeValue (theFaceIndex); + myAlgo->myMesh->Process (aFace, &mySentry); + + if (myIsParallel) + { + // use a trick to avoid mutex locks - increment the progress only within main thread + if (myHasProgress && myThreadId == OSD_Thread::Current()) + { + mySentry.Next (OSD_Parallel::NbLogicalProcessors()); + } + } + else + { + mySentry.Next(); + } + } + +private: + mutable BRepMesh_IncrementalMesh* myAlgo; + mutable Message_ProgressSentry mySentry; + Standard_ThreadId myThreadId; + Standard_Boolean myIsParallel; + Standard_Boolean myHasProgress; +}; //======================================================================= //function : Default constructor @@ -107,25 +150,13 @@ BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh( const TopoDS_Shape& theSh //function : Constructor //purpose : //======================================================================= -BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh (const TopoDS_Shape& theShape, - const BRepMesh_FastDiscret::Parameters& theParameters) : - myParameters(theParameters) -{ - myShape = theShape; - Perform(); -} -//======================================================================= -//function : Constructor -//purpose : -//======================================================================= -BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh (const TopoDS_Shape& theShape, - const BRepMesh_FastDiscret::Parameters& theParameters, - const Handle(Message_ProgressIndicator) &theProgress) +BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh(const TopoDS_Shape& theShape, + const BRepMesh_FastDiscret::Parameters& theParameters) : myParameters(theParameters) { myShape = theShape; - Perform(theProgress); + Perform(); } //======================================================================= @@ -219,49 +250,50 @@ void BRepMesh_IncrementalMesh::collectFaces() //======================================================================= void BRepMesh_IncrementalMesh::Perform() { - Handle(Message_ProgressIndicator) aProgress; - Perform(aProgress); + Perform (Handle(Message_ProgressIndicator)()); } //======================================================================= //function : Perform -//purpose : +//purpose : //======================================================================= - -void BRepMesh_IncrementalMesh::Perform(const Handle(Message_ProgressIndicator) &theProgress) +void BRepMesh_IncrementalMesh::Perform (const Handle(Message_ProgressIndicator)& theProgress) { init(); if (myMesh.IsNull()) return; - update(theProgress); + update (theProgress); } //======================================================================= //function : update() //purpose : //======================================================================= -void BRepMesh_IncrementalMesh::update(const Handle(Message_ProgressIndicator) &theProgress) +void BRepMesh_IncrementalMesh::update (const Handle(Message_ProgressIndicator)& theProgress) { - Message_ProgressSentry anOuterSentry(theProgress, "Updating", 0, 100, 1); - + Message_ProgressSentry anOuterSentry (theProgress, "Updating", 0, 100, 1); + // Update edges data - TopExp_Explorer aExplorer(myShape, TopAbs_EDGE); - int aEdgeSize = 0; - for ( ; aExplorer.More(); aExplorer.Next(), aEdgeSize++) - { - } anOuterSentry.Next(9); - aExplorer.Init(myShape, TopAbs_EDGE); - for (Message_ProgressSentry anEdgeSentry(theProgress, "Update edges data", 0, aEdgeSize, 1); - aExplorer.More() && anEdgeSentry.More(); aExplorer.Next(), anEdgeSentry.Next()) { - const TopoDS_Edge& aEdge = TopoDS::Edge(aExplorer.Current()); - if(!BRep_Tool::IsGeometric(aEdge)) - continue; + int aNbEdges = 0; + for (TopExp_Explorer aExplorer (myShape, TopAbs_EDGE); aExplorer.More(); aExplorer.Next()) + { + ++aNbEdges; + } + + Message_ProgressSentry anEdgeSentry (theProgress, "Update edges data", 0, aNbEdges, 1); + for (TopExp_Explorer aExplorer (myShape, TopAbs_EDGE); + aExplorer.More() && anEdgeSentry.More(); aExplorer.Next(), anEdgeSentry.Next()) + { + const TopoDS_Edge& aEdge = TopoDS::Edge(aExplorer.Current()); + if(!BRep_Tool::IsGeometric(aEdge)) + continue; - update(aEdge); + update(aEdge); + } } if (!anOuterSentry.More()) @@ -270,12 +302,11 @@ void BRepMesh_IncrementalMesh::update(const Handle(Message_ProgressIndicator) &t return; } anOuterSentry.Next(5); - - NCollection_Vector aFaces; + // Update faces data NCollection_Vector::Iterator aFaceIt(myFaces); - for (Message_ProgressSentry aFacesSentry(theProgress, "Update faces data", 0, myFaces.Size(), 1); - aFaceIt.More() && aFacesSentry.More(); aFaceIt.Next(), aFacesSentry.Next()) + for (Message_ProgressSentry aFacesSentry (theProgress, "Update faces data", 0, myFaces.Size(), 1); + aFaceIt.More() && aFacesSentry.More(); aFaceIt.Next(), aFacesSentry.Next()) { update(aFaceIt.Value()); } @@ -285,23 +316,26 @@ void BRepMesh_IncrementalMesh::update(const Handle(Message_ProgressIndicator) &t myStatus = BRepMesh_UserBreak; return; } + anOuterSentry.Next(80); - Message_ProgressSentry aProgrSentry(theProgress, "Mesh faces", 0, myFaces.Size(), 1); - for (NCollection_Vector::Iterator aFaceIter(myFaces); aFaceIter.More(); aFaceIter.Next()) { - aFaces.Append(BRepMesh_FaceSentry(aFaceIter.Value(), &aProgrSentry, myParameters.InParallel)); + // Mesh faces + FaceListFunctor aFacesFunctor (this, theProgress, myParameters.InParallel); + OSD_Parallel::For (0, myFaces.Size(), aFacesFunctor, !myParameters.InParallel); } - // Mesh faces - OSD_Parallel::ForEach(aFaces.begin(), aFaces.end(), *myMesh, !myParameters.InParallel); + if (!anOuterSentry.More()) { myStatus = BRepMesh_UserBreak; return; } + anOuterSentry.Next(5); - Message_ProgressSentry aSentry(theProgress, "Commit", 0, myFaces.Size(), 1); - commit(aSentry); + { + Message_ProgressSentry aSentry (theProgress, "Commit", 0, myFaces.Size(), 1); + commit (aSentry); + } anOuterSentry.Next(); clear(); } @@ -559,7 +593,7 @@ void BRepMesh_IncrementalMesh::update(const TopoDS_Face& theFace) //function : commit //purpose : //======================================================================= -void BRepMesh_IncrementalMesh::commit(Message_ProgressSentry& theSentry) +void BRepMesh_IncrementalMesh::commit (Message_ProgressSentry& theSentry) { NCollection_Vector::Iterator aFaceIt(myFaces); for (; aFaceIt.More() && theSentry.More(); aFaceIt.Next(), theSentry.Next()) diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx index 48dfadce44..84541536f9 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx @@ -22,10 +22,10 @@ #include #include #include -#include #include +class Message_ProgressIndicator; class Poly_Triangulation; class TopoDS_Shape; class TopoDS_Edge; @@ -52,7 +52,7 @@ public: //! @name mesher API //! used for the faces will be the maximum deflection of their edges. //! @param theAngDeflection angular deflection. //! @param isInParallel if TRUE shape will be meshed in parallel. - Standard_EXPORT BRepMesh_IncrementalMesh ( + Standard_EXPORT BRepMesh_IncrementalMesh( const TopoDS_Shape& theShape, const Standard_Real theLinDeflection, const Standard_Boolean isRelative = Standard_False, @@ -64,24 +64,15 @@ public: //! @name mesher API //! Automatically calls method Perform. //! @param theShape shape to be meshed. //! @param theParameters - parameters of meshing - Standard_EXPORT BRepMesh_IncrementalMesh (const TopoDS_Shape& theShape, - const BRepMesh_FastDiscret::Parameters& theParameters); - - //! Constructor. - //! Automatically calls method Perform. - //! @param theShape shape to be meshed. - //! @param theParameters - parameters of meshing - //! @param theProgress - progress indicator Standard_EXPORT BRepMesh_IncrementalMesh (const TopoDS_Shape& theShape, - const BRepMesh_FastDiscret::Parameters& theParameters, - const Handle(Message_ProgressIndicator) &theProgress); + const BRepMesh_FastDiscret::Parameters& theParameters); - // //! Performs meshing ot the shape. + //! Performs meshing ot the shape. Standard_EXPORT virtual void Perform() Standard_OVERRIDE; //! Performs meshing ot the shape. - Standard_EXPORT void Perform(const Handle(Message_ProgressIndicator) &theProgress); - + Standard_EXPORT void Perform(const Handle(Message_ProgressIndicator)& theProgress); + public: //! @name accessing to parameters. //! Returns meshing parameters @@ -139,7 +130,7 @@ protected: private: //! Builds the incremental mesh for the shape. - void update(const Handle(Message_ProgressIndicator) &theProgress = NULL); + void update(const Handle(Message_ProgressIndicator)& theProgress); //! Checks triangulation of the given face for consistency //! with the chosen tolerance. If some edge of face has no @@ -188,6 +179,9 @@ private: //! Clears internal data structures. void clear(); +private: + class FaceListFunctor; + protected: BRepMesh::DMapOfEdgeListOfTriangulationBool myEdges; diff --git a/src/BRepMesh/FILES b/src/BRepMesh/FILES index 35ebcbd759..ec39094842 100755 --- a/src/BRepMesh/FILES +++ b/src/BRepMesh/FILES @@ -23,7 +23,6 @@ BRepMesh_EdgeTessellator.cxx BRepMesh_EdgeTessellator.hxx BRepMesh_FaceAttribute.cxx BRepMesh_FaceAttribute.hxx -BRepMesh_FaceSentry.hxx BRepMesh_FactoryError.hxx BRepMesh_FastDiscret.cxx BRepMesh_FastDiscret.hxx diff --git a/src/MeshTest/MeshTest.cxx b/src/MeshTest/MeshTest.cxx index c411dbd837..7db1a42f02 100644 --- a/src/MeshTest/MeshTest.cxx +++ b/src/MeshTest/MeshTest.cxx @@ -197,7 +197,10 @@ options:\n\ aMeshParams.AdaptiveMin = isAdaptiveMin; Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1); - BRepMesh_IncrementalMesh aMesher(aShape, aMeshParams, aProgress); + BRepMesh_IncrementalMesh aMesher; + aMesher.SetShape (aShape); + aMesher.ChangeParameters() = aMeshParams; + aMesher.Perform (aProgress); di << "Meshing statuses: "; Standard_Integer statusFlags = aMesher.GetStatusFlags(); diff --git a/src/Message/Message_ProgressSentry.cxx b/src/Message/Message_ProgressSentry.cxx index 8ce27755a4..2648816f5b 100644 --- a/src/Message/Message_ProgressSentry.cxx +++ b/src/Message/Message_ProgressSentry.cxx @@ -27,8 +27,7 @@ Message_ProgressSentry::Message_ProgressSentry (const Handle(Message_ProgressInd const Standard_Real step, const Standard_Boolean isInf, const Standard_Real newScopeSpan) : - myProgress(progress), myActive(!progress.IsNull()), - myThreadId(OSD_Thread::Current()) + myProgress(progress), myActive(!progress.IsNull()) { if ( ! myActive ) return; progress->SetName ( name ); @@ -48,8 +47,7 @@ Message_ProgressSentry::Message_ProgressSentry (const Handle(Message_ProgressInd const Standard_Real step, const Standard_Boolean isInf, const Standard_Real newScopeSpan) : - myProgress(progress), myActive(!progress.IsNull()), - myThreadId(OSD_Thread::Current()) + myProgress(progress), myActive(!progress.IsNull()) { if ( ! myActive ) return; progress->SetName ( name ); diff --git a/src/Message/Message_ProgressSentry.hxx b/src/Message/Message_ProgressSentry.hxx index 287d191eec..0ffbc5d6a6 100644 --- a/src/Message/Message_ProgressSentry.hxx +++ b/src/Message/Message_ProgressSentry.hxx @@ -23,10 +23,6 @@ #include #include #include - -#include -#include - class Message_ProgressIndicator; class TCollection_HAsciiString; @@ -113,7 +109,6 @@ private: Handle(Message_ProgressIndicator) myProgress; Standard_Boolean myActive; - Standard_ThreadId myThreadId; }; diff --git a/src/Message/Message_ProgressSentry.lxx b/src/Message/Message_ProgressSentry.lxx index 86d9211128..e083a8ce46 100644 --- a/src/Message/Message_ProgressSentry.lxx +++ b/src/Message/Message_ProgressSentry.lxx @@ -20,7 +20,7 @@ inline void Message_ProgressSentry::Relieve () { - if ( !myActive || myThreadId != OSD_Thread::Current()) return; + if ( ! myActive ) return; myProgress->EndScope(); myActive = 0; } @@ -32,10 +32,7 @@ inline void Message_ProgressSentry::Relieve () inline void Message_ProgressSentry::Next (const Standard_CString name) const { - if ( myActive && myThreadId == OSD_Thread::Current()) - { - myProgress->NextScope(name); - } + if ( myActive ) myProgress->NextScope(name); } //======================================================================= @@ -46,10 +43,7 @@ inline void Message_ProgressSentry::Next (const Standard_CString name) const inline void Message_ProgressSentry::Next (const Standard_Real span, const Standard_CString name) const { - if ( myActive && myThreadId == OSD_Thread::Current()) - { - myProgress->NextScope(span, name); - } + if ( myActive ) myProgress->NextScope(span, name); } //======================================================================= @@ -60,8 +54,7 @@ inline void Message_ProgressSentry::Next (const Standard_Real span, inline void Message_ProgressSentry::Next (const Standard_Real span, const Handle(TCollection_HAsciiString)& name) const { - if ( myActive && myThreadId == OSD_Thread::Current()) - { + if ( myActive ) { myProgress->EndScope(); myProgress->NewScope(span, name); } @@ -84,8 +77,5 @@ inline Standard_Boolean Message_ProgressSentry::More () const inline void Message_ProgressSentry::Show () const { - if ( !myProgress.IsNull() && myThreadId == OSD_Thread::Current()) - { - myProgress->Show(); - } + if ( ! myProgress.IsNull() ) myProgress->Show(); } -- 2.39.5