0024826: Wrapping of parallelisation algorithms
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_2.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 //                         EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 //
7 // This file is part of Open CASCADE Technology software library.
8 //
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
14 //
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
17
18 #include <BOPAlgo_PaveFiller.ixx>
19
20 #include <TopoDS_Vertex.hxx>
21 #include <TopoDS_Edge.hxx>
22 #include <BRep_Tool.hxx>
23
24 #include <BOPCol_NCVector.hxx>
25 #include <BOPCol_Parallel.hxx>
26
27 #include <IntTools_Context.hxx>
28
29 #include <BOPDS_Iterator.hxx>
30 #include <BOPDS_VectorOfInterfVE.hxx>
31 #include <BOPDS_Interf.hxx>
32 #include <BOPDS_PassKey.hxx>
33 #include <BOPDS_MapOfPassKey.hxx>
34 #include <BRepBndLib.hxx>
35 #include <BRep_Builder.hxx>
36
37 //=======================================================================
38 //class    : BOPAlgo_VertexEdgeEdge
39 //purpose  : 
40 //=======================================================================
41 class BOPAlgo_VertexEdge : public BOPAlgo_Algo {
42
43  public:
44   DEFINE_STANDARD_ALLOC
45
46   BOPAlgo_VertexEdge() : 
47     BOPAlgo_Algo(),
48     myIV(-1), myIE(-1), myIVx(-1), myFlag(-1), myT(-1.) {
49   };
50   //
51   virtual ~BOPAlgo_VertexEdge(){
52   };
53   //
54   void SetIndices(const Standard_Integer nV,
55                   const Standard_Integer nE,
56                   const Standard_Integer nVx) {
57     myIV=nV;
58     myIE=nE;
59     myIVx=nVx;
60   }
61   //
62   void Indices(Standard_Integer& nV,
63                Standard_Integer& nE,
64                Standard_Integer& nVx) const {
65     nV=myIV;
66     nE=myIE;
67     nVx=myIVx;
68   }
69   //
70   void SetVertex(const TopoDS_Vertex& aV) {
71     myV=aV;
72   }
73   //
74   const TopoDS_Vertex& Vertex()const {
75     return myV;
76   }
77   //
78   void SetEdge(const TopoDS_Edge& aE) {
79     myE=aE;
80   }
81   //
82   const TopoDS_Edge& Edge()const {
83     return myE;
84   }
85   //
86   Standard_Integer Flag()const {
87     return myFlag;
88   }
89   //
90   Standard_Real Parameter()const {
91     return myT;
92   }
93   //
94   void SetContext(const Handle(IntTools_Context)& aContext) {
95     myContext=aContext;
96   }
97   //
98   const Handle(IntTools_Context)& Context()const {
99     return myContext;
100   }
101   //
102   virtual void Perform() {
103     BOPAlgo_Algo::UserBreak();
104     myFlag=myContext->ComputeVE (myV, myE, myT);
105   };
106   //
107  protected:
108   Standard_Integer myIV;
109   Standard_Integer myIE;
110   Standard_Integer myIVx;
111   Standard_Integer myFlag;
112   Standard_Real myT;
113   TopoDS_Vertex myV;
114   TopoDS_Edge myE;
115   Handle(IntTools_Context) myContext;
116 };
117 //=======================================================================
118 typedef BOPCol_NCVector
119   <BOPAlgo_VertexEdge> BOPAlgo_VectorOfVertexEdge; 
120 //
121 typedef BOPCol_ContextFunctor 
122   <BOPAlgo_VertexEdge,
123   BOPAlgo_VectorOfVertexEdge,
124   Handle(IntTools_Context), 
125   IntTools_Context> BOPAlgo_VertexEdgeFunctor;
126 //
127 typedef BOPCol_ContextCnt 
128   <BOPAlgo_VertexEdgeFunctor,
129   BOPAlgo_VectorOfVertexEdge,
130   Handle(IntTools_Context)> BOPAlgo_VertexEdgeCnt;
131 //
132 //=======================================================================
133 // function: PerformVE
134 // purpose: 
135 //=======================================================================
136 void BOPAlgo_PaveFiller::PerformVE()
137 {
138   Standard_Boolean bJustAdd;
139   Standard_Integer iSize, nV, nE, nVSD, iFlag, nVx,  k, aNbVE;
140   Standard_Real aT, aTolE, aTolV;
141   BOPDS_Pave aPave;
142   BOPDS_PassKey aPK;
143   BOPDS_MapOfPassKey aMPK;
144   BRep_Builder aBB;
145   BOPAlgo_VectorOfVertexEdge aVVE;
146   //
147   myErrorStatus=0;
148   //
149   myIterator->Initialize(TopAbs_VERTEX, TopAbs_EDGE);
150   iSize=myIterator->ExpectedLength();
151   if (!iSize) {
152     return; 
153   }
154   //
155   BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
156   aVEs.SetIncrement(iSize);
157   //
158   for (; myIterator->More(); myIterator->Next()) {
159     myIterator->Value(nV, nE, bJustAdd);
160     if(bJustAdd) {
161       continue;
162     }
163     //
164     const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
165     if (aSIE.HasSubShape(nV)) {
166       continue;
167     }
168     //
169     if (aSIE.HasFlag()){
170       continue;
171     }
172     //
173     if (myDS->HasInterfShapeSubShapes(nV, nE)) {
174       myDS->ChangePaveBlocks(nE);
175       continue;
176     }
177     //
178     nVx=nV;
179     if (myDS->HasShapeSD(nV, nVSD)) {
180       nVx=nVSD;
181     }
182     //
183     aPK.SetIds(nVx, nE);
184     if (!aMPK.Add(aPK)) {
185       continue;
186     }
187     //
188     const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape())); 
189     const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); 
190     //
191     BOPAlgo_VertexEdge& aVESolver=aVVE.Append1();
192     //
193     aVESolver.SetIndices(nV, nE, nVx);
194     aVESolver.SetVertex(aV);
195     aVESolver.SetEdge(aE);
196     aVESolver.SetProgressIndicator(myProgressIndicator);
197     //
198   }// for (; myIterator->More(); myIterator->Next()) {
199   //
200   aNbVE=aVVE.Extent();
201   //=============================================================
202   BOPAlgo_VertexEdgeCnt::Perform(myRunParallel, aVVE, myContext);
203   //=============================================================
204   //
205   for (k=0; k < aNbVE; ++k) {
206     const BOPAlgo_VertexEdge& aVESolver=aVVE(k);
207     iFlag=aVESolver.Flag();
208     if (!iFlag) {
209       aVESolver.Indices(nV, nE, nVx);
210       aT=aVESolver.Parameter();
211       const TopoDS_Vertex& aV=aVESolver.Vertex();
212       const TopoDS_Edge& aE=aVESolver.Edge();
213       // 1
214       BOPDS_InterfVE& aVE=aVEs.Append1();
215       aVE.SetIndices(nV, nE);
216       aVE.SetParameter(aT);
217       // 2
218       myDS->AddInterf(nV, nE);
219       // 3
220       BOPDS_ListOfPaveBlock& aLPB=myDS->ChangePaveBlocks(nE);
221       Handle(BOPDS_PaveBlock)& aPB=*((Handle(BOPDS_PaveBlock)*)&aLPB.First());
222       // 
223       aPave.SetIndex(nVx);
224       aPave.SetParameter(aT);
225       aPB->AppendExtPave(aPave);
226       aTolV = BRep_Tool::Tolerance(aV);
227       aTolE = BRep_Tool::Tolerance(aE);
228       if ( aTolV < aTolE) {
229         aBB.UpdateVertex(aV, aTolE);
230         BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVx);
231         Bnd_Box& aBoxDS=aSIDS.ChangeBox();
232         BRepBndLib::Add(aV, aBoxDS);
233       }
234     }
235   }//for (k=0; k < aNbVE; ++k) {
236