Salome HOME
b16b891745efdbc819821e42570adf62e9a1a5b6
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Calcium / testInterpolation.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : testInterpolation.cxx
24 //  Author : Eric Fayolle (EDF)
25 //  Module : KERNEL
26 // Modified by : $LastChangedBy$
27 // Date        : $LastChangedDate: 2007-01-08 19:01:14 +0100 (lun, 08 jan 2007) $
28 // Id          : $Id$
29 //
30 #include <boost/lambda/lambda.hpp>
31
32 #include <vector>
33 #include <algorithm>
34 #include <iostream>
35 #include <iterator>
36 #include <functional>
37 #include <ext/functional>
38
39 struct MyRand {
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));
44   }
45 };
46
47 int main() {
48
49  typedef long  Type;
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);
55  MyRand   myRand;
56
57   //TEST1
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;
62
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;
67
68   std::vector<Type>::iterator 
69     InIt1=vect1.begin(),
70     InIt2=vect2.begin(),
71     OutIt1=vect3.begin(),
72     OutIt2=vect4.begin();
73
74   TimeType t = 2.4;
75   TimeType t2 = 3.4;
76   TimeType t1 = 1.1;
77   TimeType deltaT = t2-t1;
78   TimeType coeff = (t2-t)/deltaT;
79
80   // Calcul avec Lambda
81   boost::lambda::placeholder1_type _1;
82   boost::lambda::placeholder2_type _2;
83
84   std::transform(InIt1,InIt1+dataSize3,InIt2,OutIt1, ( _1 - _2 ) * coeff + _2 );
85
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;
89   
90   //Calcul sans Lambda
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 ) ) 
98   //             );
99   //   InIt2 =vect2.begin();
100   //   OutIt2=vect4.begin();
101   
102   //   std::transform(InIt2,InIt2+dataSize3,OutIt2,OutIt2,
103   //             std::plus<Type>() );
104   
105   // Calcul direct
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];
111   }
112
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;
116
117 };
118