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
Cformat_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 CFORMAT_FACTORY
25 #define CFORMAT_FACTORY
26 
27 
28 
36 #include "Cformat.h"
37  #include "Cformat_char_float.h"
38  #include "Cformat_float_float.h"
39  #include "Cformat_float_double.h"
40  #include "Cformat_double_double.h"
41 
42 
46 {
47 
48  public:
49 
50  //attributes
51  std::vector<std::string> m_infos;
52  std::string class_name, m_variable, m_type;
53  CParameterNetCDF m_paramFile;
54 
55  bool m_verbose;
56  const char* m_paramPath;
57 
58 
59  Cformat_factory(const std::string name)
60  {//constructor
61 
62  class_name = "Cformat : factory";
63 
65  m_variable = name;
66 
68  m_infos.push_back("char_float");
69  m_infos.push_back("float_float");
70  m_infos.push_back("float_double");
71  m_infos.push_back("double_double");
72 
73  }
74 
75  Cformat* create(const int &number)
76  {//create from int
77 
78  Cformat* pFormat;
79 
80  switch(number)
81  {
82  case 0: pFormat = new Cformat_char_float; break;
83  case 1: pFormat = new Cformat_float_float; break;
84  case 2: pFormat = new Cformat_float_double; break;
85  case 3: pFormat = new Cformat_double_double; break;
86  default:
87  {
88  std::cerr<<class_name<<" : "<<number<<" refers to an unknown or incompatible format class"<<std::flush;
89  return NULL;
90  }
91  }
92 
93  if (m_verbose){printf("%s -> %s class loaded\n",class_name.c_str(), m_type.c_str());}
94 
95  pFormat->m_verbose = m_verbose;// active or not the verbose mode
96  pFormat->m_type = m_type;// string correl-type as member
97  pFormat->m_name = m_variable;// string correl-name as member
98 
99  return pFormat;// return pointer to specific correlation method
100 
101  }
102 
103  Cformat* create(const std::string &type)
104  {//create from string
105 
106  m_type = type;
107 
108  if(type==m_infos[0]) return create(0);
109  else if(type==m_infos[1]) return create(1);
110  else if(type==m_infos[2]) return create(2);
111  else if(type==m_infos[3]) return create(3);
112  else
113  {
114  std::cerr<<class_name<<" : "<<type<<" refers to an unknown or incompatible correlation class"<<std::flush;
115  return NULL;
116  }
117 
118  }
119 
120  Cformat* create(CParameterNetCDF &paramFile)
121  {//create from CParameterNetCDF
122 
123  m_paramFile = paramFile;
124 
125  paramFile.loadAttribute("type",m_type, &m_variable);
126 
127  return create(m_type);
128 
129  }
130 
131  Cformat* create(int argc, char *argv[])
132  {//create from (argv,argc)
133 
134  commandLine(argc,argv);//read command line argument
135 
136  Cformat* pFormat;// pointer toward a correlation class
137 
138  int error;
139 
140  if(m_paramPath!="true")
141  {// parameter.nc location is provided
142 
143  NcFile file(m_paramPath,NcFile::ReadOnly);// open the file and keep the object in file variable
144 
145  if ( error = m_paramFile.setFile(&file) !=1 )
146  {
147  std::cerr<< "Error while loading"<<m_paramPath<<" parameter file"<<std::endl;
148  return NULL;
149  }
150 
151  pFormat = create(m_paramFile);// associate pCorrel pointer to the appropriate type following parameter.nc file
152 
153  if (pFormat == NULL){return NULL;}
154 
155  return pFormat;
156 
157  }
158  else
159  {// m_paramPath = true
160 
161  std::cout<<" --format option : Command line\n";
162  std::cout<<" --building!!\n";
163 
164  return NULL;
165 
166  }
167 
168 
169  }
170 
171 
172 
173  //other methods
174  void commandLine(int argc, char *argv[])
175  {// get the comand line
176 
177  //set parameter file path
178  m_paramPath = cimg_option("-p","./parameters.nc","parameter, mesh or true");
179  //set verbose mode
180  m_verbose = cimg_option("-v",false,0);
181 
182  if(m_verbose)
183  {
184  printf("Mode Verbose\n");
185  printf("%s : %s\n",class_name.c_str(),m_paramPath);
186  }
187 
188  }
189 
190  void stringSplit(std::string manyString, std::vector<std::string> value)
191  {
192 
193  char *cstr,*ptr;
194  char *split=(char*)(" ,;");
195 
196  cstr = new char [manyString.size()+1];
197  strcpy(cstr,manyString.c_str());
198  ptr=strtok(cstr,split);
199  while (ptr!=NULL)
200  {
201  value.push_back(ptr);
202  ptr=strtok(NULL,split);
203  }
204  delete[] cstr;
205 
206  }
207 
208  void info()
209  {// print the whole set of available classes within the factory
210 
211  printf("\nclass %s\n",class_name.c_str());
212  for (int i=0; i<m_infos.size(); i++)
213  {
214 
215  printf("\t(%i) mode : %s\n",i,m_infos[i].c_str());
216 
217  }
218 
219  }
220 
221 };
222 
223 #endif
224 
Allow to choose the code format (input images and output results)
Definition: Cformat_factory.h:45
Definition: Cformat_float_double.h:37
Definition: Cformat_char_float.h:37
Definition: Cformat_float_float.h:37
Cformat_factory(const std::string name)
Definition: Cformat_factory.h:59
Definition: Cformat_double_double.h:37
Definition: Cformat.h:52