0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BRepExtrema / BRepExtrema_ShapeProximity.cxx
1 // Created on: 2014-10-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BRepExtrema_ShapeProximity.hxx>
17
18 #include <Precision.hxx>
19 #include <TopExp_Explorer.hxx>
20
21 //=======================================================================
22 //function : BRepExtrema_ShapeProximity
23 //purpose  : Creates uninitialized proximity tool
24 //=======================================================================
25 BRepExtrema_ShapeProximity::BRepExtrema_ShapeProximity (const Standard_Real theTolerance)
26 : myTolerance   (theTolerance),
27   myElementSet1 (new BRepExtrema_TriangleSet),
28   myElementSet2 (new BRepExtrema_TriangleSet)
29 {
30   // Should be initialized later
31   myIsInitS1 = myIsInitS2 = Standard_False;
32 }
33
34 //=======================================================================
35 //function : BRepExtrema_ShapeProximity
36 //purpose  : Creates proximity tool for the given two shapes
37 //=======================================================================
38 BRepExtrema_ShapeProximity::BRepExtrema_ShapeProximity (const TopoDS_Shape& theShape1,
39                                                         const TopoDS_Shape& theShape2,
40                                                         const Standard_Real theTolerance)
41 : myTolerance   (theTolerance),
42   myElementSet1 (new BRepExtrema_TriangleSet),
43   myElementSet2 (new BRepExtrema_TriangleSet)
44 {
45   LoadShape1 (theShape1);
46   LoadShape2 (theShape2);
47 }
48
49 //=======================================================================
50 //function : LoadShape1
51 //purpose  : Loads 1st shape into proximity tool
52 //=======================================================================
53 Standard_Boolean BRepExtrema_ShapeProximity::LoadShape1 (const TopoDS_Shape& theShape1)
54 {
55   myFaceList1.Clear();
56
57   for (TopExp_Explorer anIter (theShape1, TopAbs_FACE); anIter.More(); anIter.Next())
58   {
59     myFaceList1.Append (static_cast<const TopoDS_Face&> (anIter.Current()));
60   }
61
62   myOverlapTool.MarkDirty();
63
64   return myIsInitS1 = myElementSet1->Init (myFaceList1);
65 }
66
67 //=======================================================================
68 //function : LoadShape2
69 //purpose  : Loads 2nd shape into proximity tool
70 //=======================================================================
71 Standard_Boolean BRepExtrema_ShapeProximity::LoadShape2 (const TopoDS_Shape& theShape2)
72 {
73   myFaceList2.Clear();
74
75   for (TopExp_Explorer anIter (theShape2, TopAbs_FACE); anIter.More(); anIter.Next())
76   {
77     myFaceList2.Append (static_cast<const TopoDS_Face&> (anIter.Current()));
78   }
79
80   myOverlapTool.MarkDirty();
81
82   return myIsInitS2 = myElementSet2->Init (myFaceList2);
83 }
84
85 //=======================================================================
86 //function : Perform
87 //purpose  : Performs search of overlapped faces
88 //=======================================================================
89 void BRepExtrema_ShapeProximity::Perform()
90 {
91   if (!myIsInitS1 || !myIsInitS2 || myOverlapTool.IsDone())
92   {
93     return;
94   }
95
96   myOverlapTool.LoadTriangleSets (myElementSet1,
97                                   myElementSet2);
98
99   myOverlapTool.Perform (myTolerance);
100 }