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
CshapeFunction_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 CSHAPEFUNCTION_FACTORY
25 #define CSHAPEFUNCTION_FACTORY
26 
27 
28 //-----------------------------------------------------------------------
29 #include "CshapeFunction.h"
30  #include "CshapeFunction_global.h"
36  #include "CshapeFunction_FEM.h"
37  #include "CshapeFunction_FEM_Q4.h"
38  #include "CshapeFunction_FEM_C8.h"
39 //-----------------------------------------------------------------------
40 
44 template<typename T,typename Timg>
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  const char* m_paramPath;
56  bool m_verbose;
57 
58 
59  CshapeFunction_factory(std::string name)
60  {//constructor
61 
62  class_name = "CshapeFunction_factory";
63  m_variable = name;
64 
65  m_infos.push_back("rigid_body");
66  m_infos.push_back("image");
67  m_infos.push_back("blade");
68  m_infos.push_back("homogeneous");
69  m_infos.push_back("brasilian");
70  m_infos.push_back("Q4");
71  m_infos.push_back("C8");
72 
73  }
74 
75  CshapeFunction<T,Timg>* create(const int &number)
76  {//create from "int"
77 
78  CshapeFunction<T,Timg>* pShape;
79 
80  switch(number)
81  {
82  case 0: pShape = new CshapeFunction_global_rigidBody<T,Timg>; break;
83  case 1: pShape = new CshapeFunction_global_image<T,Timg>; break;
84  case 2: pShape = new CshapeFunction_global_blade<T,Timg>; break;
85  case 3: pShape = new CshapeFunction_global_homogeneous<T,Timg>;break;
86  case 4: pShape = new CshapeFunction_global_brasilian<T,Timg>;break;
87  case 5: pShape = new CshapeFunction_FEM_Q4<T,Timg>; break;
88  case 6: pShape = new CshapeFunction_FEM_C8<T,Timg>; break;
89  default:
90  {
91  std::cerr<<class_name<<" : "<<number<<" refers to an unknown or incompatible correlation class"<<std::flush;
92  return NULL;
93  }
94  }
95 
96  if (m_verbose){printf("%s -> %s class loaded\n",class_name.c_str(), m_type.c_str());}
97 
98  pShape->m_verbose = m_verbose;// string correl-type as member
99  pShape->m_paramPath = m_paramPath;// string correl-name as member
100 
101  pShape->m_type = m_type;// string correl-type as member
102  pShape->m_name = m_variable;// string correl-name as member
103 
104  pShape->init(m_paramFile);//specific init
105 
106 
107  return pShape;// return pointer to specific correlation method
108 
109  }
110 
111  CshapeFunction<T,Timg>* create(const std::string &type)
112  {//create from "string"
113 
114  m_type = type;
115 
116  if(type == m_infos[0]) return create(0);
117  else if(type==m_infos[1]) return create(1);
118  else if(type==m_infos[2]) return create(2);
119  else if(type==m_infos[3]) return create(3);
120  else if(type==m_infos[4]) return create(4);
121  else if(type==m_infos[5]) return create(5);
122  else if(type==m_infos[6]) return create(6);
123  else
124  {
125  std::cerr<<class_name<<"::"<<__func__<<": error: type = "<<type<<" is unknown.\n"<<std::flush;
126  return NULL;
127  }
128 
129  }
130 
131  CshapeFunction<T,Timg>* create(CParameterNetCDF &paramFile)
132  {//create from "parameter file"
133 
134  m_paramFile = paramFile;
135 
136  int var(0);
137 
138  paramFile.loadVar(var,&m_variable);
139  m_paramFile.loadAttribute("shape",m_type);
140 
141  return create(m_type);
142 
143  }
144 
145  CshapeFunction<T,Timg>* create(int argc, char *argv[])
146  {//create from (argv,argc)
147 
148  commandLine(argc,argv);//read command line argument
149 
150  CshapeFunction<T,Timg> *pShape;// pointer toward a correlation class
151 
152  int error;
153 
154  if(m_paramPath!="true")
155  {// parameter.nc location is provided
156 
157  NcFile file(m_paramPath,NcFile::ReadOnly);// open the file and keep the object in file variable
158 
159  if ( error = m_paramFile.setFile(&file) !=1 )
160  {
161  std::cerr<< "Error while loading"<<m_paramPath<<" parameter file"<<std::endl;
162  return NULL;
163  }
164 
165  pShape = create(m_paramFile);// associate pCorrel pointer to the appropriate type following parameter.nc file
166  if (pShape == NULL){return NULL;}
167 
168  return pShape;
169 
170  }
171  else
172  {// m_option = true
173 
174  std::cout<<" --correlator option : Command line\n";
175  std::cout<<" --building!!\n";
176 
177  return NULL;
178 
179  }
180 
181 
182  }
183 
184 
185 
186  //other methods
187  void commandLine(int argc, char *argv[])
188  {// read the command line
189 
190  //set parameter file path
191  m_paramPath = cimg_option("-p","./parameters.nc","parameter, mesh or true");
192  //set verbose mode
193  m_verbose = cimg_option("-v",false,0);
194 
195  if(m_verbose)
196  {
197  printf("Mode Verbose\n");
198  printf("%s : %s\n",class_name.c_str(),m_paramPath);
199  }
200 
201  }
202 
203  void stringSplit(std::string manyString, std::vector<std::string> value)
204  {
205 
206  char *cstr,*ptr;
207  char *split=(char*)(" ,;");
208 
209  cstr = new char [manyString.size()+1];
210  strcpy(cstr,manyString.c_str());
211  ptr=strtok(cstr,split);
212  while (ptr!=NULL)
213  {
214  value.push_back(ptr);
215  ptr=strtok(NULL,split);
216  }
217  delete[] cstr;
218 
219  }
220 
221  void info()
222  {// print the whole set of available classes within the factory
223 
224  printf("\nclass %s\n",class_name.c_str());
225  for (int i=0; i<m_infos.size(); i++)
226  {
227 
228  printf("\t(%i) mode : %s\n",i,m_infos[i].c_str());
229 
230  }
231 
232  }
233 
234 };
235 
236 #endif
This factory create a pointer toward the required ShapeFunction class. The pointer creation could onl...
Definition: CshapeFunction_factory.h:45
This class implements C8P1 shape functions available for 3D cases.
Definition: CshapeFunction_FEM_C8.h:39
This class implements Q4P1 shape functions available for 2D cases.
Definition: CshapeFunction_FEM_Q4.h:39
This class implements Homogeneous deformation shape functions available for 2D and 3D cases...
Definition: CshapeFunction_global_homogeneous.h:41
This is the mother class of shape function objets (virtual pure).
Definition: CshapeFunction.h:48
This class implements Brasilian shape functions available for 2D case (isotropic elasticity). The implemented mode is called "B" and a link toward Homogeneous modes is provided. Brasilian mode within the entire set of required modes by user is noted "m_modB" and the identified parameter is 1/E with E the Young modulus:
Definition: CshapeFunction_global_brasilian.h:46
Definition: CshapeFunction_global_image.h:40
This class implements Rigid Body shape functions available for 2D and 3D cases. It implements 3 rigid...
Definition: CshapeFunction_global_rigidBody.h:41
This class implements Blade flexion and compression shape functions available for 2D case (CL encastr...
Definition: CshapeFunction_global_blade.h:44