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
Cpeak_barycenter.h
Go to the documentation of this file.
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 CPEAK_BARYCENTER
25 #define CPEAK_BARYCENTER
26 
37 #include "Cpeak_subPix.h"
38 
39 
42 template<typename T>
43 class Cpeak_barycenter : public Cpeak_subPix<T>
44 {
45 
46  public:
47 
48  std::string class_name;
49 
51  {// constructor
52 
53  class_name = "Cpeak_barycenter";
54 
55  }
56 
57  virtual void sub_pixel(CImg<T> &img)
58  {
59 
60  std::vector<float> mass;
61  float sum(0), neighb(5);
62 
63  for (int i=0; i<this->m_pos.size(); i++)
64  {//initialization of directionnal mass
65  mass.push_back(0);
66  }
67 
68  CImg<T> imgC;
69  switch(this->m_pos.size())
70  {
71  case 1: imgC = img.get_crop(this->m_pos[0]-neighb,0,0,0,this->m_pos[0]+neighb,0,0,0, false); break;
72  case 2: imgC = img.get_crop(this->m_pos[0]-neighb,this->m_pos[1]-neighb,0,0,this->m_pos[0]+neighb,this->m_pos[1]+neighb,0,0, false); break;
73  case 3: imgC = img.get_crop(this->m_pos[0]-neighb,this->m_pos[1]-neighb,this->m_pos[2]-neighb,0,this->m_pos[0]+neighb,this->m_pos[1]+neighb,this->m_pos[2]+neighb,0, false); break;
74  case 4: imgC = img.get_crop(this->m_pos[0]-neighb,this->m_pos[1]-neighb,this->m_pos[2]-neighb,this->m_pos[3]-neighb,this->m_pos[0]+neighb,this->m_pos[1]+neighb,this->m_pos[2]+neighb,this->m_pos[3]+neighb, false); break;
75  default:
76  {
77  std::cerr<<class_name<<"::"<<__func__<<": error: id="<<this->m_pos.size()<<" is unknown as CImg dimensions\n"<<std::flush;break;
78  }
79  }
80 
81  cimg_forXYZC(imgC, x, y, z, c)
82  {
83  mass[0]+=imgC(x,y,z,c)*(x-neighb);
84  if(mass.size()>1){mass[1]+=imgC(x,y,z,c)*(y-neighb);}
85  if(mass.size()>2){mass[2]+=imgC(x,y,z,c)*(z-neighb);}
86  if(mass.size()>3){mass[3]+=imgC(x,y,z,c)*(c-neighb);}
87  }
88 
89  sum = imgC.sum();
90 
91  for (int i =0; i<this->m_pos.size(); i++)
92  {
93  this->m_pos[i] = this->m_pos[i] + mass[i]/sum;
94  }
95 
96  }
97 
98 };
99 
100 #endif
Definition: Cpeak_barycenter.h:43
Definition: Cpeak_subPix.h:42