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
Cimage_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 CIMAGE_FACTORY
25 #define CIMAGE_FACTORY
26 
27 
28 
36 //-----------------------------------------------------------------------
37 #define cimg_plugin "plugins/add_fileformat.h"
38 #define cimg_use_netcdf
39 #ifdef cimg_use_netcdf
40  #include "../NetCDF.Tool/struct_parameter_NetCDF.h"
41  #define cimg_plugin2 "plugins/netcdf_file_format4CImg2.h"
42  #define cimglist_plugin2 "plugins/netcdf_file_format4CImgList2.h"
43  #include "../CImg.Tool/CImg_NetCDF.h"
44 #endif
45 
46 #define NO_USB
47 
48 #include "Cimage.h"
49  #include "Cimage_file.h"
50  #ifndef NO_USB
51  #include "Cimage_grab.h"
52  #endif
53 //-----------------------------------------------------------------------
54 
55 
60 template<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  std::vector<std::string> m_element;
70  CParameterNetCDF m_paramFile;
71 
72  const char* m_paramPath;
73  bool m_verbose;
74 
75 
76  Cimage_factory(const std::string name)
77  {//constructor
78 
79  class_name = "Image : factory";
80 
81  m_variable = name;
82 
83  m_infos.push_back("File");
84  #ifndef NO_USB
85  m_infos.push_back("Grab");
86  #endif
87 
88  }
89 
90  Cimage<Timg>* create(const int &number)
91  {//create from int
92 
93  Cimage<Timg>* pImage;
94 
95  switch(number)
96  {
97  case 0: pImage = new Cimage_file<Timg>; break;
98  #ifndef NO_USB
99  case 1: pImage = new Cimage_grab<Timg>; break;
100  #endif
101  default:
102  {
103  std::cerr<<class_name<<" : "<<number<<" refers to an unknown or incompatible correlation class"<<std::flush;
104  return NULL;
105  }
106  }
107 
108  if (m_verbose){printf("%s -> %s class loaded\n",class_name.c_str(), m_type.c_str());}
109 
110  pImage->m_verbose = m_verbose;// active or not the verbose mode
111  pImage->m_paramPath = m_paramPath;// string correl-name as member
112  pImage->m_type = m_type;// string correl-type as member
113  pImage->m_name = m_variable;// string correl-name as member
114  pImage->init(m_paramFile);//specific init
115 
116  return pImage;// return pointer to specific correlation method
117 
118  }
119 
120  Cimage<Timg>* create(const std::string &type)
121  {//create from string
122 
123  if(type==m_infos[0]) return create(0);
124  #ifndef NO_USB
125  else if(type==m_infos[1]) return create(1);
126  #endif
127  else
128  {
129  std::cerr<<class_name<<" : "<<type<<" refers to an unknown or incompatible correlation class"<<std::flush;
130  return NULL;
131  }
132 
133  }
134 
135  Cimage<Timg>* create(CParameterNetCDF &paramFile)
136  {//create from CParameterNetCDF
137 
138  //variable and attribute name
139  std::string attribute_name("type");
140  int error = paramFile.loadAttribute(attribute_name,m_type, &m_variable);
141 
142  return create(m_type);
143 
144  }
145 
146  Cimage<Timg>* create(int argc, char *argv[])
147  {//create from (argv,argc)
148 
149  commandLine(argc,argv);//read command line argument
150 
151  Cimage<Timg> *pImage;// pointer toward a image class
152 
153  int error;
154 
155  if(m_paramPath!="true")
156  {// parameter.nc location is provided
157 
158  NcFile file(m_paramPath,NcFile::ReadOnly);// open the file and keep the object in file variable
159 
160  if ( error = m_paramFile.setFile(&file) !=1 )
161  {
162  std::cerr<< "Error while loading"<<m_paramPath<<" parameter file"<<std::endl;
163  return NULL;
164  }
165 
166  pImage = create(m_paramFile);// associate pCorrel pointer to the appropriate type following parameter.nc file
167 
168  if (pImage == NULL){return NULL;}
169 
170  return pImage;
171 
172  }
173  else
174  {// m_paramPath = true
175 
176  std::cout<<" --correlator option : Command line\n";
177  std::cout<<" --building!!\n";
178 
179  return NULL;
180 
181  }
182 
183 
184  }
185 
186 
187 
188  //other methods
189  void commandLine(int argc, char *argv[])
190  {// get the comand line
191 
192  //set parameter file path
193  m_paramPath = cimg_option("-p","./parameters.nc","parameter, mesh or true");
194  //set verbose mode
195  m_verbose = cimg_option("-v",false,0);
196 
197  if(m_verbose)
198  {
199  printf("Mode Verbose\n");
200  printf("%s : %s\n",class_name.c_str(),m_paramPath);
201  }
202 
203  }
204 
205  void stringSplit(std::string manyString, std::vector<std::string> value)
206  {
207 
208  char *cstr,*ptr;
209  char *split=(char*)(" ,;");
210 
211  cstr = new char [manyString.size()+1];
212  strcpy(cstr,manyString.c_str());
213  ptr=strtok(cstr,split);
214  while (ptr!=NULL)
215  {
216  value.push_back(ptr);
217  ptr=strtok(NULL,split);
218  }
219  delete[] cstr;
220 
221  }
222 
223  void info()
224  {// print the whole set of available classes within the factory
225 
226  printf("\nclass %s\n",class_name.c_str());
227  for (int i=0; i<m_infos.size(); i++)
228  {
229 
230  printf("\t(%i) mode : %s\n",i,m_infos[i].c_str());
231 
232  }
233 
234  }
235 
236 };
237 
238 #endif
239 
load image and mask from cdl and store fields. It also creates a resized version of data in the case ...
Definition: Cimage_file.h:38
load image and mask from cdl and store fields. It also creates a resized version of data in the case ...
Definition: Cimage.h:57
Definition: Cimage_grab.h:46
It returns a pointer toward a specific Image loader class 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: Cimage_factory.h:61