1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
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
7 // This file is part of Open CASCADE Technology software library.
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
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.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
18 #include <BOPAlgo_CheckerSI.hxx>
20 #include <BOPDS_DS.hxx>
21 #include <BOPDS_Interf.hxx>
22 #include <BOPDS_IteratorSI.hxx>
24 #include <BOPTools_Parallel.hxx>
26 #include <BRep_Tool.hxx>
27 #include <BRepClass3d_SolidClassifier.hxx>
29 #include <IntTools_Context.hxx>
33 #include <NCollection_Vector.hxx>
34 #include <TopAbs_State.hxx>
35 #include <TopoDS_Vertex.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopoDS_Solid.hxx>
39 /////////////////////////////////////////////////////////////////////////
40 //=======================================================================
41 //class : BOPAlgo_VertexSolid
43 //=======================================================================
44 class BOPAlgo_VertexSolid {
49 : myIV(-1), myIZ(-1), myState(TopAbs_UNKNOWN) {
52 virtual ~BOPAlgo_VertexSolid(){
55 void SetIndices(const Standard_Integer nV,
56 const Standard_Integer nZ){
61 void Indices(Standard_Integer& nV,
62 Standard_Integer& nZ) const {
67 void SetVertex(const TopoDS_Vertex& aV) {
71 const TopoDS_Vertex& Vertex()const {
75 void SetSolid(const TopoDS_Solid& aZ) {
79 const TopoDS_Solid& Solid()const {
83 void SetContext(const Handle(IntTools_Context)& aContext) {
87 const Handle(IntTools_Context)& Context()const {
91 TopAbs_State State() const{
99 BRepClass3d_SolidClassifier& aSC=myContext->SolidClassifier(myZ);
101 aPV=BRep_Tool::Pnt(myV);
102 aTol=BRep_Tool::Tolerance(myV);
104 aSC.Perform(aPV, aTol);
110 Standard_Integer myIV;
111 Standard_Integer myIZ;
112 TopAbs_State myState;
115 Handle(IntTools_Context) myContext;
117 //=======================================================================
118 typedef NCollection_Vector
119 <BOPAlgo_VertexSolid> BOPAlgo_VectorOfVertexSolid;
121 typedef BOPTools_ContextFunctor
122 <BOPAlgo_VertexSolid,
123 BOPAlgo_VectorOfVertexSolid,
124 Handle(IntTools_Context),
125 IntTools_Context> BOPAlgo_VertexSolidFunctor;
127 typedef BOPTools_ContextCnt
128 <BOPAlgo_VertexSolidFunctor,
129 BOPAlgo_VectorOfVertexSolid,
130 Handle(IntTools_Context)> BOPAlgo_VertexSolidCnt;
131 /////////////////////////////////////////////////////////////////////////
132 //=======================================================================
133 //class : BOPAlgo_ShapeSolid
135 //=======================================================================
136 class BOPAlgo_ShapeSolid {
138 DEFINE_STANDARD_ALLOC
140 BOPAlgo_ShapeSolid() :
143 myHasInterf(Standard_False),
147 virtual ~BOPAlgo_ShapeSolid(){
150 void SetIndices(const Standard_Integer nE,
151 const Standard_Integer nZ){
156 void Indices(Standard_Integer& nE,
157 Standard_Integer& nZ) const {
162 void SetDS(BOPDS_DS* pDS) {
166 Standard_Boolean HasInterf() const{
170 virtual void Perform() {
171 Standard_Boolean bHasInterf;
173 myHasInterf=Standard_False;
175 bHasInterf=myDS->HasInterfShapeSubShapes(myIE, myIZ);
177 myHasInterf=myDS->HasInterfShapeSubShapes(myIZ, myIE);
182 Standard_Integer myIE;
183 Standard_Integer myIZ;
184 Standard_Boolean myHasInterf;
187 //=======================================================================
188 typedef NCollection_Vector
189 <BOPAlgo_ShapeSolid> BOPAlgo_VectorOfShapeSolid;
191 typedef BOPTools_Functor
193 BOPAlgo_VectorOfShapeSolid> BOPAlgo_ShapeSolidFunctor;
196 <BOPAlgo_ShapeSolidFunctor,
197 BOPAlgo_VectorOfShapeSolid> BOPAlgo_ShapeSolidCnt;
199 /////////////////////////////////////////////////////////////////////////
200 //=======================================================================
201 //class : BOPAlgo_SolidSolid
203 //=======================================================================
204 class BOPAlgo_SolidSolid : public BOPAlgo_ShapeSolid {
206 DEFINE_STANDARD_ALLOC
208 BOPAlgo_SolidSolid() :
209 BOPAlgo_ShapeSolid() {
212 virtual ~BOPAlgo_SolidSolid(){
215 virtual void Perform() {
216 Standard_Boolean bFlag;
218 bFlag=Standard_False;
219 myHasInterf=Standard_False;
221 myHasInterf=myDS->HasInterfShapeSubShapes(myIZ, myIE, bFlag);
223 myHasInterf=myDS->HasInterfShapeSubShapes(myIE, myIZ, bFlag);
227 //=======================================================================
228 typedef NCollection_Vector
229 <BOPAlgo_SolidSolid> BOPAlgo_VectorOfSolidSolid;
231 typedef BOPTools_Functor
233 BOPAlgo_VectorOfSolidSolid> BOPAlgo_SolidSolidFunctor;
236 <BOPAlgo_SolidSolidFunctor,
237 BOPAlgo_VectorOfSolidSolid> BOPAlgo_SolidSolidCnt;
239 /////////////////////////////////////////////////////////////////////////
241 //=======================================================================
242 //function : PerformVZ
244 //=======================================================================
245 void BOPAlgo_CheckerSI::PerformVZ()
247 Standard_Integer iSize, nV, nZ, k, aNbVVS;
249 BOPDS_MapOfPair aMPK;
251 myIterator->Initialize(TopAbs_VERTEX, TopAbs_SOLID);
252 iSize=myIterator->ExpectedLength();
257 BOPDS_VectorOfInterfVZ& aVZs=myDS->InterfVZ();
258 aVZs.SetIncrement(iSize);
260 BOPAlgo_VectorOfVertexSolid aVVS;
262 for (; myIterator->More(); myIterator->Next()) {
263 myIterator->Value(nV, nZ);
265 if (myDS->HasInterfShapeSubShapes(nV, nZ)) {
269 Standard_Integer nVSD = nV;
270 myDS->HasShapeSD(nV, nVSD);
273 aPK.SetIndices(nVSD, nZ);
274 if (!aMPK.Add(aPK)) {
278 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nVSD));
279 const TopoDS_Solid& aZ=*((TopoDS_Solid*)&myDS->Shape(nZ));
281 BOPAlgo_VertexSolid& aVertexSolid=aVVS.Appended();
282 aVertexSolid.SetIndices(nV, nZ);
283 aVertexSolid.SetVertex(aV);
284 aVertexSolid.SetSolid(aZ);
287 aNbVVS=aVVS.Length();
288 //=============================================================
289 BOPAlgo_VertexSolidCnt::Perform(myRunParallel, aVVS, myContext);
290 //=============================================================
291 for (k=0; k < aNbVVS; ++k) {
292 const BOPAlgo_VertexSolid& aVertexSolid=aVVS(k);
293 aState=aVertexSolid.State();
294 if (aState==TopAbs_IN) {
295 aVertexSolid.Indices(nV, nZ);
297 BOPDS_InterfVZ& aVZ=aVZs.Appended();
298 aVZ.SetIndices(nV, nZ);
300 myDS->AddInterf(nV, nZ);
304 //=======================================================================
305 //function : PerformEZ
307 //=======================================================================
308 void BOPAlgo_CheckerSI::PerformEZ()
310 PerformSZ(TopAbs_EDGE);
312 //=======================================================================
313 //function : PerformFZ
315 //=======================================================================
316 void BOPAlgo_CheckerSI::PerformFZ()
318 PerformSZ(TopAbs_FACE);
320 //=======================================================================
321 //function : PerformZZ
323 //=======================================================================
324 void BOPAlgo_CheckerSI::PerformZZ()
326 Standard_Boolean bHasInterf;
327 Standard_Integer iSize, nZ1, nZ, k, aNbSolidSolid;
329 myIterator->Initialize(TopAbs_SOLID, TopAbs_SOLID);
330 iSize=myIterator->ExpectedLength();
335 BOPAlgo_VectorOfSolidSolid aVSolidSolid;
337 for (; myIterator->More(); myIterator->Next()) {
338 myIterator->Value(nZ1, nZ);
340 BOPAlgo_SolidSolid& aSolidSolid=aVSolidSolid.Appended();
341 aSolidSolid.SetIndices(nZ1, nZ);
342 aSolidSolid.SetDS(myDS);
345 aNbSolidSolid=aVSolidSolid.Length();
346 //======================================================
347 BOPAlgo_SolidSolidCnt::Perform(myRunParallel, aVSolidSolid);
348 //======================================================
350 BOPDS_VectorOfInterfZZ& aZZs=myDS->InterfZZ();
352 aZZs.SetIncrement(iSize);
354 for (k=0; k < aNbSolidSolid; ++k) {
355 const BOPAlgo_SolidSolid& aSolidSolid=aVSolidSolid(k);
356 bHasInterf=aSolidSolid.HasInterf();
358 aSolidSolid.Indices(nZ1, nZ);
360 BOPDS_InterfZZ& aZZ=aZZs.Appended();
361 aZZ.SetIndices(nZ1, nZ);
363 myDS->AddInterf(nZ1, nZ);
367 //=======================================================================
368 //function : PerformSZ
370 //=======================================================================
371 void BOPAlgo_CheckerSI::PerformSZ(const TopAbs_ShapeEnum aTS)
373 Standard_Boolean bHasInterf;
374 Standard_Integer iSize, nS, nZ, k, aNbShapeSolid;
376 myIterator->Initialize(aTS, TopAbs_SOLID);
377 iSize=myIterator->ExpectedLength();
382 BOPAlgo_VectorOfShapeSolid aVShapeSolid;
384 for (; myIterator->More(); myIterator->Next()) {
385 myIterator->Value(nS, nZ);
387 BOPAlgo_ShapeSolid& aShapeSolid=aVShapeSolid.Appended();
388 aShapeSolid.SetIndices(nS, nZ);
389 aShapeSolid.SetDS(myDS);
392 aNbShapeSolid=aVShapeSolid.Length();
393 //======================================================
394 BOPAlgo_ShapeSolidCnt::Perform(myRunParallel, aVShapeSolid);
395 //======================================================
397 BOPDS_VectorOfInterfEZ& aEZs=myDS->InterfEZ();
398 BOPDS_VectorOfInterfFZ& aFZs=myDS->InterfFZ();
400 if (aTS==TopAbs_EDGE) {
401 aEZs.SetIncrement(iSize);
403 else {//if (aTS==TopAbs_FACE)
404 aFZs.SetIncrement(iSize);
407 for (k=0; k < aNbShapeSolid; ++k) {
408 const BOPAlgo_ShapeSolid& aShapeSolid=aVShapeSolid(k);
409 bHasInterf=aShapeSolid.HasInterf();
411 aShapeSolid.Indices(nS, nZ);
413 if (aTS==TopAbs_EDGE) {
414 BOPDS_InterfEZ& aEZ=aEZs.Appended();
415 aEZ.SetIndices(nS, nZ);
417 else {//if (aTS==TopAbs_FACE)
418 BOPDS_InterfFZ& aFZ=aFZs.Appended();
419 aFZ.SetIndices(nS, nZ);
422 myDS->AddInterf(nS, nZ);