BOPAlgo_PaveFiller_4.cxx 8.75 KB
Newer Older
1
// Created by: Peter KURNEV
2
// Copyright (c) 2010-2014 OPEN CASCADE SAS
3
4
5
6
// Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
// Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
//                         EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
7
// This file is part of Open CASCADE Technology software library.
8
//
9
10
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
11
12
13
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
14
//
15
16
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
17
18

#include <BOPAlgo_PaveFiller.ixx>
19
//
20
#include <NCollection_IncAllocator.hxx>
21
//
22
23
24
25
26
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Face.hxx>
#include <BRep_Tool.hxx>
#include <BRep_Builder.hxx>
#include <BRepBndLib.hxx>
27
//
28
#include <BOPCol_MapOfInteger.hxx>
29
#include <BOPCol_NCVector.hxx>
30
#include <BOPCol_Parallel.hxx>
31
//
32
#include <IntTools_Context.hxx>
33
//
34
35
36
37
38
39
40
#include <BOPDS_Iterator.hxx>
#include <BOPDS_VectorOfInterfVF.hxx>
#include <BOPDS_Interf.hxx>
#include <BOPDS_SubIterator.hxx>
#include <BOPDS_MapOfPaveBlock.hxx>
#include <BOPDS_FaceInfo.hxx>

41
42
43
44
//=======================================================================
//class    : BOPAlgo_VertexFace
//purpose  : 
//=======================================================================
45
class BOPAlgo_VertexFace : public BOPAlgo_Algo {
46
 public:
47
48
49
50
51
  DEFINE_STANDARD_ALLOC

  BOPAlgo_VertexFace() : 
    BOPAlgo_Algo(),
    myIV(-1), myIF(-1), myIVx(-1), 
52
53
54
    myFlag(-1), myT1(-1.),  myT2(-1.) {
  }
  //
55
  virtual ~BOPAlgo_VertexFace(){
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  }
  //
  void SetIndices(const Standard_Integer nV,
                  const Standard_Integer nF,
                  const Standard_Integer nVx) {
    myIV=nV;
    myIF=nF;
    myIVx=nVx;
  }
  //
  void Indices(Standard_Integer& nV,
               Standard_Integer& nF,
               Standard_Integer& nVx) const {
    nV=myIV;
    nF=myIF;
    nVx=myIVx;
  }
  //
  void SetVertex(const TopoDS_Vertex& aV) {
    myV=aV;
  }
  //
  const TopoDS_Vertex& Vertex()const {
    return myV;
  }
  //
  void SetFace(const TopoDS_Face& aF) {
    myF=aF;
  }
  //
  const TopoDS_Face& Face()const {
    return myF;
  }
  //
  Standard_Integer Flag()const {
    return myFlag;
  }
  //
  void Parameters(Standard_Real& aT1,
                  Standard_Real& aT2)const {
    aT1=myT1;
    aT2=myT2;
  }
  //
100
  void SetContext(const Handle(IntTools_Context)& aContext) {
101
102
103
    myContext=aContext;
  }
  //
104
  const Handle(IntTools_Context)& Context()const {
105
106
107
    return myContext;
  }
  //
108
109
  virtual void Perform() {
    BOPAlgo_Algo::UserBreak();
110
111
112
113
114
115
116
117
118
119
120
121
    myFlag=myContext->ComputeVF(myV, myF, myT1, myT2);
  }
  //
 protected:
  Standard_Integer myIV;
  Standard_Integer myIF;
  Standard_Integer myIVx;
  Standard_Integer myFlag;
  Standard_Real myT1;
  Standard_Real myT2;
  TopoDS_Vertex myV;
  TopoDS_Face myF;
122
  Handle(IntTools_Context) myContext;
123
124
125
126
127
};
//=======================================================================
typedef BOPCol_NCVector<BOPAlgo_VertexFace>
  BOPAlgo_VectorOfVertexFace; 
//
128
typedef BOPCol_ContextFunctor 
129
130
  <BOPAlgo_VertexFace,
  BOPAlgo_VectorOfVertexFace,
131
132
  Handle(IntTools_Context), 
  IntTools_Context> BOPAlgo_VertexFaceFunctor;
133
//
134
typedef BOPCol_ContextCnt 
135
136
  <BOPAlgo_VertexFaceFunctor,
  BOPAlgo_VectorOfVertexFace,
137
  Handle(IntTools_Context)> BOPAlgo_VertexFaceCnt;
138
//
139
140
141
142
//=======================================================================
// function: PerformVF
// purpose: 
//=======================================================================
143
void BOPAlgo_PaveFiller::PerformVF()
144
145
{
  Standard_Boolean bJustAdd;
146
  Standard_Integer iSize, nV, nF, nVSD, iFlag, nVx, aNbVF, k;
147
148
  Standard_Real aT1, aT2, aTolF, aTolV;
  BRep_Builder aBB;
149
  BOPAlgo_VectorOfVertexFace aVVF; 
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
  //
  myErrorStatus=0;
  //
  myIterator->Initialize(TopAbs_VERTEX, TopAbs_FACE);
  iSize=myIterator->ExpectedLength();
  if (iSize) {
    //
    BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
    aVFs.SetIncrement(iSize);
    //
    for (; myIterator->More(); myIterator->Next()) {
      myIterator->Value(nV, nF, bJustAdd);
      if(bJustAdd) {
        continue;
      }
      //
      if (myDS->IsSubShape(nV, nF)) {
        continue;
      }
      //
      if (myDS->HasInterfShapeSubShapes(nV, nF)) {
171
        myDS->ChangeFaceInfo(nF);
172
173
174
175
176
177
178
179
180
181
182
183
        continue;
      }
      //
      nVx=nV;
      if (myDS->HasShapeSD(nV, nVSD)) {
        nVx=nVSD;
      }
      //
      if (myDS->HasInterf(nVx, nF)) {
        continue;
      }
      //
184
185
      myDS->ChangeFaceInfo(nF);// !
      //
186
187
188
      const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); 
      const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); 
      //
189
190
191
192
193
      BOPAlgo_VertexFace& aVertexFace=aVVF.Append1();
      //
      aVertexFace.SetIndices(nV, nF, nVx);
      aVertexFace.SetVertex(aV);
      aVertexFace.SetFace(aF);
194
      aVertexFace.SetProgressIndicator(myProgressIndicator);
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
    }//for (; myIterator->More(); myIterator->Next()) {
    //
    aNbVF=aVVF.Extent();
    //================================================================
    BOPAlgo_VertexFaceCnt::Perform(myRunParallel, aVVF, myContext);
    //================================================================
    //
    for (k=0; k < aNbVF; ++k) {
      const BOPAlgo_VertexFace& aVertexFace=aVVF(k);
      // 
      iFlag=aVertexFace.Flag();
      if (iFlag) {
        continue;
      }
      //
      aVertexFace.Indices(nV, nF, nVx);
      aVertexFace.Parameters(aT1, aT2);
      const TopoDS_Vertex& aV=aVertexFace.Vertex();
      const TopoDS_Face& aF=aVertexFace.Face();
      // 1
215
      BOPDS_InterfVF& aVF=aVFs.Append1();
216
217
218
219
220
221
222
223
224
      aVF.SetIndices(nVx, nF);
      aVF.SetUV(aT1, aT2);
      // 2
      myDS->AddInterf(nVx, nF);
      // 3
      BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
      BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
      aMVIn.Add(nVx);
      // 4
225
226
      aTolV = BRep_Tool::Tolerance(aV);
      aTolF = BRep_Tool::Tolerance(aF);
227
228
229
230
231
      if (aTolV < aTolF) {
        aBB.UpdateVertex(aV, aTolF);
        BOPDS_ShapeInfo& aSIV = myDS->ChangeShapeInfo(nVx);
        Bnd_Box& aBoxV = aSIV.ChangeBox();
        BRepBndLib::Add(aV, aBoxV);
232
      }
233
    }//for (k=0; k < aNbVF; ++k) {
234
235
236
237
238
239
  }// if (iSize) {
  else {
    iSize=10;
    BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
    aVFs.SetIncrement(iSize);
  }
240
  //
241
  TreatVerticesEE();
242
}
243
244
245
246
//=======================================================================
//function : TreatVerticesEE
//purpose  : 
//=======================================================================
247
void BOPAlgo_PaveFiller::TreatVerticesEE()
248
{
249
  Standard_Integer i, aNbS,aNbEEs, nF, nV, iFlag;
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
  Standard_Real aT1, aT2;
  BOPCol_ListIteratorOfListOfInteger aItLI;
  Handle(NCollection_IncAllocator) aAllocator;
  //
  aAllocator=new NCollection_IncAllocator();
  BOPCol_ListOfInteger aLIV(aAllocator), aLIF(aAllocator);
  BOPCol_MapOfInteger aMI(100, aAllocator);
  BOPDS_MapOfPaveBlock aMPBF(100, aAllocator);
  //
  myErrorStatus=0;
  //
  
  aNbS=myDS->NbSourceShapes();
  //
  BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
  aNbEEs=aEEs.Extent();
  for (i=0; i<aNbEEs; ++i) {
    BOPDS_InterfEE& aEE=aEEs(i);
    if (aEE.HasIndexNew()) {
      nV=aEE.IndexNew();
      if (aMI.Add(nV)) {
        aLIV.Append(nV);
      }   
    }   
  }
  if (!aLIV.Extent()) {
    aAllocator.Nullify();
    return;
  }
  //
  aNbS=myDS->NbSourceShapes();
  for (nF=0; nF<aNbS; ++nF) {
    const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(nF);
    if (aSI.ShapeType()==TopAbs_FACE) {
      aLIF.Append(nF);
    }
  }
  if (!aLIF.Extent()) {
    aAllocator.Nullify();
    return;
  }
  //-------------------------------------------------------------
  BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
  //
  BOPDS_SubIterator aIt(aAllocator);
  //
  aIt.SetDS(myDS);
  aIt.SetSubSet1(aLIF);
  aIt.SetSubSet2(aLIV);
  aIt.Prepare();
  aIt.Initialize();
  for (; aIt.More(); aIt.Next()) {
    aIt.Value(nV, nF);
    //
    BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
    const BOPCol_MapOfInteger& aMVOn=aFI.VerticesOn();
    //
    if (!aMVOn.Contains(nV)) {
      const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV))); 
      const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); 
      iFlag=myContext->ComputeVF(aV, aF, aT1, aT2);
      if (!iFlag) {
        // 1
313
314
        BOPDS_InterfVF& aVF=aVFs.Append1();
        i=aVFs.Extent()-1;
315
316
317
318
319
320
321
322
323
324
325
326
327
        aVF.SetIndices(nV, nF);
        aVF.SetUV(aT1, aT2);
        // 2
        myDS->AddInterf(nV, nF);
        //
        BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
        aMVIn.Add(nV);
      }
    }
  }
  //
  aAllocator.Nullify();
}