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.
18 #include <Adaptor3d_HCurve.hxx>
19 #include <Adaptor3d_HSurface.hxx>
20 #include <AppCont_Function.hxx>
21 #include <AppParCurves_MultiCurve.hxx>
22 #include <Approx_FitAndDivide.hxx>
23 #include <BSplCLib.hxx>
24 #include <Extrema_ExtPS.hxx>
25 #include <Extrema_POnSurf.hxx>
26 #include <Geom_BSplineCurve.hxx>
28 #include <Precision.hxx>
29 #include <ProjLib_ProjectOnSurface.hxx>
30 #include <Standard_NoSuchObject.hxx>
31 #include <TColgp_Array1OfPnt.hxx>
32 #include <TColStd_Array1OfInteger.hxx>
33 #include <TColStd_Array1OfReal.hxx>
35 //=======================================================================
36 //function : OnSurface_Value
37 //purpose : Evaluate current point of the projected curve
38 //=======================================================================
39 static gp_Pnt OnSurface_Value(const Standard_Real U,
40 const Handle(Adaptor3d_HCurve)& myCurve,
41 Extrema_ExtPS * myExtPS)
43 // on essaie de rendre le point solution le plus proche.
44 myExtPS->Perform(myCurve->Value(U));
46 Standard_Real Dist2Min = RealLast();
47 Standard_Integer Index = 0;
49 for ( Standard_Integer i = 1; i <= myExtPS->NbExt(); i++) {
50 if ( myExtPS->SquareDistance(i) < Dist2Min) {
52 Dist2Min = myExtPS->SquareDistance(Index);
56 cout << " Extrema non trouve pour U = " << U << endl;
57 return gp_Pnt(0.,0.,0.);
60 return (myExtPS->Point(Index)).Value();
64 //=======================================================================
65 //function : OnSurface_D1
67 //=======================================================================
69 static Standard_Boolean OnSurface_D1(const Standard_Real , // U,
72 const Handle(Adaptor3d_HCurve)& , // myCurve,
73 Extrema_ExtPS *) // myExtPS)
75 return Standard_False;
79 //=======================================================================
80 // class : ProjLib_OnSurface
81 //purpose : Use to approximate the projection on a plane
82 //=======================================================================
84 class ProjLib_OnSurface : public AppCont_Function
89 ProjLib_OnSurface(const Handle(Adaptor3d_HCurve) & C,
90 const Handle(Adaptor3d_HSurface) & S)
95 Standard_Real U = myCurve->FirstParameter();
96 gp_Pnt P = myCurve->Value(U);
97 Standard_Real Tol = Precision::PConfusion();
98 myExtPS = new Extrema_ExtPS(P,S->Surface(),Tol,Tol);
101 ~ProjLib_OnSurface() { delete myExtPS; }
103 Standard_Real FirstParameter() const
104 {return myCurve->FirstParameter();}
106 Standard_Real LastParameter() const
107 {return myCurve->LastParameter();}
109 Standard_Boolean Value(const Standard_Real theT,
110 NCollection_Array1<gp_Pnt2d>& /*thePnt2d*/,
111 NCollection_Array1<gp_Pnt>& thePnt) const
113 thePnt(1) = OnSurface_Value(theT, myCurve, myExtPS);
114 return Standard_True;
117 Standard_Boolean D1(const Standard_Real theT,
118 NCollection_Array1<gp_Vec2d>& /*theVec2d*/,
119 NCollection_Array1<gp_Vec>& theVec) const
122 return OnSurface_D1(theT, aPnt, theVec(1), myCurve, myExtPS);
126 ProjLib_OnSurface (const ProjLib_OnSurface&);
127 ProjLib_OnSurface& operator= (const ProjLib_OnSurface&);
130 Handle(Adaptor3d_HCurve) myCurve;
131 Extrema_ExtPS* myExtPS;
135 //=====================================================================//
137 // D E S C R I P T I O N O F T H E C L A S S : //
139 // 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 //
141 //=====================================================================//
144 //=======================================================================
145 //function : ProjLib_ProjectOnSurface
147 //=======================================================================
149 ProjLib_ProjectOnSurface::ProjLib_ProjectOnSurface() :
150 myIsDone(Standard_False)
154 //=======================================================================
155 //function : ProjLib_ProjectOnSurface
157 //=======================================================================
159 ProjLib_ProjectOnSurface::ProjLib_ProjectOnSurface
160 (const Handle(Adaptor3d_HSurface)& S ) :
161 myIsDone(Standard_False)
166 void ProjLib_ProjectOnSurface::Load(const Handle(Adaptor3d_HCurve)& C,
167 const Standard_Real Tolerance)
169 myTolerance = Tolerance ;
171 myIsDone = Standard_False ;
172 if (!mySurface.IsNull()) {
174 ProjLib_OnSurface F(myCurve, mySurface);
176 Standard_Integer Deg1, Deg2;
179 Approx_FitAndDivide Fit(F,Deg1,Deg2,Precision::Approximation(),
180 Precision::PApproximation(),Standard_True);
182 Standard_Integer NbCurves = Fit.NbMultiCurves();
183 Standard_Integer MaxDeg = 0;
185 // Pour transformer la MultiCurve en BSpline, il faut que toutes
186 // les Bezier la constituant aient le meme degre -> Calcul de MaxDeg
187 Standard_Integer NbPoles = 1;
188 for (i = 1; i <= NbCurves; i++) {
189 Standard_Integer Deg = Fit.Value(i).Degree();
190 MaxDeg = Max ( MaxDeg, Deg);
192 NbPoles = MaxDeg * NbCurves + 1; //Poles sur la BSpline
193 TColgp_Array1OfPnt Poles( 1, NbPoles);
195 TColgp_Array1OfPnt TempPoles( 1, MaxDeg + 1); //pour augmentation du degre
197 TColStd_Array1OfReal Knots( 1, NbCurves + 1); //Noeuds de la BSpline
199 Standard_Integer Compt = 1;
200 for (i = 1; i <= Fit.NbMultiCurves(); i++) {
201 Fit.Parameters(i, Knots(i), Knots(i+1));
203 AppParCurves_MultiCurve MC = Fit.Value( i); //Charge la Ieme Curve
204 TColgp_Array1OfPnt LocalPoles( 1, MC.Degree() + 1);//Recupere les poles
207 //Augmentation eventuelle du degre
208 Standard_Integer Inc = MaxDeg - MC.Degree();
210 BSplCLib::IncreaseDegree( Inc, LocalPoles, BSplCLib::NoWeights(),
211 TempPoles, BSplCLib::NoWeights());
212 //mise a jour des poles de la PCurve
213 for (Standard_Integer j = 1 ; j <= MaxDeg + 1; j++) {
214 Poles.SetValue( Compt, TempPoles( j));
219 //mise a jour des poles de la PCurve
220 for (Standard_Integer j = 1 ; j <= MaxDeg + 1; j++) {
221 Poles.SetValue( Compt, LocalPoles( j));
229 //mise a jour des fields de ProjLib_Approx
231 Standard_Integer NbKnots = NbCurves + 1;
233 TColStd_Array1OfInteger Mults( 1, NbKnots);
234 Mults.SetValue( 1, MaxDeg + 1);
235 for ( i = 2; i <= NbCurves; i++) {
236 Mults.SetValue( i, MaxDeg);
238 Mults.SetValue(NbKnots, MaxDeg + 1);
240 new Geom_BSplineCurve(Poles,
245 myIsDone = Standard_True ;
249 //=======================================================================
250 //function : ~ProjLib_ProjectOnSurface
252 //=======================================================================
254 ProjLib_ProjectOnSurface::~ProjLib_ProjectOnSurface()
257 //=======================================================================
260 //=======================================================================
262 Handle(Geom_BSplineCurve) ProjLib_ProjectOnSurface::BSpline() const
264 Standard_NoSuchObject_Raise_if
266 "ProjLib_ProjectOnSurface:BSpline");
270 //=======================================================================
273 //=======================================================================
275 Standard_Boolean ProjLib_ProjectOnSurface::IsDone() const