1 // Created on: 1994-09-15
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1994-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 <ProjLib_ProjectOnSurface.ixx>
19 #include <AppCont_Function.hxx>
20 #include <Approx_FitAndDivide.hxx>
21 #include <AppParCurves_MultiCurve.hxx>
22 #include <Standard_NoSuchObject.hxx>
23 #include <Extrema_POnSurf.hxx>
24 #include <Precision.hxx>
25 #include <BSplCLib.hxx>
27 #include <Adaptor3d_HCurve.hxx>
28 #include <Geom_BSplineCurve.hxx>
29 #include <TColgp_Array1OfPnt.hxx>
30 #include <TColStd_Array1OfReal.hxx>
31 #include <TColStd_Array1OfInteger.hxx>
32 #include <Extrema_ExtPS.hxx>
35 //=======================================================================
36 //function : OnSurface_Value
37 //purpose : Evaluate current point of the projected curve
38 //=======================================================================
40 static gp_Pnt OnSurface_Value(const Standard_Real U,
41 const Handle(Adaptor3d_HCurve)& myCurve,
42 Extrema_ExtPS * myExtPS)
44 // on essaie de rendre le point solution le plus proche.
45 myExtPS->Perform(myCurve->Value(U));
47 Standard_Real Dist2Min = RealLast();
48 Standard_Integer Index = 0;
50 for ( Standard_Integer i = 1; i <= myExtPS->NbExt(); i++) {
51 if ( myExtPS->SquareDistance(i) < Dist2Min) {
53 Dist2Min = myExtPS->SquareDistance(Index);
57 cout << " Extrema non trouve pour U = " << U << endl;
58 return gp_Pnt(0.,0.,0.);
61 return (myExtPS->Point(Index)).Value();
65 //=======================================================================
66 //function : OnSurface_D1
68 //=======================================================================
70 static Standard_Boolean OnSurface_D1(const Standard_Real , // U,
73 const Handle(Adaptor3d_HCurve)& , // myCurve,
74 Extrema_ExtPS *) // myExtPS)
76 return Standard_False;
80 //=======================================================================
81 // class : ProjLib_OnSurface
82 //purpose : Use to approximate the projection on a plane
83 //=======================================================================
85 class ProjLib_OnSurface : public AppCont_Function
88 Handle(Adaptor3d_HCurve) myCurve;
89 Extrema_ExtPS *myExtPS;
93 ProjLib_OnSurface(const Handle(Adaptor3d_HCurve) & C,
94 const Handle(Adaptor3d_HSurface) & S)
99 Standard_Real U = myCurve->FirstParameter();
100 gp_Pnt P = myCurve->Value(U);
101 Standard_Real Tol = Precision::PConfusion();
102 myExtPS = new Extrema_ExtPS(P,S->Surface(),Tol,Tol);
105 ~ProjLib_OnSurface() { delete myExtPS; }
107 Standard_Real FirstParameter() const
108 {return myCurve->FirstParameter();}
110 Standard_Real LastParameter() const
111 {return myCurve->LastParameter();}
113 Standard_Boolean Value(const Standard_Real theT,
114 NCollection_Array1<gp_Pnt2d>& /*thePnt2d*/,
115 NCollection_Array1<gp_Pnt>& thePnt) const
117 thePnt(1) = OnSurface_Value(theT, myCurve, myExtPS);
118 return Standard_True;
121 Standard_Boolean D1(const Standard_Real theT,
122 NCollection_Array1<gp_Vec2d>& /*theVec2d*/,
123 NCollection_Array1<gp_Vec>& theVec) const
126 return OnSurface_D1(theT, aPnt, theVec(1), myCurve, myExtPS);
131 //=====================================================================//
133 // D E S C R I P T I O N O F T H E C L A S S : //
135 // P r o j L i b _ A p p r o x P r o j e c t O n P l a n e //
137 //=====================================================================//
140 //=======================================================================
141 //function : ProjLib_ProjectOnSurface
143 //=======================================================================
145 ProjLib_ProjectOnSurface::ProjLib_ProjectOnSurface() :
146 myIsDone(Standard_False)
150 //=======================================================================
151 //function : ProjLib_ProjectOnSurface
153 //=======================================================================
155 ProjLib_ProjectOnSurface::ProjLib_ProjectOnSurface
156 (const Handle(Adaptor3d_HSurface)& S ) :
157 myIsDone(Standard_False)
162 void ProjLib_ProjectOnSurface::Load(const Handle(Adaptor3d_HCurve)& C,
163 const Standard_Real Tolerance)
165 myTolerance = Tolerance ;
167 myIsDone = Standard_False ;
168 if (!mySurface.IsNull()) {
170 ProjLib_OnSurface F(myCurve, mySurface);
172 Standard_Integer Deg1, Deg2;
175 Approx_FitAndDivide Fit(F,Deg1,Deg2,Precision::Approximation(),
176 Precision::PApproximation(),Standard_True);
178 Standard_Integer NbCurves = Fit.NbMultiCurves();
179 Standard_Integer MaxDeg = 0;
181 // Pour transformer la MultiCurve en BSpline, il faut que toutes
182 // les Bezier la constituant aient le meme degre -> Calcul de MaxDeg
183 Standard_Integer NbPoles = 1;
184 for (i = 1; i <= NbCurves; i++) {
185 Standard_Integer Deg = Fit.Value(i).Degree();
186 MaxDeg = Max ( MaxDeg, Deg);
188 NbPoles = MaxDeg * NbCurves + 1; //Poles sur la BSpline
189 TColgp_Array1OfPnt Poles( 1, NbPoles);
191 TColgp_Array1OfPnt TempPoles( 1, MaxDeg + 1); //pour augmentation du degre
193 TColStd_Array1OfReal Knots( 1, NbCurves + 1); //Noeuds de la BSpline
195 Standard_Integer Compt = 1;
196 for (i = 1; i <= Fit.NbMultiCurves(); i++) {
197 Fit.Parameters(i, Knots(i), Knots(i+1));
199 AppParCurves_MultiCurve MC = Fit.Value( i); //Charge la Ieme Curve
200 TColgp_Array1OfPnt LocalPoles( 1, MC.Degree() + 1);//Recupere les poles
203 //Augmentation eventuelle du degre
204 Standard_Integer Inc = MaxDeg - MC.Degree();
206 BSplCLib::IncreaseDegree( Inc, LocalPoles, PLib::NoWeights(),
207 TempPoles, PLib::NoWeights());
208 //mise a jour des poles de la PCurve
209 for (Standard_Integer j = 1 ; j <= MaxDeg + 1; j++) {
210 Poles.SetValue( Compt, TempPoles( j));
215 //mise a jour des poles de la PCurve
216 for (Standard_Integer j = 1 ; j <= MaxDeg + 1; j++) {
217 Poles.SetValue( Compt, LocalPoles( j));
225 //mise a jour des fields de ProjLib_Approx
227 Standard_Integer NbKnots = NbCurves + 1;
229 TColStd_Array1OfInteger Mults( 1, NbKnots);
230 Mults.SetValue( 1, MaxDeg + 1);
231 for ( i = 2; i <= NbCurves; i++) {
232 Mults.SetValue( i, MaxDeg);
234 Mults.SetValue(NbKnots, MaxDeg + 1);
236 new Geom_BSplineCurve(Poles,
241 myIsDone = Standard_True ;
245 void ProjLib_ProjectOnSurface::Delete()
248 //=======================================================================
251 //=======================================================================
253 Handle(Geom_BSplineCurve) ProjLib_ProjectOnSurface::BSpline() const
255 Standard_NoSuchObject_Raise_if
257 "ProjLib_ProjectOnSurface:BSpline");
261 //=======================================================================
264 //=======================================================================
266 Standard_Boolean ProjLib_ProjectOnSurface::IsDone() const