0025477: Boolean Operations with additional tolerance - Fuzzy Boolean operations
[occt.git] / src / BRepAlgoAPI / BRepAlgoAPI_Check.cxx
CommitLineData
6aca4d39 1// Created on: 2012-12-17
4e57c75e 2// Created by: Eugeny MALTCHIKOV
6aca4d39 3// Copyright (c) 2012-2014 OPEN CASCADE SAS
4e57c75e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
4e57c75e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
4e57c75e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
4e57c75e 15
16#include <BRepAlgoAPI_Check.ixx>
17#include <BOPAlgo_ArgumentAnalyzer.hxx>
4e57c75e 18#include <BRepCheck_Analyzer.hxx>
19
20//=======================================================================
21//function : BRepAlgoAPI_Check
22//purpose :
23//=======================================================================
b1d15f53 24BRepAlgoAPI_Check::BRepAlgoAPI_Check()
25:
26 BRepAlgoAPI_Algo(),
27 myAnalyzer(NULL),
28 myFuzzyValue(0.)
4e57c75e 29{
30}
31
32//=======================================================================
33//function : BRepAlgoAPI_Check
34//purpose :
35//=======================================================================
b1d15f53 36BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS,
37 const Standard_Boolean bTestSE,
38 const Standard_Boolean bTestSI)
39: BRepAlgoAPI_Algo(),
40 myFuzzyValue(0.)
4e57c75e 41{
42 Init(theS, TopoDS_Shape(), BOPAlgo_UNKNOWN, bTestSE, bTestSI);
43 //
44 Perform();
45}
46
47//=======================================================================
48//function : BRepAlgoAPI_Check
49//purpose :
50//=======================================================================
b1d15f53 51BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS1,
52 const TopoDS_Shape& theS2,
53 const BOPAlgo_Operation theOp,
54 const Standard_Boolean bTestSE,
55 const Standard_Boolean bTestSI)
56: BRepAlgoAPI_Algo(),
57 myFuzzyValue(0.)
4e57c75e 58{
59 Init(theS1, theS2, theOp, bTestSE, bTestSI);
60 //
61 Perform();
62}
63
64//=======================================================================
65//function : ~BRepAlgoAPI_Check
66//purpose :
67//=======================================================================
b1d15f53 68BRepAlgoAPI_Check::~BRepAlgoAPI_Check()
4e57c75e 69{
70 if(myAnalyzer){
71 delete myAnalyzer;
72 myAnalyzer=NULL;
73 }
74 myResult.Clear();
75}
76
77//=======================================================================
b1d15f53 78//function : SetFuzzyValue
79//purpose :
80//=======================================================================
81void BRepAlgoAPI_Check::SetFuzzyValue(const Standard_Real theFuzz)
82{
83 if (theFuzz > 0.) {
84 myFuzzyValue = theFuzz;
85 }
86}
87//=======================================================================
88//function : FuzzyValue
89//purpose :
90//=======================================================================
91Standard_Real BRepAlgoAPI_Check::FuzzyValue() const
92{
93 return myFuzzyValue;
94}
95
96//=======================================================================
4e57c75e 97//function : SetData
98//purpose :
99//=======================================================================
b1d15f53 100void BRepAlgoAPI_Check::SetData(const TopoDS_Shape& theS,
101 const Standard_Boolean bTestSE,
102 const Standard_Boolean bTestSI)
4e57c75e 103{
104 Init(theS, TopoDS_Shape(), BOPAlgo_UNKNOWN, bTestSE, bTestSI);
105}
106
107//=======================================================================
108//function : SetData
109//purpose :
110//=======================================================================
b1d15f53 111void BRepAlgoAPI_Check::SetData(const TopoDS_Shape& theS1,
112 const TopoDS_Shape& theS2,
113 const BOPAlgo_Operation theOp,
114 const Standard_Boolean bTestSE,
115 const Standard_Boolean bTestSI)
4e57c75e 116{
117 Init(theS1, theS2, theOp, bTestSE, bTestSI);
118}
4e57c75e 119//=======================================================================
120//function : Init
121//purpose :
122//=======================================================================
b1d15f53 123void BRepAlgoAPI_Check::Init(const TopoDS_Shape& theS1,
124 const TopoDS_Shape& theS2,
125 const BOPAlgo_Operation theOp,
126 const Standard_Boolean bTestSE,
127 const Standard_Boolean bTestSI)
4e57c75e 128{
129 myResult.Clear();
a967f104 130 myS1 = theS1;
131 myS2 = theS2;
4e57c75e 132 //
133 myAnalyzer = new BOPAlgo_ArgumentAnalyzer();
134 //
135 myAnalyzer->SetShape1(myS1);
136 myAnalyzer->SetShape2(myS2);
a967f104 137 myAnalyzer->OperationType() = theOp;
4e57c75e 138 myAnalyzer->ArgumentTypeMode() = Standard_True;
139 myAnalyzer->SmallEdgeMode() = bTestSE;
140 myAnalyzer->SelfInterMode() = bTestSI;
b1d15f53 141 //
142 myAnalyzer->SetRunParallel(myRunParallel);
143 myAnalyzer->SetProgressIndicator(myProgressIndicator);
144 myAnalyzer->SetFuzzyValue(myFuzzyValue);
4e57c75e 145}
146
147//=======================================================================
148//function : Result
149//purpose :
150//=======================================================================
b1d15f53 151const BOPAlgo_ListOfCheckResult& BRepAlgoAPI_Check::Result()
4e57c75e 152{
153 return myResult;
154}
155
156//=======================================================================
157//function : IsValid
158//purpose :
159//=======================================================================
b1d15f53 160Standard_Boolean BRepAlgoAPI_Check::IsValid()
4e57c75e 161{
162 return myResult.IsEmpty();
163}
164
165//=======================================================================
166//function : Perform
167//purpose :
168//=======================================================================
b1d15f53 169void BRepAlgoAPI_Check::Perform()
4e57c75e 170{
171 Standard_Boolean isS1, isS2;
172 //incompatibility of shape types, small edges and self-interference
173 myAnalyzer->Perform();
174 if (myAnalyzer->HasFaulty()) {
175 myResult = myAnalyzer->GetCheckResult();
176 }
177
178 //topological validity
179 isS1 = !myS1.IsNull();
180 isS2 = !myS2.IsNull();
181 if (isS1) {
182 BRepCheck_Analyzer anS1(myS1);
183 isS1 = anS1.IsValid();
184 } else {
185 isS1 = Standard_True;
186 }
187 //
188 if (isS2) {
189 BRepCheck_Analyzer anS2(myS2);
190 isS2 = anS2.IsValid();
191 } else {
192 isS2 = Standard_True;
193 }
194 if (!isS1 || !isS2) {
195 BOPAlgo_CheckResult aRes;
196 aRes.SetCheckStatus(BOPAlgo_NotValid);
197 if (!isS1) {
198 aRes.SetShape1(myS1);
199 }
200 if (!isS1) {
201 aRes.SetShape2(myS2);
202 }
203 myResult.Append(aRes);
204 }
205}