Warnings on vc14 were eliminated
[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
19 #include <BOPAlgo_PaveFiller.hxx>
20 #include <BOPAlgo_SectionAttribute.hxx>
21 #include <BOPCol_NCVector.hxx>
22 #include <BOPCol_Parallel.hxx>
23 #include <BOPDS_Curve.hxx>
24 #include <BOPDS_DS.hxx>
25 #include <BOPDS_Interf.hxx>
26 #include <BOPDS_Iterator.hxx>
27 #include <BOPDS_MapOfPair.hxx>
28 #include <BOPDS_Pair.hxx>
29 #include <BOPDS_PaveBlock.hxx>
30 #include <BOPDS_VectorOfInterfVE.hxx>
31 #include <BOPTools_AlgoTools.hxx>
32 #include <BRep_Builder.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BRepBndLib.hxx>
35 #include <gp_Pnt.hxx>
36 #include <IntTools_Context.hxx>
37 #include <IntTools_Tools.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Face.hxx>
40 #include <TopoDS_Vertex.hxx>
41 #include <Precision.hxx>
42
43 //=======================================================================
44 //class    : BOPAlgo_VertexEdgeEdge
45 //purpose  : 
46 //=======================================================================
47 class BOPAlgo_VertexEdge : public BOPAlgo_Algo {
48
49  public:
50   DEFINE_STANDARD_ALLOC
51
52   BOPAlgo_VertexEdge() : 
53     BOPAlgo_Algo(),
54     myIV(-1), myIE(-1), myFlag(-1), myT(-1.), myTolVNew(-1.) {
55   };
56   //
57   virtual ~BOPAlgo_VertexEdge(){
58   };
59   //
60   void SetIndices(const Standard_Integer nV,
61                   const Standard_Integer nE) {
62     myIV=nV;
63     myIE=nE;
64   }
65   //
66   void Indices(Standard_Integer& nV,
67                Standard_Integer& nE) const {
68     nV=myIV;
69     nE=myIE;
70   }
71   //
72   void SetVertex(const TopoDS_Vertex& aV) {
73     myV=aV;
74   }
75   //
76   void SetEdge(const TopoDS_Edge& aE) {
77     myE=aE;
78   }
79   //
80   const TopoDS_Vertex& Vertex() const {
81     return myV;
82   }
83   //
84   const TopoDS_Edge& Edge() const {
85     return myE;
86   }
87   //
88   Standard_Integer Flag()const {
89     return myFlag;
90   }
91   //
92   Standard_Real Parameter()const {
93     return myT;
94   }
95   //
96   Standard_Real VertexNewTolerance()const {
97     return myTolVNew;
98   }
99   //
100   void SetContext(const Handle(IntTools_Context)& aContext) {
101     myContext=aContext;
102   }
103   //
104   const Handle(IntTools_Context)& Context()const {
105     return myContext;
106   }
107   //
108   virtual void Perform() {
109     BOPAlgo_Algo::UserBreak();
110     myFlag=myContext->ComputeVE (myV, myE, myT, myTolVNew, myFuzzyValue);
111   };
112   //
113  protected:
114   Standard_Integer myIV;
115   Standard_Integer myIE;
116   Standard_Integer myFlag;
117   Standard_Real myT;
118   Standard_Real myTolVNew;
119   TopoDS_Vertex myV;
120   TopoDS_Edge myE;
121   Handle(IntTools_Context) myContext;
122 };
123 //=======================================================================
124 typedef BOPCol_NCVector
125   <BOPAlgo_VertexEdge> BOPAlgo_VectorOfVertexEdge; 
126 //
127 typedef BOPCol_ContextFunctor 
128   <BOPAlgo_VertexEdge,
129   BOPAlgo_VectorOfVertexEdge,
130   Handle(IntTools_Context), 
131   IntTools_Context> BOPAlgo_VertexEdgeFunctor;
132 //
133 typedef BOPCol_ContextCnt 
134   <BOPAlgo_VertexEdgeFunctor,
135   BOPAlgo_VectorOfVertexEdge,
136   Handle(IntTools_Context)> BOPAlgo_VertexEdgeCnt;
137 //
138 //=======================================================================
139 // function: PerformVE
140 // purpose: 
141 //=======================================================================
142 void BOPAlgo_PaveFiller::PerformVE()
143 {
144   Standard_Integer iSize, nV, nE, nVSD, iFlag, nVx,  k, aNbVE;
145   Standard_Real aT, aT1, aT2, aTS1, aTS2;
146   BOPDS_Pave aPave;
147   BOPDS_Pair aPK;
148   BOPDS_MapOfPair aMPK;
149   BOPAlgo_VectorOfVertexEdge aVVE;
150   //
151   myErrorStatus=0;
152   //
153   FillShrunkData(TopAbs_VERTEX, TopAbs_EDGE);
154   //
155   myIterator->Initialize(TopAbs_VERTEX, TopAbs_EDGE);
156   iSize=myIterator->ExpectedLength();
157   if (!iSize) {
158     return; 
159   }
160   //
161   BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
162   aVEs.SetIncrement(iSize);
163   //
164   for (; myIterator->More(); myIterator->Next()) {
165     myIterator->Value(nV, nE);
166     //
167     const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
168     if (aSIE.HasSubShape(nV)) {
169       continue;
170     }
171     //
172     if (aSIE.HasFlag()){
173       continue;
174     }
175     //
176     if (myDS->HasInterfShapeSubShapes(nV, nE)) {
177       myDS->ChangePaveBlocks(nE);
178       continue;
179     }
180     //
181     nVx=nV;
182     if (myDS->HasShapeSD(nV, nVSD)) {
183       nVx=nVSD;
184     }
185     //
186     aPK.SetIndices(nVx, nE);
187     if (!aMPK.Add(aPK)) {
188       continue;
189     }
190     //
191     const BOPDS_ListOfPaveBlock& aLPB = myDS->PaveBlocks(nE);
192     if (aLPB.IsEmpty()) {
193       continue;
194     }
195     //
196     const Handle(BOPDS_PaveBlock)& aPB = aLPB.First();
197     if (!aPB->IsSplittable()) {
198       // this is a micro edge, ignore it
199       continue;
200     }
201     //
202     const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape())); 
203     const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); 
204     //
205     BOPAlgo_VertexEdge& aVESolver=aVVE.Append1();
206     //
207     aVESolver.SetIndices(nV, nE);
208     aVESolver.SetVertex(aV);
209     aVESolver.SetEdge(aE);
210     aVESolver.SetFuzzyValue(myFuzzyValue);
211     aVESolver.SetProgressIndicator(myProgressIndicator);
212     //
213   }// for (; myIterator->More(); myIterator->Next()) {
214   //
215   aNbVE=aVVE.Extent();
216   //=============================================================
217   BOPAlgo_VertexEdgeCnt::Perform(myRunParallel, aVVE, myContext);
218   //=============================================================
219   //
220   for (k=0; k < aNbVE; ++k) {
221     const BOPAlgo_VertexEdge& aVESolver=aVVE(k);
222     iFlag=aVESolver.Flag();
223     if (!iFlag) {
224       aVESolver.Indices(nV, nE);
225       aT=aVESolver.Parameter();
226       // 
227       // check if vertex hits beyond shrunk range, in such case create V-V interf
228       const BOPDS_ListOfPaveBlock& aLPB = myDS->PaveBlocks(nE);
229       const Handle(BOPDS_PaveBlock)& aPB = aLPB.First();
230       Bnd_Box aBox;
231       Standard_Boolean bIsPBSplittable;
232       aPB->Range(aT1, aT2);
233       aPB->ShrunkData(aTS1, aTS2, aBox, bIsPBSplittable);
234       IntTools_Range aPaveR[2] = { IntTools_Range(aT1, aTS1), IntTools_Range(aTS2, aT2) };
235       Standard_Real aTol = Precision::Confusion();
236       Standard_Boolean isOnPave = Standard_False;
237       for (Standard_Integer i = 0; i < 2; i++) {
238         if (!bIsPBSplittable || IntTools_Tools::IsOnPave1(aT, aPaveR[i], aTol)) {
239           Standard_Integer nV1 = (i == 0 ? aPB->Pave1().Index() : aPB->Pave2().Index());
240           if (!myDS->HasInterf(nV, nV1)) {
241             BOPCol_ListOfInteger aLI;
242             aLI.Append(nV);
243             aLI.Append(nV1);
244             MakeSDVertices(aLI);
245           }
246           isOnPave = Standard_True;
247           break;
248         }
249       }
250       if (isOnPave)
251         continue;
252       //
253       // 1
254       BOPDS_InterfVE& aVE=aVEs.Append1();
255       aVE.SetIndices(nV, nE);
256       aVE.SetParameter(aT);
257       // 2
258       myDS->AddInterf(nV, nE);
259       //
260       // 3 update vertex V/E if necessary
261       Standard_Real aTolVNew = aVESolver.VertexNewTolerance();
262       nVx=UpdateVertex(nV, aTolVNew);
263       //4
264       if (myDS->IsNewShape(nVx)) {
265         aVE.SetIndexNew(nVx);
266       }
267       //5 append ext pave to pave block
268       aPave.SetIndex(nVx);
269       aPave.SetParameter(aT);
270       aPB->AppendExtPave(aPave);
271     }
272   }//for (k=0; k < aNbVE; ++k) {
273