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_import_image.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_IMPORT_IMAGE
25 #define CMESH_IMPORT_IMAGE
26 
27 
37 #include "Cmesh_import.h"
38 
39 
40 
41 template<typename T,typename Timg>
42 class Cmesh_import_image : public Cmesh_import<T,Timg>
43 {
44 
45  public:
46 
47  CImg<Timg> m_map;
48  CImgList<unsigned int> m_list;
49 
50 
52  {// constructor
53 
54  this->class_name = "Cmesh_import_image";
55 
56  }
57 
58  virtual int exec(const Cimage<Timg> &oImage)
59  {//exec
60 
61  load(this->m_path);
62 
63  m_list.assign(m_map.max());
64 
65  std::vector<int> set;
66  CImg<int> cimg_set;
67  CImg<int> permut_map;
68  m_map.sort(permut_map,true); // Sort by ascending order.
69  int val(m_map[0]),pos(0);
70 
71  for (int p=0;p<m_map.size(); p++)
72  {
73 
74  if (m_map[p] != val)
75  {
76  cimg_set.assign(set.size(),1,1,1,0);
77  cimg_forX(cimg_set,x){cimg_set[x]=set[x];}
78  m_list[pos] = cimg_set;
79  set.clear();
80  val = m_map[p];
81  pos++;
82  }
83 
84  set.push_back(permut_map[p]);
85 
86  }
87  m_list.remove(pos,m_map.max()-1);
88 
89 
90  int error = assign(oImage);
91 
92 //
93 // #pragma omp parallel
94 // {
95 // set_nodes(oImage, m_node); //generate node table
96 // set_connectivity(oImage, m_node, m_connect);// generate connectivity table
97 // }
98 
99  return error;
100 
101  }
102 
103 // void sort(CImg<Timg> &m_map)
104 // {
105 //
106 // CImg<int> permut;
107 // m_map.sort(permut,true);
108 //
109 // #pragma omp for schedule(runtime)
110 // for (int p=0; p<m_map.size(); p++)
111 // {//domain loops
112 //
113 // if(tmp[1][m_map[p]] == 0){m_list.pushback}
114 //
115 // }
116 //
117 // }
118 
119  virtual void load(const std::string &path)
120  {// init from file
121 
122  m_map.load(path.c_str());
123 
124  }
125 
126  virtual int assign(const Cimage<Timg> &oImage)
127  {// initialize attribute dimensions
128 
129  //degree of freedom
130  this->m_dof = m_map.max();
131  if (this->m_verbose){printf("\tDegree Of Freedom : %i\n",this->m_dof);}
132 
133  //node table
134  this->m_node.assign(this->num_var(),m_map.max(),1,1,1,0);
135  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());}
136 
137  //connectivity table
138  this->m_connect.assign(m_map.max(),1,1,1,1,0);
139 
140  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());}
141 
142  //number of pixels
143  this->m_numPix = oImage.m_curImg[0].size();
144 
145  return 0;
146 
147  }
148 
149  virtual void set_nodes(const Cimage<Timg> &oImage, CImgList<T> &nodes)
150  {// node table definition
151 
152 
153 
154  }
155 
156  virtual void set_connectivity(const Cimage<Timg> &oImage, const CImgList<T> &nodes, CImgList<int> &elements)
157  {// element and connectivity table definition
158 
159  }
160 
161 
162  virtual int cropList(const Cimage<Timg> &oImage, const int &elem, CImg<Timg> &list, std::vector<T> &coord0) const
163  {//extract sub_box from global image one using node and element table
164 
169  int msk = 1;
170 
171 // list.assign(coord1[0]-coord0[0]+1, coord1[1]-coord0[1]+1, coord1[2]-coord0[2]+1, 1, 0);
172 
173 
174  return msk;
175 
176  }
177 
178  virtual int grid_dims(const int &i) const
179  {// return mesh grid dimensions
180 
181  switch(i)
182  {
183  case 0: return this->m_node[0].width(); break;
184  case 1: return this->m_node[0].height(); break;
185  case 2: return this->m_node[0].depth(); break;
186  case 3: return 1; break;
187  default:
188  {
189  std::cerr<<this->class_name<<"::"<<__func__<<": error: id="<<i<<" which is over [0-3]\n"<<std::flush;
190  return 0;
191  }
192  }
193 
194  }
195 
196 
197 };
198 
199 #endif
Definition: Cmesh_import_image.h:42
Definition: Cmesh_import.h:42
Definition: Cimage.h:57
virtual int cropList(const Cimage< Timg > &oImage, const int &elem, CImg< Timg > &list, std::vector< T > &coord0) const
Definition: Cmesh_import_image.h:162