0026738: Make Boolean operations safely treating arguments when running with fuzzy...
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_1.cxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 2010-2014 OPEN CASCADE SAS
4e57c75e 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//
973c2be1 7// This file is part of Open CASCADE Technology software library.
4e57c75e 8//
d5f74e42 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
973c2be1 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.
4e57c75e 14//
973c2be1 15// Alternatively, this file may be used under the terms of Open CASCADE
16// commercial license or contractual agreement.
4e57c75e 17
4e57c75e 18
19#include <Bnd_Box.hxx>
42cf5bc1 20#include <BOPAlgo_PaveFiller.hxx>
21#include <BOPAlgo_SectionAttribute.hxx>
22#include <BOPAlgo_Tools.hxx>
3510db62 23#include <BOPCol_DataMapOfIntegerInteger.hxx>
4e57c75e 24#include <BOPCol_DataMapOfIntegerListOfInteger.hxx>
4e57c75e 25#include <BOPCol_ListOfShape.hxx>
42cf5bc1 26#include <BOPCol_MapOfInteger.hxx>
27#include <BOPDS_Curve.hxx>
4e57c75e 28#include <BOPDS_DS.hxx>
29#include <BOPDS_Iterator.hxx>
42cf5bc1 30#include <BOPDS_PaveBlock.hxx>
4e57c75e 31#include <BOPDS_ShapeInfo.hxx>
42cf5bc1 32#include <BOPDS_VectorOfInterfVV.hxx>
33#include <BOPTools_AlgoTools.hxx>
34#include <BRepBndLib.hxx>
3510db62 35#include <BRep_TVertex.hxx>
36#include <BRep_Tool.hxx>
42cf5bc1 37#include <gp_Pnt.hxx>
38#include <IntTools_Context.hxx>
39#include <NCollection_BaseAllocator.hxx>
3510db62 40#include <Precision.hxx>
41#include <TopoDS.hxx>
42cf5bc1 42#include <TopoDS_Face.hxx>
43#include <TopoDS_Vertex.hxx>
4e57c75e 44
45//=======================================================================
46// function: PerformVV
47// purpose:
48//=======================================================================
488e5b9d 49void BOPAlgo_PaveFiller::PerformVV()
4e57c75e 50{
51 Standard_Boolean bWithSubShape;
3510db62 52 Standard_Integer n1, n2, iFlag, aSize, k, aNbBlocks;
488e5b9d 53 Handle(NCollection_BaseAllocator) aAllocator;
4e57c75e 54 //
55 myErrorStatus=0;
56 //
57 myIterator->Initialize(TopAbs_VERTEX, TopAbs_VERTEX);
58 aSize=myIterator->ExpectedLength();
59 if (!aSize) {
60 return;
61 }
62 //
4e57c75e 63 BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
4e57c75e 64 aVVs.SetIncrement(aSize);
4e57c75e 65 //
66 //-----------------------------------------------------scope f
488e5b9d 67 aAllocator=
68 NCollection_BaseAllocator::CommonBaseAllocator();
4e57c75e 69 BOPCol_IndexedDataMapOfIntegerListOfInteger aMILI(100, aAllocator);
70 BOPCol_DataMapOfIntegerListOfInteger aMBlocks(100, aAllocator);
4e57c75e 71 //
72 // 1. Map V/LV
73 for (; myIterator->More(); myIterator->Next()) {
74 myIterator->Value(n1, n2, bWithSubShape);
75 //
76 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(n1)));
77 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(n2)));
78 //
0d0481c7 79 iFlag=BOPTools_AlgoTools::ComputeVV(aV1, aV2, myFuzzyValue);
4e57c75e 80 if (!iFlag) {
81 BOPAlgo_Tools::FillMap(n1, n2, aMILI, aAllocator);
82 }
83 }
84 //
85 // 2. Make blocks
86 BOPAlgo_Tools::MakeBlocksCnx(aMILI, aMBlocks, aAllocator);
87 //
88 // 3. Make vertices
89 aNbBlocks=aMBlocks.Extent();
90 for (k=0; k<aNbBlocks; ++k) {
91 const BOPCol_ListOfInteger& aLI=aMBlocks.Find(k);
92 //
3510db62 93 MakeSDVertices(aLI);
94 }
95 //
96 BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aItDMII;
97 //
98 BOPCol_DataMapOfIntegerInteger& aDMII=myDS->ShapesSD();
99 aItDMII.Initialize(aDMII);
100 for (; aItDMII.More(); aItDMII.Next()) {
101 n1=aItDMII.Key();
102 myDS->InitPaveBlocksForVertex(n1);
4e57c75e 103 }
4e57c75e 104 //
105 //-----------------------------------------------------scope t
4e57c75e 106 aMBlocks.Clear();
107 aMILI.Clear();
4e57c75e 108}
3510db62 109
110//=======================================================================
111// function: PerformVV
112// purpose:
113//=======================================================================
0d0481c7 114Standard_Integer BOPAlgo_PaveFiller::MakeSDVertices
115 (const BOPCol_ListOfInteger& theVertIndices,
116 const Standard_Boolean theAddInterfs)
3510db62 117{
118 TopoDS_Vertex aVSD, aVn;
0d0481c7 119 Standard_Integer nSD = -1;
3510db62 120 BOPCol_ListIteratorOfListOfInteger aItLI(theVertIndices);
121 BOPCol_ListOfShape aLV;
122 for (; aItLI.More(); aItLI.Next()) {
0d0481c7 123 Standard_Integer nX = aItLI.Value(), nSD1;
124 if (myDS->HasShapeSD(nX, nSD1)) {
125 const TopoDS_Shape& aVSD1 = myDS->Shape(nSD1);
126 if (nSD == -1) {
127 aVSD = TopoDS::Vertex(aVSD1);
128 nSD = nSD1;
129 }
130 else {
131 aLV.Append(aVSD1);
132 }
3510db62 133 }
134 const TopoDS_Shape& aV = myDS->Shape(nX);
135 aLV.Append(aV);
136 }
137 BOPTools_AlgoTools::MakeVertex(aLV, aVn);
0d0481c7 138 Standard_Integer nV;
139 if (nSD != -1) {
3510db62 140 // update old SD vertex with new value
141 Handle(BRep_TVertex)& aTVertex =
142 reinterpret_cast<Handle(BRep_TVertex)&>(const_cast<Handle(TopoDS_TShape)&>(aVSD.TShape()));
143 aTVertex->Pnt(BRep_Tool::Pnt(aVn));
144 aTVertex->Tolerance(BRep_Tool::Tolerance(aVn));
0d0481c7 145 aVn = aVSD;
146 nV = nSD;
3510db62 147 }
0d0481c7 148 else {
149 // Append new vertex to the DS
150 BOPDS_ShapeInfo aSIn;
151 aSIn.SetShapeType(TopAbs_VERTEX);
152 aSIn.SetShape(aVn);
153 nV = myDS->Append(aSIn);
154 }
155 BOPDS_ShapeInfo& aSIDS = myDS->ChangeShapeInfo(nV);
3510db62 156 Bnd_Box& aBox = aSIDS.ChangeBox();
157 BRepBndLib::Add(aVn, aBox);
158 aBox.SetGap(aBox.GetGap() + Precision::Confusion());
159 //
160 // Fill ShapesSD
161 BOPDS_VectorOfInterfVV& aVVs = myDS->InterfVV();
0d0481c7 162 if (theAddInterfs)
163 aVVs.SetIncrement(theVertIndices.Extent());
3510db62 164 //
165 aItLI.Initialize(theVertIndices);
166 for (; aItLI.More(); aItLI.Next()) {
167 Standard_Integer n1 = aItLI.Value();
0d0481c7 168 myDS->AddShapeSD(n1, nV);
3510db62 169 //
0d0481c7 170 if (theAddInterfs) {
171 BOPCol_ListIteratorOfListOfInteger aItLI2 = aItLI;
172 aItLI2.Next();
173 for (; aItLI2.More(); aItLI2.Next()) {
174 Standard_Integer n2 = aItLI2.Value();
175 //
176 myDS->AddInterf(n1, n2);
177 BOPDS_InterfVV& aVV = aVVs.Append1();
178 //
179 aVV.SetIndices(n1, n2);
180 aVV.SetIndexNew(nV);
181 }
3510db62 182 }
183 }
0d0481c7 184 return nV;
3510db62 185}