1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <Bnd_Box.hxx>
17 #include <BndLib_Add3dCurve.hxx>
18 #include <BRep_Tool.hxx>
19 #include <BRepAdaptor_Curve.hxx>
20 #include <GCPnts_AbscissaPoint.hxx>
21 #include <IntTools_ShrunkRange.hxx>
22 #include <Precision.hxx>
24 //=======================================================================
27 //=======================================================================
28 IntTools_ShrunkRange::IntTools_ShrunkRange ()
34 myIsDone=Standard_False;
35 myIsSplittable=Standard_False;
37 //=======================================================================
40 //=======================================================================
41 IntTools_ShrunkRange::~IntTools_ShrunkRange ()
44 //=======================================================================
47 //=======================================================================
48 void IntTools_ShrunkRange::SetData(const TopoDS_Edge& aE,
49 const Standard_Real aT1,
50 const Standard_Real aT2,
51 const TopoDS_Vertex& aV1,
52 const TopoDS_Vertex& aV2)
59 myIsDone=Standard_False;
60 myIsSplittable=Standard_False;
62 //=======================================================================
63 //function : SetContext
65 //=======================================================================
66 void IntTools_ShrunkRange::SetContext(const Handle(IntTools_Context)& aCtx)
70 //=======================================================================
73 //=======================================================================
74 const Handle(IntTools_Context)& IntTools_ShrunkRange::Context()const
78 //=======================================================================
81 //=======================================================================
82 const TopoDS_Edge& IntTools_ShrunkRange::Edge() const
86 //=======================================================================
87 //function : ShrunkRange
89 //=======================================================================
90 void IntTools_ShrunkRange::ShrunkRange(Standard_Real& aT1,
91 Standard_Real& aT2) const
96 //=======================================================================
99 //=======================================================================
100 const Bnd_Box& IntTools_ShrunkRange::BndBox() const
104 //=======================================================================
105 //function : SetShrunkRange
107 //=======================================================================
108 void IntTools_ShrunkRange::SetShrunkRange(const Standard_Real aT1,
109 const Standard_Real aT2)
114 BRepAdaptor_Curve aBAC(myEdge);
115 BndLib_Add3dCurve::Add(aBAC, aT1, aT2, 0., myBndBox);
118 //=======================================================================
121 //=======================================================================
122 void IntTools_ShrunkRange::Perform()
124 myIsDone = Standard_False;
125 myIsSplittable = Standard_False;
127 // default tolerance - Precision::Confusion()
128 Standard_Real aDTol = Precision::Confusion();
129 // default parametric tolerance - Precision::PConfusion()
130 Standard_Real aPDTol = Precision::PConfusion();
132 if (myT2 - myT1 < aPDTol) {
136 Standard_Real aTolE, aTolV1, aTolV2;
137 aTolE = BRep_Tool::Tolerance(myEdge);
138 aTolV1 = BRep_Tool::Tolerance(myV1);
139 aTolV2 = BRep_Tool::Tolerance(myV2);
141 if (aTolV1 < aTolE) {
145 if (aTolV2 < aTolE) {
149 // to have correspondence with intersection precision
150 // the tolerances of vertices are increased on Precision::Confusion()
154 BRepAdaptor_Curve aBAC(myEdge);
155 // parametric tolerance for the edge
156 // to be used in AbscissaPoint computations
157 Standard_Real aPTolE = aBAC.Resolution(aTolE);
158 // for the edges with big tolerance use
159 // min parametric tolerance - 1% of its range
160 Standard_Real aPTolEMin = (myT2 - myT1) / 100.;
161 if (aPTolE > aPTolEMin) {
165 // compute the shrunk range - part of the edge not covered
166 // by the tolerance spheres of its vertices
167 GCPnts_AbscissaPoint aPC1(aBAC, aTolV1, myT1, aPTolE);
168 // if Abscissa is unable to compute the parameter
169 // use the resolution of the curve
170 myTS1 = aPC1.IsDone() ? aPC1.Parameter() : (myT1 + aBAC.Resolution(aTolV1));
171 if (myT2 - myTS1 < aPDTol) {
176 GCPnts_AbscissaPoint aPC2(aBAC, -aTolV2, myT2, aPTolE);
177 myTS2 = aPC2.IsDone() ? aPC2.Parameter() : (myT2 - aBAC.Resolution(aTolV2));
178 if (myTS2 - myT1 < aPDTol) {
183 if ((myTS2 - myTS1) < aPDTol) {
188 // compute the length of the edge on the shrunk range
189 Standard_Real anEdgeLength =
190 GCPnts_AbscissaPoint::Length(aBAC, myTS1, myTS2, aPTolE);
191 if (anEdgeLength < aDTol) {
196 myIsDone = Standard_True;
198 // check the shrunk range to have the length not less than
199 // 2*aTolE+2*Precision::Confusion()
200 // for the edge to have possibility to be split at least once:
201 // 2*TolE - minimal diameter of tolerance sphere of splitting vertex
202 // 2*Precision::Confusion() - minimal length of the new edges
203 if (anEdgeLength > (2 * aTolE + 2 * aDTol)) {
204 myIsSplittable = Standard_True;
207 // build bounding box for the edge on the shrunk range
208 BndLib_Add3dCurve::Add(aBAC, myTS1, myTS2,
209 aTolE + aDTol, myBndBox);