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_factory.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 CCORRELATION_FACTORY
25 #define CCORRELATION_FACTORY
26 
27 
28 
38 //-----------------------------------------------------------------------
39 #include "Ccorrelation.h"
40 
47 
48  #include "Ccorrelation_intercor.h"
54 //-----------------------------------------------------------------------
55 
60 template<typename T, typename Timg>
62 {
63 
64  public:
65 
66  //attributes
67  std::vector<std::string> m_infos;
68  std::string class_name, m_variable, m_type;
69  CParameterNetCDF m_paramFile;
70 
71  bool m_verbose;
72  const char* m_paramPath;
73 
74 
75 
76  Ccorrelation_factory(const std::string name)
77  {//constructor
78 
79  class_name = "Correlation : factory";
80 
82  m_variable = name;
83 
85  m_infos.push_back("IC_direct");
86  m_infos.push_back("IC_fftw");
87  m_infos.push_back("IC_fftw_phase");
88  m_infos.push_back("IC_fft");
89  m_infos.push_back("IC_fft_phase");
90  m_infos.push_back("OFI");
91  m_infos.push_back("OFIB");
92  m_infos.push_back("OFFEM_newton");
93  m_infos.push_back("OFFEM_gradient");
94 
95  }
96 
97  Ccorrelation<T,Timg>* create(const int &number)
98  {//create from int
99 
100  Ccorrelation<T,Timg>* pCorrel;
101 
102  switch(number)
103  {
104  case 0: pCorrel = new Ccorrelation_intercor_direct<T,Timg>; break;
105  case 1: pCorrel = new Ccorrelation_intercor_fftw<T,Timg>; break;
106  case 2: pCorrel = new Ccorrelation_intercor_fftw_phase<T,Timg>; break;
107  case 3: pCorrel = new Ccorrelation_intercor_fft<T,Timg>; break;
108  case 4: pCorrel = new Ccorrelation_intercor_fft_phase<T,Timg>; break;
109  case 5: pCorrel = new Ccorrelation_opticalFlow_integrated<T,Timg>; break;
110  case 6: pCorrel = new Ccorrelation_opticalFlow_integrated_block<T,Timg>; break;
111  case 7: pCorrel = new Ccorrelation_opticalFlow_fem_newton<T,Timg>; break;
112  case 8: pCorrel = new Ccorrelation_opticalFlow_fem_gradient<T,Timg>; break;
113  default:
114  {
115  std::cerr<<class_name<<" : "<<number<<" refers to an unknown or incompatible correlation class"<<std::flush;
116  return NULL;
117  }
118  }
119 
120  if (m_verbose){printf("%s -> %s class loaded\n",class_name.c_str(), m_type.c_str());}
121 
122  pCorrel->m_verbose = m_verbose;// active or not the verbose mode
123  pCorrel->m_correl_type = m_type;// string correl-type as member
124  pCorrel->m_correl_name = m_variable;// string correl-name as member
125 
126  pCorrel->init(m_paramFile);//specific init
127 
128  return pCorrel;// return pointer to specific correlation method
129 
130  }
131 
132  Ccorrelation<T,Timg>* create(const std::string &type)
133  {//create from string
134 
135  if(type==m_infos[0]) return create(0);
136  else if(type==m_infos[1]) return create(1);
137  else if(type==m_infos[2]) return create(2);
138  else if(type==m_infos[3]) return create(3);
139  else if(type==m_infos[4]) return create(4);
140  else if(type==m_infos[5]) return create(5);
141  else if(type==m_infos[6]) return create(6);
142  else if(type==m_infos[7]) return create(7);
143  else if(type==m_infos[8]) return create(8);
144  else
145  {
146  std::cerr<<class_name<<" : "<<type<<" refers to an unknown or incompatible correlation class"<<std::flush;
147  return NULL;
148  }
149 
150  }
151 
152  Ccorrelation<T,Timg>* create(CParameterNetCDF &paramFile)
153  {//create from CParameterNetCDF
154 
155  std::string method, m_corType;
156 
157  paramFile.loadAttribute("type",m_type, &m_variable);
158  m_corType = m_type;
159 
160  if (m_type=="OFFEM")
161  {
162  paramFile.loadAttribute("method",method, &m_variable);
163  m_corType = m_corType + "_" + method;
164  }
165 
166  return create(m_corType);
167 
168  }
169 
170  Ccorrelation<T,Timg>* create(int argc, char *argv[])
171  {//create from (argv,argc)
172 
173  commandLine(argc,argv);//read command line argument
174 
175  Ccorrelation<T,Timg> *pCorrel;// pointer toward a correlation class
176 
177  int error;
178 
179  if(m_paramPath!="true")
180  {// parameter.nc location is provided
181 
182  NcFile file(m_paramPath,NcFile::ReadOnly);// open the file and keep the object in file variable
183 
184  if ( error = m_paramFile.setFile(&file) !=1 )
185  {
186  std::cerr<< "Error while loading"<<m_paramPath<<" parameter file"<<std::endl;
187  return NULL;
188  }
189 
190  pCorrel = create(m_paramFile);// associate pCorrel pointer to the appropriate type following parameter.nc file
191 
192  if (pCorrel == NULL){return NULL;}
193 
194  return pCorrel;
195 
196  }
197  else
198  {// m_paramPath = true
199 
200  std::cout<<" --correlator option : Command line\n";
201  std::cout<<" --building!!\n";
202 
203  return NULL;
204 
205  }
206 
207 
208  }
209 
210 
211 
212  //other methods
213  void commandLine(int argc, char *argv[])
214  {// get the comand line
215 
216  //set parameter file path
217  m_paramPath = cimg_option("-p","./parameters.nc","parameter, mesh or true");
218  //set verbose mode
219  m_verbose = cimg_option("-v",false,0);
220 
221  if(m_verbose)
222  {
223  printf("Mode Verbose\n");
224  printf("%s : %s\n",class_name.c_str(),m_paramPath);
225  }
226 
227  }
228 
229  void stringSplit(std::string manyString, std::vector<std::string> value)
230  {
231 
232  char *cstr,*ptr;
233  char *split=(char*)(" ,;");
234 
235  cstr = new char [manyString.size()+1];
236  strcpy(cstr,manyString.c_str());
237  ptr=strtok(cstr,split);
238  while (ptr!=NULL)
239  {
240  value.push_back(ptr);
241  ptr=strtok(NULL,split);
242  }
243  delete[] cstr;
244 
245  }
246 
247  void info()
248  {// print the whole set of available classes within the factory
249 
250  printf("\nclass %s\n",class_name.c_str());
251  for (int i=0; i<m_infos.size(); i++)
252  {
253 
254  printf("\t(%i) mode : %s\n",i,m_infos[i].c_str());
255 
256  }
257 
258  }
259 
260 };
261 
262 #endif
263 
It implements optical flow strategy for FEM method using newton method.
this branch doesn't requires image size equal to a power of 2 since it uses FFtw which already implem...
It implements optical flow strategy for FEM method.
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
It implements the Optical Flow with Integrated kinematics within independant block such as Block-matc...
Definition: Ccorrelation_opticalFlow_integrated_block.h:43
Definition: Ccorrelation_intercor_direct.h:38
Definition: Ccorrelation_intercor_fftw_phase.h:46
Definition: Ccorrelation_opticalFlow_integrated.h:43
It implements optical flow strategy for global shape functions.
this is the mother class of every correlation classes. m_correl_type refers to the the type of correl...
Definition: Ccorrelation.h:65
It implements optical flow strategy.
Definition: Ccorrelation_opticalFlow_fem_newton.h:43
Definition: Ccorrelation_intercor_fftw.h:39
Definition: Ccorrelation_intercor_fft.h:47
Definition: Ccorrelation_opticalFlow_fem_gradient.h:43
!!!!It implements the zeroPadding but doesn't work with fftw lib and the actual architecture since th...
implement the cross correlation between correlogram[0] and correlogram[1] using CImg function...
it links to zeroPadd method and normalization one of anySize_normalized
It implements optical flow strategy for FEM method using gradient algorithm.
this class implement 2 functions:
Definition: Ccorrelation_intercor_fft_phase.h:45
Ccorrelation_factory(const std::string name)
Definition: Ccorrelation_factory.h:76