1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0025113: Mesh - Progress indication and user break functionality for BRepMesh component

Added Progress Indicator to BRep_Mesh
This commit is contained in:
emv
2020-07-10 14:19:31 +03:00
committed by bugmaster
parent 99ca2eec6b
commit ce97cd9708
33 changed files with 266 additions and 84 deletions

View File

@@ -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();
}
}

View File

@@ -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:

View File

@@ -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*/)
{
}
};

View File

@@ -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);
}
//=======================================================================

View File

@@ -29,6 +29,7 @@
#include <TColStd_Array1OfInteger.hxx>
#include <TColStd_SequenceOfInteger.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <Message_ProgressRange.hxx>
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();

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -18,6 +18,7 @@
#include <Standard_Type.hxx>
#include <TopoDS_Shape.hxx>
#include <Standard_Transient.hxx>
#include <Message_ProgressRange.hxx>
//! 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)

View File

@@ -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;

View File

@@ -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:

View File

@@ -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<Message_ProgressRange> 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&)
{

View File

@@ -20,6 +20,7 @@
#include <IMeshTools_Parameters.hxx>
#include <IMeshData_Types.hxx>
#include <IMeshTools_MeshAlgoFactory.hxx>
#include <NCollection_Array1.hxx>
//! 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:

View File

@@ -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();
}

View File

@@ -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.

View File

@@ -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())

View File

@@ -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:

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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();
}