00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef FEM_IMAGE2GRID_H
00010 #define FEM_IMAGE2GRID_H
00011
00012 #include <fem/Image2Grid_impl.hpp>
00013 #include <image/Image.hpp>
00014 #include <image/ScalarImage.hpp>
00015
00016
00017 namespace imaging
00018 {
00049 template<class fem_types>
00050 class Image2Grid
00051 {
00052 typedef ublas::fixed_vector<float_t, fem_types::data_dimension> vertex_t;
00053 ublas::fixed_vector<size_t, fem_types::data_dimension> _size;
00054
00055 public:
00057 Image2Grid(const ublas::fixed_vector<size_t, fem_types::data_dimension> & dimensions) { _size = dimensions; }
00058
00060 void construct_grid(Grid<fem_types> & grid) const
00061 {
00062 ublas::fixed_vector<float_t, fem_types::data_dimension> zeros(0.0);
00063 construct_grid(grid, ScalarImage<fem_types::data_dimension, ublas::fixed_vector<float_t, fem_types::data_dimension> >(_size, zeros));
00064 }
00065
00067 template <class vector_image_accessor_t>
00068 void construct_grid(Grid<fem_types> & grid, const vector_image_accessor_t & displacements) const;
00069
00071 void stiffness_matrix_prototype(ublas::compressed_matrix<float_t> & stiffness_matrix, size_t system_size = 1) const
00072 {
00073 size_t n_nodes = 1;
00074
00075 for(size_t i = 0; i < fem_types::data_dimension; ++i)
00076 n_nodes *= _size(i);
00077
00078 stiffness_matrix.resize(n_nodes * system_size, n_nodes * system_size, false);
00079 }
00080
00085 template <class float_accessor_t>
00086 void image2vector(const float_accessor_t & image, ublas::vector<float_t> & vector) const;
00087
00092 template <class float_accessor_t>
00093 void vector2image(const ublas::vector<float_t> & vector, float_accessor_t & image) const;
00094
00099 template <class vector_image_accessor_t>
00100 void vector2vector_image(const ublas::vector<float_t> & vector, vector_image_accessor_t & vector_image) const;
00101
00106 template <class float_accessor_t>
00107 void image2boundary_vector(const float_accessor_t & image, ublas::mapped_vector<float_t> & vector)const;
00108 }
00109 ;
00110
00112 template <>
00113 void Image2Grid<fem_2d_square_types>::stiffness_matrix_prototype(ublas::compressed_matrix<float_t> & stiffness_matrix, size_t system_size) const;
00114
00115 template <>
00116 void Image2Grid<fem_2d_triangle_types>::stiffness_matrix_prototype(ublas::compressed_matrix<float_t> & stiffness_matrix, size_t system_size) const;
00117
00118 template<>
00119 template <class float_accessor_t>
00120 void Image2Grid<fem_2d_square_types>::image2vector(const float_accessor_t & image, ublas::vector<float_t> & vector) const
00121 {
00122 image2grid_impl::image2vector_2d(_size, image, vector);
00123 }
00124
00125
00126 template<>
00127 template <class float_accessor_t>
00128 void Image2Grid<fem_2d_square_types>::vector2image(const ublas::vector<float_t> & vector, float_accessor_t & image) const
00129 {
00130 image2grid_impl::vector2image_2d(_size, vector, image);
00131 }
00132
00133
00134 template<>
00135 template <class vector_image_accessor_t>
00136 void Image2Grid<fem_2d_square_types>::vector2vector_image(const ublas::vector<float_t> & vector, vector_image_accessor_t & vector_image) const
00137 {
00138 image2grid_impl::vector2vector_image_2d(_size, vector, vector_image);
00139 }
00140
00141
00142 template<>
00143 template <class float_accessor_t>
00144 void Image2Grid<fem_2d_square_types>::image2boundary_vector(const float_accessor_t & image, ublas::mapped_vector<float_t> & vector) const
00145 {
00146 image2grid_impl::image2boundary_vector_2d(_size, image, vector);
00147 }
00148
00149 template<>
00150 template <class float_accessor_t>
00151 void Image2Grid<fem_2d_triangle_types>::image2vector(const float_accessor_t & image, ublas::vector<float_t> & vector) const
00152 {
00153 image2grid_impl::image2vector_2d(_size, image, vector);
00154 }
00155
00156
00157 template<>
00158 template <class float_accessor_t>
00159 void Image2Grid<fem_2d_triangle_types>::vector2image(const ublas::vector<float_t> & vector, float_accessor_t & image) const
00160 {
00161 image2grid_impl::vector2image_2d(_size, vector, image);
00162 }
00163
00164
00165 template<>
00166 template <class vector_image_accessor_t>
00167 void Image2Grid<fem_2d_triangle_types>::vector2vector_image(const ublas::vector<float_t> & vector, vector_image_accessor_t & vector_image) const
00168 {
00169 image2grid_impl::vector2vector_image_2d(_size, vector, vector_image);
00170 }
00171
00172
00173 template<>
00174 template <class float_accessor_t>
00175 void Image2Grid<fem_2d_triangle_types>::image2boundary_vector(const float_accessor_t & image, ublas::mapped_vector<float_t> & vector) const
00176 {
00177 image2grid_impl::image2boundary_vector_2d(_size, image, vector);
00178 }
00179
00180
00181 template<>
00182 template <class float_accessor_t>
00183 void Image2Grid<fem_3d_cube_types>::image2vector(const float_accessor_t & image, ublas::vector<float_t> & vector) const
00184 {
00185 image2grid_impl::image2vector_3d(_size, image, vector);
00186 }
00187
00188
00189 template<>
00190 template <class float_accessor_t>
00191 void Image2Grid<fem_3d_cube_types>::vector2image(const ublas::vector<float_t> & vector, float_accessor_t & image) const
00192 {
00193 image2grid_impl::vector2image_3d(_size, vector, image);
00194 }
00195
00196
00197 template<>
00198 template <class vector_image_accessor_t>
00199 void Image2Grid<fem_3d_cube_types>::vector2vector_image(const ublas::vector<float_t> & vector, vector_image_accessor_t & vector_image) const
00200 {
00201 image2grid_impl::vector2vector_image_3d(_size, vector, vector_image);
00202 }
00203
00204
00205 template<>
00206 template <class float_accessor_t>
00207 void Image2Grid<fem_3d_cube_types>::image2boundary_vector(const float_accessor_t & image, ublas::mapped_vector<float_t> & vector) const
00208 {
00209 image2grid_impl::image2boundary_vector_3d(_size, image, vector);
00210 }
00211
00212
00213 template<>
00214 template <class float_accessor_t>
00215 void Image2Grid<fem_3d_tetrahedra_types>::image2vector(const float_accessor_t & image, ublas::vector<float_t> & vector) const
00216 {
00217 image2grid_impl::image2vector_3d(_size, image, vector);
00218 }
00219
00220 template<>
00221 template <class float_accessor_t>
00222 void Image2Grid<fem_3d_tetrahedra_types>::vector2image(const ublas::vector<float_t> & vector, float_accessor_t & image) const
00223 {
00224 image2grid_impl::vector2image_3d(_size, vector, image);
00225 }
00226
00227
00228 template<>
00229 template <class vector_image_accessor_t>
00230 void Image2Grid<fem_3d_tetrahedra_types>::vector2vector_image(const ublas::vector<float_t> & vector, vector_image_accessor_t & vector_image) const
00231 {
00232 image2grid_impl::vector2vector_image_3d(_size, vector, vector_image);
00233 }
00234
00235
00236 template<>
00237 template <class float_accessor_t>
00238 void Image2Grid<fem_3d_tetrahedra_types>::image2boundary_vector(const float_accessor_t & image, ublas::mapped_vector<float_t> & vector) const
00239 {
00240 image2grid_impl::image2boundary_vector_3d(_size, image, vector);
00241 }
00242
00243 template<>
00244 template <class vector_image_accessor_t>
00245 void Image2Grid<fem_2d_square_types>::construct_grid(Grid<fem_2d_square_types> & grid, const vector_image_accessor_t & displacements) const
00246 {
00247 size_t n_x_vertices = _size(0);
00248 size_t n_y_vertices = _size(1);
00249 size_t n_x_elements = _size(0) - 1;
00250 size_t n_y_elements = _size(1) - 1;
00251
00252 grid.set_dimensions( n_x_vertices * n_y_vertices,
00253 n_x_elements * n_y_elements,
00254 2 * (n_x_elements + n_y_elements),
00255 n_x_vertices * n_y_vertices );
00256
00257 grid.set_regular(true);
00258
00259 image2grid_impl::construct_regular_2d_vertices(grid, _size, displacements);
00260 image2grid_impl::populate_grid(grid, _size);
00261 }
00262
00263 template<>
00264 template <class vector_image_accessor_t>
00265 void Image2Grid<fem_2d_triangle_types>::construct_grid(Grid<fem_2d_triangle_types> & grid, const vector_image_accessor_t & displacements) const
00266 {
00267 size_t n_x_vertices = _size(0);
00268 size_t n_y_vertices = _size(1);
00269 size_t n_x_elements = _size(0) - 1;
00270 size_t n_y_elements = _size(1) - 1;
00271
00272 grid.set_dimensions( n_x_vertices * n_y_vertices,
00273 2 * (n_x_elements * n_y_elements),
00274 2 * (n_x_elements + n_y_elements),
00275 n_x_vertices * n_y_vertices );
00276
00277 grid.set_regular(true);
00278
00279 image2grid_impl::construct_regular_2d_vertices(grid, _size, displacements);
00280 image2grid_impl::populate_grid(grid, _size);
00281 }
00282
00283 template<>
00284 template <class vector_image_accessor_t>
00285 void Image2Grid<fem_3d_cube_types>::construct_grid(Grid<fem_3d_cube_types> & grid, const vector_image_accessor_t & displacements) const
00286 {
00287 size_t n_x_vertices = _size(0);
00288 size_t n_y_vertices = _size(1);
00289 size_t n_z_vertices = _size(2);
00290 size_t n_x_elements = _size(0) - 1;
00291 size_t n_y_elements = _size(1) - 1;
00292 size_t n_z_elements = _size(2) - 1;
00293
00294 grid.set_dimensions(n_x_vertices * n_y_vertices * n_z_vertices,
00295 n_x_elements * n_y_elements * n_z_elements,
00296 2 * (n_x_elements * n_y_elements + n_y_elements * n_z_elements + n_z_elements * n_x_elements),
00297 n_x_vertices * n_y_vertices * n_z_vertices);
00298
00299 grid.set_regular(true);
00300
00301 image2grid_impl::construct_regular_3d_vertices(grid, _size, displacements);
00302 image2grid_impl::populate_grid(grid, _size);
00303 }
00304
00305
00306 template<>
00307 template <class vector_image_accessor_t>
00308 void Image2Grid<fem_3d_tetrahedra_types>::construct_grid(Grid<fem_3d_tetrahedra_types> & grid, const vector_image_accessor_t & displacements) const
00309 {
00310 size_t n_x_vertices = _size(0);
00311 size_t n_y_vertices = _size(1);
00312 size_t n_z_vertices = _size(2);
00313 size_t n_x_elements = _size(0) - 1;
00314 size_t n_y_elements = _size(1) - 1;
00315 size_t n_z_elements = _size(2) - 1;
00316
00317 grid.set_dimensions( n_x_vertices * n_y_vertices * n_z_vertices,
00318 6 * (n_x_elements * n_y_elements * n_z_elements),
00319 4 * (n_x_elements * n_y_elements + n_y_elements * n_z_elements + n_z_elements * n_x_elements),
00320 n_x_vertices * n_y_vertices * n_z_vertices);
00321
00322 grid.set_regular(false);
00323
00324 image2grid_impl::construct_regular_3d_vertices(grid, _size, displacements);
00325 image2grid_impl::populate_grid(grid, _size);
00326 }
00328 }
00329
00330
00331 #endif