1 // Created on: 1992-10-12
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1992-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.
17 #include <Standard_ConstructionError.hxx>
18 #include <Bnd_Box.hxx>
19 #include <TColgp_Array1OfPnt.hxx>
25 //======================================================================
26 //== On echantillonne sur le Domain de la Curve NbPts Points
27 //== a parametres constants.
29 //== On estime la fleche maximum en prenant la distance maxi entre la
30 //== droite Curve.Value(X(i))-->Curve.Value(X(i+1))
31 //== et le point Curve.Value(X(i+1/2))
32 //======================================================================
33 IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve& C,
34 const Standard_Integer tNbPts):
35 ThePnts(1,(tNbPts<5)? 5 : tNbPts)
37 Standard_Integer NbPts = (tNbPts<5)? 5 : tNbPts;
39 Binf = TheCurveTool::FirstParameter(C);
40 Bsup = TheCurveTool::LastParameter(C);
46 IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve& C,
47 const Standard_Real U1,
48 const Standard_Real U2,
49 const Standard_Integer tNbPts):
50 ThePnts(1,(tNbPts<5)? 5 : tNbPts) , Binf(U1) , Bsup(U2)
54 Standard_Integer NbPts = (tNbPts<5)? 5 : tNbPts;
59 //=======================================================================
60 //function : IntCurveSurface_Polygon
62 //=======================================================================
64 IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve& C,
65 const TColStd_Array1OfReal& Upars):
66 ThePnts(1,Upars.Length()) , Binf(Upars(Upars.Lower())) , Bsup(Upars(Upars.Upper()))
69 //ddout << "IntCurveSurface_Polygon::IntCurveSurface_Polygon" << endl;
70 Standard_Integer NbPts = Upars.Length();
71 //ddout << "NbPts :" << NbPts << endl;
77 void IntCurveSurface_Polygon::Init(const TheCurve& C) {
80 Standard_Real u1=Bsup;
81 Standard_Real du=(u1-u)/(Standard_Real)(NbPntIn-1);
85 TheCurveTool::D0(C,u,P);
87 ThePnts.SetValue(i,P);
94 //-----------------------------------------------------
95 //--- Calcul d un majorant de fleche approche
106 gp_Pnt Pm=TheCurveTool::Value(C,u);
107 gp_Pnt P1=ThePnts.Value(i);
108 gp_Pnt P2=ThePnts.Value(i+1);
109 gp_Lin L(P1,gp_Dir(gp_Vec(P1,P2)));
110 Standard_Real t=L.Distance(Pm);
112 if(t>TheDeflection) {
120 TheBnd.Enlarge(1.5*TheDeflection);
123 TheBnd.Enlarge(1e-10);
125 ClosedPolygon = Standard_False;
128 //=======================================================================
131 //=======================================================================
133 void IntCurveSurface_Polygon::Init(const TheCurve& C,
134 const TColStd_Array1OfReal& Upars) {
136 //ddout << "IntCurveSurface_Polygon::Init" << endl;
137 Standard_Real u=Binf;
138 Standard_Integer i=1, i0 = Upars.Lower()-1;
141 myParams = new TColStd_HArray1OfReal(1, Upars.Length());
143 //ddout << "-------------Parameter : " << i << " " << Upars(i+i0) << endl;
144 myParams->SetValue(i, Upars(i+i0));
145 TheCurveTool::D0(C,Upars(i+i0),P);
146 //ddout << "P : " << P.X() << " " << P.Y() << " " << P.Z() << endl;
148 ThePnts.SetValue(i,P);
154 //-----------------------------------------------------
155 //--- Calcul d un majorant de fleche approche
162 //ddout << "Deflection estimation" << endl;
164 u = 0.5*(Upars(i0+i)+Upars(i0+i+1));
165 //ddout << "===========Parameter : " << i << " " << u << endl;
166 gp_Pnt Pm=TheCurveTool::Value(C,u);
167 //ddout << "Pm : " << Pm.X() << " " << Pm.Y() << " " << Pm.Z() << endl;
168 gp_Pnt P1=ThePnts.Value(i);
169 //ddout << "P1 : " << P1.X() << " " << P1.Y() << " " << P1.Z() << endl;
170 gp_Pnt P2=ThePnts.Value(i+1);
171 //ddout << "P2 : " << P2.X() << " " << P2.Y() << " " << P2.Z() << endl;
172 gp_Lin L(P1,gp_Dir(gp_Vec(P1,P2)));
173 Standard_Real t=L.Distance(Pm);
174 //ddout << "Distance " << t << endl;
175 if(t>TheDeflection) {
181 //ddout << " TheDeflection = " << TheDeflection << endl;
182 TheBnd.Enlarge(1.5*TheDeflection);
185 TheBnd.Enlarge(1e-10);
187 ClosedPolygon = Standard_False;
191 //======================================================================
192 Standard_Real IntCurveSurface_Polygon::ApproxParamOnCurve(const Standard_Integer TheIndex,
193 const Standard_Real TheParamOnLine) const
195 //ddout << "IntCurveSurface_Polygon::ApproxParamOnCurve" << endl;
196 if(TheParamOnLine < 0.0 || TheParamOnLine >1.0) {
198 cout<<" ParamOnLine = "<<TheParamOnLine<<" avec Index = "
199 <<TheIndex<<" dans IntCurveSurface_Polygon::ApproxParamOnCurve"<<endl;
201 return(Binf+(TheParamOnLine*(Bsup-Binf))/(Standard_Real)(NbPntIn-1));
204 Standard_Integer Index = TheIndex;
205 Standard_Real ParamOnLine = TheParamOnLine;
207 if (Index > NbPntIn) {
208 cout << "OutOfRange Polygon::ApproxParamOnCurve " <<endl;
211 if((Index == NbPntIn) && (ParamOnLine == 0.0)) {
212 Index--; ParamOnLine=1.0;
216 if (myParams.IsNull())
218 du = (Bsup-Binf)/(Standard_Real)(NbPntIn-1);
219 u = Binf + du * (Standard_Real)(Index-1);
223 du = myParams->Value(Index+1) - myParams->Value(Index);
224 u = myParams->Value(Index);
227 u += du * ParamOnLine;
232 //======================================================================
233 void IntCurveSurface_Polygon::Dump(void) const {
235 static Standard_Integer Compteur=0;
238 sprintf(tamp,"Poly%d",Compteur);
239 cout<<" @@@@@@@@@@@ F i c h i e r : "<<tamp<<" @@@@@@@@@@"<<endl;
243 cout<<"PolyGonGen::Erreur en Ouverture Fichier"<<tamp<<endl;
246 fprintf(fp,"\n#Discretisation de : %f ---> %f \n",Binf,Bsup);
247 fprintf(fp,"\npol %d %d %f",Compteur,NbPntIn,TheDeflection);
249 for (Standard_Integer iObje=1; iObje<=NbSegments(); iObje++) {
250 p1=BeginOfSeg(iObje);
251 fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y());
253 p1=EndOfSeg(NbSegments());
254 fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y());
255 fprintf(fp,"\ndispol %d\n#\n",Compteur);
259 //======================================================================
260 //======================================================================