1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

Compare commits

...

1 Commits

Author SHA1 Message Date
isn
4132320dda 0028873: Optimization of HLR
draft version. Parallelization of:
1) contour's building, 2) BRep-adaptor creation of original shapes, 3) BRep-adaptor creation of outlined shapes
Also, some code re-factoring/re-design to provide the thread-safety of Contap functions.
2017-06-27 17:45:28 +03:00
14 changed files with 243 additions and 63 deletions

View File

@@ -286,7 +286,13 @@ void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
OCC_CATCH_SIGNALS
switch (TypeOfHLR()) {
case Prs3d_TOH_Algo:
StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
{
OSD_Timer tt;
tt.Start();
StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
tt.Stop();
tt.Show();
}
break;
case Prs3d_TOH_PolyAlgo:
default:

View File

@@ -67,7 +67,7 @@ void BRepTopAdaptor_Tool::Init(const Handle(Adaptor3d_HSurface)& surface,
myloaded=Standard_True;
}
Handle(BRepTopAdaptor_TopolTool) BRepTopAdaptor_Tool::GetTopolTool() {
Handle(BRepTopAdaptor_TopolTool) BRepTopAdaptor_Tool::GetTopolTool() const{
if(myloaded) {
return(myTopolTool);
}
@@ -79,7 +79,7 @@ Handle(BRepTopAdaptor_TopolTool) BRepTopAdaptor_Tool::GetTopolTool() {
}
}
Handle(Adaptor3d_HSurface) BRepTopAdaptor_Tool::GetSurface() {
Handle(Adaptor3d_HSurface) BRepTopAdaptor_Tool::GetSurface() const{
if(myloaded) {
return(myHSurface);
}

View File

@@ -46,11 +46,11 @@ public:
Standard_EXPORT void Init (const Handle(Adaptor3d_HSurface)& Surface, const Standard_Real Tol2d);
Standard_EXPORT Handle(BRepTopAdaptor_TopolTool) GetTopolTool();
Standard_EXPORT Handle(BRepTopAdaptor_TopolTool) GetTopolTool() const;
Standard_EXPORT void SetTopolTool (const Handle(BRepTopAdaptor_TopolTool)& TT);
Standard_EXPORT Handle(Adaptor3d_HSurface) GetSurface();
Standard_EXPORT Handle(Adaptor3d_HSurface) GetSurface() const;
Standard_EXPORT void Destroy();
~BRepTopAdaptor_Tool()

View File

@@ -36,14 +36,15 @@ void Contap_ArcFunction::Set(const Handle(Adaptor3d_HSurface)& S)
{
mySurf = S;
Standard_Integer i;
Standard_Integer nbs = Contap_HContTool::NbSamplePoints(S);
Standard_Real uinf, vinf, usup, vsup;
Standard_Integer nbs = Contap_HContTool::NbSamplePoints(S, uinf, vinf, usup, vsup);
Standard_Real U,V;
// gp_Vec d1u,d1v;
gp_Vec norm;
if (nbs > 0) {
myMean = 0.;
for (i = 1; i <= nbs; i++) {
Contap_HContTool::SamplePoint(S,i,U,V);
Contap_HContTool::SamplePoint(S,i,U,V, uinf, vinf, usup, vsup);
// Adaptor3d_HSurfaceTool::D1(S,U,V,solpt,d1u,d1v);
// myMean = myMean + d1u.Crossed(d1v).Magnitude();
Contap_SurfProps::Normale(S,U,V,solpt,norm);

View File

@@ -24,8 +24,6 @@
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
static Standard_Real uinf,vinf,usup,vsup;
Standard_Integer Contap_HContTool::NbSamplesV
(const Handle(Adaptor3d_HSurface)& S,
const Standard_Real ,
@@ -125,7 +123,7 @@ Standard_Integer Contap_HContTool::NbSamplesU
}
Standard_Integer Contap_HContTool::NbSamplePoints
(const Handle(Adaptor3d_HSurface)& S)
(const Handle(Adaptor3d_HSurface)& S, Standard_Real& uinf, Standard_Real& vinf, Standard_Real& usup, Standard_Real& vsup)
{
uinf = S->FirstUParameter();
usup = S->LastUParameter();
@@ -175,7 +173,11 @@ Standard_Integer Contap_HContTool::NbSamplePoints
void Contap_HContTool::SamplePoint (const Handle(Adaptor3d_HSurface)& S,
const Standard_Integer Index,
Standard_Real& U,
Standard_Real& V )
Standard_Real& V,
const Standard_Real& uinf,
const Standard_Real& vinf,
const Standard_Real& usup,
const Standard_Real& vsup)
{
if(S->GetType() == GeomAbs_BSplineSurface) {
Standard_Integer nbIntU = NbSamplesU(S,uinf,usup)/3;

View File

@@ -44,9 +44,10 @@ public:
Standard_EXPORT static Standard_Integer NbSamplesV (const Handle(Adaptor3d_HSurface)& S, const Standard_Real v1, const Standard_Real v2);
Standard_EXPORT static Standard_Integer NbSamplePoints (const Handle(Adaptor3d_HSurface)& S);
Standard_EXPORT static Standard_Integer NbSamplePoints (const Handle(Adaptor3d_HSurface)& S, Standard_Real& uinf, Standard_Real& vinf, Standard_Real& usup, Standard_Real& vsup);
Standard_EXPORT static void SamplePoint (const Handle(Adaptor3d_HSurface)& S, const Standard_Integer Index, Standard_Real& U, Standard_Real& V);
Standard_EXPORT static void SamplePoint (const Handle(Adaptor3d_HSurface)& S, const Standard_Integer Index, Standard_Real& U, Standard_Real& V,
const Standard_Real& uinf, const Standard_Real& vinf, const Standard_Real& usup, const Standard_Real& vsup);
//! Returns True if all the intersection point and edges
//! are known on the Arc.

View File

@@ -42,13 +42,14 @@ void Contap_SurfFunction::Set(const Handle(Adaptor3d_HSurface)& S)
{
mySurf = S;
Standard_Integer i;
Standard_Integer nbs = Contap_HContTool::NbSamplePoints(S);
Standard_Real uinf,vinf,usup,vsup;
Standard_Integer nbs = Contap_HContTool::NbSamplePoints(S,uinf,vinf,usup,vsup);
Standard_Real U,V;
gp_Vec norm;
if (nbs > 0) {
myMean = 0.;
for (i = 1; i <= nbs; i++) {
Contap_HContTool::SamplePoint(S,i,U,V);
Contap_HContTool::SamplePoint(S,i,U,V,uinf,vinf,usup,vsup);
// Adaptor3d_HSurfaceTool::D1(S,U,V,solpt,d1u,d1v);
// myMean = myMean + d1u.Crossed(d1v).Magnitude();
Contap_SurfProps::Normale(S,U,V,solpt,norm);

View File

@@ -38,10 +38,12 @@ myFlags(0),mySize(0)
void HLRBRep_FaceData::Set (const TopoDS_Face& FG,
const TopAbs_Orientation Or,
const Standard_Boolean Cl,
const Standard_Integer NW)
const Standard_Integer NW,
const Standard_Boolean isInitSurf) //TODO isInitSurf can be deleted
{
Closed(Cl);
Geometry().Surface(FG);
if (isInitSurf)
Geometry().Surface(FG);
myTolerance = (Standard_ShortReal)(BRep_Tool::Tolerance(FG));
Orientation(Or);
Wires() = new HLRAlgo_WiresBlock(NW);

View File

@@ -46,7 +46,7 @@ public:
//! if the face belongs to a closed volume. <NW> is
//! the number of wires ( or block of edges ) of the
//! face.
Standard_EXPORT void Set (const TopoDS_Face& FG, const TopAbs_Orientation Or, const Standard_Boolean Cl, const Standard_Integer NW);
Standard_EXPORT void Set (const TopoDS_Face& FG, const TopAbs_Orientation Or, const Standard_Boolean Cl, const Standard_Integer NW, const Standard_Boolean isInitSurf);
//! Set <NE> the number of edges of the wire number
//! <WI>.

View File

@@ -39,6 +39,7 @@
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_MapOfShape.hxx>
#include <OSD_Parallel.hxx>
//=======================================================================
// Function : Load
@@ -173,7 +174,7 @@ HLRBRep_ShapeToHLR::Load(const Handle(HLRTopoBRep_OutLiner)& S,
void
HLRBRep_ShapeToHLR::ExploreFace(const Handle(HLRTopoBRep_OutLiner)& S,
const Handle(HLRBRep_Data)& DS,
Handle(HLRBRep_Data)& DS,
const TopTools_IndexedMapOfShape& FM,
const TopTools_IndexedMapOfShape& EM,
Standard_Integer& i,
@@ -193,7 +194,7 @@ HLRBRep_ShapeToHLR::ExploreFace(const Handle(HLRTopoBRep_OutLiner)& S,
for (Ex1.Init(theFace, TopAbs_WIRE); Ex1.More(); Ex1.Next())
nw++;
fd.Set (theFace, orient, closed, nw);
fd.Set (theFace, orient, closed, nw, Standard_False);
nw = 0;
for (Ex1.Init(theFace, TopAbs_WIRE); Ex1.More(); Ex1.Next()) {
@@ -234,15 +235,47 @@ HLRBRep_ShapeToHLR::ExploreFace(const Handle(HLRTopoBRep_OutLiner)& S,
//purpose :
//=======================================================================
class ParallelSurfInitFunctor
{
public:
ParallelSurfInitFunctor(HLRBRep_Array1OfFData& theFaceDataArr, const TopTools_IndexedMapOfShape& theFM)
: myFaceDataArr (theFaceDataArr), myFM (theFM)
{
}
void operator() (const Standard_Integer theIndex) const
{
const TopoDS_Face& aF = TopoDS::Face(myFM(theIndex));
HLRBRep_FaceData& fd = myFaceDataArr.ChangeValue(theIndex);
fd.Geometry().Surface( TopoDS::Face(aF.Oriented (TopAbs_FORWARD)));
}
private:
ParallelSurfInitFunctor( const ParallelSurfInitFunctor& );
ParallelSurfInitFunctor& operator =( ParallelSurfInitFunctor& );
private:
HLRBRep_Array1OfFData& myFaceDataArr;
const TopTools_IndexedMapOfShape& myFM;
};
void
HLRBRep_ShapeToHLR::ExploreShape (const Handle(HLRTopoBRep_OutLiner)& S,
const Handle(HLRBRep_Data)& DS,
Handle(HLRBRep_Data)& DS,
const TopTools_IndexedMapOfShape& FM,
const TopTools_IndexedMapOfShape& EM)
{
TopTools_MapOfShape ShapeMap;
TopExp_Explorer exshell, exface, exedge;
Standard_Integer i = 0;
Standard_Integer i = 1;
ParallelSurfInitFunctor aFunctor2(DS->FDataArray(), FM);
OSD_Parallel::For(1, FM.Extent() + 1, aFunctor2, false);
i = 0;
for (exshell.Init (S->OriginalShape(), TopAbs_SHELL);
exshell.More ();
@@ -276,7 +309,7 @@ HLRBRep_ShapeToHLR::ExploreShape (const Handle(HLRTopoBRep_OutLiner)& S,
delete [] flag;
flag = NULL;
}
for (exface.Init(exshell.Current(), TopAbs_FACE);
exface.More();
exface.Next()) {

View File

@@ -57,9 +57,9 @@ protected:
private:
Standard_EXPORT static void ExploreFace (const Handle(HLRTopoBRep_OutLiner)& S, const Handle(HLRBRep_Data)& DS, const TopTools_IndexedMapOfShape& FM, const TopTools_IndexedMapOfShape& EM, Standard_Integer& i, const TopoDS_Face& F, const Standard_Boolean closed);
Standard_EXPORT static void ExploreFace (const Handle(HLRTopoBRep_OutLiner)& S, Handle(HLRBRep_Data)& DS, const TopTools_IndexedMapOfShape& FM, const TopTools_IndexedMapOfShape& EM, Standard_Integer& i, const TopoDS_Face& F, const Standard_Boolean closed);
Standard_EXPORT static void ExploreShape (const Handle(HLRTopoBRep_OutLiner)& S, const Handle(HLRBRep_Data)& DS, const TopTools_IndexedMapOfShape& FM, const TopTools_IndexedMapOfShape& EM);
Standard_EXPORT static void ExploreShape (const Handle(HLRTopoBRep_OutLiner)& S, Handle(HLRBRep_Data)& DS, const TopTools_IndexedMapOfShape& FM, const TopTools_IndexedMapOfShape& EM);

View File

@@ -62,14 +62,106 @@
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <HLRAlgo_Projector.hxx>
#include <Adaptor3d_HSurface.hxx>
#include <NCollection_Handle.hxx>
#include <BRepAdaptor_HSurface.hxx>
#include <OSD_Parallel.hxx>
struct ContourSurfInfo
{
ContourSurfInfo() : myDomain(NULL), mySurface(NULL)
{};
ContourSurfInfo(NCollection_Handle<Contap_Contour> theHFO,
const Handle(BRepTopAdaptor_TopolTool)& theDomain,
const Handle(Adaptor3d_HSurface) theSurface) :
myHFO(theHFO), myDomain (theDomain.get()), mySurface (theSurface.get())
{};
ContourSurfInfo& operator=( const ContourSurfInfo& otherSurfInfo)
{
myHFO = otherSurfInfo.myHFO;
myDomain = otherSurfInfo.myDomain;
mySurface = otherSurfInfo.mySurface;
return *this;
};
NCollection_Handle<Contap_Contour> myHFO;
const BRepTopAdaptor_TopolTool* myDomain;
const Adaptor3d_HSurface* mySurface;
};
struct BRTInfo
{
BRTInfo()
{};
BRTInfo(BRepTopAdaptor_Tool* thepBRT, ContourSurfInfo* theCSI, const TopoDS_Face& theF )
: mypBRT (thepBRT), myCSI (theCSI), myF (theF)
{};
BRepTopAdaptor_Tool* mypBRT;
ContourSurfInfo* myCSI;
TopoDS_Face myF;
};
class ParallelContourFunctor
{
public:
ParallelContourFunctor(NCollection_Array1<ContourSurfInfo>& theContourSurfInfo)
: myContourSurfInfo (theContourSurfInfo)
{
}
void operator() (const Standard_Integer theIndex) const
{
ContourSurfInfo& aCSInfo = myContourSurfInfo(theIndex);
aCSInfo.myHFO->Perform(aCSInfo.mySurface, aCSInfo.myDomain);
}
private:
ParallelContourFunctor( const ParallelContourFunctor& );
ParallelContourFunctor& operator =( ParallelContourFunctor& );
private:
NCollection_Array1<ContourSurfInfo>& myContourSurfInfo;
};
class ParallelBRTInitFunctor
{
public:
ParallelBRTInitFunctor(NCollection_Array1<BRTInfo>& theBRTInfo)
: myBRTInfo (theBRTInfo)
{
}
void operator() (const Standard_Integer theIndex) const
{
BRTInfo& BI = myBRTInfo(theIndex);
BI.mypBRT->Init(BI.myF,Precision::PConfusion());
BI.myCSI->myDomain = BI.mypBRT->GetTopolTool().get();
BI.myCSI->mySurface = BI.mypBRT->GetSurface().get();
}
private:
ParallelBRTInitFunctor( const ParallelBRTInitFunctor& );
ParallelBRTInitFunctor& operator =( ParallelBRTInitFunctor& );
private:
NCollection_Array1<BRTInfo>& myBRTInfo;
};
//=======================================================================
//function : Insert
//purpose : explore the faces and insert them
//=======================================================================
void HLRTopoBRep_DSFiller::Insert (const TopoDS_Shape& S,
Contap_Contour& FO,
const HLRAlgo_Projector& P,
const gp_Vec& Vecz,
HLRTopoBRep_Data& DS,
BRepTopAdaptor_MapOfShapeTool& MST,
const Standard_Integer nbIso)
@@ -78,35 +170,86 @@ void HLRTopoBRep_DSFiller::Insert (const TopoDS_Shape& S,
TopExp_Explorer ex(S,TopAbs_FACE);
DS.Clear();
Standard_Boolean withPCurve = Standard_True; // instead of nbIso != 0;
Standard_Integer f = 0;
while (ex.More()) {
if (ShapeMap.Add(ex.Current())) {
f++;
gp_Pnt Eye;
gp_Dir DirZ;
if (P.Perspective ())
Eye.SetXYZ (P.Focus ()*Vecz.XYZ ());
else
DirZ = Vecz;
NCollection_List<ContourSurfInfo> ContourSurfInfoList;
NCollection_List<BRTInfo> nonInitBRTs;
while (ex.More())
{
if (ShapeMap.Add(ex.Current()))
{
TopoDS_Face S1 = TopoDS::Face(ex.Current());
S1.Orientation(TopAbs_FORWARD);
Handle(BRepTopAdaptor_TopolTool) Domain;
Handle(Adaptor3d_HSurface) Surface;
if(MST.IsBound(S1)) {
BRepTopAdaptor_Tool& BRT = MST.ChangeFind(S1);
Domain = BRT.GetTopolTool();
Surface = BRT.GetSurface();
//
NCollection_Handle<Contap_Contour> HFO = new Contap_Contour();
if (P.Perspective ())
HFO->Init(Eye);
else
HFO->Init(DirZ);
//
BRepTopAdaptor_Tool* pBRT = MST.ChangeSeek(S1);
if(pBRT)
{
ContourSurfInfo CSInfo(HFO, pBRT->GetTopolTool(), pBRT->GetSurface());
ContourSurfInfoList.Append(CSInfo);
}
else {
BRepTopAdaptor_Tool BRT(S1,Precision::PConfusion());
MST.Bind(S1,BRT);
Domain = BRT.GetTopolTool();
Surface = BRT.GetSurface();
else
{
pBRT = MST.Bound(S1,BRepTopAdaptor_Tool());
BRTInfo& brtI = nonInitBRTs.Append(BRTInfo());
brtI.mypBRT = pBRT;
brtI.myCSI = &ContourSurfInfoList.Append(ContourSurfInfo(HFO, NULL, NULL));
brtI.myF = S1;
}
FO.Perform(Surface, Domain);
if (FO.IsDone()) {
if (!FO.IsEmpty())
InsertFace(f,S1,FO,DS,withPCurve);
}
if (nbIso != 0) HLRTopoBRep_FaceIsoLiner::Perform(f,S1,DS,nbIso);
}
ex.Next();
}
//
NCollection_List<BRTInfo>::Iterator itBRTIt(nonInitBRTs);
NCollection_Array1<BRTInfo> nonInitBRTArr(1, nonInitBRTs.Extent());
Standard_Integer f = 1;
for (;itBRTIt.More();itBRTIt.Next(), f++)
nonInitBRTArr(f) = itBRTIt.Value();
ParallelBRTInitFunctor aFunctor1(nonInitBRTArr);
OSD_Parallel::For(nonInitBRTArr.Lower(), nonInitBRTArr.Upper() + 1, aFunctor1, false);
//
//
NCollection_List<ContourSurfInfo>::Iterator itCS(ContourSurfInfoList);
int nbC = ContourSurfInfoList.Extent();
f = 1;
NCollection_Array1<ContourSurfInfo> aContourSurfInfoArray(1, nbC);
for (;itCS.More();itCS.Next(), f++)
aContourSurfInfoArray(f) = itCS.Value();
//
ParallelContourFunctor aFunctor(aContourSurfInfoArray);
OSD_Parallel::For(aContourSurfInfoArray.Lower(), aContourSurfInfoArray.Upper() + 1, aFunctor, false);
//
for (f = aContourSurfInfoArray.Lower(); f <= aContourSurfInfoArray.Upper(); f++)
{
ContourSurfInfo& CSInfo = aContourSurfInfoArray(f);
Handle(BRepAdaptor_HSurface) BrepSurf = Handle(BRepAdaptor_HSurface)::DownCast(CSInfo.mySurface);
const TopoDS_Face& S1 = BrepSurf->ChangeSurface().Face();
if (CSInfo.myHFO->IsDone())
if (!CSInfo.myHFO->IsEmpty())
InsertFace(f,S1,*CSInfo.myHFO,DS,withPCurve);
if (nbIso != 0)
HLRTopoBRep_FaceIsoLiner::Perform(f,S1,DS,nbIso);
}
//
ProcessEdges(DS);
}
@@ -117,7 +260,7 @@ void HLRTopoBRep_DSFiller::Insert (const TopoDS_Shape& S,
void HLRTopoBRep_DSFiller::InsertFace (const Standard_Integer /*FI*/,
const TopoDS_Face& F,
Contap_Contour& FO,
const Contap_Contour& FO,
HLRTopoBRep_Data& DS,
const Standard_Boolean withPCurve)
{

View File

@@ -32,6 +32,7 @@ class TopoDS_Face;
class TopoDS_Vertex;
class Contap_Point;
class TopoDS_Edge;
class HLRAlgo_Projector;
//! Provides methods to fill a HLRTopoBRep_Data.
@@ -44,7 +45,7 @@ public:
//! Stores in <DS> the outlines of <S> using the current
//! outliner and stores the isolines in <DS> using a Hatcher.
Standard_EXPORT static void Insert (const TopoDS_Shape& S, Contap_Contour& FO, HLRTopoBRep_Data& DS, BRepTopAdaptor_MapOfShapeTool& MST, const Standard_Integer nbIso);
Standard_EXPORT static void Insert (const TopoDS_Shape& S,const HLRAlgo_Projector& P, const gp_Vec& Vecz, HLRTopoBRep_Data& DS, BRepTopAdaptor_MapOfShapeTool& MST, const Standard_Integer nbIso);
@@ -60,7 +61,7 @@ private:
//! Stores in <DS> the outlines of <F> using the current
//! outliner.
Standard_EXPORT static void InsertFace (const Standard_Integer FI, const TopoDS_Face& F, Contap_Contour& FO, HLRTopoBRep_Data& DS, const Standard_Boolean withPCurve);
Standard_EXPORT static void InsertFace (const Standard_Integer FI, const TopoDS_Face& F, const Contap_Contour& FO, HLRTopoBRep_Data& DS, const Standard_Boolean withPCurve);
//! Make a vertex from an intersection point <P>and
//! store it in the data structure <DS>.

View File

@@ -82,17 +82,7 @@ void HLRTopoBRep_OutLiner::Fill(const HLRAlgo_Projector& P,
gp_Trsf Tr (P.Transformation ());
Tr.Invert ();
Vecz.Transform (Tr);
Contap_Contour FO;
if (P.Perspective ()) {
gp_Pnt Eye;
Eye.SetXYZ (P.Focus ()*Vecz.XYZ ());
FO.Init(Eye);
}
else {
gp_Dir DirZ(Vecz);
FO.Init(DirZ);
}
HLRTopoBRep_DSFiller::Insert(myOriginalShape,FO,myDS,MST,nbIso);
HLRTopoBRep_DSFiller::Insert(myOriginalShape,P,Vecz,myDS,MST,nbIso);
BuildShape(MST);
}
}