1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : testInterpolation.cxx
24 // Author : Eric Fayolle (EDF)
26 // Modified by : $LastChangedBy$
27 // Date : $LastChangedDate: 2007-01-08 19:01:14 +0100 (lun, 08 jan 2007) $
30 #include <boost/lambda/lambda.hpp>
37 #include <ext/functional>
40 static const double MAXVALUE = 150.0;
41 MyRand() { srand(getpid()); }
42 int operator()() const {
43 return 1+(int) ( MAXVALUE *rand()/(RAND_MAX +1.0));
50 typedef double TimeType;
51 const int dataSize1=20;
52 const int dataSize2=30;
53 const int dataSize3=std::min< size_t >(dataSize1,dataSize2);
54 std::vector<Type> vect1(dataSize1),vect2(dataSize2),vect3(dataSize3),vect4(dataSize3);
58 std::generate(vect1.begin(),vect1.end(),myRand);
59 std::cout << "Vecteur1 généré aléatoirement :" << std::endl;
60 std::copy(vect1.begin(),vect1.end(),std::ostream_iterator<Type>(std::cout," "));
61 std::cout<< std::endl;
63 std::generate(vect2.begin(),vect2.end(),myRand);
64 std::cout << "Vecteur2 généré aléatoirement :" << std::endl;
65 std::copy(vect2.begin(),vect2.end(),std::ostream_iterator<Type>(std::cout," "));
66 std::cout<< std::endl;
68 std::vector<Type>::iterator
77 TimeType deltaT = t2-t1;
78 TimeType coeff = (t2-t)/deltaT;
81 boost::lambda::placeholder1_type _1;
82 boost::lambda::placeholder2_type _2;
84 std::transform(InIt1,InIt1+dataSize3,InIt2,OutIt1, ( _1 - _2 ) * coeff + _2 );
86 std::cout << "Vecteur3 calculé :" << std::endl;
87 std::copy(vect3.begin(),vect3.end(),std::ostream_iterator<Type>(std::cout," "));
88 std::cout<< std::endl;
91 // ERREUR : il faut produire une binary pas avec compose2
92 // std::transform(InIt1,InIt1+dataSize3,InIt2,OutIt2,
93 // //std::minus<Type>(),
94 // __gnu_cxx::compose2(std::minus<Type>(),
95 // // __gnu_cxx::identity<Type>(),
96 // std::bind2nd( std::multiplies<Type>(), 1. ),
97 // std::bind2nd( std::multiplies<Type>(), 1.1 ) )
99 // InIt2 =vect2.begin();
100 // OutIt2=vect4.begin();
102 // std::transform(InIt2,InIt2+dataSize3,OutIt2,OutIt2,
103 // std::plus<Type>() );
106 InIt1=vect1.begin(); InIt2=vect2.begin();OutIt2=vect4.begin();
107 for(int i =0; i < dataSize3; ++i) {
108 // *OutIt2=(*InIt1 - *InIt2) * coeff + *InIt2;
109 // ++InIt1;++InIt2;++OutIt2;
110 OutIt2[i]=(InIt1[i] - InIt2[i]) * coeff + InIt2[i];
113 std::cout << "Vecteur4 calculé :" << std::endl;
114 std::copy(vect4.begin(),vect4.end(),std::ostream_iterator<Type>(std::cout," "));
115 std::cout<< std::endl;