0025477: Boolean Operations with additional tolerance - Fuzzy Boolean operations
[occt.git] / src / BOPAlgo / BOPAlgo_Builder_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
18#include <BOPAlgo_Builder.ixx>
19
20#include <TopAbs_ShapeEnum.hxx>
21#include <TopoDS_Shape.hxx>
22#include <TopoDS_Iterator.hxx>
23#include <BRep_Builder.hxx>
24
25
26#include <BOPCol_DataMapOfIntegerInteger.hxx>
27#include <BOPCol_ListOfShape.hxx>
28#include <BOPCol_MapOfShape.hxx>
29
30#include <BOPDS_DS.hxx>
31#include <BOPDS_VectorOfListOfPaveBlock.hxx>
32#include <BOPDS_PaveBlock.hxx>
33#include <BOPDS_ListOfPaveBlock.hxx>
34#include <BOPDS_ShapeInfo.hxx>
35
36#include <BOPTools_AlgoTools.hxx>
37
38//=======================================================================
39//function : FillImagesVertices
40//purpose :
41//=======================================================================
42 void BOPAlgo_Builder::FillImagesVertices()
43{
44 myErrorStatus=0;
45 //
46 Standard_Integer nV, nVSD;
47 BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aIt;
48 //
49 const BOPCol_DataMapOfIntegerInteger& aMSDV=myDS->ShapesSD();
50 aIt.Initialize(aMSDV);
51 for (; aIt.More(); aIt.Next()) {
52 nV=aIt.Key();
53 nVSD=aIt.Value();
54 const TopoDS_Shape& aV=myDS->Shape(nV);
55 const TopoDS_Shape& aVSD=myDS->Shape(nVSD);
56 //
57 BOPCol_ListOfShape aLVSD(myAllocator);
58 //
59 aLVSD.Append(aVSD);
60 myImages.Bind(aV, aLVSD);
61 //
62 myShapesSD.Bind(aV, aVSD);
63 }
64}
65//=======================================================================
66//function : FillImagesEdges
67//purpose :
68//=======================================================================
69 void BOPAlgo_Builder::FillImagesEdges()
70{
71 myErrorStatus=0;
72 //
73 Standard_Integer i, aNbPBP, nE, nSp, nSpR;
74 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
75 //
76 const BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->PaveBlocksPool();
77 aNbPBP=aPBP.Extent();
78 for (i=0; i<aNbPBP; ++i) {
79 const BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
80 if (aLPB.Extent()) {
81 BOPCol_ListOfShape aLS(myAllocator);
82 //
83 const Handle(BOPDS_PaveBlock)& aPB1=aLPB.First();
84 nE=aPB1->OriginalEdge();
85 const TopoDS_Shape& aE=myDS->Shape(nE);
86 //
87 aItPB.Initialize(aLPB);
88 for (; aItPB.More(); aItPB.Next()) {
89 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
5a77460e 90 const Handle(BOPDS_PaveBlock)& aPBR=myDS->RealPaveBlock(aPB);
4e57c75e 91 //
92 nSpR=aPBR->Edge();
93 const TopoDS_Shape& aSpR=myDS->Shape(nSpR);
94 aLS.Append(aSpR);
95 myOrigins.Bind(aSpR, aE);
96 //
5a77460e 97 if (myDS->IsCommonBlockOnEdge(aPB)) {
4e57c75e 98 nSp=aPB->Edge();
99 const TopoDS_Shape& aSp=myDS->Shape(nSp);
100 myShapesSD.Bind(aSp, aSpR);
101 }
102 }
103 myImages.Bind(aE, aLS);
104 }
105 }
106}
107//=======================================================================
108// function: IsInterferred
109// purpose:
110//=======================================================================
111 Standard_Boolean BOPAlgo_Builder::IsInterferred(const TopoDS_Shape& theS)const
112{
113 Standard_Boolean bInterferred;
114 TopoDS_Iterator aIt;
115 //
116 bInterferred=Standard_False;
117 aIt.Initialize(theS);
118 for (; aIt.More(); aIt.Next()) {
119 const TopoDS_Shape& aSx=aIt.Value();
120 if (myImages.IsBound(aSx)) {
121 bInterferred=!bInterferred;
122 break;
123 }
124 }
125 return bInterferred;
126}
127//=======================================================================
128//function : BuildResult
129//purpose :
130//=======================================================================
131 void BOPAlgo_Builder::BuildResult(const TopAbs_ShapeEnum theType)
132{
133 myErrorStatus=0;
134 //
135 TopAbs_ShapeEnum aType;
136 BRep_Builder aBB;
137 BOPCol_MapOfShape aM;
138 BOPCol_ListIteratorOfListOfShape aIt, aItIm;
139 //
140 aIt.Initialize(myArguments);
141 for (; aIt.More(); aIt.Next()) {
142 const TopoDS_Shape& aS=aIt.Value();
143 aType=aS.ShapeType();
144 if (aType==theType) {
145 if (myImages.IsBound(aS)){
146 const BOPCol_ListOfShape& aLSIm=myImages.Find(aS);
147 aItIm.Initialize(aLSIm);
148 for (; aItIm.More(); aItIm.Next()) {
149 const TopoDS_Shape& aSIm=aItIm.Value();
150 if (aM.Add(aSIm)) {
151 aBB.Add(myShape, aSIm);
152 }
153 }
154 }
155 else {
156 if (aM.Add(aS)) {
157 aBB.Add(myShape, aS);
158 }
159 }
160 }
161 }
162}
163//=======================================================================
164// function: FillImagesContainers
165// purpose:
166//=======================================================================
167 void BOPAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
168{
169 myErrorStatus=0;
170 //
171 Standard_Integer i, aNbS;
172 BOPCol_MapOfShape aMFP(100, myAllocator);
173 //
174 aNbS=myDS->NbSourceShapes();
175 for (i=0; i<aNbS; ++i) {
176 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
177 if (aSI.ShapeType()==theType) {
178 const TopoDS_Shape& aC=aSI.Shape();
179 FillImagesContainer(aC, theType);
180 }
181 }// for (; aItS.More(); aItS.Next()) {
182}
183//=======================================================================
184// function: FillImagesCompounds
185// purpose:
186//=======================================================================
187 void BOPAlgo_Builder::FillImagesCompounds()
188{
189 myErrorStatus=0;
190 //
191 Standard_Integer i, aNbS;
192 BOPCol_MapOfShape aMFP(100, myAllocator);
193 //
194 aNbS=myDS->NbSourceShapes();
195 for (i=0; i<aNbS; ++i) {
196 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
197 if (aSI.ShapeType()==TopAbs_COMPOUND) {
198 const TopoDS_Shape& aC=aSI.Shape();
199 FillImagesCompound(aC, aMFP);
200 }
201 }// for (; aItS.More(); aItS.Next()) {
202}
203//=======================================================================
204//function : FillImagesContainer
205//purpose :
206//=======================================================================
207 void BOPAlgo_Builder::FillImagesContainer(const TopoDS_Shape& theS,
208 const TopAbs_ShapeEnum theType)
209{
210 Standard_Boolean bInterferred, bToReverse;
211 TopoDS_Iterator aIt;
212 BRep_Builder aBB;
213 BOPCol_ListIteratorOfListOfShape aItIm;
214 //
215 bInterferred=IsInterferred(theS);
216 if (!bInterferred){
217 return;
218 }
219 //
220 TopoDS_Shape aCIm;
221 BOPTools_AlgoTools::MakeContainer(theType, aCIm);
222 //
223 aIt.Initialize(theS);
224 for (; aIt.More(); aIt.Next()) {
225 const TopoDS_Shape& aSx=aIt.Value();
226 if (myImages.IsBound(aSx)) {
227 const BOPCol_ListOfShape& aLFIm=myImages.Find(aSx);
228 aItIm.Initialize(aLFIm);
229 for (; aItIm.More(); aItIm.Next()) {
230 TopoDS_Shape aSxIm=aItIm.Value();
231 //
232 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSxIm, aSx, myContext);
233 if (bToReverse) {
234 aSxIm.Reverse();
235 }
236 aBB.Add(aCIm, aSxIm);
237 }
238 }
239 else {
240 aBB.Add(aCIm, aSx);
241 }
242 }
243 //
244 BOPCol_ListOfShape aLSIm(myAllocator);
245 aLSIm.Append(aCIm);
246 myImages.Bind(theS, aLSIm);
247}
248//=======================================================================
249//function : FillImagesCompound
250//purpose :
251//=======================================================================
252 void BOPAlgo_Builder::FillImagesCompound(const TopoDS_Shape& theS,
253 BOPCol_MapOfShape& theMFP)
254{
255 Standard_Boolean bInterferred;
256 TopAbs_Orientation aOrX;
257 TopoDS_Iterator aIt;
258 BRep_Builder aBB;
259 BOPCol_ListIteratorOfListOfShape aItIm;
260 //
261 if (!theMFP.Add(theS)) {
262 return;
263 }
264 //
265 bInterferred=Standard_False;
266 aIt.Initialize(theS);
267 for (; aIt.More(); aIt.Next()) {
268 const TopoDS_Shape& aSx=aIt.Value();
269 if (aSx.ShapeType()==TopAbs_COMPOUND) {
270 FillImagesCompound(aSx, theMFP);
271 }
272 if (myImages.IsBound(aSx)) {
273 bInterferred=Standard_True;
274 }
275 }
276 if (!bInterferred){
277 return;
278 }
279 //
280 TopoDS_Shape aCIm;
281 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCIm);
282 //
283 aIt.Initialize(theS);
284 for (; aIt.More(); aIt.Next()) {
285 const TopoDS_Shape& aSX=aIt.Value();
286 aOrX=aSX.Orientation();
287 if (myImages.IsBound(aSX)) {
288 const BOPCol_ListOfShape& aLFIm=myImages.Find(aSX);
289 aItIm.Initialize(aLFIm);
290 for (; aItIm.More(); aItIm.Next()) {
291 TopoDS_Shape aSXIm=aItIm.Value();
292 aSXIm.Orientation(aOrX);
293 aBB.Add(aCIm, aSXIm);
294 }
295 }
296 else {
297 aBB.Add(aCIm, aSX);
298 }
299 }
300 //
301 BOPCol_ListOfShape aLSIm(myAllocator);
302 aLSIm.Append(aCIm);
303 myImages.Bind(theS, aLSIm);
304}