1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: NMTTools_PaveFiller_7.cxx
21 // Created: Thu Dec 18 15:14:55 2003
22 // Author: Peter KURNEV
26 #include <NMTTools_PaveFiller.ixx>
28 #include <Bnd_HArray1OfBox.hxx>
29 #include <Bnd_BoundSortBox.hxx>
30 #include <Bnd_Box.hxx>
31 #include <BRepBndLib.hxx>
33 #include <TColStd_MapOfInteger.hxx>
34 #include <TColStd_ListIteratorOfListOfInteger.hxx>
35 #include <TopTools_DataMapOfShapeListOfInteger.hxx>
36 #include <TColStd_ListOfInteger.hxx>
37 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TopAbs_Orientation.hxx>
41 #include <TopoDS_Vertex.hxx>
42 #include <TopoDS_Edge.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopoDS_Compound.hxx>
47 #include <TopTools_DataMapIteratorOfDataMapOfIntegerShape.hxx>
48 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
49 #include <TopTools_DataMapOfShapeInteger.hxx>
50 #include <TopTools_DataMapOfShapeShape.hxx>
51 #include <TopTools_DataMapOfShapeListOfInteger.hxx>
52 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfInteger.hxx>
53 #include <TopTools_DataMapOfIntegerShape.hxx>
55 #include <BRep_Builder.hxx>
56 #include <BRep_Tool.hxx>
58 #include <TopExp_Explorer.hxx>
61 #include <IntTools_SequenceOfPntOn2Faces.hxx>
62 #include <IntTools_PntOnFace.hxx>
63 #include <IntTools_PntOn2Faces.hxx>
65 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
67 #include <BOPTools_SSInterference.hxx>
68 #include <BOPTools_CArray1OfSSInterference.hxx>
69 #include <BOPTools_CArray1OfVVInterference.hxx>
70 #include <BOPTools_VVInterference.hxx>
71 #include <BOPTools_Tools.hxx>
72 #include <BOPTools_ListOfPaveBlock.hxx>
73 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
74 #include <BOPTools_PaveBlock.hxx>
75 #include <BOPTools_Pave.hxx>
76 #include <BOPTools_Tools.hxx>
78 #include <NMTDS_Iterator.hxx>
79 #include <NMTDS_ShapesDataStructure.hxx>
80 #include <NMTDS_InterfPool.hxx>
82 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
83 // Modified Thu Sep 14 14:35:18 2006
84 // Contribution of Samtech www.samcef.com BEGIN
86 void FuseVertices(const TopoDS_Shape& aCompound,
87 TopTools_DataMapOfShapeShape& aDMVV);
88 // Contribution of Samtech www.samcef.com END
90 //=======================================================================
91 // function: MakeSplitEdges
93 //=======================================================================
94 void NMTTools_PaveFiller::MakeSplitEdges()
96 myIsDone=Standard_False;
98 Standard_Boolean bIsNewVertex1, bIsNewVertex2;
99 Standard_Integer i, aNbS, nV1, nV2, aNbPaveBlocks, aNewShapeIndex;
100 Standard_Real t1, t2;
101 TopAbs_Orientation anOri;
102 TopoDS_Edge aE, aESplit;
103 TopoDS_Vertex aV1, aV2;
105 aNbS=myDS->NumberOfShapesOfTheObject();
106 for (i=1; i<=aNbS; ++i) {
107 if (myDS->GetShapeType(i) != TopAbs_EDGE)
111 aE=TopoDS::Edge(myDS->Shape(i));
112 if (BRep_Tool::Degenerated(aE)){
116 anOri=aE.Orientation();
117 aE.Orientation(TopAbs_FORWARD);
119 // Making Split Edges
121 // Split Set for the Original Edge i
122 BOPTools_ListOfPaveBlock& aSplitEdges=mySplitShapesPool(myDS->RefEdge(i));
123 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);
125 aNbPaveBlocks=aSplitEdges.Extent();
127 for (; aPBIt.More(); aPBIt.Next()) {
128 BOPTools_PaveBlock& aPB=aPBIt.Value();
130 const BOPTools_Pave& aPave1=aPB.Pave1();
133 aV1=TopoDS::Vertex(myDS->GetShape(nV1));
134 aV1.Orientation(TopAbs_FORWARD);
136 const BOPTools_Pave& aPave2=aPB.Pave2();
139 aV2=TopoDS::Vertex(myDS->GetShape(nV2));
140 aV2.Orientation(TopAbs_REVERSED);
142 if (aNbPaveBlocks==1) {
143 bIsNewVertex1=myDS->IsNewShape (nV1);
144 bIsNewVertex2=myDS->IsNewShape (nV2);
145 if (!bIsNewVertex1 && !bIsNewVertex2) {
151 BOPTools_Tools::MakeSplitEdge(aE, aV1, t1, aV2, t2, aESplit);
153 // Add Split Part of the Original Edge to the DS
154 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
156 anASSeq.SetNewSuccessor(nV1);
157 anASSeq.SetNewOrientation(aV1.Orientation());
159 anASSeq.SetNewSuccessor(nV2);
160 anASSeq.SetNewOrientation(aV2.Orientation());
162 if (anOri==TopAbs_INTERNAL) {
163 anASSeq.SetNewAncestor(i);
164 aESplit.Orientation(anOri);
167 myDS->InsertShapeAndAncestorsSuccessors(aESplit, anASSeq);
168 aNewShapeIndex=myDS->NumberOfInsertedShapes();
169 myDS->SetState(aNewShapeIndex, BooleanOperations_UNKNOWN);
171 // Fill Split Set for the Original Edge
172 aPB.SetEdge(aNewShapeIndex);
176 myIsDone=Standard_True;
178 //=======================================================================
179 // function: UpdateCommonBlocks
181 //=======================================================================
182 void NMTTools_PaveFiller::UpdateCommonBlocks()
184 myIsDone=Standard_False;
186 Standard_Integer nE, aNbS, nSp, nEx, nSpx;
187 NMTTools_ListIteratorOfListOfCommonBlock aCBIt;
188 BOPTools_ListIteratorOfListOfPaveBlock aPBIt;
190 aNbS=myDS->NumberOfShapesOfTheObject();
192 for (nE=1; nE<=aNbS; ++nE) {
193 if (myDS->GetShapeType(nE)!=TopAbs_EDGE){
196 if (BRep_Tool::Degenerated(TopoDS::Edge(myDS->Shape(nE)))){
200 NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE));
201 BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool (myDS->RefEdge(nE));
203 aCBIt.Initialize(aLCB);
204 for (; aCBIt.More(); aCBIt.Next()) {
205 NMTTools_CommonBlock& aCB=aCBIt.Value();
207 //modified by NIZNHY-PKV Wed Nov 8 15:59:46 2006f
208 // Among all PBs of aCB the first PB will be one
209 // that have max tolerance value
211 Standard_Real aTolEx, aTolExMax;
212 BOPTools_ListOfPaveBlock *pLPB, aLPBx;
215 pLPB=(BOPTools_ListOfPaveBlock *)&aCB.PaveBlocks();
216 aPBIt.Initialize(*pLPB);
217 for (; aPBIt.More(); aPBIt.Next()) {
218 const BOPTools_PaveBlock& aPBx=aPBIt.Value();
219 nEx=aPBx.OriginalEdge();
220 const TopoDS_Edge& aEx=TopoDS::Edge(myDS->Shape(nEx));
221 aTolEx=BRep_Tool::Tolerance(aEx);
222 if (aTolEx>aTolExMax) {
234 //modified by NIZNHY-PKV Wed Nov 8 15:59:50 2006t
236 BOPTools_PaveBlock& aPB=aCB.PaveBlock1(nE);
240 const BOPTools_ListOfPaveBlock& aCBLPB=aCB.PaveBlocks();
241 aPBIt.Initialize(aCBLPB);
242 for (; aPBIt.More(); aPBIt.Next()) {
243 BOPTools_PaveBlock& aPBx=aPBIt.Value();
244 nEx=aPBx.OriginalEdge();
249 nSpx=SplitIndex(aPBx);
256 //=======================================================================
257 // function: SplitIndex
259 //=======================================================================
260 Standard_Integer NMTTools_PaveFiller::SplitIndex(const BOPTools_PaveBlock& aPBx)const
262 Standard_Integer anOriginalEdge, anEdgeIndex=0;
264 anOriginalEdge=aPBx.OriginalEdge();
266 const BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(anOriginalEdge));
268 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
269 for (; anIt.More(); anIt.Next()) {
270 BOPTools_PaveBlock& aPB=anIt.Value();
271 if (aPB.IsEqual(aPBx)) {
272 anEdgeIndex=aPB.Edge();
278 //=======================================================================
279 // function: UpdatePaveBlocks
281 //=======================================================================
282 void NMTTools_PaveFiller::UpdatePaveBlocks()
284 myIsDone=Standard_False;
287 Standard_Integer i, aNbFFs, nF1, nF2, aNbF, nF, iRankF, nE, nV1, nV2, aNbPB;
288 Standard_Real aT1, aT2;
289 TColStd_IndexedMapOfInteger aMF, aME;
290 TopExp_Explorer aExp;
291 TopoDS_Vertex aV1, aV2;
293 BOPTools_Pave aPave1, aPave2;
294 BOPTools_PaveBlock aPB;
296 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
298 aNbFFs=aFFs.Extent();
299 for (i=1; i<=aNbFFs; ++i) {
300 BOPTools_SSInterference& aFFi=aFFs(i);
301 aFFi.Indices(nF1, nF2);
307 for(i=1; i<=aNbF; ++i) {
309 iRankF=myDS->Rank(nF);
310 const TopoDS_Shape aF=myDS->Shape(nF);//mpv
311 aExp.Init(aF, TopAbs_EDGE);
312 for(; aExp.More(); aExp.Next()) {
313 aE=TopoDS::Edge(aExp.Current());
315 if (BRep_Tool::Degenerated(aE)) {
319 nE=myDS->ShapeIndex(aE, iRankF);
321 if (aME.Contains(nE)) {
326 BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
331 TopExp::Vertices(aE, aV1, aV2);
333 nV1=myDS->ShapeIndex(aV1, iRankF);
334 aT1=BRep_Tool::Parameter(aV1, aE);
335 aPave1.SetIndex(nV1);
336 aPave1.SetParam(aT1);
338 nV2=myDS->ShapeIndex(aV2, iRankF);
339 aT2=BRep_Tool::Parameter(aV2, aE);
340 aPave2.SetIndex(nV2);
341 aPave2.SetParam(aT2);
344 aPB.SetOriginalEdge(nE);
345 aPB.SetPave1(aPave1);
346 aPB.SetPave2(aPave2);
353 // to treat Alone Vertices between faces
354 // Thu Sep 14 14:35:18 2006
355 // Contribution of Samtech www.samcef.com BEGIN
356 //=======================================================================
357 // function: MakeAloneVertices
359 //=======================================================================
360 void NMTTools_PaveFiller::MakeAloneVertices()
362 Standard_Integer i, aNbFFs, nF1, nF2, j, aNbPnts, nFx, aNbV;
363 Standard_Real aTolF1, aTolF2, aTolSum, aTolV;
364 TColStd_ListIteratorOfListOfInteger aIt;
365 TColStd_ListOfInteger aLI;
367 TopoDS_Compound aCompound;
369 TopTools_DataMapOfShapeListOfInteger aDMVFF, aDMVFF1;
370 TopTools_DataMapIteratorOfDataMapOfShapeListOfInteger aItDMVFF;
371 TopTools_DataMapOfShapeShape aDMVV;
372 TopTools_DataMapOfIntegerShape aDMIV;
373 TopTools_DataMapOfShapeInteger aDMVI;
374 TopTools_DataMapIteratorOfDataMapOfShapeInteger aItDMVI;
375 TopTools_DataMapIteratorOfDataMapOfIntegerShape aItDMIV;
377 aBB.MakeCompound(aCompound);
379 myAloneVertices.Clear();
381 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
383 // 1. Collect alone vertices from FFs
385 aNbFFs=aFFs.Extent();
386 for (i=1; i<=aNbFFs; ++i) {
387 BOPTools_SSInterference& aFFi=aFFs(i);
388 aFFi.Indices(nF1, nF2);
390 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
391 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
393 aTolF1=BRep_Tool::Tolerance(aF1);
394 aTolF2=BRep_Tool::Tolerance(aF2);
395 aTolSum=aTolF1+aTolF2;
401 const IntTools_SequenceOfPntOn2Faces& aSeqAlonePnts=aFFi.AlonePnts();
402 aNbPnts=aSeqAlonePnts.Length();
403 for (j=1; j<=aNbPnts; ++j) {
404 const gp_Pnt& aP=aSeqAlonePnts(j).P1().Pnt();
405 BOPTools_Tools::MakeNewVertex(aP, aTolSum, aV);
406 aDMVFF.Bind(aV, aLI);
407 aBB.Add(aCompound, aV);
415 // 2. Try to fuse alone vertices themselves;
416 FuseVertices(aCompound, aDMVV);
418 // if some are fused, replace them by new ones
419 aItDMVFF.Initialize(aDMVFF);
420 for (; aItDMVFF.More(); aItDMVFF.Next()) {
421 const TopoDS_Shape& aVx=aItDMVFF.Key();
422 const TColStd_ListOfInteger& aLIx=aItDMVFF.Value();
424 if (!aDMVV.IsBound(aVx)) {
425 aDMVFF1.Bind(aVx, aLIx);
428 const TopoDS_Shape& aVy=aDMVV.Find(aVx);
430 if (aDMVFF1.IsBound(aVy)) {
431 TColStd_ListOfInteger& aLIy=aDMVFF1.ChangeFind(aVy);
432 aIt.Initialize(aLIx);
433 for(; aIt.More(); aIt.Next()) {
439 aDMVFF1.Bind(aVy, aLIx);
445 // refine lists of faces in aDMVFF1;
446 aItDMVFF.Initialize(aDMVFF1);
447 for (; aItDMVFF.More(); aItDMVFF.Next()) {
448 TColStd_MapOfInteger aMIy;
449 TColStd_ListOfInteger aLIy;
451 const TopoDS_Shape& aVx=aItDMVFF.Key();
452 TColStd_ListOfInteger& aLIx=aDMVFF1.ChangeFind(aVx);
453 aIt.Initialize(aLIx);
454 for(; aIt.More(); aIt.Next()) {
463 //==================================
465 // 3. Collect vertices from DS
466 Standard_Integer aNbS, nV, nVSD, aNbVDS, i1, i2, aNbVSD;
468 aNbS=myDS->NumberOfShapesOfTheObject();
470 for (i=1; i<=aNbS; ++i) {
471 const TopoDS_Shape& aS=myDS->Shape(i);
472 if (aS.ShapeType() != TopAbs_VERTEX){
476 nVSD=FindSDVertex(i);
477 nV=(nVSD) ? nVSD : i;
478 const TopoDS_Shape& aVx=myDS->Shape(nV);
479 if (!aDMVI.IsBound(aVx)) {
484 i1=myDS->NumberOfSourceShapes()+1;
485 i2=myDS->NumberOfInsertedShapes();
486 for (i=i1; i<=i2; ++i) {
487 const TopoDS_Shape aS=myDS->Shape(i);//mpv
488 if (aS.ShapeType() != TopAbs_VERTEX){
491 if (!aDMVI.IsBound(aS)) {
496 // 4. Initialize BoundSortBox on aDMVI
498 Handle(Bnd_HArray1OfBox) aHAB;
499 Bnd_BoundSortBox aBSB;
501 aNbVDS=aDMVI.Extent();
502 aHAB=new Bnd_HArray1OfBox(1, aNbVDS);
504 aItDMVI.Initialize(aDMVI);
505 for (i=1; aItDMVI.More(); aItDMVI.Next(), ++i) {
509 aV=TopoDS::Vertex(aItDMVI.Key());
510 aTolV=BRep_Tool::Tolerance(aV);
512 BRepBndLib::Add(aV, aBox);
513 aHAB->SetValue(i, aBox);
517 aBSB.Initialize(aHAB);
520 aItDMVFF.Initialize(aDMVFF1);
521 for (; aItDMVFF.More(); aItDMVFF.Next()) {
524 const TColStd_ListOfInteger& aLIFF=aItDMVFF.Value();
525 aV=TopoDS::Vertex(aItDMVFF.Key());
527 aTolV=BRep_Tool::Tolerance(aV);
529 BRepBndLib::Add(aV, aBoxV);
531 const TColStd_ListOfInteger& aLIVSD=aBSB.Compare(aBoxV);
532 aNbVSD=aLIVSD.Extent();
534 // add new vertex in DS and update map myAloneVertices
535 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
537 myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
538 nV=myDS->NumberOfInsertedShapes();
540 aIt.Initialize(aLIFF);
541 for (; aIt.More(); aIt.Next()) {
543 if (myAloneVertices.Contains(nFx)) {
544 TColStd_IndexedMapOfInteger& aMVx=myAloneVertices.ChangeFromKey(nFx);
548 TColStd_IndexedMapOfInteger aMVx;
550 myAloneVertices.Add(nFx, aMVx);
557 Standard_Integer aNbF, aNbAV, nF, k;
558 NMTTools_IndexedDataMapOfIndexedMapOfInteger aMAVF;
560 aNbF=myAloneVertices.Extent();
565 // 1. fill map Alone Vertex/Face -> aMAVF
566 for (i=1; i<=aNbF; ++i) {
567 nF=myAloneVertices.FindKey(i);
568 const TColStd_IndexedMapOfInteger& aMAV=myAloneVertices(i);
570 for(j=1; j<=aNbAV; ++j) {
572 if (aMAVF.Contains(nV)) {
573 TColStd_IndexedMapOfInteger& aMF=aMAVF.ChangeFromKey(nV);
577 TColStd_IndexedMapOfInteger aMF;
584 // 2 Obtain pairs of faces
585 aNbAV=aMAVF.Extent();
586 for (i=1; i<=aNbAV; ++i) {
587 const TColStd_IndexedMapOfInteger& aMF=aMAVF(i);
589 for(j=1; j<aNbF; ++j) {
591 for(k=j+1; k<=aNbF; ++k) {
593 myIP->Add(nF1, nF2, Standard_True, NMTDS_TI_FF);
600 //=======================================================================
601 // function: AloneVertices
603 //=======================================================================
604 const NMTTools_IndexedDataMapOfIndexedMapOfInteger& NMTTools_PaveFiller::AloneVertices()const
606 return myAloneVertices;
608 //=======================================================================
609 // function: FuseVertices
611 //=======================================================================
612 void NMTTools_PaveFiller::FuseVertices(const TopoDS_Shape& aCompound,
613 TopTools_DataMapOfShapeShape& aDMVV)const
615 Standard_Integer i, aNbVV, n1, n2, nX;
616 NMTTools_PaveFiller tPF;
618 tPF.SetCompositeShape(aCompound);
623 //tPF.PerformNewVertices(); //qq
625 NMTDS_ShapesDataStructure& tDS=*(tPF.DS());
626 NMTDS_InterfPool& tInterfPool=*(tPF.IP());
627 BOPTools_CArray1OfVVInterference& aVVt=tInterfPool.VVInterferences();
630 for (i=1; i<=aNbVV; ++i) {
631 const BOPTools_VVInterference& aVV=aVVt(i);
635 const TopoDS_Shape& aV1=tDS.Shape(n1);
636 const TopoDS_Shape& aV2=tDS.Shape(n2);
637 const TopoDS_Shape& aVx=tDS.Shape(nX);
638 aDMVV.Bind(aV1, aVx);
639 aDMVV.Bind(aV2, aVx);
643 // Contribution of Samtech www.samcef.com END