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
Cmesh_factory.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 CMESH_FACTORY
25 #define CMESH_FACTORY
26 
27 
28 //-----------------------------------------------------------------------
29 #include "Cmesh.h"
30  #include "Cmesh_global.h"
31  #include "Cmesh_import.h"
32  #include "Cmesh_import_image.h"
33 // #include "Cmesh_import_T3.h"
34  #include "Cmesh_generate.h"
36  #include "Cmesh_generate_centroid.h"
38 //-----------------------------------------------------------------------
39 
40 
41 template<typename T, typename Timg>
43 {
44 
45  public:
46 
47  //attributes
48  std::string class_name, m_variable, m_type;
49  std::vector<std::string> m_infos;
50  CParameterNetCDF m_paramFile;
51 
52  const char* m_paramPath;
53  bool m_verbose;
54 
56  long m_num_mode;
57 
58 
59  Cmesh_factory(const std::string &name)
60  {//constructor
61 
62  class_name="Mesh : factory";
63 
64  m_variable = name;
65 
66  m_infos.push_back("global");
67  m_infos.push_back("generate_regularFem");
68  m_infos.push_back("generate_centroid");
69  m_infos.push_back("generate_centroid_integrated");
70  m_infos.push_back("import_image");
71 
72  }
73 
74  Cmesh<T,Timg>* create(const int &number)
75  {//create from int
76 
77  Cmesh<T,Timg>* pMesh;
78 
79  switch(number)
80  {
81  case 0:
82  pMesh = new Cmesh_global<T,Timg>;
83  pMesh->m_dof = m_num_mode;
84  break;
85  case 1: pMesh = new Cmesh_generate_regularFem<T,Timg>; break;
86  case 2: pMesh = new Cmesh_generate_centroid<T,Timg>; break;
87  case 3:
89  pMesh->m_dof = m_num_mode;
90  break;
91  case 4:
92  pMesh = new Cmesh_import_image<T,Timg>;
93  pMesh->m_dof = m_num_mode;
94  break;
95  default:
96  {
97  std::cerr<<class_name<<" : "<<number<<" refers to an unknown or incompatible mesh class"<<std::flush;
98  return NULL;
99  }
100  }
101 
102  if (m_verbose){printf("%s -> %s class loaded\n",class_name.c_str(), m_type.c_str());}
103 
104  pMesh->m_verbose = m_verbose;// active or not the verbose mode
105  pMesh->m_type = m_type;// string correl-type as member
106  pMesh->m_name = m_variable;// string correl-name as member
107 
108  pMesh->init(m_paramFile);//specific init
109 
110  return pMesh;// return pointer to specific correlation method
111 
112  }
113 
114  Cmesh<T,Timg>* create(const std::string &type)
115  {//create from string
116 
117  //if this function is used directly
118  m_type = type;
119 
120  if(type==m_infos[0]) return create(0);
121  else if(type==m_infos[1]) return create(1);
122  else if(type==m_infos[2]) return create(2);
123  else if(type==m_infos[3]) return create(3);
124  else if(type==m_infos[4]) return create(4);
125  else
126  {
127  std::cerr<<class_name<<" : "<<type<<" refers to an unknown or incompatible mesh class"<<std::flush;
128  return NULL;
129  }
130 
131  }
132 
133  Cmesh<T,Timg>* create(CParameterNetCDF &paramFile)
134  {//create from CParameterNetCDF
135 
136  //if this function is used directly
137  m_paramFile = paramFile;
138 
139  //find the variable name associated to the mesh attribute within correlation method
140  std::string mesh_name;
141  int var(0);
142 
143  paramFile.loadVar(var,&m_variable);
144  paramFile.loadAttribute("mesh", mesh_name);
145 
146  if(m_verbose){printf("mesh name : %s\n", mesh_name.c_str());}
147 
149  if (m_variable.compare(0,3,"OFI") == 0)
150  {
151  std::vector<std::string> modes;
152  m_paramFile.loadAttribute("modes", modes);
153  m_num_mode += modes.size() - 1;
154  }
155 
156  //find the mesh type
157  m_variable = mesh_name;
158  paramFile.loadVar(var,&m_variable);
159  paramFile.loadAttribute("type", m_type);
160 
161  if(m_verbose){printf("mesh type : %s\n", m_type.c_str());}
162 
163  return create(m_type);
164 
165  }
166 
167  Cmesh<T,Timg>* create(int argc, char *argv[])
168  {//create from (argv,argc)
169 
170  commandLine(argc,argv);//read command line argument
171 
172  Cmesh<T,Timg> *pMesh;// pointer toward a correlation class
173 
174  int error;
175 
176  if(m_paramPath!="true")
177  {// parameter.nc location is provided
178 
179  NcFile file(m_paramPath,NcFile::ReadOnly);// open the file and keep the object in file variable
180 
182  NcToken name = "dim_mode";
183  NcDim* dim = file.get_dim(name);
184  m_num_mode = dim->size();
185 
186  if(m_verbose){std::cout<<"num modes : "<<m_num_mode<<"\n";}
187 
188  if ( error = m_paramFile.setFile(&file) !=1 )
189  {
190  std::cerr<< "Error while loading"<<m_paramPath<<" parameter file"<<std::endl;
191  return NULL;
192  }
193 
194  pMesh = create(m_paramFile);// associate pCorrel pointer to the appropriate type following parameter.nc file
195 
196  if (pMesh == NULL){return NULL;}
197 
198  return pMesh;
199 
200  }
201  else
202  {// m_paramPath = true
203 
204  std::cout<<" --mesh option : Command line\n";
205  std::cout<<" --building!!\n";
206 
207  return NULL;
208 
209  }
210 
211 
212  }
213 
214 
215  //other methods
216  void commandLine(int argc, char *argv[])
217  {// get the comand line
218 
219  //set parameter file path
220  m_paramPath = cimg_option("-p","./parameters.nc","parameter, mesh or true");
221  //set verbose mode
222  m_verbose = cimg_option("-v",false,0);
223 
224  if(m_verbose)
225  {
226  printf("Mode Verbose\n");
227  printf("%s : %s\n",class_name.c_str(),m_paramPath);
228  }
229 
230  }
231 
232  void stringSplit(std::string manyString, std::vector<std::string> value)
233  {
234 
235  char *cstr,*ptr;
236  char *split=(char*)(" ,;");
237 
238  cstr = new char [manyString.size()+1];
239  strcpy(cstr,manyString.c_str());
240  ptr=strtok(cstr,split);
241  while (ptr!=NULL)
242  {
243  value.push_back(ptr);
244  ptr=strtok(NULL,split);
245  }
246  delete[] cstr;
247 
248  }
249 
250  void info()
251  {// print the whole set of available classes within the factory
252 
253  printf("\nclass %s\n",class_name.c_str());
254  for (int i=0; i<m_infos.size(); i++)
255  {
256 
257  printf("\t(%i) mode : %s\n",i,m_infos[i].c_str());
258 
259  }
260 
261  }
262 
263 
264 
265 };
266 
267 #endif
268 
Definition: Cmesh_import_image.h:42
As Cmesh_Q4 this class is based on regular and rectangular elements. This class works on 7 main attri...
Definition: Cmesh_generate_centroid.h:58
Cmesh< T, Timg > * create(CParameterNetCDF &paramFile)
Definition: Cmesh_factory.h:133
As Cmesh_Q4 this class is based on regular and rectangular elements. This class works on 7 main attri...
Definition: Cmesh_generate_centroid_integrated.h:55
Definition: Cmesh_factory.h:42
long m_num_mode
to improve//
Definition: Cmesh_factory.h:56
Class is based on Q4 elements, i.e. 4 nodes elements. This class works on 7 main attributes declared ...
Definition: Cmesh_generate_regularFem.h:52
Cmesh< T, Timg > * create(int argc, char *argv[])
Definition: Cmesh_factory.h:167
Definition: Cmesh.h:61
Definition: Cmesh_global.h:40