0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / IntTools / IntTools_ShrunkRange.cxx
CommitLineData
b311480e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
7fd59977 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15
42cf5bc1 16#include <Bnd_Box.hxx>
c0a1a35f 17#include <BRepLib.hxx>
42cf5bc1 18#include <BndLib_Add3dCurve.hxx>
7fd59977 19#include <BRep_Tool.hxx>
7fd59977 20#include <BRepAdaptor_Curve.hxx>
01b5b3df 21#include <GCPnts_AbscissaPoint.hxx>
42cf5bc1 22#include <IntTools_ShrunkRange.hxx>
23#include <Precision.hxx>
7fd59977 24
25//=======================================================================
4e57c75e 26//function :
7fd59977 27//purpose :
28//=======================================================================
1e143abb 29 IntTools_ShrunkRange::IntTools_ShrunkRange ()
7fd59977 30{
4e57c75e 31 myT1=-99;
32 myT2=myT1;
33 myTS1=myT1;
34 myTS2=myT1;
01b5b3df 35 myIsDone=Standard_False;
36 myIsSplittable=Standard_False;
d3578357 37 myLength = 0.0;
7fd59977 38}
7fd59977 39//=======================================================================
505abfb8 40//function : ~
41//purpose :
42//=======================================================================
1e143abb 43IntTools_ShrunkRange::~IntTools_ShrunkRange ()
505abfb8 44{
45}
46//=======================================================================
4e57c75e 47//function : SetData
7fd59977 48//purpose :
49//=======================================================================
1e143abb 50void IntTools_ShrunkRange::SetData(const TopoDS_Edge& aE,
51 const Standard_Real aT1,
52 const Standard_Real aT2,
53 const TopoDS_Vertex& aV1,
54 const TopoDS_Vertex& aV2)
7fd59977 55{
56 myEdge=aE;
57 myV1=aV1;
58 myV2=aV2;
4e57c75e 59 myT1=aT1;
60 myT2=aT2;
01b5b3df 61 myIsDone=Standard_False;
62 myIsSplittable=Standard_False;
d3578357 63 myLength = 0.0;
4f189102
P
64}
65//=======================================================================
505abfb8 66//function : SetContext
67//purpose :
68//=======================================================================
1e143abb 69void IntTools_ShrunkRange::SetContext(const Handle(IntTools_Context)& aCtx)
505abfb8 70{
71 myCtx=aCtx;
72}
73//=======================================================================
74//function : Context
75//purpose :
76//=======================================================================
1e143abb 77const Handle(IntTools_Context)& IntTools_ShrunkRange::Context()const
505abfb8 78{
79 return myCtx;
80}
81//=======================================================================
7fd59977 82//function : Edge
83//purpose :
84//=======================================================================
1e143abb 85const TopoDS_Edge& IntTools_ShrunkRange::Edge() const
7fd59977 86{
87 return myEdge;
88}
89//=======================================================================
90//function : ShrunkRange
91//purpose :
92//=======================================================================
1e143abb 93void IntTools_ShrunkRange::ShrunkRange(Standard_Real& aT1,
94 Standard_Real& aT2) const
7fd59977 95{
4e57c75e 96 aT1=myTS1;
97 aT2=myTS2;
7fd59977 98}
99//=======================================================================
100//function : BndBox
101//purpose :
102//=======================================================================
1e143abb 103const Bnd_Box& IntTools_ShrunkRange::BndBox() const
7fd59977 104{
105 return myBndBox;
106}
7fd59977 107//=======================================================================
4e57c75e 108//function : SetShrunkRange
7fd59977 109//purpose :
110//=======================================================================
1e143abb 111void IntTools_ShrunkRange::SetShrunkRange(const Standard_Real aT1,
112 const Standard_Real aT2)
7fd59977 113{
4e57c75e 114 myTS1=aT1;
115 myTS2=aT2;
116 //
117 BRepAdaptor_Curve aBAC(myEdge);
01b5b3df 118 BndLib_Add3dCurve::Add(aBAC, aT1, aT2, 0., myBndBox);
7fd59977 119}
4e57c75e 120
7fd59977 121//=======================================================================
122//function : Perform
123//purpose :
124//=======================================================================
1e143abb 125void IntTools_ShrunkRange::Perform()
7fd59977 126{
01b5b3df 127 myIsDone = Standard_False;
128 myIsSplittable = Standard_False;
129 //
130 // default tolerance - Precision::Confusion()
131 Standard_Real aDTol = Precision::Confusion();
132 // default parametric tolerance - Precision::PConfusion()
133 Standard_Real aPDTol = Precision::PConfusion();
134 //
135 if (myT2 - myT1 < aPDTol) {
136 return;
137 }
7fd59977 138 //
c0a1a35f 139 gp_Pnt aP1 = BRep_Tool::Pnt(myV1);
140 gp_Pnt aP2 = BRep_Tool::Pnt(myV2);
01b5b3df 141 Standard_Real aTolE, aTolV1, aTolV2;
142 aTolE = BRep_Tool::Tolerance(myEdge);
143 aTolV1 = BRep_Tool::Tolerance(myV1);
144 aTolV2 = BRep_Tool::Tolerance(myV2);
4f189102 145 //
4e57c75e 146 if (aTolV1 < aTolE) {
147 aTolV1 = aTolE;
148 }
4f189102 149 //
4e57c75e 150 if (aTolV2 < aTolE) {
151 aTolV2 = aTolE;
152 }
153 //
01b5b3df 154 // to have correspondence with intersection precision
155 // the tolerances of vertices are increased on Precision::Confusion()
156 aTolV1 += aDTol;
157 aTolV2 += aDTol;
c0a1a35f 158
01b5b3df 159 // compute the shrunk range - part of the edge not covered
160 // by the tolerance spheres of its vertices
c0a1a35f 161 BRepAdaptor_Curve aBAC(myEdge);
162 if (!BRepLib::FindValidRange(aBAC, aTolE, myT1, aP1, aTolV1,
163 myT2, aP2, aTolV2, myTS1, myTS2)) {
164 // no valid range
7fd59977 165 return;
166 }
01b5b3df 167 if ((myTS2 - myTS1) < aPDTol) {
168 // micro edge
169 return;
7fd59977 170 }
171 //
01b5b3df 172 // compute the length of the edge on the shrunk range
c0a1a35f 173 //
174 // parametric tolerance for the edge
175 // to be used in AbscissaPoint computations
176 Standard_Real aPTolE = aBAC.Resolution(aTolE);
177 // for the edges with big tolerance use
178 // min parametric tolerance - 1% of its range
179 Standard_Real aPTolEMin = (myT2 - myT1) / 100.;
180 if (aPTolE > aPTolEMin) {
181 aPTolE = aPTolEMin;
182 }
d3578357 183 myLength = GCPnts_AbscissaPoint::Length(aBAC, myTS1, myTS2, aPTolE);
184 if (myLength < aDTol) {
01b5b3df 185 // micro edge
186 return;
7fd59977 187 }
505abfb8 188 //
01b5b3df 189 myIsDone = Standard_True;
4e57c75e 190 //
01b5b3df 191 // check the shrunk range to have the length not less than
192 // 2*aTolE+2*Precision::Confusion()
193 // for the edge to have possibility to be split at least once:
194 // 2*TolE - minimal diameter of tolerance sphere of splitting vertex
195 // 2*Precision::Confusion() - minimal length of the new edges
d3578357 196 if (myLength > (2 * aTolE + 2 * aDTol)) {
01b5b3df 197 myIsSplittable = Standard_True;
4e57c75e 198 }
199 //
01b5b3df 200 // build bounding box for the edge on the shrunk range
d3578357 201 BndLib_Add3dCurve::Add(aBAC, myTS1, myTS2, aTolE + aDTol, myBndBox);
7fd59977 202}