24 #ifndef CMESH_GENERATE_REGULARFEM
25 #define CMESH_GENERATE_REGULARFEM
51 template<
typename T,
typename Timg>
61 this->class_name =
"Cmesh_generate_regularFem";
65 virtual int get_attributes(CParameterNetCDF &fp)
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];}
82 {printf(
"\tMesh resolution : [%i %i %i]\n",this->m_pitch[0], this->m_pitch[1], this->m_pitch[2]);}
90 this->m_grid.assign(3,1);
91 for (
int i=0; i<this->num_var(); i++)
93 this->m_grid[i] = (int)ceil((
float)oImage.cur_dim(i)/(float)this->m_pitch[i])+1;
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);}
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());}
105 if (this->num_var() == 2)
107 this->m_connect.assign((this->m_grid[0]-1)*(this->m_grid[1]-1),2,2,1,1,0);
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);
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());}
116 this->m_numPix = oImage.m_curImg[0].size();
132 #pragma omp for schedule(runtime)
133 for (
int nd=0; nd<nodes[0].size(); nd++)
137 nodes[0].contains(nodes[0][nd],x[0],x[1],x[2]);
139 cimglist_for(nodes, dim)
142 if (x[dim] == this->m_grid[dim]-1)
143 {nodes[dim][nd] = oImage.cur_dim(dim)-1;}
145 {nodes[dim][nd] = x[dim] * this->m_pitch[dim];}
164 #pragma omp for schedule(runtime)
165 for (
int elem=0; elem<elements.size(); elem++)
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));
174 cimg_forZ(elements[elem], c)
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);
188 virtual int cropList(
const Cimage<Timg> &oImage,
const int &elem, CImg<Timg> &list, std::vector<T> &coord0)
const
196 std::vector<T> coord1;
197 coord0.assign(3,0);coord1.assign(3,0);
200 cimglist_for(this->m_node, dim)
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;
207 if (coord0[dim] == 0)
212 double unmasked((coord1[0]-coord0[0]+1)*(coord1[1]-coord0[1]+1)*(coord1[2]-coord0[2]+1));
214 if (!oImage.m_curMask.is_empty())
216 unmasked = oImage.m_curMask.get_crop(coord0[0],coord0[1],coord0[2],0,coord1[0],coord1[1],coord1[2],0,0).sum();
219 if (unmasked >= 10*(coord1[0]-coord0[0]+1)*(coord1[1]-coord0[1]+1)*(coord1[2]-coord0[2]+1)/100)
220 {list.assign(coord1[0]-coord0[0]+1, coord1[1]-coord0[1]+1, coord1[2]-coord0[2]+1, 1, 0);}
228 virtual int grid_dims(
const int &i)
const
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;
239 std::cerr<<this->class_name<<
"::"<<__func__<<
": error: id="<<i<<
" which is over [0-3]\n"<<std::flush;
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