1 // File: IntTools_ShrunkRange.cxx
2 // Created: Sun Mar 11 10:38:43 2001
3 // Author: Peter KURNEV
7 #include <IntTools_ShrunkRange.ixx>
9 #include <Precision.hxx>
13 #include <gp_Circ.hxx>
17 #include <Geom_Curve.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepBuilderAPI_MakeVertex.hxx>
21 #include <BRepAdaptor_Curve.hxx>
22 #include <BndLib_Add3dCurve.hxx>
24 #include <IntTools_Tools.hxx>
26 //=======================================================================
27 //function : IntTools_ShrunkRange
29 //=======================================================================
30 IntTools_ShrunkRange::IntTools_ShrunkRange ()
34 //=======================================================================
35 //function : IntTools_ShrunkRange
37 //=======================================================================
38 IntTools_ShrunkRange::IntTools_ShrunkRange (const TopoDS_Edge& aE,
39 const TopoDS_Vertex& aV1,
40 const TopoDS_Vertex& aV2,
41 const IntTools_Range& aR,
42 const Handle(IntTools_Context)& aCtx)
49 myIsDone=Standard_False;
53 //=======================================================================
54 //function : SetContext
56 //=======================================================================
57 void IntTools_ShrunkRange::SetContext(const Handle(IntTools_Context)& aContext)
61 //=======================================================================
64 //=======================================================================
65 const Handle(IntTools_Context)& IntTools_ShrunkRange::Context()const
69 //=======================================================================
72 //=======================================================================
73 const TopoDS_Edge& IntTools_ShrunkRange::Edge() const
77 //=======================================================================
78 //function : ShrunkRange
80 //=======================================================================
81 const IntTools_Range& IntTools_ShrunkRange::ShrunkRange() const
85 //=======================================================================
88 //=======================================================================
89 const Bnd_Box& IntTools_ShrunkRange::BndBox() const
93 //=======================================================================
96 //=======================================================================
97 Standard_Boolean IntTools_ShrunkRange::IsDone() const
101 //=======================================================================
102 //function : ErrorStatus
104 //=======================================================================
105 Standard_Integer IntTools_ShrunkRange::ErrorStatus() const
107 return myErrorStatus;
109 //=======================================================================
112 //=======================================================================
113 void IntTools_ShrunkRange::Perform()
115 Standard_Real aCF, aCL, aTolE, aTolV1, aTolV2, t1, t11, t1C, t2, t12, t2C;
116 Standard_Real aCoeff, dt1, dt2, aR;
117 Standard_Integer pri;
118 Standard_Boolean bInf1, bInf2;
119 GeomAbs_CurveType aCurveType;
120 Handle(Geom_Curve) aC;
122 if (myContext.IsNull()) {
123 myContext=new IntTools_Context;
126 aTolE =BRep_Tool::Tolerance(myEdge);
127 aTolV1=BRep_Tool::Tolerance(myV1);
128 aTolV2=BRep_Tool::Tolerance(myV2);
130 myRange.Range (t1, t2);
132 BRepAdaptor_Curve aBAC(myEdge);
133 aCurveType=aBAC.GetType();
135 aC=BRep_Tool::Curve(myEdge, aCF, aCL);
136 BRep_Tool::Range(myEdge, aCF, aCL);
138 if (t1 < aCF || t2 > aCL) {
150 if (aCurveType==GeomAbs_Line) {
151 Standard_Real aTV1, aTV2, aEps;
152 gp_Pnt aPV1, aPV2, aPC1, aPC2;
155 aEps=Precision::Confusion();
156 aEps=aEps*aEps;//1.e-14;
159 aPV1=BRep_Tool::Pnt(myV1);
160 aTV1=ElCLib::Parameter(aL, aPV1);
162 aPV2=BRep_Tool::Pnt(myV2);
163 aTV2=ElCLib::Parameter(aL, aPV2);
165 if (fabs(aTV1-aCF)<aEps && fabs(aTV2-aCL)<aEps) {
170 dt1=aCoeff*(aTolV1+aTolE);
171 dt2=aCoeff*(aTolV2+aTolE);
174 if (aCurveType==GeomAbs_Line) {
175 Standard_Real dt1x, dt2x;
177 dt1x = aBAC.Resolution(dt1);
180 dt2x = aBAC.Resolution(dt2);
183 if (t11>t2 || t12<t1) {
186 myShrunkRange.SetFirst(t1C);
187 myShrunkRange.SetLast (t2C);
190 Standard_Real ddx=aTolE;//1.e-12;
191 BndLib_Add3dCurve::Add (aBAC, t1C, t2C, ddx, myBndBox);
194 myIsDone=Standard_True;
199 if (aCurveType==GeomAbs_Circle) {
200 gp_Circ aCrc=aBAC.Circle();
212 bInf1=Precision::IsNegativeInfinite(t1);
218 Standard_Real d1 = aCoeff*(aTolV1+aTolE);
219 // dt1 = aBAC.Resolution(d1);
223 aBAC.D1(t1, aPoint, aD1vec1);
224 Standard_Real ad1length1 = aD1vec1.Magnitude();
225 Standard_Boolean bTryOtherPoints = Standard_False;
226 dt1 = (t2 - t1) * 0.5;
228 if(ad1length1 > 1.e-12) {
229 dt1 = d1 / ad1length1;
231 if(dt1 > (t2 - t1)) {
232 // bad parametrization, big tolerance or too small range
233 bTryOtherPoints = Standard_True;
237 bTryOtherPoints = Standard_True;
240 if(bTryOtherPoints) {
241 Standard_Integer nbsamples = 5;
242 Standard_Integer ii = 0;
243 Standard_Real adelta = (t2 - t1) / (nbsamples + 1);
244 Standard_Boolean bFound = Standard_False;
246 for(ii = 1; ii <= nbsamples; ii++) {
247 Standard_Real aparameter = t1 + (adelta * ii);
249 aBAC.D1(aparameter, aPoint2, aD1vec1);
251 if(aPoint.Distance(aPoint2) < d1)
253 ad1length1 = aD1vec1.Magnitude();
255 if(ad1length1 > 1.e-12) {
256 dt1 = d1 / ad1length1;
258 if(dt1 < (t2 - t1)) {
259 bFound = Standard_True;
266 if(dt1 > (t2 - t1)) {
267 dt1 = aBAC.Resolution(d1);
276 gp_Vec aV11(aP1, aP11);
277 // avoid exception if aP1 == aP11
278 if (aV11.SquareMagnitude() < gp::Resolution())
285 aP1L.SetCoord (aP1.X()+d1*aD11.X(),
287 aP1.Z()+d1*aD11.Z());
289 BRepBuilderAPI_MakeVertex aMV1(aP1L);
290 const TopoDS_Vertex& aV1L=aMV1.Vertex();
292 pri=myContext->ComputeVE (aV1L, myEdge, t1C);
304 bInf2=Precision::IsPositiveInfinite(t2);
310 Standard_Real d2 = aCoeff*(aTolV2+aTolE);
311 // dt2 = aBAC.Resolution(d2);
316 aBAC.D1(t2, aPoint, aD1vec2);
317 Standard_Real ad1length2 = aD1vec2.Magnitude();
318 Standard_Boolean bTryOtherPoints = Standard_False;
319 dt2 = (t2 - t1) * 0.5;
321 if(ad1length2 > 1.e-12) {
322 dt2 = d2 / ad1length2;
324 if(dt2 > (t2 - t1)) {
325 bTryOtherPoints = Standard_True;
329 bTryOtherPoints = Standard_True;
332 if(bTryOtherPoints) {
333 Standard_Integer nbsamples = 5;
334 Standard_Integer ii = 0;
335 Standard_Real adelta = (t2 - t1) / (nbsamples + 1);
336 Standard_Boolean bFound = Standard_False;
338 for(ii = 1; ii <= nbsamples; ii++) {
339 Standard_Real aparameter = t2 - (adelta * ii);
341 aBAC.D1(aparameter, aPoint2, aD1vec2);
343 if(aPoint.Distance(aPoint2) < d2)
345 ad1length2 = aD1vec2.Magnitude();
347 if(ad1length2 > 1.e-12) {
348 dt2 = d2 / ad1length2;
350 if(dt2 < (t2 - t1)) {
351 bFound = Standard_True;
358 if(dt2 > (t2 - t1)) {
359 dt2 = aBAC.Resolution(d2);
368 gp_Vec aV12(aP2, aP12);
369 // avoid exception if aP1 == aP11
370 if (aV12.SquareMagnitude() < gp::Resolution())
377 aP2L.SetCoord (aP2.X()+d2*aD12.X(),
379 aP2.Z()+d2*aD12.Z());
381 BRepBuilderAPI_MakeVertex aMV2(aP2L);
382 const TopoDS_Vertex& aV2L=aMV2.Vertex();
384 pri=myContext->ComputeVE (aV2L, myEdge, t2C);
396 t2C=t1C+0.1*(t2-t1C);
400 t2C=t1C+0.1*(t2-t1C);
403 myShrunkRange.SetFirst(t1C);
404 myShrunkRange.SetLast (t2C);
407 Standard_Real ddx=aTolE;//1.e-12;
408 BndLib_Add3dCurve::Add (aBAC, t1C, t2C, ddx, myBndBox);
412 myIsDone=Standard_True;
415 //=======================================================================
416 //function : SetShrunkRange
418 //=======================================================================
419 void IntTools_ShrunkRange::SetShrunkRange(const IntTools_Range& aR)
424 myShrunkRange.SetFirst(f);
425 myShrunkRange.SetLast (l);
427 BRepAdaptor_Curve aBAC(myEdge);
428 BndLib_Add3dCurve::Add (aBAC, f, l, 0., myBndBox);
431 /////////////////////////////////////////////////////////////////////////
435 // 1- Nothing has been done
436 // 2- The source range is out of the edge's range
437 // 3- t1 < t2 for source range
438 // 4- Can not project V1L to the Edge;
439 // 5- Can not project V2L to the Edge;
440 // 6- for obtained shrunk range [t11, t12] -> t11>t2 || t12<t1;