From 416d4426c462a05f0ccf3377de070d0e84ee036e Mon Sep 17 00:00:00 2001 From: azn <azn@opencascade.com> Date: Fri, 23 Mar 2012 15:31:00 +0400 Subject: [PATCH] 0022867: Avoid performing mesh of a singled face model in parallel mode when flag IsParallel is set to true. --- src/BRepMesh/BRepMesh_IncrementalMesh.cdl | 9 ++++---- src/BRepMesh/BRepMesh_IncrementalMesh.cxx | 5 +++-- src/MeshTest/MeshTest.cxx | 27 ++++++++++++++++++----- src/QAAMINO/QAAMINO.cxx | 2 +- src/StlAPI/StlAPI_Writer.cdl | 5 ++++- src/StlAPI/StlAPI_Writer.cxx | 8 +++---- src/StlTransfer/StlTransfer.cdl | 3 ++- src/StlTransfer/StlTransfer.cxx | 9 ++++---- src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx | 19 +++++++++++----- 9 files changed, 59 insertions(+), 28 deletions(-) diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.cdl b/src/BRepMesh/BRepMesh_IncrementalMesh.cdl index f717fe3f61..f145a28631 100755 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.cdl +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.cdl @@ -44,10 +44,11 @@ is returns IncrementalMesh from BRepMesh; ---C++: alias "Standard_EXPORT virtual ~BRepMesh_IncrementalMesh();" - Create (S : Shape from TopoDS; - D : Real from Standard; - Relatif : Boolean from Standard = Standard_False; - Ang : Real from Standard = 0.5) + Create (S : Shape from TopoDS; + D : Real from Standard; + Relatif : Boolean from Standard = Standard_False; + Ang : Real from Standard = 0.5; + InParallel : Boolean from Standard = Standard_False) returns IncrementalMesh from BRepMesh; ---Purpose: If the boolean <Relatif> is True, the -- deflection used for the polygonalisation of diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx index d4246b7934..8c3aa81c88 100755 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx @@ -86,9 +86,10 @@ BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh() BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh (const TopoDS_Shape& theShape, const Standard_Real theDeflection, const Standard_Boolean theRelative, - const Standard_Real theAngle) + const Standard_Real theAngle, + const Standard_Boolean theInParallel) : myRelative (theRelative), - myInParallel (Standard_False), + myInParallel (theInParallel), myModified (Standard_False), myStatus (0) { diff --git a/src/MeshTest/MeshTest.cxx b/src/MeshTest/MeshTest.cxx index ecab187972..956c2833a0 100755 --- a/src/MeshTest/MeshTest.cxx +++ b/src/MeshTest/MeshTest.cxx @@ -189,13 +189,28 @@ static Standard_Integer planesection(Draw_Interpretor&, Standard_Integer nbarg, static Standard_Integer incrementalmesh(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv) { - if (nbarg < 3) return 1; + if (nbarg < 3) { + di << " use incmesh shape deflection [inParallel (0/1) : 0 by default]\n"; + return 0; + } - Standard_Real d = atof(argv[2]); - TopoDS_Shape S = DBRep::Get(argv[1]); - if (S.IsNull()) return 1; + TopoDS_Shape aShape = DBRep::Get(argv[1]); + if (aShape.IsNull()) { + di << " null shapes is not allowed here\n"; + return 0; + } + Standard_Real aDeflection = atof(argv[2]); - BRepMesh_IncrementalMesh MESH(S,d); + Standard_Boolean isInParallel = Standard_False; + if (nbarg == 4) { + isInParallel = atoi(argv[3]) == 1; + } + di << "Incremental Mesh, multi-threading " + << (isInParallel ? "ON\n" : "OFF\n"); + + Standard::SetReentrant(isInParallel); + + BRepMesh_IncrementalMesh MESH(aShape, aDeflection, Standard_False, 0.5, isInParallel); Standard_Integer statusFlags = MESH.GetStatusFlags(); di << "Meshing statuses: "; @@ -1597,7 +1612,7 @@ void MeshTest::Commands(Draw_Interpretor& theCommands) theCommands.Add("shpsec","shpsec result shape shape",__FILE__, shapesection, g); theCommands.Add("plnsec","plnsec result shape plane",__FILE__, planesection, g); - theCommands.Add("incmesh","incmesh shape deflection",__FILE__, incrementalmesh, g); + theCommands.Add("incmesh","incmesh shape deflection [inParallel (0/1) : 0 by default]",__FILE__, incrementalmesh, g); theCommands.Add("MemLeakTest","MemLeakTest",__FILE__, MemLeakTest, g); theCommands.Add("fastdiscret","fastdiscret shape deflection [shared [nbiter]]",__FILE__, fastdiscret, g); theCommands.Add("mesh","mesh result Shape deflection [save partage]",__FILE__, triangule, g); diff --git a/src/QAAMINO/QAAMINO.cxx b/src/QAAMINO/QAAMINO.cxx index ebc578c92a..6c620c91c5 100755 --- a/src/QAAMINO/QAAMINO.cxx +++ b/src/QAAMINO/QAAMINO.cxx @@ -191,7 +191,7 @@ static Standard_Integer OCC1048 (Draw_Interpretor& di, Standard_Integer argc, co Standard_Real theDeflection = 0.006; Handle(StlMesh_Mesh) theStlMesh = new StlMesh_Mesh; - StlTransfer::BuildIncrementalMesh(aShape, theDeflection, theStlMesh); + StlTransfer::BuildIncrementalMesh(aShape, theDeflection, Standard_False, theStlMesh); Standard_Integer NBTRIANGLES = theStlMesh->NbTriangles(); di<<"Info: Number of triangles = "<<NBTRIANGLES<<"\n"; diff --git a/src/StlAPI/StlAPI_Writer.cdl b/src/StlAPI/StlAPI_Writer.cdl index cef3342516..94847e07fd 100755 --- a/src/StlAPI/StlAPI_Writer.cdl +++ b/src/StlAPI/StlAPI_Writer.cdl @@ -65,7 +65,10 @@ is -- file is an ASCII file. If the mode returns False, the -- generated file is a binary file. - Write(me : in out; aShape : Shape from TopoDS; aFileName : CString from Standard); + Write(me : in out; + aShape : Shape from TopoDS; + aFileName : CString from Standard; + InParallel : Boolean from Standard = Standard_False); ---Purpose: Converts a given shape to STL format and writes it to file with a given filename. fields diff --git a/src/StlAPI/StlAPI_Writer.cxx b/src/StlAPI/StlAPI_Writer.cxx index d42e08ab9d..2ec9925c42 100755 --- a/src/StlAPI/StlAPI_Writer.cxx +++ b/src/StlAPI/StlAPI_Writer.cxx @@ -54,17 +54,17 @@ Standard_Boolean& StlAPI_Writer::ASCIIMode() return theASCIIMode; } -void StlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFileName) +void StlAPI_Writer::Write(const TopoDS_Shape& theShape, const Standard_CString theFileName, const Standard_Boolean theInParallel) { - OSD_Path aFile(aFileName); + OSD_Path aFile(theFileName); if (theRelativeMode) { Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; Bnd_Box Total; - BRepBndLib::Add(aShape, Total); + BRepBndLib::Add(theShape, Total); Total.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); theDeflection = MAX3(aXmax-aXmin , aYmax-aYmin , aZmax-aZmin)*theCoefficient; } - StlTransfer::BuildIncrementalMesh(aShape, theDeflection, theStlMesh); + StlTransfer::BuildIncrementalMesh(theShape, theDeflection, theInParallel, theStlMesh); // Write the built mesh if (theASCIIMode) { RWStl::WriteAscii(theStlMesh, aFile); diff --git a/src/StlTransfer/StlTransfer.cdl b/src/StlTransfer/StlTransfer.cdl index fab40f7fa3..ea2e4de6d9 100755 --- a/src/StlTransfer/StlTransfer.cdl +++ b/src/StlTransfer/StlTransfer.cdl @@ -38,7 +38,8 @@ uses is BuildIncrementalMesh (Shape : in Shape from TopoDS; - Deflection : in Real from Standard; + Deflection : in Real from Standard; + InParallel : in Boolean from Standard; Mesh : Mesh from StlMesh) raises ConstructionError; end StlTransfer; diff --git a/src/StlTransfer/StlTransfer.cxx b/src/StlTransfer/StlTransfer.cxx index f365a3041f..a374893925 100755 --- a/src/StlTransfer/StlTransfer.cxx +++ b/src/StlTransfer/StlTransfer.cxx @@ -36,7 +36,7 @@ #include <CSLib.hxx> #include <gp_Dir.hxx> #include <gp_XYZ.hxx> -#include <BRepMesh.hxx> +#include <BRepMesh_IncrementalMesh.hxx> #include <TopAbs.hxx> #include <Precision.hxx> #include <TopExp_Explorer.hxx> @@ -113,15 +113,16 @@ static void Normal(const TopoDS_Face& aFace, } void StlTransfer::BuildIncrementalMesh (const TopoDS_Shape& Shape, - const Standard_Real Deflection, - const Handle(StlMesh_Mesh)& Mesh) + const Standard_Real Deflection, + const Standard_Boolean InParallel, + const Handle(StlMesh_Mesh)& Mesh) { if (Deflection <= Precision::Confusion ()) { Standard_ConstructionError::Raise ("StlTransfer::BuildIncrementalMesh"); } Standard_Integer NbVertices, NbTriangles; - BRepMesh::Mesh (Shape, Deflection); + BRepMesh_IncrementalMesh aMesher(Shape, Deflection, Standard_False, 0.5, InParallel); for (TopExp_Explorer itf(Shape,TopAbs_FACE); itf.More(); itf.Next()) { TopoDS_Face face = TopoDS::Face(itf.Current()); TopLoc_Location Loc, loc; diff --git a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx index d10ab17dd9..d6dd714002 100755 --- a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx +++ b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx @@ -89,15 +89,24 @@ static Standard_Integer writestl (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { - if (argc<3 || argc>4) di << "Use: " << argv[0] << "shape file [ascii/binary (0/1) : 1 by default]" << "\n"; - else { - TopoDS_Shape shape = DBRep::Get(argv[1]); + if (argc < 3 || argc > 5) { + di << "Use: " << argv[0] + << " shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]" << "\n"; + } else { + TopoDS_Shape aShape = DBRep::Get(argv[1]); Standard_Boolean anASCIIMode = Standard_False; + Standard_Boolean isInParallel = Standard_False; if (argc==4) { Standard_Integer mode = atoi(argv[3]); if (mode==0) anASCIIMode = Standard_True; } - StlAPI::Write(shape, argv[2],anASCIIMode); + if (argc==5) { + isInParallel = atoi(argv[4]) == 1; + Standard::SetReentrant(isInParallel); + } + StlAPI_Writer aWriter; + aWriter.ASCIIMode() = anASCIIMode; + aWriter.Write (aShape, argv[2], isInParallel); } return 0; } @@ -961,7 +970,7 @@ void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands) //XSDRAW::LoadDraw(theCommands); theCommands.Add ("writevrml", "shape file",__FILE__,writevrml,g); - theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default]",__FILE__,writestl,g); + theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g); theCommands.Add ("readstl", "shape file",__FILE__,readstl,g); theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g); theCommands.Add ("storevrml" , "shape file defl [type]",__FILE__,storevrml,g);