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_fem.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_FEM
25 #define CFIELD_OPTICALFLOW_FEM
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 
48 template<typename T, typename Timg>
50 {
51 
52  public:
53 
54 
56  {
58  this->class_name = "Field : Optical Flow Finite Element Method";
59 
60  }
61 
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)
63  {
66  this->m_mode.assign(oMesh.num_var(), oMesh.grid_dims(0),oMesh.grid_dims(1),oMesh.grid_dims(2), 1, 0);
67 
68  Cfield<T,Timg>::exec(oImage, oMesh, modes_prev, oShape_prev, ref_prev, nodes_prev);
69 
70  }
71 
72 
73  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)
74  {//project modes on new base
75 
76  if ((oShape_prev.m_name).compare(0,5,"OFFEM") == 0)
77  {//basic linear interpolation from previous the current grid of modes [U, V, W]
78 
79  Field2Field(modes_prev, modes_cur);
80 
81  }
82  else if((oShape_prev.m_name).compare(0,2,"IC") == 0)
83  {//basic linear interpolation from previous the current grid of modes [U, V, W]
84 
85  //build U map on previous mesh
86  CImgList<T> U(oMesh.num_var(), modes_prev[0].width(), modes_prev[0].height(), modes_prev[0].depth(), 1, 0);
87  cimglist_for(U, mode)
88  {U[mode] = modes_prev[mode+2];}
89 
90  Field2Field(U, modes_cur);
91 
92  }
93  else if((oShape_prev.m_name).compare(0,4,"OFIB") == 0)
94  {//basic linear interpolation from previous the current grid and building of U, V and W at previous element centroid
95 
97  CImgList<T> U(oMesh.num_var(), modes_prev[0].width(), modes_prev[0].height(), modes_prev[0].depth(), 1, 0);
98  OFIBU(oMesh, oImage, oShape_prev, ref_prev, nodes_prev, modes_prev, U);
99 
100  Field2Field(U, modes_cur);
101 
102  }
103  else if((oShape_prev.m_name).compare(0,3,"OFI") == 0)
104  {
105 
106  OFIU(oMesh, oImage, oShape_prev, ref_prev, nodes_prev, modes_prev, modes_cur);
107 
108  }
109  else{printf("unknown name for previous correlation method");}
110 
111  }
112 
113  void OFIU(const Cmesh<T,Timg> &oMesh, const Cimage<Timg> &oImage, CshapeFunction<T,Timg> &oShape_prev, std::vector<T> ref_prev, const CImgList<T> &nodes_prev, CImgList<T> &modes_prev, CImgList<T> &modes_cur)
114  {//build U from OFI
115 
116  for (int dim=0; dim<oMesh.num_var(); dim++)
117  {
118  if (ref_prev[dim] == -1)
119  {
120  ref_prev[dim] = (oImage.cur_dim(dim)*oImage.m_pix[dim])/2;
121  }
122  }
123 
124  std::vector<T> X;X.assign(3,0);
125  CImgList<T> N(oMesh.num_var(), (oShape_prev).m_dof,1,1,1, 0);
126 
127  cimglist_for(modes_cur, dim)
128  {//linear interpolation
129  cimglist_for(modes_prev, mode)
130  {//linear interpolation
131  cimg_forXYZ(oMesh.m_node[dim],x,y,z)
132  {
133 
134  X[0] = oMesh.m_node(0, x,y,z)*oImage.m_pix[0] - ref_prev[0];
135  X[1] = oMesh.m_node(1, x,y,z)*oImage.m_pix[1] - ref_prev[1];
136  if (this->_3D){X[2] = oMesh.m_node(2, x,y,z)*oImage.m_pix[2] - ref_prev[2];}
137 
138  oShape_prev.exec(modes_cur[dim], X, N);
139  modes_cur(dim, x,y,z) += modes_prev[mode][0]*N[dim][mode];
140  }
141  }
142  }
143 
144  }
145 
146  void OFIBU(const Cmesh<T,Timg> &oMesh, const Cimage<Timg> &oImage, CshapeFunction<T,Timg> &oShape_prev, std::vector<T> ref_prev, const CImgList<T> &nodes_prev, const CImgList<T> &modes_prev, CImgList<T> &U)
147  {// build U from OFIB
148 
149  std::vector<T> X; X.assign(3,0);
150  CImgList<T> N(oMesh.num_var(), (oShape_prev).m_dof,1,1,1, 0);
151 
152  cimglist_for(U, dim)
153  {//linear interpolation
154  cimglist_for(modes_prev, mode)
155  {//linear interpolation
156  cimg_forXYZ(nodes_prev[0],x,y,z)
157  {
158 
159  if (ref_prev[0] != -1){X[0] = nodes_prev(0,x,y,z) - ref_prev[0];}
160  if (ref_prev[1] != -1){X[1] = nodes_prev(1,x,y,z) - ref_prev[1];}
161  if (ref_prev[2] != -1 and nodes_prev.size()==3){X[2] = nodes_prev(2,x,y,z) - ref_prev[2];}
162 
163  oShape_prev.exec(U[dim], X, N);
164  U(dim, x,y,z) += modes_prev(mode, x,y,z)*N[dim][mode];
165  }
166  }
167  }
168 
169  }
170 
171  void Field2Field(const CImgList<T> &U, CImgList<T> &modes_cur)
172  {
173 
174  cimglist_for(modes_cur, mode)
175  {
176  modes_cur[mode] = U[mode].get_resize(this->grid_dims(0),this->grid_dims(1),this->grid_dims(2),this->grid_dims(3),3);
177  }
178 
179  }
180 
181 
182 
183 };
184 
185 #endif
this class implement the initialization of fields, residue map and deformed image from data coming fr...
Definition: Cfield_opticalFlow.h:50
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 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
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_fem.h:62
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_fem.h:73
Cfield_opticalFlow_fem()
Definition: Cfield_opticalFlow_fem.h:55
Definition: Cmesh.h:61
Definition: Cimage.h:57