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
7 // This file is part of Open CASCADE Technology software library.
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.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
19 #include <BOPAlgo_PaveFiller.hxx>
20 #include <BOPAlgo_Alerts.hxx>
21 #include <BOPAlgo_SectionAttribute.hxx>
22 #include <BOPCol_MapOfInteger.hxx>
23 #include <BOPCol_NCVector.hxx>
24 #include <BOPCol_Parallel.hxx>
25 #include <BOPDS_Curve.hxx>
26 #include <BOPDS_DS.hxx>
27 #include <BOPDS_FaceInfo.hxx>
28 #include <BOPDS_Interf.hxx>
29 #include <BOPDS_Iterator.hxx>
30 #include <BOPDS_MapOfPaveBlock.hxx>
31 #include <BOPDS_PaveBlock.hxx>
32 #include <BOPDS_SubIterator.hxx>
33 #include <BOPDS_VectorOfInterfVF.hxx>
34 #include <BRep_Builder.hxx>
35 #include <BRep_Tool.hxx>
36 #include <BRepBndLib.hxx>
38 #include <IntTools_Context.hxx>
39 #include <TopoDS_Face.hxx>
40 #include <TopoDS_Vertex.hxx>
42 //=======================================================================
43 //class : BOPAlgo_VertexFace
45 //=======================================================================
46 class BOPAlgo_VertexFace : public BOPAlgo_Algo {
50 BOPAlgo_VertexFace() :
53 myFlag(-1), myT1(-1.), myT2(-1.), myTolVNew(-1.) {
56 virtual ~BOPAlgo_VertexFace(){
59 void SetIndices(const Standard_Integer nV,
60 const Standard_Integer nF) {
65 void Indices(Standard_Integer& nV,
66 Standard_Integer& nF) const {
71 void SetVertex(const TopoDS_Vertex& aV) {
75 const TopoDS_Vertex& Vertex()const {
79 void SetFace(const TopoDS_Face& aF) {
83 const TopoDS_Face& Face()const {
87 Standard_Integer Flag()const {
91 void Parameters(Standard_Real& aT1,
92 Standard_Real& aT2)const {
97 Standard_Real VertexNewTolerance()const {
101 void SetContext(const Handle(IntTools_Context)& aContext) {
105 const Handle(IntTools_Context)& Context()const {
109 virtual void Perform() {
110 BOPAlgo_Algo::UserBreak();
115 myFlag=myContext->ComputeVF(myV, myF, myT1, myT2, myTolVNew, myFuzzyValue);
117 catch (Standard_Failure)
119 AddError(new BOPAlgo_AlertIntersectionFailed);
124 Standard_Integer myIV;
125 Standard_Integer myIF;
126 Standard_Integer myFlag;
129 Standard_Real myTolVNew;
132 Handle(IntTools_Context) myContext;
134 //=======================================================================
135 typedef BOPCol_NCVector<BOPAlgo_VertexFace>
136 BOPAlgo_VectorOfVertexFace;
138 typedef BOPCol_ContextFunctor
140 BOPAlgo_VectorOfVertexFace,
141 Handle(IntTools_Context),
142 IntTools_Context> BOPAlgo_VertexFaceFunctor;
144 typedef BOPCol_ContextCnt
145 <BOPAlgo_VertexFaceFunctor,
146 BOPAlgo_VectorOfVertexFace,
147 Handle(IntTools_Context)> BOPAlgo_VertexFaceCnt;
149 //=======================================================================
150 // function: PerformVF
152 //=======================================================================
153 void BOPAlgo_PaveFiller::PerformVF()
155 myIterator->Initialize(TopAbs_VERTEX, TopAbs_FACE);
156 Standard_Integer iSize = myIterator->ExpectedLength();
158 Standard_Integer nV, nF;
160 if (myGlue == BOPAlgo_GlueFull) {
161 // there is no need to intersect vertices with faces in this mode
162 // just initialize FaceInfo for all faces
163 for (; myIterator->More(); myIterator->Next()) {
164 myIterator->Value(nV, nF);
165 if (!myDS->IsSubShape(nV, nF)) {
166 myDS->ChangeFaceInfo(nF);
172 BOPDS_VectorOfInterfVF& aVFs = myDS->InterfVF();
175 aVFs.SetIncrement(iSize);
181 Standard_Integer nVSD, iFlag, nVx, aNbVF, k;
182 Standard_Real aT1, aT2;
183 BOPAlgo_VectorOfVertexFace aVVF;
185 aVFs.SetIncrement(iSize);
187 for (; myIterator->More(); myIterator->Next()) {
188 myIterator->Value(nV, nF);
190 if (myDS->IsSubShape(nV, nF)) {
194 myDS->ChangeFaceInfo(nF);
195 if (myDS->HasInterfShapeSubShapes(nV, nF)) {
200 if (myDS->HasShapeSD(nV, nVSD)) {
204 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
205 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
207 BOPAlgo_VertexFace& aVertexFace=aVVF.Append1();
209 aVertexFace.SetIndices(nV, nF);
210 aVertexFace.SetVertex(aV);
211 aVertexFace.SetFace(aF);
212 aVertexFace.SetFuzzyValue(myFuzzyValue);
213 aVertexFace.SetProgressIndicator(myProgressIndicator);
214 }//for (; myIterator->More(); myIterator->Next()) {
217 //================================================================
218 BOPAlgo_VertexFaceCnt::Perform(myRunParallel, aVVF, myContext);
219 //================================================================
221 for (k=0; k < aNbVF; ++k) {
222 const BOPAlgo_VertexFace& aVertexFace=aVVF(k);
224 iFlag=aVertexFace.Flag();
226 if (aVertexFace.HasErrors())
228 // Warn about failed intersection of sub-shapes
229 AddIntersectionFailedWarning(aVertexFace.Vertex(), aVertexFace.Face());
234 aVertexFace.Indices(nV, nF);
235 aVertexFace.Parameters(aT1, aT2);
237 BOPDS_InterfVF& aVF=aVFs.Append1();
238 aVF.SetIndices(nV, nF);
241 myDS->AddInterf(nV, nF);
243 // 3 update vertex V/F if necessary
244 Standard_Real aTolVNew = aVertexFace.VertexNewTolerance();
245 nVx=UpdateVertex(nV, aTolVNew);
248 if (myDS->IsNewShape(nVx)) {
249 aVF.SetIndexNew(nVx);
252 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
253 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
255 }//for (k=0; k < aNbVF; ++k) {
259 //=======================================================================
260 //function : TreatVerticesEE
262 //=======================================================================
263 void BOPAlgo_PaveFiller::TreatVerticesEE()
265 Standard_Integer i, aNbS,aNbEEs, nF, nV, iFlag;
266 Standard_Real aT1, aT2, dummy;
267 BOPCol_ListIteratorOfListOfInteger aItLI;
268 Handle(NCollection_BaseAllocator) aAllocator;
271 NCollection_BaseAllocator::CommonBaseAllocator();
272 BOPCol_ListOfInteger aLIV(aAllocator), aLIF(aAllocator);
273 BOPCol_MapOfInteger aMI(100, aAllocator);
274 BOPDS_MapOfPaveBlock aMPBF(100, aAllocator);
276 aNbS=myDS->NbSourceShapes();
278 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
279 aNbEEs=aEEs.Extent();
280 for (i=0; i<aNbEEs; ++i) {
281 BOPDS_InterfEE& aEE=aEEs(i);
282 if (aEE.HasIndexNew()) {
289 if (!aLIV.Extent()) {
290 aAllocator.Nullify();
294 aNbS=myDS->NbSourceShapes();
295 for (nF=0; nF<aNbS; ++nF) {
296 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(nF);
297 if (aSI.ShapeType()==TopAbs_FACE) {
301 if (!aLIF.Extent()) {
302 aAllocator.Nullify();
305 //-------------------------------------------------------------
306 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
308 BOPDS_SubIterator aIt(aAllocator);
311 aIt.SetSubSet1(aLIF);
312 aIt.SetSubSet2(aLIV);
315 for (; aIt.More(); aIt.Next()) {
318 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
319 const BOPCol_MapOfInteger& aMVOn=aFI.VerticesOn();
321 if (!aMVOn.Contains(nV)) {
322 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV)));
323 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
324 iFlag = myContext->ComputeVF(aV, aF, aT1, aT2, dummy, myFuzzyValue);
327 BOPDS_InterfVF& aVF=aVFs.Append1();
329 aVF.SetIndices(nV, nF);
332 myDS->AddInterf(nV, nF);
334 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();