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
Ccorrelation_opticalFlow_integrated_block_AA.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 CCORRELATION_OPTICALFLOW_INTEGRATED_BLOCK_A
25 #define CCORRELATION_OPTICALFLOW_INTEGRATED_BLOCK_A
26 
27 
28 
39 
42 template<typename T,typename Timg>
44 {
45 
46  public:
47 
49  {// constructor
50 
51  this->class_name = "Correlation : Optical Flow Integrated per Block version AA";
52 
53  }
54 
55  virtual void init(CParameterNetCDF &fp)
56  {// init from parameter file
57 
63 
64  std::string attribute_name = "median_filter";
65  int error = fp.loadAttribute(attribute_name,this->m_medianFilter);
66  if (this->m_verbose){printf("\t\t median filter over following domain -> %i\n",this->m_medianFilter);}
67 
68  }
69 
70  virtual void exec(const Cimage<Timg> &oImage, const Cmesh<T,Timg> &oMesh, Cfield<T,Timg> &oField)
71  {// exec optical flow correlation
72 
73  //-----------------------------INIT--------------------------------------
74  this->_3D = oMesh._3D;
75 
76  int iter(0), converged(1), thread(0);
77  T previous_res(1e10);
78 
79  CImg<T> box;
80  CImgList<T> Ke,Fe,Ve;//elementary tensors
81  CImgList<T> solution(oField.m_mode);
82  assign(oMesh, this->m_threadNB, Ke, Fe, Ve);
83 
84  CImgList<T> N(oMesh.num_var(), oMesh.num_mod(),1,1,1, 0);//Shape function at pix
85 
86  CImg<T> current_res(this->m_threadNB,1,1,1,0);
87 
88  CImg<T> tmp1(Fe[0].width(), Fe[0].height(), Fe[0].depth(),1,0), tmp2(Ke[0].width(), Ke[0].height(), Ke[0].depth(),1,0);
89 
90  T residue(0), deformed(0);
91 
92  std::vector<T> ref, offset, lCoor, gCoor, grad, U;
93  ref.assign(3,0);offset.assign(3,0);lCoor.assign(3,0); gCoor.assign(3,0); U.assign(3,0); grad.assign(oMesh.num_var(),0);
94  //-----------------------------------------------------------------------
95 
96  do
97  {//while the convergency velocity is higher than a certain level
98 
99 
101 // #pragma omp parallel for if (oMesh.m_connect.size()>=oMesh.m_win[0]*oMesh.m_win[1]*oMesh.m_win[2]) firstprivate(ref, N, Ve, tmp1, tmp2, grad, U, residue, deformed, lCoor, gCoor, offset, box, thread) schedule(runtime)
102  #pragma omp parallel for firstprivate(ref, N, Ve, tmp1, tmp2, grad, U, residue, deformed, lCoor, gCoor, offset, box, thread) schedule(runtime)
103  cimglist_for(oMesh.m_connect, elem)
104  {//for every elements
105 
106  //extract cropped box
107  if (this->cropBox(oMesh, oImage, elem, box, offset))
108  {//if the box is not entirely masked
109 
110  thread = omp_get_thread_num();
111 
112  this->metric(thread, oImage,oMesh,elem, oField, N,Ve,Ke,Fe, current_res,ref,grad,U, residue, deformed, lCoor, gCoor, box, offset);
113 
114  tmp1 = Fe[0].get_channel(thread);
115  tmp2 = Ke[0].get_channel(thread);
116 
117  solve_CImg(tmp2,tmp1,oMesh,solution);
118 
119  cimg_forY(tmp1,y){solution[y][elem] += tmp1[y];}
120 
121  }
122 
123  }//implied barrier
124 
125  //sum of square residues over threads and normalization
126  oField.m_meanRes.push_back(std::sqrt(current_res.sum())/oMesh.m_numPix);
127  current_res.fill(0);
128 
129  if (this->m_medianFilter){this->regularize(oMesh, oImage, solution);}
130 
131  //actualized residue
132  this->actu(thread, oImage, oMesh, oField, solution, converged, N, current_res, ref,U, residue, deformed, lCoor, gCoor, box, offset);
133 
134  //condition test
135  this->test(solution, this->m_current_res, this->m_epsilon, oField, previous_res, iter, converged);
136 
137  }
138  while(converged);
139 
140  //actualize field from converged solution vector
141  if (oImage.m_storeActiv)
142  {actu(thread, oImage, oMesh, oField, oField.m_mode, converged, N, current_res, ref,U, residue, deformed, lCoor, gCoor, box, offset);}
143 
144  }
145 
146 };
147 
148 #endif
virtual void regularize(const Cmesh< T, Timg > &oMesh, const Cimage< Timg > &oImage, CImgList< T > &solution)
Definition: Ccorrelation.h:96
virtual void init(CParameterNetCDF &fp)
Definition: Ccorrelation_opticalFlow_integrated.h:56
It implements the Optical Flow with Integrated kinematics within independant block such as Block-matc...
Definition: Ccorrelation_opticalFlow_integrated_block.h:43
Definition: Cmesh.h:61
Definition: Cfield.h:51
Definition: Cimage.h:57
virtual void init(CParameterNetCDF &fp)
Definition: Ccorrelation_opticalFlow_integrated_block_AA.h:55
It implements the Optical Flow with Integrated kinematics within independant block such as Block-matc...
Definition: Ccorrelation_opticalFlow_integrated_block_A.h:43
virtual void exec(const Cimage< Timg > &oImage, const Cmesh< T, Timg > &oMesh, Cfield< T, Timg > &oField)
Definition: Ccorrelation_opticalFlow_integrated_block_AA.h:70