0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / BRepExtrema / BRepExtrema_ShapeProximity.cxx
CommitLineData
558e68ea 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
ae9a414a 23//purpose : Creates uninitialized proximity tool
558e68ea 24//=======================================================================
25BRepExtrema_ShapeProximity::BRepExtrema_ShapeProximity (const Standard_Real theTolerance)
ae9a414a 26: myTolerance (theTolerance),
27 myElementSet1 (new BRepExtrema_TriangleSet),
28 myElementSet2 (new BRepExtrema_TriangleSet)
558e68ea 29{
30 // Should be initialized later
ae9a414a 31 myIsInitS1 = myIsInitS2 = Standard_False;
558e68ea 32}
33
34//=======================================================================
35//function : BRepExtrema_ShapeProximity
36//purpose : Creates proximity tool for the given two shapes
37//=======================================================================
38BRepExtrema_ShapeProximity::BRepExtrema_ShapeProximity (const TopoDS_Shape& theShape1,
39 const TopoDS_Shape& theShape2,
40 const Standard_Real theTolerance)
ae9a414a 41: myTolerance (theTolerance),
42 myElementSet1 (new BRepExtrema_TriangleSet),
43 myElementSet2 (new BRepExtrema_TriangleSet)
558e68ea 44{
45 LoadShape1 (theShape1);
46 LoadShape2 (theShape2);
47}
48
49//=======================================================================
50//function : LoadShape1
51//purpose : Loads 1st shape into proximity tool
52//=======================================================================
53Standard_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
ae9a414a 62 myOverlapTool.MarkDirty();
558e68ea 63
ae9a414a 64 return myIsInitS1 = myElementSet1->Init (myFaceList1);
558e68ea 65}
66
67//=======================================================================
68//function : LoadShape2
69//purpose : Loads 2nd shape into proximity tool
70//=======================================================================
71Standard_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
ae9a414a 80 myOverlapTool.MarkDirty();
558e68ea 81
ae9a414a 82 return myIsInitS2 = myElementSet2->Init (myFaceList2);
558e68ea 83}
84
85//=======================================================================
86//function : Perform
ae9a414a 87//purpose : Performs search of overlapped faces
558e68ea 88//=======================================================================
89void BRepExtrema_ShapeProximity::Perform()
90{
ae9a414a 91 if (!myIsInitS1 || !myIsInitS2 || myOverlapTool.IsDone())
558e68ea 92 {
93 return;
94 }
95
ae9a414a 96 myOverlapTool.LoadTriangleSets (myElementSet1,
97 myElementSet2);
558e68ea 98
ae9a414a 99 myOverlapTool.Perform (myTolerance);
558e68ea 100}