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
Cfield_opticalFlow_integrated.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 CFIELD_OPTICALFLOW_INTEGRATED
25 #define CFIELD_OPTICALFLOW_INTEGRATED
26 
27 
28 //-----------------------------CIMG_NETCDF-------------------------------
29 #define cimg_plugin "plugins/add_fileformat.h"
30 #define cimg_use_netcdf
31 
32 #ifdef cimg_use_netcdf
33  #include "../NetCDF.Tool/struct_parameter_NetCDF.h"
34 // #define cimg_plugin1 "plugins/netcdf_file_format4CImg1.h"
35 // #define cimglist_plugin1 "plugins/netcdf_file_format4CImgList1.h"
36  #define cimg_plugin2 "plugins/netcdf_file_format4CImg2.h"
37  #define cimglist_plugin2 "plugins/netcdf_file_format4CImgList2.h"
38  #include "../CImg.Tool/CImg_NetCDF.h"
39 #endif
40 //-----------------------------CIMG_NETCDF-------------------------------
41 
42 #include "Cfield_opticalFlow.h"
43 
49 template<typename T, typename Timg>
51 {
52 
53  public:
54 
55 
57  {
59  this->class_name = "Field : Optical Flow Integrated";
60 
61  }
62 
63  virtual void init(CParameterNetCDF &fp)
64  {
67 
68  this->m_ref.assign(3,-1);
70  std::string attribute_name("refX");
71  int error = fp.loadAttribute(attribute_name,this->m_ref[0]);
72  attribute_name = "refY";
73  error = fp.loadAttribute(attribute_name,this->m_ref[1]);
74  attribute_name = "refZ";
75  error = fp.loadAttribute(attribute_name,this->m_ref[2]);
76 
77  if (this->m_verbose){printf("\tReference system : [%f,%f,%f]\n", this->m_ref[0], this->m_ref[1], this->m_ref[2]);}
78 
79  }
80 
81 
82  virtual void exec(const Cimage<Timg> &oImage, const Cmesh<T,Timg> &oMesh, CImgList<T> &modes_prev, CshapeFunction<T,Timg> &oShape_prev, const std::vector<T> &ref_prev, const CImgList<T> &nodes_prev)
83  {
86  this->m_mode.assign(this->m_pShape->m_dof, 1,1,1,1, 0);
87 
88  Cfield<T,Timg>::exec(oImage, oMesh, modes_prev, oShape_prev, ref_prev, nodes_prev);
89 
90  }
91 
92 
93  virtual void project(const Cmesh<T,Timg> &oMesh, const Cimage<Timg> &oImage, CImgList<T> &modes_prev, CshapeFunction<T,Timg> &oShape_prev, const std::vector<T> &ref_prev, const CImgList<T> &nodes_prev, CImgList<T> &modes_cur)
94  {//project modes on new base
95 
96  if ((oShape_prev.m_name).compare(0,5,"OFFEM") == 0)
97  {//previous step was a FEM type
98 
99  //project U on current modes
100  Field2Mod(oImage, oMesh, nodes_prev, modes_prev, modes_cur);
101 
102  }
103  else if((oShape_prev.m_name).compare(0,2,"IC") == 0)
104  {
105 
106  //build U map on previous mesh
107  CImgList<T> U(oMesh.num_var(), modes_prev[0].width(), modes_prev[0].height(), modes_prev[0].depth(), 1, 0);
108  cimglist_for(U, mode)
109  {U[mode] = modes_prev[mode+2];}
110 
111  //project U on current modes
112  Field2Mod(oImage, oMesh, nodes_prev, U, modes_cur);
113 
114  }
115  else if((oShape_prev.m_name).compare(0,4,"OFIB") == 0)
116  {
117 
118  //build U map on previous mesh
120  CImgList<T> U(oMesh.num_var(), modes_prev[0].width(), modes_prev[0].height(), modes_prev[0].depth(), 1, 0);
121  this->OFIBU(oMesh, oImage, oShape_prev, ref_prev, nodes_prev, modes_prev, U);
122 
123  //project U on current modes
124  Field2Mod(oImage, oMesh, nodes_prev, U, modes_cur);
125 
126  }
127  else if((oShape_prev.m_name).compare(0,3,"OFI") == 0)
128  {
129 
130  if (modes_cur.size() == modes_prev.size())
131  {modes_cur = modes_prev;}
132  else
133  {printf("warning : modes have been changes for multi-scale OFI strategy!!!");}
134 
135  }
136  else{printf("unknown name for previous correlation method");}
137 
138 
139  }
140 
141 
142  virtual void e_ref(const Cimage<Timg> &oImage, const Cmesh<T,Timg> &oMesh, const int &elem, std::vector<T> &ref)
143  {// store position of upper left corner as element position reference "0"
144 
145 
146  for (int dim=0; dim<oMesh.num_var(); dim++)
147  {
148  if (ref[dim] == -1)
149  {//set the reference position at image center location
150  ref[dim] = (oImage.cur_dim(dim)*oImage.m_pix[dim])/2;
151  }
152  else
153  {//apply scaling to reference position provided by user.
154  ref[dim] = ref[dim]*oImage.m_Rpxmm;
155  }
156  }
157 
158  }
159 
160  virtual void Field2Mod(const Cimage<Timg> &oImage, const Cmesh<T,Timg> &oMesh, const CImgList<T> &nodes_prev, const CImgList<T> &U, CImgList<T> &Ti)
161  {
174  std::vector<T> X;X.assign(3,0);
175  CImgList<T> N(oMesh.num_var(), Ti.size());
176  CImg<T> K(Ti.size(), Ti.size(),1,1,0), F(1,Ti.size(),1,1,0);
177 
178  cimglist_for(oMesh.m_connect, elem)
179  {
180 
181  e_ref(oImage, oMesh, elem, this->m_ref);
182 
183  K.fill(0);
184  F.fill(0);
185 
186  cimglist_for(U, dim)
187  {//for every dims
188 
189  cimg_forXYZ(nodes_prev[dim],x,y,z)
190  {//for every nodes
191 
192  //physical coordonates of previous nodes considering the new reference system.
193  X[0] = nodes_prev(0, x,y,z) - this->m_ref[0];
194  X[1] = nodes_prev(1, x,y,z) - this->m_ref[1];
195  if(nodes_prev.size() == 3){X[2] = nodes_prev(2, x,y,z) - this->m_ref[2];}
196 
197  //shape function at such location
198  this->m_pShape->exec(U[dim],X, N);
199 
200  K += matrixProduct(N[dim].get_transpose(),N[dim]);
201  F += (N[dim].get_transpose())*U(dim, x,y,z);
202 
203  }
204 
205  }
206 
207  F.solve(K);
208  cimg_forY(F,y)
209  {
210  Ti[y][elem] = F[y];
211  }
212 
213  }
214 
215  }
216 
217 
218 };
219 
220 #endif
In this class, specific projection field method is implemented. In the case of F.E.M. the node value is equal to the field at node position, so "fromField2Mod" simply implements a parallelized loop over elements and extracts from previous fields the node value at node location.
Definition: Cfield_opticalFlow_fem.h:49
virtual void Field2Mod(const Cimage< Timg > &oImage, const Cmesh< T, Timg > &oMesh, const CImgList< T > &nodes_prev, const CImgList< T > &U, CImgList< T > &Ti)
Definition: Cfield_opticalFlow_integrated.h:160
virtual void exec(const Cimage< Timg > &oImage, const Cmesh< T, Timg > &oMesh, CImgList< T > &modes_prev, CshapeFunction< T, Timg > &oShape_prev, const std::vector< T > &ref_prev, const CImgList< T > &nodes_prev)
Definition: Cfield.h:100
This is the mother class of shape function objets (virtual pure).
Definition: CshapeFunction.h:48
In this class, specific projection field method is implemented. In the case of O.F.F.E.M. the node value must be identified through a projection, so "fromField2Mod" implements a parallelized loop over image pixel and identifies modes from a least square method strategy.
Definition: Cfield_opticalFlow_integrated.h:50
virtual void init(CParameterNetCDF &fp)
Definition: Cfield_opticalFlow.h:62
virtual void exec(const Cimage< Timg > &oImage, const Cmesh< T, Timg > &oMesh, CImgList< T > &modes_prev, CshapeFunction< T, Timg > &oShape_prev, const std::vector< T > &ref_prev, const CImgList< T > &nodes_prev)
Definition: Cfield_opticalFlow_integrated.h:82
virtual void init(CParameterNetCDF &fp)
Definition: Cfield_opticalFlow_integrated.h:63
Definition: Cmesh.h:61
virtual void project(const Cmesh< T, Timg > &oMesh, const Cimage< Timg > &oImage, CImgList< T > &modes_prev, CshapeFunction< T, Timg > &oShape_prev, const std::vector< T > &ref_prev, const CImgList< T > &nodes_prev, CImgList< T > &modes_cur)
Definition: Cfield_opticalFlow_integrated.h:93
Definition: Cimage.h:57
Cfield_opticalFlow_integrated()
Definition: Cfield_opticalFlow_integrated.h:56