1 // Created on: 1995-07-17
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <GeomAbs_CurveType.hxx>
19 #include <GeomAbs_Shape.hxx>
20 #include <Geom_BezierCurve.hxx>
21 #include <Geom_BSplineCurve.hxx>
23 #include <TColStd_Array1OfReal.hxx>
24 #include <TColStd_Array1OfBoolean.hxx>
25 #include <gce_MakeLin.hxx>
30 //============================================================
31 Standard_Integer IntCurveSurface_HCurveTool::NbSamples (const CurveGen& C,
32 const Standard_Real U0,
33 const Standard_Real U1) {
34 GeomAbs_CurveType typC = C->GetType();
35 const Standard_Real nbsOther = 10.0;
36 Standard_Real nbs = nbsOther;
38 if(typC == GeomAbs_Line)
40 else if(typC == GeomAbs_BezierCurve)
41 nbs = 3 + C->NbPoles();
42 else if(typC == GeomAbs_BSplineCurve) {
45 nbs*= C->LastParameter()- C->FirstParameter();
51 return((Standard_Integer)nbs);
53 //============================================================
54 void IntCurveSurface_HCurveTool::SamplePars (const CurveGen& C,
55 const Standard_Real U0,
56 const Standard_Real U1,
57 const Standard_Real Defl,
58 const Standard_Integer NbMin,
59 Handle(TColStd_HArray1OfReal)& Pars) {
60 GeomAbs_CurveType typC = C->GetType();
61 const Standard_Real nbsOther = 10.0;
62 Standard_Real nbs = nbsOther;
64 if(typC == GeomAbs_Line)
66 else if(typC == GeomAbs_BezierCurve) {
67 nbs = 3 + C->NbPoles();
70 if(typC != GeomAbs_BSplineCurve) {
73 Standard_Integer nnbs = (Standard_Integer)nbs;
75 Pars = new TColStd_HArray1OfReal(1, nnbs);
76 Standard_Real du = (U1-U0)/(nnbs - 1);
78 Pars->SetValue(1, U0);
79 Pars->SetValue(nnbs, U1);
82 for(i = 2, u = U0+du; i < nnbs; ++i, u += du) {
88 const Handle(Geom_BSplineCurve)& aBC = C->BSpline();
90 Standard_Integer i, j, k, nbi;
91 Standard_Real t1, t2, dt;
92 Standard_Integer ui1 = aBC->FirstUKnotIndex();
93 Standard_Integer ui2 = aBC->LastUKnotIndex();
95 for(i = ui1; i < ui2; ++i) {
96 if(U0 >= aBC->Knot(i) && U0 < aBC->Knot(i+1)) {
102 for(i = ui2; i > ui1; --i) {
103 if(U1 <= aBC->Knot(i) && U1 > aBC->Knot(i-1)) {
109 Standard_Integer nbsu = ui2-ui1+1; nbsu += (nbsu - 1) * (aBC->Degree()-1);
110 Standard_Boolean bUniform = Standard_False;
113 bUniform = Standard_True;
116 TColStd_Array1OfReal aPars(1, nbsu);
117 TColStd_Array1OfBoolean aFlg(1, nbsu);
118 //Filling of sample parameters
122 dt = (t2 - t1)/(nbsu - 1);
124 aFlg(1) = Standard_False;
126 aFlg(nbsu) = Standard_False;
127 for(i = 2, t1 += dt; i < nbsu; ++i, t1 += dt) {
129 aFlg(i) = Standard_False;
136 for(i = ui1+1; i <= ui2; ++i) {
137 if(i == ui2) t2 = U1;
138 else t2 = aBC->Knot(i);
144 aFlg(k) = Standard_False;
153 //Analysis of deflection
156 Standard_Real aDefl2 = Max(Defl*Defl, 1.e-9);
157 Standard_Real tol = Max(0.01*aDefl2, 1.e-9);
160 Standard_Integer NbSamples = 2;
161 aFlg(1) = Standard_True;
162 aFlg(nbsu) = Standard_True;
164 Standard_Boolean bCont = Standard_True;
165 while (j < nbsu-1 && bCont) {
173 gp_Pnt p1 = aBC->Value(t2);
174 for(k = j+2; k <= nbsu; ++k) {
176 gp_Pnt p2 = aBC->Value(t2);
178 if(p1.SquareDistance(p2) <= tol) continue;
180 gce_MakeLin MkLin(p1, p2);
181 const gp_Lin& lin = MkLin.Value();
182 Standard_Boolean ok = Standard_True;
183 for(l = j+1; l < k; ++l) {
190 gp_Pnt pp = aBC->Value(aPars(l));
191 Standard_Real d = lin.SquareDistance(pp);
193 if(d <= aDefl2) continue;
201 aFlg(j) = Standard_True;
214 if(k >= nbsu) bCont = Standard_False;
218 if(NbSamples < myMinPnts) {
219 //uniform distribution
220 NbSamples = myMinPnts;
221 Pars = new TColStd_HArray1OfReal(1, NbSamples);
224 dt = (t2 - t1)/(NbSamples - 1);
225 Pars->SetValue(1, t1);
226 Pars->SetValue(NbSamples, t2);
227 for(i = 2, t1 += dt; i < NbSamples; ++i, t1 += dt) {
228 Pars->SetValue(i, t1);
233 Pars = new TColStd_HArray1OfReal(1, NbSamples);
235 for(i = 1; i <= nbsu; ++i) {
238 Pars->SetValue(j,aPars(i));