Warning, /include/opencascade/IntCurveSurface_HCurveTool.gxx is written in an unsupported language. File is not indexed.
0001 // Created on: 1995-07-17
0002 // Created by: Modelistation
0003 // Copyright (c) 1995-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016
0017 #include CurveGen_hxx
0018 #include <GeomAbs_CurveType.hxx>
0019 #include <GeomAbs_Shape.hxx>
0020 #include <Geom_BezierCurve.hxx>
0021 #include <Geom_BSplineCurve.hxx>
0022
0023 #include <TColStd_Array1OfReal.hxx>
0024 #include <TColStd_Array1OfBoolean.hxx>
0025 #include <gce_MakeLin.hxx>
0026 #include <gp_Pnt.hxx>
0027 #include <gp_Lin.hxx>
0028
0029 #define myMinPnts 5
0030 //============================================================
0031 Standard_Integer IntCurveSurface_HCurveTool::NbSamples (const CurveGen& C,
0032 const Standard_Real U0,
0033 const Standard_Real U1) {
0034 GeomAbs_CurveType typC = C->GetType();
0035 const Standard_Real nbsOther = 10.0;
0036 Standard_Real nbs = nbsOther;
0037
0038 if(typC == GeomAbs_Line)
0039 nbs = 2;
0040 else if(typC == GeomAbs_BezierCurve)
0041 nbs = 3 + C->NbPoles();
0042 else if(typC == GeomAbs_BSplineCurve) {
0043 nbs = C->NbKnots();
0044 nbs*= C->Degree();
0045 nbs*= C->LastParameter()- C->FirstParameter();
0046 nbs/= U1-U0;
0047 if(nbs < 2.0) nbs=2;
0048 }
0049 if(nbs>50)
0050 nbs = 50;
0051 return((Standard_Integer)nbs);
0052 }
0053 //============================================================
0054 void IntCurveSurface_HCurveTool::SamplePars (const CurveGen& C,
0055 const Standard_Real U0,
0056 const Standard_Real U1,
0057 const Standard_Real Defl,
0058 const Standard_Integer NbMin,
0059 Handle(TColStd_HArray1OfReal)& Pars) {
0060 GeomAbs_CurveType typC = C->GetType();
0061 const Standard_Real nbsOther = 10.0;
0062 Standard_Real nbs = nbsOther;
0063
0064 if(typC == GeomAbs_Line)
0065 nbs = 2;
0066 else if(typC == GeomAbs_BezierCurve) {
0067 nbs = 3 + C->NbPoles();
0068 }
0069
0070 if(typC != GeomAbs_BSplineCurve) {
0071 if(nbs>50)
0072 nbs = 50;
0073 Standard_Integer nnbs = (Standard_Integer)nbs;
0074
0075 Pars = new TColStd_HArray1OfReal(1, nnbs);
0076 Standard_Real du = (U1-U0)/(nnbs - 1);
0077
0078 Pars->SetValue(1, U0);
0079 Pars->SetValue(nnbs, U1);
0080 Standard_Integer i;
0081 Standard_Real u;
0082 for(i = 2, u = U0+du; i < nnbs; ++i, u += du) {
0083 Pars->SetValue(i, u);
0084 }
0085 return;
0086 }
0087
0088 const Handle(Geom_BSplineCurve)& aBC = C->BSpline();
0089
0090 Standard_Integer i, j, k, nbi;
0091 Standard_Real t1, t2, dt;
0092 Standard_Integer ui1 = aBC->FirstUKnotIndex();
0093 Standard_Integer ui2 = aBC->LastUKnotIndex();
0094
0095 for(i = ui1; i < ui2; ++i) {
0096 if(U0 >= aBC->Knot(i) && U0 < aBC->Knot(i+1)) {
0097 ui1 = i;
0098 break;
0099 }
0100 }
0101
0102 for(i = ui2; i > ui1; --i) {
0103 if(U1 <= aBC->Knot(i) && U1 > aBC->Knot(i-1)) {
0104 ui2 = i;
0105 break;
0106 }
0107 }
0108
0109 Standard_Integer nbsu = ui2-ui1+1; nbsu += (nbsu - 1) * (aBC->Degree()-1);
0110 Standard_Boolean bUniform = Standard_False;
0111 if(nbsu < NbMin) {
0112 nbsu = NbMin;
0113 bUniform = Standard_True;
0114 }
0115
0116 TColStd_Array1OfReal aPars(1, nbsu);
0117 TColStd_Array1OfBoolean aFlg(1, nbsu);
0118 //Filling of sample parameters
0119 if(bUniform) {
0120 t1 = U0;
0121 t2 = U1;
0122 dt = (t2 - t1)/(nbsu - 1);
0123 aPars(1) = t1;
0124 aFlg(1) = Standard_False;
0125 aPars(nbsu) = t2;
0126 aFlg(nbsu) = Standard_False;
0127 for(i = 2, t1 += dt; i < nbsu; ++i, t1 += dt) {
0128 aPars(i) = t1;
0129 aFlg(i) = Standard_False;
0130 }
0131 }
0132 else {
0133 nbi = aBC->Degree();
0134 k = 0;
0135 t1 = U0;
0136 for(i = ui1+1; i <= ui2; ++i) {
0137 if(i == ui2) t2 = U1;
0138 else t2 = aBC->Knot(i);
0139 dt = (t2 - t1)/nbi;
0140 j = 1;
0141 do {
0142 ++k;
0143 aPars(k) = t1;
0144 aFlg(k) = Standard_False;
0145 t1 += dt;
0146 }
0147 while (++j <= nbi);
0148 t1 = t2;
0149 }
0150 ++k;
0151 aPars(k) = t1;
0152 }
0153 //Analysis of deflection
0154
0155
0156 Standard_Real aDefl2 = Max(Defl*Defl, 1.e-9);
0157 Standard_Real tol = Max(0.01*aDefl2, 1.e-9);
0158 Standard_Integer l;
0159
0160 Standard_Integer NbSamples = 2;
0161 aFlg(1) = Standard_True;
0162 aFlg(nbsu) = Standard_True;
0163 j = 1;
0164 Standard_Boolean bCont = Standard_True;
0165 while (j < nbsu-1 && bCont) {
0166
0167 if(aFlg(j+1)) {
0168 ++j;
0169 continue;
0170 }
0171
0172 t2 = aPars(j);
0173 gp_Pnt p1 = aBC->Value(t2);
0174 for(k = j+2; k <= nbsu; ++k) {
0175 t2 = aPars(k);
0176 gp_Pnt p2 = aBC->Value(t2);
0177
0178 if(p1.SquareDistance(p2) <= tol) continue;
0179
0180 gce_MakeLin MkLin(p1, p2);
0181 const gp_Lin& lin = MkLin.Value();
0182 Standard_Boolean ok = Standard_True;
0183 for(l = j+1; l < k; ++l) {
0184
0185 if(aFlg(l)) {
0186 ok = Standard_False;
0187 break;
0188 }
0189
0190 gp_Pnt pp = aBC->Value(aPars(l));
0191 Standard_Real d = lin.SquareDistance(pp);
0192
0193 if(d <= aDefl2) continue;
0194
0195 ok = Standard_False;
0196 break;
0197 }
0198
0199 if(!ok) {
0200 j = k - 1;
0201 aFlg(j) = Standard_True;
0202 ++NbSamples;
0203 break;
0204 }
0205
0206 if(aFlg(k)) {
0207 j = k;
0208 break;
0209 }
0210
0211
0212 }
0213
0214 if(k >= nbsu) bCont = Standard_False;
0215
0216 }
0217
0218 if(NbSamples < myMinPnts) {
0219 //uniform distribution
0220 NbSamples = myMinPnts;
0221 Pars = new TColStd_HArray1OfReal(1, NbSamples);
0222 t1 = U0;
0223 t2 = U1;
0224 dt = (t2 - t1)/(NbSamples - 1);
0225 Pars->SetValue(1, t1);
0226 Pars->SetValue(NbSamples, t2);
0227 for(i = 2, t1 += dt; i < NbSamples; ++i, t1 += dt) {
0228 Pars->SetValue(i, t1);
0229 }
0230 return;
0231 }
0232
0233 Pars = new TColStd_HArray1OfReal(1, NbSamples);
0234 j = 0;
0235 for(i = 1; i <= nbsu; ++i) {
0236 if(aFlg(i)) {
0237 ++j;
0238 Pars->SetValue(j,aPars(i));
0239 }
0240 }
0241
0242
0243
0244 }