1 // Created on: 1994-09-15
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <ProjLib_ProjectOnSurface.ixx>
24 #include <AppCont_Function.hxx>
25 #include <Approx_FitAndDivide.hxx>
26 #include <AppParCurves_MultiCurve.hxx>
27 #include <Standard_NoSuchObject.hxx>
28 #include <Extrema_POnSurf.hxx>
29 #include <Precision.hxx>
30 #include <BSplCLib.hxx>
32 #include <Adaptor3d_HCurve.hxx>
33 #include <Handle_Adaptor3d_HCurve.hxx>
34 #include <Geom_BSplineCurve.hxx>
35 #include <Handle_Geom_BSplineCurve.hxx>
36 #include <TColgp_Array1OfPnt.hxx>
37 #include <TColStd_Array1OfReal.hxx>
38 #include <TColStd_Array1OfInteger.hxx>
39 #include <Extrema_ExtPS.hxx>
42 //=======================================================================
43 //function : OnSurface_Value
44 //purpose : Evaluate current point of the projected curve
45 //=======================================================================
47 static gp_Pnt OnSurface_Value(const Standard_Real U,
48 const Handle(Adaptor3d_HCurve)& myCurve,
49 Extrema_ExtPS * myExtPS)
51 // on essaie de rendre le point solution le plus proche.
52 myExtPS->Perform(myCurve->Value(U));
54 Standard_Real Dist2Min = RealLast();
55 Standard_Integer Index = 0;
57 for ( Standard_Integer i = 1; i <= myExtPS->NbExt(); i++) {
58 if ( myExtPS->SquareDistance(i) < Dist2Min) {
60 Dist2Min = myExtPS->SquareDistance(Index);
64 cout << " Extrema non trouve pour U = " << U << endl;
65 return gp_Pnt(0.,0.,0.);
68 return (myExtPS->Point(Index)).Value();
72 //=======================================================================
73 //function : OnSurface_D1
75 //=======================================================================
77 static Standard_Boolean OnSurface_D1(const Standard_Real , // U,
80 const Handle(Adaptor3d_HCurve)& , // myCurve,
81 Extrema_ExtPS *) // myExtPS)
83 return Standard_False;
87 //=======================================================================
88 // class : ProjLib_OnSurface
89 //purpose : Use to approximate the projection on a plane
90 //=======================================================================
92 class ProjLib_OnSurface : public AppCont_Function
95 Handle(Adaptor3d_HCurve) myCurve;
96 Extrema_ExtPS *myExtPS;
100 ProjLib_OnSurface(const Handle(Adaptor3d_HCurve) & C,
101 const Handle(Adaptor3d_HSurface) & S)
103 {Standard_Real U = myCurve->FirstParameter();
104 gp_Pnt P = myCurve->Value(U);
105 Standard_Real Tol = Precision::PConfusion();
106 myExtPS = new Extrema_ExtPS(P,S->Surface(),Tol,Tol);}
108 ~ProjLib_OnSurface() { delete myExtPS; }
110 Standard_Real FirstParameter() const
111 {return myCurve->FirstParameter();}
113 Standard_Real LastParameter() const
114 {return myCurve->LastParameter();}
116 gp_Pnt Value( const Standard_Real t) const
117 {return OnSurface_Value(t,myCurve,myExtPS);}
119 Standard_Boolean D1(const Standard_Real t, gp_Pnt& P, gp_Vec& V) const
120 {return OnSurface_D1(t,P,V,myCurve,myExtPS);}
126 //=====================================================================//
128 // D E S C R I P T I O N O F T H E C L A S S : //
130 // 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 //
132 //=====================================================================//
135 //=======================================================================
136 //function : ProjLib_ProjectOnSurface
138 //=======================================================================
140 ProjLib_ProjectOnSurface::ProjLib_ProjectOnSurface() :
141 myIsDone(Standard_False)
145 //=======================================================================
146 //function : ProjLib_ProjectOnSurface
148 //=======================================================================
150 ProjLib_ProjectOnSurface::ProjLib_ProjectOnSurface
151 (const Handle(Adaptor3d_HSurface)& S ) :
152 myIsDone(Standard_False)
157 void ProjLib_ProjectOnSurface::Load(const Handle(Adaptor3d_HCurve)& C,
158 const Standard_Real Tolerance)
160 myTolerance = Tolerance ;
162 myIsDone = Standard_False ;
163 if (!mySurface.IsNull()) {
165 ProjLib_OnSurface F(myCurve, mySurface);
167 Standard_Integer Deg1, Deg2;
170 Approx_FitAndDivide Fit(F,Deg1,Deg2,Precision::Approximation(),
171 Precision::PApproximation(),Standard_True);
173 Standard_Integer NbCurves = Fit.NbMultiCurves();
174 Standard_Integer MaxDeg = 0;
176 // Pour transformer la MultiCurve en BSpline, il faut que toutes
177 // les Bezier la constituant aient le meme degre -> Calcul de MaxDeg
178 Standard_Integer NbPoles = 1;
179 for (i = 1; i <= NbCurves; i++) {
180 Standard_Integer Deg = Fit.Value(i).Degree();
181 MaxDeg = Max ( MaxDeg, Deg);
183 NbPoles = MaxDeg * NbCurves + 1; //Poles sur la BSpline
184 TColgp_Array1OfPnt Poles( 1, NbPoles);
186 TColgp_Array1OfPnt TempPoles( 1, MaxDeg + 1); //pour augmentation du degre
188 TColStd_Array1OfReal Knots( 1, NbCurves + 1); //Noeuds de la BSpline
190 Standard_Integer Compt = 1;
191 for (i = 1; i <= Fit.NbMultiCurves(); i++) {
192 Fit.Parameters(i, Knots(i), Knots(i+1));
194 AppParCurves_MultiCurve MC = Fit.Value( i); //Charge la Ieme Curve
195 TColgp_Array1OfPnt LocalPoles( 1, MC.Degree() + 1);//Recupere les poles
198 //Augmentation eventuelle du degre
199 Standard_Integer Inc = MaxDeg - MC.Degree();
201 BSplCLib::IncreaseDegree( Inc, LocalPoles, PLib::NoWeights(),
202 TempPoles, PLib::NoWeights());
203 //mise a jour des poles de la PCurve
204 for (Standard_Integer j = 1 ; j <= MaxDeg + 1; j++) {
205 Poles.SetValue( Compt, TempPoles( j));
210 //mise a jour des poles de la PCurve
211 for (Standard_Integer j = 1 ; j <= MaxDeg + 1; j++) {
212 Poles.SetValue( Compt, LocalPoles( j));
220 //mise a jour des fields de ProjLib_Approx
222 Standard_Integer NbKnots = NbCurves + 1;
224 TColStd_Array1OfInteger Mults( 1, NbKnots);
225 Mults.SetValue( 1, MaxDeg + 1);
226 for ( i = 2; i <= NbCurves; i++) {
227 Mults.SetValue( i, MaxDeg);
229 Mults.SetValue(NbKnots, MaxDeg + 1);
231 new Geom_BSplineCurve(Poles,
236 myIsDone = Standard_True ;
240 void ProjLib_ProjectOnSurface::Delete()
243 //=======================================================================
246 //=======================================================================
248 Handle(Geom_BSplineCurve) ProjLib_ProjectOnSurface::BSpline() const
250 Standard_NoSuchObject_Raise_if
252 "ProjLib_ProjectOnSurface:BSpline");
256 //=======================================================================
259 //=======================================================================
261 Standard_Boolean ProjLib_ProjectOnSurface::IsDone() const