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_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 CFIELD_FACTORY
25 #define CFIELD_FACTORY
26 
27 
28 
38 //-----------------------------------------------------------------------
39 #include "Cfield.h"
40  #include "Cfield_intercor.h"
41  #include "Cfield_opticalFlow.h"
42  #include "Cfield_opticalFlow_fem.h"
43  #include "Cfield_opticalFlow_integrated.h"
44  #include "Cfield_opticalFlow_integrated_block.h"
45 //-----------------------------------------------------------------------
46 
51 template<typename T,typename Timg>
53 {
54 
55  public:
56 
57  //attributes
58  std::vector<std::string> m_infos;
59  std::string class_name, m_type, m_variable;
60  CParameterNetCDF m_paramFile;
61 
62  const char* m_paramPath;
63  bool m_verbose;
64 
65 
66  Cfield_factory(const std::string name)
67  {//constructor
68 
69  class_name = "Field : factory";
70 
72  m_variable = name;
73 
75  m_infos.clear();
76  m_infos.push_back("field_IC");
77  m_infos.push_back("field_OFI");
78  m_infos.push_back("field_OFIB");
79  m_infos.push_back("field_OFFEM");
80 
81  }
82 
83  Cfield<T,Timg>* create(const int &number)
84  {//create from int
85 
86  Cfield<T,Timg>* pField;
87 
88  switch(number)
89  {
90  case 0: pField = new Cfield_intercor<T,Timg>; break;
91  case 1: pField = new Cfield_opticalFlow_integrated<T,Timg>; break;
92  case 2: pField = new Cfield_opticalFlow_integrated_block<T,Timg>; break;
93  case 3: pField = new Cfield_opticalFlow_fem<T,Timg>; break;
94  default:
95  {
96  std::cerr<<class_name<<" : "<<number<<" refers to an unknown or incompatible correlation class"<<std::flush;
97  return NULL;
98  }
99  }
100 
101  if (m_verbose){printf("%s -> %s class loaded\n",class_name.c_str(), m_type.c_str());}
102 
104  pField->m_paramPath = m_paramPath;
106  pField->m_verbose = m_verbose;
108  pField->m_type = m_type;
110  pField->m_name = m_variable;
111 
113  pField->init(m_paramFile);
114 
116  return pField;
117 
118  }
119 
120  Cfield<T,Timg>* create(const std::string &type)
121  {//create from string
122 
123  m_type = type;
124 
125  if(type==m_infos[0]) return create(0);
126  else if(type==m_infos[1]) return create(1);
127  else if(type==m_infos[2]) return create(2);
128  else if(type==m_infos[3]) return create(3);
129  else{std::cerr<<class_name<<" : "<<type<<" refers to an unknown or incompatible correlation class"<<std::flush;return NULL;}
130 
131  }
132 
133  Cfield<T,Timg>* create(CParameterNetCDF &paramFile)
134  {//create from CParameterNetCDF
135 
136  m_paramFile = paramFile;
137 
138  std::string type_name;
139  int var(0);
140 
141  paramFile.loadVar(var,&m_variable);
142  paramFile.loadAttribute("type", type_name);
143 
144  if(m_verbose){printf("correlation type : %s\n", type_name.c_str());}
145 
146  if (type_name.compare(0,2,"IC") == 0)
147  {m_type = "field_IC";}
148  else if(type_name.compare(0,4,"OFIB") == 0)
149  {m_type = "field_OFIB";}
150  else if(type_name.compare(0,3,"OFI") == 0)
151  {m_type = "field_OFI";}
152  else if(type_name.compare(0,5,"OFFEM") == 0)
153  {m_type = "field_OFFEM";}
154  else
155  {std::cerr<<class_name<<" : "<<type_name<<" is unknown"<<std::flush;return NULL;}
156 
157  if(m_verbose){printf("field type : %s\n", m_type.c_str());}
158 
159  return create(m_type);
160 
161  }
162 
163  Cfield<T,Timg>* create(int argc, char *argv[])
164  {//create from (argv,argc)
165 
166  commandLine(argc,argv);//read command line argument
167 
168  Cfield<T,Timg> *pField;// pointer toward a correlation class
169 
170  int error;
171 
172  if(m_paramPath!="true")
173  {// parameter.nc location is provided
174 
175 
176  NcFile file(m_paramPath,NcFile::ReadOnly);// open the file and keep the object in file variable
177 
178  error = m_paramFile.setFile(&file);
179  if ( error != 1 ){std::cerr<< "Error while loading"<<m_paramPath<<" parameter file"<<std::endl;return NULL;}
180 
181  pField = create(m_paramFile);// associate pCorrel pointer to the appropriate type following parameter.nc file
182  if (pField == NULL){std::cerr<< "Error while loading"<<pField<<" pointer"<<std::endl;return NULL;}
183 
184  return pField;
185 
186  }
187  else
188  {// m_paramPath = true
189 
190  std::cout<<" --correlator option : Command line\n";
191  std::cout<<" --building!!\n";
192 
193  return NULL;
194 
195  }
196 
197 
198  }
199 
200 
201 
202  //other methods
203  void commandLine(int argc, char *argv[])
204  {// get the comand line
205 
206  //set parameter file path
207  m_paramPath = cimg_option("-p","./parameters.nc","parameter, mesh or true");
208  //set verbose mode
209  m_verbose = cimg_option("-v",false,0);
210 
211  if(m_verbose)
212  {
213  printf("Mode Verbose\n");
214  printf("%s : %s\n",class_name.c_str(),m_paramPath);
215  }
216 
217  }
218 
219  void info()
220  {// print the whole set of available classes within the factory
221 
222  printf("\nclass %s\n",class_name.c_str());
223  for (int i=0; i<m_infos.size(); i++)
224  {
225 
226  printf("\t(%i) mode : %s\n",i,m_infos[i].c_str());
227 
228  }
229 
230  }
231 
232 };
233 
234 #endif
235 
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
Cfield_factory(const std::string name)
Definition: Cfield_factory.h:66
Cfield< T, Timg > * create(const int &number)
Definition: Cfield_factory.h:83
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
Definition: Cfield.h:51
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_block.h:49
Definition: Cfield_intercor.h:46
It returns a pointer toward a specific field container according to a parameter.nc file...
Definition: Cfield_factory.h:52