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 <BRepLib.hxx>
18 #include <BndLib_Add3dCurve.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAdaptor_Curve.hxx>
21 #include <GCPnts_AbscissaPoint.hxx>
22 #include <IntTools_ShrunkRange.hxx>
23 #include <Precision.hxx>
25 //=======================================================================
28 //=======================================================================
29 IntTools_ShrunkRange::IntTools_ShrunkRange ()
35 myIsDone=Standard_False;
36 myIsSplittable=Standard_False;
39 //=======================================================================
42 //=======================================================================
43 IntTools_ShrunkRange::~IntTools_ShrunkRange ()
46 //=======================================================================
49 //=======================================================================
50 void 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)
61 myIsDone=Standard_False;
62 myIsSplittable=Standard_False;
65 //=======================================================================
66 //function : SetContext
68 //=======================================================================
69 void IntTools_ShrunkRange::SetContext(const Handle(IntTools_Context)& aCtx)
73 //=======================================================================
76 //=======================================================================
77 const Handle(IntTools_Context)& IntTools_ShrunkRange::Context()const
81 //=======================================================================
84 //=======================================================================
85 const TopoDS_Edge& IntTools_ShrunkRange::Edge() const
89 //=======================================================================
90 //function : ShrunkRange
92 //=======================================================================
93 void IntTools_ShrunkRange::ShrunkRange(Standard_Real& aT1,
94 Standard_Real& aT2) const
99 //=======================================================================
102 //=======================================================================
103 const Bnd_Box& IntTools_ShrunkRange::BndBox() const
107 //=======================================================================
108 //function : SetShrunkRange
110 //=======================================================================
111 void IntTools_ShrunkRange::SetShrunkRange(const Standard_Real aT1,
112 const Standard_Real aT2)
117 BRepAdaptor_Curve aBAC(myEdge);
118 BndLib_Add3dCurve::Add(aBAC, aT1, aT2, 0., myBndBox);
121 //=======================================================================
124 //=======================================================================
125 void IntTools_ShrunkRange::Perform()
127 myIsDone = Standard_False;
128 myIsSplittable = Standard_False;
130 // default tolerance - Precision::Confusion()
131 Standard_Real aDTol = Precision::Confusion();
132 // default parametric tolerance - Precision::PConfusion()
133 Standard_Real aPDTol = Precision::PConfusion();
135 if (myT2 - myT1 < aPDTol) {
139 gp_Pnt aP1 = BRep_Tool::Pnt(myV1);
140 gp_Pnt aP2 = BRep_Tool::Pnt(myV2);
141 Standard_Real aTolE, aTolV1, aTolV2;
142 aTolE = BRep_Tool::Tolerance(myEdge);
143 aTolV1 = BRep_Tool::Tolerance(myV1);
144 aTolV2 = BRep_Tool::Tolerance(myV2);
146 if (aTolV1 < aTolE) {
150 if (aTolV2 < aTolE) {
154 // to have correspondence with intersection precision
155 // the tolerances of vertices are increased on Precision::Confusion()
159 // compute the shrunk range - part of the edge not covered
160 // by the tolerance spheres of its vertices
161 BRepAdaptor_Curve aBAC(myEdge);
162 if (!BRepLib::FindValidRange(aBAC, aTolE, myT1, aP1, aTolV1,
163 myT2, aP2, aTolV2, myTS1, myTS2)) {
167 if ((myTS2 - myTS1) < aPDTol) {
172 // compute the length of the edge on the shrunk range
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) {
183 myLength = GCPnts_AbscissaPoint::Length(aBAC, myTS1, myTS2, aPTolE);
184 if (myLength < aDTol) {
189 myIsDone = Standard_True;
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
196 if (myLength > (2 * aTolE + 2 * aDTol)) {
197 myIsSplittable = Standard_True;
200 // build bounding box for the edge on the shrunk range
201 BndLib_Add3dCurve::Add(aBAC, myTS1, myTS2, aTolE + aDTol, myBndBox);