Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/opencascade/AppParCurves_BSpFunction.gxx is written in an unsupported language. File is not indexed.

0001 // Copyright (c) 1995-1999 Matra Datavision
0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #include <AppParCurves_MultiBSpCurve.hxx>
0016 #include <AppParCurves_MultiPoint.hxx>
0017 #include <TColStd_Array1OfReal.hxx>
0018 #include <TColStd_Array1OfInteger.hxx>
0019 #include <TColStd_HArray1OfInteger.hxx>
0020 #include <gp_Pnt.hxx>
0021 #include <gp_Pnt2d.hxx>
0022 #include <gp_Vec.hxx>
0023 #include <gp_Vec2d.hxx>
0024 #include <TColgp_Array1OfPnt.hxx>
0025 #include <TColgp_Array1OfPnt2d.hxx>
0026 #include <math_Vector.hxx>
0027 #include <AppParCurves_ConstraintCouple.hxx>
0028 #include <AppParCurves_HArray1OfConstraintCouple.hxx>
0029 
0030 
0031 AppParCurves_BSpFunction::
0032   AppParCurves_BSpFunction(const MultiLine& SSP,
0033          const Standard_Integer FirstPoint,
0034          const Standard_Integer LastPoint,
0035          const Handle(AppParCurves_HArray1OfConstraintCouple)& TheConstraints,
0036          const math_Vector& Parameters,
0037          const TColStd_Array1OfReal& Knots,
0038          const TColStd_Array1OfInteger& Mults,
0039          const Standard_Integer NbPol) :
0040          MyMultiLine(SSP),
0041          MyMultiBSpCurve(NbPol),
0042          myParameters(Parameters.Lower(), Parameters.Upper()),
0043          ValGrad_F(FirstPoint, LastPoint),
0044          MyF(FirstPoint, LastPoint, 
0045              1, ToolLine::NbP3d(SSP)+ToolLine::NbP2d(SSP), 0.0),
0046          PTLX(FirstPoint, LastPoint, 
0047              1, ToolLine::NbP3d(SSP)+ToolLine::NbP2d(SSP), 0.0),
0048          PTLY(FirstPoint, LastPoint, 
0049              1, ToolLine::NbP3d(SSP)+ToolLine::NbP2d(SSP), 0.0),
0050          PTLZ(FirstPoint, LastPoint, 
0051              1, ToolLine::NbP3d(SSP)+ToolLine::NbP2d(SSP), 0.0),
0052          A(FirstPoint, LastPoint, 1, NbPol),
0053          DA(FirstPoint, LastPoint, 1, NbPol),
0054          MyLeastSquare(SSP, Knots, Mults, FirstPoint, LastPoint, 
0055                        FirstConstraint(TheConstraints, FirstPoint),
0056                        LastConstraint(TheConstraints, LastPoint), NbPol)
0057 {
0058   Standard_Integer i; 
0059   for (i = Parameters.Lower(); i <= Parameters.Upper(); i++)
0060     myParameters(i) = Parameters(i);
0061   FirstP = FirstPoint;
0062   LastP = LastPoint;
0063   myConstraints = TheConstraints;
0064   NbP = LastP-FirstP+1;
0065   Adeb = FirstP;
0066   Afin = LastP;
0067   nbpoles = NbPol;
0068   MyMultiBSpCurve.SetKnots(Knots);
0069   MyMultiBSpCurve.SetMultiplicities(Mults);
0070   Contraintes = Standard_False;
0071   Standard_Integer myindex;
0072   Standard_Integer low = TheConstraints->Lower(), upp= TheConstraints->Upper();
0073   AppParCurves_ConstraintCouple mycouple;
0074   AppParCurves_Constraint Cons;
0075 
0076   for (i = low; i <= upp; i++) {
0077     mycouple = TheConstraints->Value(i);
0078     Cons = mycouple.Constraint();
0079     myindex = mycouple.Index();
0080     if (myindex == FirstP) {
0081       if (Cons >= 1) Adeb = Adeb+1;
0082     }
0083     else if (myindex == LastP) {
0084       if (Cons >= 1) Afin = Afin-1;
0085     }
0086     else {
0087       if (Cons >= 1) Contraintes = Standard_True;
0088     }
0089   }
0090 
0091   Standard_Integer nb3d = ToolLine::NbP3d(SSP);
0092   Standard_Integer nb2d = ToolLine::NbP2d(SSP);
0093   Standard_Integer mynb3d= nb3d, mynb2d=nb2d;
0094   if (nb3d == 0) mynb3d = 1;
0095   if (nb2d == 0) mynb2d = 1;
0096 
0097   NbCu = nb3d+nb2d;
0098   tabdim = new TColStd_HArray1OfInteger(0, NbCu-1);
0099 
0100   if (Contraintes) {
0101     for (i = 1; i <= NbCu; i++) {
0102       if (i <= nb3d) tabdim->SetValue(i-1, 3);
0103       else tabdim->SetValue(i-1, 2);
0104     }
0105 
0106     TColgp_Array1OfPnt TabP(1, mynb3d);
0107     TColgp_Array1OfPnt2d TabP2d(1, mynb2d);
0108     
0109     for ( i = FirstP; i <= LastP; i++) {
0110       if (nb3d != 0 && nb2d != 0) ToolLine::Value(SSP, i, TabP, TabP2d);
0111       else if (nb3d != 0)         ToolLine::Value(SSP, i, TabP);
0112       else                        ToolLine::Value(SSP, i, TabP2d);
0113       for (Standard_Integer j = 1; j <= NbCu; j++) {
0114         if (tabdim->Value(j-1) == 3) {
0115           TabP(j).Coord(PTLX(i, j), PTLY(i, j),PTLZ(i, j));
0116         }
0117         else {
0118           TabP2d(j).Coord(PTLX(i, j), PTLY(i, j));
0119         }
0120       }
0121     }
0122   }
0123 }
0124 
0125 
0126 AppParCurves_Constraint AppParCurves_BSpFunction::FirstConstraint
0127   (const Handle(AppParCurves_HArray1OfConstraintCouple)& TheConstraints,
0128    const Standard_Integer FirstPoint) const
0129 {
0130   Standard_Integer i, myindex;
0131   Standard_Integer low = TheConstraints->Lower(), upp= TheConstraints->Upper();
0132   AppParCurves_ConstraintCouple mycouple;
0133   AppParCurves_Constraint Cons = AppParCurves_NoConstraint;
0134 
0135   for (i = low; i <= upp; i++) {
0136     mycouple = TheConstraints->Value(i);
0137     Cons = mycouple.Constraint();
0138     myindex = mycouple.Index();
0139     if (myindex == FirstPoint) {
0140       break;
0141     }
0142   }
0143   return Cons;
0144 }
0145 
0146 
0147 AppParCurves_Constraint AppParCurves_BSpFunction::LastConstraint
0148   (const Handle(AppParCurves_HArray1OfConstraintCouple)& TheConstraints,
0149    const Standard_Integer LastPoint) const
0150 {
0151   Standard_Integer i, myindex;
0152   Standard_Integer low = TheConstraints->Lower(), upp= TheConstraints->Upper();
0153   AppParCurves_ConstraintCouple mycouple;
0154   AppParCurves_Constraint Cons = AppParCurves_NoConstraint;
0155 
0156   for (i = low; i <= upp; i++) {
0157     mycouple = TheConstraints->Value(i);
0158     Cons = mycouple.Constraint();
0159     myindex = mycouple.Index();
0160     if (myindex == LastPoint) {
0161       break;
0162     }
0163   }
0164   return Cons;
0165 }
0166 
0167 
0168 
0169 
0170 Standard_Boolean AppParCurves_BSpFunction::Value (const math_Vector& X, 
0171                                                   Standard_Real& F) {
0172 
0173   myParameters = X;
0174 
0175   // Resolution moindres carres:
0176   // ===========================
0177   MyLeastSquare.Perform(myParameters, mylambda1, mylambda2);
0178   if (!(MyLeastSquare.IsDone())) { 
0179     Done = Standard_False;
0180     return Standard_False;
0181   }
0182   if (!Contraintes) {
0183     MyLeastSquare.Error(FVal, ERR3d, ERR2d);
0184     F = FVal;
0185   }
0186 
0187   // Resolution avec contraintes:
0188   // ============================
0189   else { 
0190   }  
0191   return Standard_True;
0192 }
0193 
0194 
0195 
0196 
0197 void AppParCurves_BSpFunction::Perform(const math_Vector& X) {
0198   Standard_Integer j;
0199 
0200   myParameters = X;
0201   // Resolution moindres carres:
0202   // ===========================
0203   MyLeastSquare.Perform(myParameters, mylambda1, mylambda2);
0204 
0205   if (!(MyLeastSquare.IsDone())) { 
0206     Done = Standard_False;
0207     return;
0208   }
0209 
0210   for(j = myParameters.Lower(); j <= myParameters.Upper(); j++) {
0211     ValGrad_F(j) = 0.0;
0212   }
0213 
0214   if (!Contraintes) {
0215     MyLeastSquare.ErrorGradient(ValGrad_F, FVal, ERR3d, ERR2d);
0216   }
0217   else {
0218   }
0219 }
0220 
0221 
0222 
0223 void AppParCurves_BSpFunction::SetFirstLambda(const Standard_Real l1)
0224 {
0225   mylambda1 = l1;
0226 }
0227 
0228 void AppParCurves_BSpFunction::SetLastLambda(const Standard_Real l2)
0229 {
0230   mylambda2 = l2;
0231 }
0232 
0233 
0234 
0235 Standard_Integer AppParCurves_BSpFunction::NbVariables() const{ 
0236   return NbP;
0237 }
0238 
0239 
0240 Standard_Boolean AppParCurves_BSpFunction::Gradient (const math_Vector& X,
0241                                                      math_Vector& G) {
0242 
0243   Perform(X);
0244   G = ValGrad_F;
0245 
0246   return Standard_True;
0247 }
0248 
0249 
0250 Standard_Boolean AppParCurves_BSpFunction::Values (const math_Vector& X, 
0251                                                    Standard_Real& F, 
0252                                                    math_Vector& G) {
0253 
0254 
0255   Perform(X);
0256   F = FVal;
0257   G = ValGrad_F;
0258 
0259 /*
0260   math_Vector mygradient = G;
0261   math_Vector myx = X;
0262   Standard_Real myf = FVal;
0263   Standard_Real F2 = FVal;
0264   math_Vector G2 = ValGrad_F;
0265   for (Standard_Integer i = 1; i <= X.Length(); i++) {
0266     myx = X;
0267     myx(i) = X(i) + 1.0e-10;
0268     Value(myx, F2);
0269     mygradient(i) = (F2 - myf)/(1.0e-10);
0270   }
0271 
0272 cout << " Gradient calcule : " << G2 << endl;
0273 cout << " Gradient interpole : " <<  mygradient << endl;
0274 */
0275   return Standard_True;
0276 }
0277 
0278 
0279 AppParCurves_MultiBSpCurve AppParCurves_BSpFunction::CurveValue() {
0280   if (!Contraintes)  MyMultiBSpCurve = MyLeastSquare.BSplineValue();
0281   return MyMultiBSpCurve;
0282 }
0283 
0284 
0285 Standard_Real AppParCurves_BSpFunction::Error(const Standard_Integer IPoint,
0286                                      const Standard_Integer CurveIndex) {
0287   const math_Matrix& DD = MyLeastSquare.Distance();
0288   Standard_Real d = DD.Value(IPoint, CurveIndex);
0289   if (!Contraintes)  return d;
0290   else return Sqrt(MyF(IPoint, CurveIndex));
0291 }
0292 
0293 Standard_Real AppParCurves_BSpFunction::MaxError3d() const
0294 {
0295   return ERR3d;
0296 }
0297 
0298 Standard_Real AppParCurves_BSpFunction::MaxError2d() const
0299 {
0300   return ERR2d;
0301 }
0302 
0303 
0304 
0305 const math_Vector& AppParCurves_BSpFunction::NewParameters() const
0306 {
0307   return myParameters;
0308 }
0309 
0310 
0311 const math_Matrix& AppParCurves_BSpFunction::FunctionMatrix() const
0312 {
0313   return MyLeastSquare.FunctionMatrix();
0314 }
0315 
0316 const math_Matrix& AppParCurves_BSpFunction::DerivativeFunctionMatrix() const
0317 {
0318   return MyLeastSquare.DerivativeFunctionMatrix();
0319 }
0320 
0321 
0322 const math_IntegerVector& AppParCurves_BSpFunction::Index() const
0323 {
0324   return MyLeastSquare.KIndex();
0325 }