YaDICs  V04.14.a
Yet another Digital Image Correlation software: platform dedicated to 2/3D Fluid and Solid kinematics field measurements.
 All Classes Files Functions Variables Pages
CImg_math.h
1 /**********************************************************************
2  * Copyright (C) 2012, The YaDICs Project Developers.
3  * See the COPYRIGHT file at the top-level directory of this distribution ./COPYRIGHT.
4  * See ./COPYING file for copying and redistribution conditions.
5  *
6  * This file is part of YaDICs.
7  * YaDICs is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * YaDICs is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with YaDICs. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * Information about how to use the software are provided at http://yadic.univ-lille1.fr/
21  **********************************************************************/
22 
23 
24 #ifndef CIMG_MATH
25 #define CIMG_MATH
26 
27 #include "../CImg/CImg.h"
28  using namespace cimg_library;
29 
30 //---------------------------------------------------------------
31 template<typename T>
32 void matrixDisplay(const CImg<T> &a);
33 template<typename T>
34 CImg<T> matrixProduct(const CImg<T> &a,const CImg<T> &b);
35 //---------------------------------------------------------------
36 
37 
40 template<typename T>
41 void matrixDisplay(const CImg<T> &a) {
42 
43  int I(a.height()), J(a.width()), K(a.depth()), L(a.spectrum());
44 
45  cimg_forXY(a,x,y) {
46  if((J-1)==0){
47  if(x==0){
48  std::cout<<"[";
49  }
50  std::cout<<a(x,y)<<"]\n";
51  }
52  else if(x%(J-1)==0&&x!=0){
53  std::cout<<a(x,y)<<"]\n";
54  }
55  else{
56  if(x==0){
57  std::cout<<"[";
58  }
59  std::cout<<a(x,y)<<"\t";
60  };
61  };
62 
63 }
64 
65 
66 
67 
69 template<typename T>
70 CImg<T> matrixProduct(const CImg<T> &a,const CImg<T> &b){
71 
72  int Ia(a.height()), Ja(a.width()), Ka(a.depth()), La(a.spectrum());
73  int Ib(b.height()), Jb(b.width()), Kb(b.depth()), Lb(b.spectrum());
74 
75  CImg<double> c(Jb, Ia, Ka, La, 0);
76 
77  if (Ja==Ib){
78  cimg_forXY(c,x,y){
79  for (int k=0; k<Ja; k++) {
80  c(x,y)+=(double)a(k,y)*(double)b(x,k);
81  };
82  };
83  return c;
84  }
85  else {
86  throw CImgInstanceException("Error dimension: enter such a product A(i,j)xB(j,k)\n");
87  };
88 }
89 
90 
91 
92 #endif