1 // Created on: 1995-07-19
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Adaptor3d_Curve.hxx>
19 #include <Extrema_CurveTool.hxx>
20 #include <Geom_BezierCurve.hxx>
21 #include <Geom_BSplineCurve.hxx>
22 #include <gp_Pnt.hxx>
23 #include <gp_Vec.hxx>
24 #include <GCPnts_TangentialDeflection.hxx>
25
26 //=======================================================================
27 //function : IsPeriodic
28 //purpose :
29 //=======================================================================
IsPeriodic(const Adaptor3d_Curve & C)30 Standard_Boolean Extrema_CurveTool::IsPeriodic(const Adaptor3d_Curve& C)
31 {
32 GeomAbs_CurveType aType = GetType(C);
33 if (aType == GeomAbs_Circle ||
34 aType == GeomAbs_Ellipse)
35 return Standard_True;
36 else
37 return C.IsPeriodic();
38 }
39
40 //=======================================================================
41 //function : DeflCurvIntervals
42 //purpose :
43 //=======================================================================
Handle(TColStd_HArray1OfReal)44 Handle(TColStd_HArray1OfReal)
45 Extrema_CurveTool::DeflCurvIntervals(const Adaptor3d_Curve& C)
46 {
47 const Standard_Real epsd = 1.e-3;
48 const Standard_Real maxdefl = 1.e3;
49 const Standard_Real mindefl = 1.e-3;
50 Handle(TColStd_HArray1OfReal) Intervals;
51 Standard_Integer nbpnts = 23, i;
52 Standard_Real L = 0.;
53 Standard_Real tf = C.FirstParameter(), tl = C.LastParameter();
54 gp_Pnt aP = C.Value(tf);
55 for (i = 2; i <= nbpnts; ++i)
56 {
57 Standard_Real t = (tf * (nbpnts - i) + (i - 1) * tl) / (nbpnts - 1);
58 gp_Pnt aP1 = C.Value(t);
59 L += aP.Distance(aP1);
60 }
61 //
62 Standard_Real dLdt = L / (tl - tf);
63 if (L <= Precision::Confusion() || dLdt < epsd || (tl - tf) > 10000.) // To avoid problemwith GCPnts
64 {
65 nbpnts = 2;
66 Intervals = new TColStd_HArray1OfReal(1, nbpnts);
67 Intervals->SetValue(1, tf);
68 Intervals->SetValue(nbpnts, tl);
69 return Intervals;
70 }
71 //
72 Standard_Real aDefl = Max(0.01 * L / (2. * M_PI), mindefl);
73 if (aDefl > maxdefl)
74 {
75 nbpnts = 2;
76 Intervals = new TColStd_HArray1OfReal(1, nbpnts);
77 Intervals->SetValue(1, tf);
78 Intervals->SetValue(nbpnts, tl);
79 return Intervals;
80 }
81 //
82 Standard_Real aMinLen = Max(.00001*L, Precision::Confusion());
83 Standard_Real aTol = Max(0.00001*(tl - tf), Precision::PConfusion());
84 //
85 GCPnts_TangentialDeflection aPntGen(C, M_PI / 6, aDefl, 2, aTol, aMinLen);
86 nbpnts = aPntGen.NbPoints();
87 Intervals = new TColStd_HArray1OfReal(1, nbpnts);
88 for (i = 1; i <= nbpnts; ++i)
89 {
90 Intervals->SetValue(i, aPntGen.Parameter(i));
91 }
92 return Intervals;
93 }
94