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
Csequence.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 CSEQUENCE
25 #define CSEQUENCE
26 
27 
28 
37 //-----------------------------CIMG_NETCDF-------------------------------
38 #define cimg_plugin "plugins/add_fileformat.h"
39 #define cimg_use_netcdf
40 
41 #ifdef cimg_use_netcdf
42  #include "../NetCDF.Tool/struct_parameter_NetCDF.h"
43 // #define cimg_plugin1 "plugins/netcdf_file_format4CImg1.h"
44 // #define cimglist_plugin1 "plugins/netcdf_file_format4CImgList1.h"
45  #define cimg_plugin2 "plugins/netcdf_file_format4CImg2.h"
46  #define cimglist_plugin2 "plugins/netcdf_file_format4CImgList2.h"
47  #include "../CImg.Tool/CImg_NetCDF.h"
48 #endif
49 //-----------------------------CIMG_NETCDF-------------------------------
50 
51 
52 #include "Cimage.h"
53 #include "Cfield_factory.h"
54 #include "Cmesh_factory.h"
55 #include "CNpeak.h"
56 #include "CshapeFunction_factory.h"
57 #include "Ccorrelation_factory.h"
58 
59 #include <unistd.h>
60 
61 template<typename T,typename Timg>
62 class Csequence
63 {
64 
65  public:
66 
67  std::string class_name;
68  std::vector<std::string> m_sequence;
69  std::vector<int> m_filter;
70 // int m_reset;
71 
72  //mesh, field and correlation method associated to a specific sequence
73  Cmesh<T,Timg>* m_pMesh;
74  Ccorrelation<T,Timg>* m_pCorrel;
75  Cfield<T,Timg>* m_pField;
76 
77  //ultimate results from a correlation sequence
78  CImgList<T> m_modes, m_strain;
79  CImgList<T> m_node;
80  //optional
81  CImgList<T> m_fields;
82  CImg<T> m_residues, m_deformed, m_correlograms;
83  CshapeFunction<T,Timg>* m_pShape;
84  std::vector<T> m_ref, m_meanRes;
85 
86  bool m_verbose;
87 
88 
89  Csequence()
90  {// constructor
91 
92  class_name = "Sequence : mother";
93  }
94 
95  void init(int argc, char *argv[])
96  {// init
97 
98  //set parameter file path
99  const char* paramPath;
100  paramPath = cimg_option("-p","./parameters.nc","parameter, mesh or true");
101  //set verbose mode
102  m_verbose = cimg_option("-v",false,0);
103 
104  if(m_verbose)
105  {
106  printf("Mode Verbose\n");
107  printf("%s : %s\n",class_name.c_str(),paramPath);
108  }
109 
110  NcFile file(paramPath,NcFile::ReadOnly);
111  CParameterNetCDF paramFile;
112  int error = paramFile.setFile(&file);
113 
114  std::string var_name = "sequence",
115  att_name = "analysis";
116  error = paramFile.loadAttribute(att_name,m_sequence, &var_name);
117  if (this->m_verbose){std::cout<<"\tSequence analysis -> [ ";for (int i=0; i<m_sequence.size(); i++){std::cout<<m_sequence[i]<<" ";}std::cout<<"]\n";}
118 
119  att_name = "filter";//piramidal filter
120  error = paramFile.loadAttribute(att_name,m_filter, &var_name);
121  if (this->m_verbose){std::cout<<"\tPiramidal filter -> [ ";for (int i=0; i<m_filter.size(); i++){std::cout<<m_filter[i]<<" ";}std::cout<<"]\n";}
122 
123 // att_name = "reset";
124 // error = paramFile.loadAttribute(att_name,m_reset, &var_name);
125 // if (this->m_verbose){std::cout<<"\treset -> ["<<m_reset<<"]\n";}
126 
127  m_meanRes.clear();
128 
129  }
130 
131 
132  int exec(int argc, char *argv[], Cimage<Timg> &oImage)
133  {// implement a specific correlation sequence
134 
135  int error(0);
136 
137  for (int s=0; s<m_sequence.size(); s++)
138  {
139 
140  printf("\n----------------------\nSequence : %i\n----------------------\n\n", s);
141 
142  preprocessing(argc, argv, s, oImage);
143 
144  processing(argc, argv, oImage, *m_pMesh, *m_pField, *m_pCorrel);
145 
146  postprocessing(s, oImage, *m_pField, *m_pCorrel, *m_pMesh);
147 
148  }
149 
150  return error;
151 
152  }
153 
154 
155  void preprocessing(int argc, char *argv[], const int &s, Cimage<Timg> &oImage)
156  {
157 
158 
159  Cmesh_factory<T,Timg> mesh_factory(m_sequence[s].c_str());
160  Cfield_factory<T,Timg> field_factory(m_sequence[s].c_str());
161  Ccorrelation_factory<T,Timg> correlator_factory(m_sequence[s].c_str());
162 
163 
164  if (m_verbose){printf("* Mesh preproc\n");}
165  m_pMesh = mesh_factory.create(argc,argv);
166 
167  if (m_verbose){printf("* Field preproc\n");}
168  m_pField = field_factory.create(argc,argv);
169 
170  if (m_verbose){printf("* Correlation preproc\n");}
171  m_pCorrel = correlator_factory.create(argc,argv);
172 
173  if (m_verbose){cimg::tic();printf("* Image resizing for multiscale\n");}
174  oImage.resize(m_filter[s]);
175  if (m_verbose){cimg::toc();}
176 
177  printf("\n\n* Current scale : %f\n\n", std::pow(2,m_filter[s]));
178 
179  }
180 
181  int processing(int argc, char *argv[], Cimage<Timg> &oImage, Cmesh<T,Timg> &oMesh, Cfield<T,Timg> &oField, Ccorrelation<T,Timg> &oCorrel)
182  {
183 
184  int error(0);
185 
186  //create mesh properties : m_node, m_connect and m_mask which contains
187  if (m_verbose){printf("* Mesh proc\n");}
188  oMesh.exec(oImage);
189 
190  if (m_verbose){printf("* Field proc\n");}
191  oField.exec(oImage, oMesh, m_modes, *m_pShape, m_ref, m_node);//assign oField.m_field with m_dataField as init
192 
193  //store the current shape function object
194  CshapeFunction_factory<T,Timg> shape_factory(oField.m_name.c_str());
195  if (oField.m_name.compare(0,2,"IC") != 0)
196  {
197  m_pShape = shape_factory.create(argc,argv);
198  }
199  else
200  {
201  m_pShape = shape_factory.create(5);
202  }
203 
204  if (m_verbose){cimg::tic();printf("* Correlation proc\n");}
205  oCorrel.exec(oImage,oMesh,oField);//perform correlation
206  if (m_verbose){cimg::toc();}
207 
208  return error;
209 
210  }
211 
212  void postprocessing(const int &s, Cimage<Timg> &oImage, Cfield<T,Timg> &oField, Ccorrelation<T,Timg> &oCorrel, Cmesh<T,Timg> &oMesh)
213  {
216  unsigned char color[] = {0};
217 
218  //store the current eigen values
219  (oField.m_mode).move_to(m_modes);
220  //store the current node table
221  (oMesh.m_node).move_to(m_node);
222 
223  //store correlograms
224  if (!oField.m_correlogram.is_empty()){(oField.m_correlogram).move_to(m_correlograms);}
225 
226  //store the current reference system
227  m_ref = oField.m_ref;
228 
229  //convergency
230 // for (int step=0; step<oField.m_meanRes.size(); step++)
231 // {
232 // m_meanRes.push_back(oField.m_meanRes[step]);
233 // }
234 
235  if (s == m_sequence.size() - 1)
236  {
237 
238  m_meanRes.push_back(oField.m_meanRes.back());
239 
240  if (!oField.m_field.is_empty())
241  {(oField.m_field).move_to(m_fields);}
242  if (!oField.m_res.is_empty())
243  {(oField.m_res).move_to(m_residues);if(!oImage.m_curMask.is_empty()){m_residues.mul(oImage.m_curMask);}}
244  if (!oField.m_def.is_empty())
245  {(oField.m_def).move_to(m_deformed);if(!oImage.m_curMask.is_empty()){m_deformed.mul(oImage.m_curMask);}}
246 
247  if (!m_fields.is_empty())
248  {
249  cimglist_for(m_fields, var)
250  {
251  if(!oImage.m_curMask.is_empty()){m_fields[var].mul(oImage.m_curMask);}
252  }
253  }
254 
255  }
256 
257  //convert mesh location in physical units
258  cimglist_for(m_node,dim){m_node[dim]*=oImage.m_pix[dim];}
259 
260  //clear pointers
261  delete m_pMesh;
262  delete m_pField;
263  delete m_pCorrel;
264 
265  }
266 
267 
268 
269 };
270 
271 #endif
This factory create a pointer toward the required ShapeFunction class. The pointer creation could onl...
Definition: CshapeFunction_factory.h:45
load image and mask from cdl and store fields. It also creates a resized version of data in the case ...
Definition: Csequence.h:62
void postprocessing(const int &s, Cimage< Timg > &oImage, Cfield< T, Timg > &oField, Ccorrelation< T, Timg > &oCorrel, Cmesh< T, Timg > &oMesh)
Definition: Csequence.h:212
Definition: Cmesh_factory.h:42
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
It returns a pointer toward a specific correlation method according to a parameter.nc file. The parameter file is set by default or could be provide by command line. create function could be called using : int, string = type, CParameterNetCDF, and finally [argv,argc] !!!! The function to get parameters directly from command line doesn't work yet.
Definition: Ccorrelation_factory.h:61
Cfield< T, Timg > * create(const int &number)
Definition: Cfield_factory.h:83
this is the mother class of every correlation classes. m_correl_type refers to the the type of correl...
Definition: Ccorrelation.h:65
void resize(const int &filter)
Definition: Cimage.h:178
CImg< T > m_correlogram
to improve, they shouldn't be here//
Definition: Cfield.h:74
Definition: Cmesh.h:61
Definition: Cfield.h:51
It implements a vector of n pointer toward a specific Cpeak class to detected successive peaks within...
It returns a pointer toward a specific field container according to a parameter.nc file...
Definition: Cfield_factory.h:52
Definition: Cimage.h:57