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_generate_regularFem.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 CMESH_GENERATE_REGULARFEM
25 #define CMESH_GENERATE_REGULARFEM
26 
35 #include "Cmesh_generate.h"
36 
51 template<typename T, typename Timg>
53 {
54 
55 
56  public:
57 
59  {// constructor
60 
61  this->class_name = "Cmesh_generate_regularFem";
62 
63  }
64 
65  virtual int get_attributes(CParameterNetCDF &fp)
66  {// requires to load pitch[x,y,z]
67 
68  // load components
70 
71  int error(0);
72  std::string att;
73 
74  // store pitch sizes within vector[3] named m_pitch. The last value is one in the 2D case.
75  att = "pitch";
76  error = fp.loadAttribute(att,this->m_pitch);
77  for (int i=this->m_pitch.size(); i<3; i++){this->m_pitch.push_back(1);}
78  this->m_win.assign(3,0);
79  for (int i=0; i<3; i++){this->m_win[i] = this->m_pitch[i];}
80 
81  if (this->m_verbose)
82  {printf("\tMesh resolution : [%i %i %i]\n",this->m_pitch[0], this->m_pitch[1], this->m_pitch[2]);}
83 
84  }
85 
86  virtual int assign(const Cimage<Timg> &oImage)
87  {// initialize attribute dimensions
88 
89  //grid dimensions
90  this->m_grid.assign(3,1);
91  for (int i=0; i<this->num_var(); i++)
92  {
93  this->m_grid[i] = (int)ceil((float)oImage.cur_dim(i)/(float)this->m_pitch[i])+1;
94  }
95 
96  //degree of freedom
97  this->m_dof = this->m_grid[0]*this->m_grid[1]*this->m_grid[2]*this->num_var();
98  if (this->m_verbose){printf("\tDegree Of Freedom : %i\n",this->m_dof);}
99 
100  //node table
101  this->m_node.assign(this->num_var(),this->m_grid[0],this->m_grid[1],this->m_grid[2],1,0);
102  if (this->m_verbose){printf("\tNode table : [%i](%i,%i,%i)\n",this->m_node.size(), this->m_node[0].width(), this->m_node[0].height(), this->m_node[0].depth());}
103 
104  //connectivity table
105  if (this->num_var() == 2)
106  {//2D
107  this->m_connect.assign((this->m_grid[0]-1)*(this->m_grid[1]-1),2,2,1,1,0);
108  }
109  else
110  {//3D
111  this->m_connect.assign((this->m_grid[0]-1)*(this->m_grid[1]-1)*(this->m_grid[2]-1),2,2,2,1,0);
112  }
113  if (this->m_verbose){printf("\tElement table : [%i](%i,%i,%i)\n",this->m_connect.size(), this->m_connect[0].width(), this->m_connect[0].height(), this->m_connect[0].depth());}
114 
115  //number of pixels
116  this->m_numPix = oImage.m_curImg[0].size();
117 
118  return 0;
119 
120  }
121 
122  virtual void set_nodes(const Cimage<Timg> &oImage, CImgList<T> &nodes)
123  {// node table definition
124 
129  std::vector<int> x;
130  x.assign(3,0);
131 
132  #pragma omp for schedule(runtime)
133  for (int nd=0; nd<nodes[0].size(); nd++)
134  {//fill node table
135 
136  //find back spatial coordonnates of nodes
137  nodes[0].contains(nodes[0][nd],x[0],x[1],x[2]);
138 
139  cimglist_for(nodes, dim)
140  {//allow different element size at image borders to obtain nodes at each image corner
141 
142  if (x[dim] == this->m_grid[dim]-1)
143  {nodes[dim][nd] = oImage.cur_dim(dim)-1;}
144  else
145  {nodes[dim][nd] = x[dim] * this->m_pitch[dim];}
146 
147  }
148 
149  }
150 
151 
152  }
153 
154  virtual void set_connectivity(const Cimage<Timg> &oImage, const CImgList<T> &nodes, CImgList<int> &elements)
155  {// element and connectivity table definition
156 
161  std::vector<int> x;
162  x.assign(3,0);
163 
164  #pragma omp for schedule(runtime)
165  for (int elem=0; elem<elements.size(); elem++)
166  {//fill element table
167 
168  //find back spatial coordonnates within element table
169  x[0] = elem%(this->m_grid[0]-1);
170  x[1] = (elem/(this->m_grid[0]-1))%(this->m_grid[1]-1);
171  x[2] = elem/((this->m_grid[1]-1)*(this->m_grid[0]-1));
172 
173  //fond associated nodes
174  cimg_forZ(elements[elem], c)
175  {
176  elements(elem, 0,0,c) = nodes[0].offset(x[0],x[1],x[2]+c,0);
177  elements(elem, 1,0,c) = nodes[0].offset(x[0]+1,x[1],x[2]+c,0);
178  elements(elem, 1,1,c) = nodes[0].offset(x[0]+1,x[1]+1,x[2]+c,0);
179  elements(elem, 0,1,c) = nodes[0].offset(x[0],x[1]+1,x[2]+c,0);
180  }
181 
182  }
183 
184 
185 
186  }
187 
188  virtual int cropList(const Cimage<Timg> &oImage, const int &elem, CImg<Timg> &list, std::vector<T> &coord0) const
189  {//extract sub_box from global image one using node and element table
190 
196  std::vector<T> coord1;
197  coord0.assign(3,0);coord1.assign(3,0);
198  int msk(1);
199 
200  cimglist_for(this->m_node, dim)
201  {//set corner box positions
202 
203  //upper left and lower righ nodes
204  coord0[dim] = this->m_node[dim][this->m_connect[elem].front()];
205  coord1[dim] = this->m_node[dim][this->m_connect[elem].back()]-1;
206 
207  if (coord0[dim] == 0)
208  {coord0[dim]++;}
209 
210  }
211 
212  double unmasked((coord1[0]-coord0[0]+1)*(coord1[1]-coord0[1]+1)*(coord1[2]-coord0[2]+1));
213 
214  if (!oImage.m_curMask.is_empty())
215  {//number of unmasked pixels within element
216  unmasked = oImage.m_curMask.get_crop(coord0[0],coord0[1],coord0[2],0,coord1[0],coord1[1],coord1[2],0,0).sum();
217  }
218 
219  if (unmasked >= 10*(coord1[0]-coord0[0]+1)*(coord1[1]-coord0[1]+1)*(coord1[2]-coord0[2]+1)/100) //(coord1[0]-coord0[0]+1)*(coord1[1]-coord0[1]+1)*(coord1[2]-coord0[2]+1))
220  {list.assign(coord1[0]-coord0[0]+1, coord1[1]-coord0[1]+1, coord1[2]-coord0[2]+1, 1, 0);}
221  else
222  {msk = 0;}
223 
224  return msk;
225 
226  }
227 
228  virtual int grid_dims(const int &i) const
229  {
230 
231  switch(i)
232  {
233  case 0: return this->m_grid[0]; break;
234  case 1: return this->m_grid[1]; break;
235  case 2: return this->m_grid[2]; break;
236  case 3: return 1; break;
237  default:
238  {
239  std::cerr<<this->class_name<<"::"<<__func__<<": error: id="<<i<<" which is over [0-3]\n"<<std::flush;
240  return 0;
241  }
242  }
243 
244  }
245 
246 };
247 
248 #endif
virtual void set_nodes(const Cimage< Timg > &oImage, CImgList< T > &nodes)
Definition: Cmesh_generate_regularFem.h:122
virtual int cropList(const Cimage< Timg > &oImage, const int &elem, CImg< Timg > &list, std::vector< T > &coord0) const
Definition: Cmesh_generate_regularFem.h:188
Definition: Cmesh_generate.h:43
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
virtual void set_connectivity(const Cimage< Timg > &oImage, const CImgList< T > &nodes, CImgList< int > &elements)
Definition: Cmesh_generate_regularFem.h:154
Definition: Cmesh.h:61
Definition: Cimage.h:57