15#ifndef IMAGE_BASED_RECONSTRUCTION_GETINITIALGRID_HPP
16#define IMAGE_BASED_RECONSTRUCTION_GETINITIALGRID_HPP
23#include "Vector/vector_dist.hpp"
24#include "Grid/grid_dist_id.hpp"
25#include "data_type/aggregate.hpp"
26#include "Decomposition/CartDecomposition.hpp"
29typedef signed char BYTE;
31inline bool exists_test (
const std::string& name) {
33 return (stat (name.c_str(), &buffer) == 0);
44std::vector<int>
get_size(
const std::string & path_to_file)
46 std::vector<int> stack_dimst_1d;
48 if(!exists_test(path_to_file)){
49 std::cout <<
"------------------------------------------------------------------------" << std::endl;
50 std::cout <<
"Error: file " << path_to_file <<
" does not exist. Aborting..." << std::endl;
51 std::cout <<
"------------------------------------------------------------------------" << std::endl;
54 std::ifstream file(path_to_file);
58 std::streampos fileSize;
59 file.seekg(0, std::ios::end);
60 fileSize = file.tellg();
61 file.seekg(0, std::ios::beg);
64 stack_dimst_1d.reserve(fileSize);
67 while ( getline(file, field) )
69 std::istringstream iss(field);
72 stack_dimst_1d.push_back(val);
76 std::reverse(std::begin(stack_dimst_1d), std::end(stack_dimst_1d));
78 return stack_dimst_1d;
91template <
size_t Phi_0,
typename gr
id_type>
94 constexpr size_t x = 0;
95 constexpr size_t y = 1;
96 constexpr size_t z = 2;
99 if(!exists_test(file_name)){
100 std::cout <<
"------------------------------------------------------------------------" << std::endl;
101 std::cout <<
"Error: file " << file_name <<
" does not exist. Aborting..." << std::endl;
102 std::cout <<
"------------------------------------------------------------------------" << std::endl;
105 std::ifstream file_stream (file_name, std::ifstream::binary);
107 auto & v_cl = create_vcluster();
108 if (v_cl.rank() == 0)
112 std::cout <<
"# grid points in dimension " << d <<
" = " <<
grid.size(d) << std::endl;
117 auto dom =
grid.getDomainIterator();
118 std::vector<BYTE> pixel_line;
123 sz_img[d] = stack_dims[d];
130 refinement[d] = (double)
grid.size(d) / (double)stack_dims[d];
131 if (v_cl.rank() == 0) std::cout <<
"effective refinement in dimension " << d <<
" = " << refinement[d] << std::endl;
136 auto key = dom.get();
137 auto gkey =
grid.getGKey(key);
141 int rest_offset = (int) (fmod(gkey.get(0), refinement[x]));
145 auto & gbox =
grid.getLocalGridsInfo();
146 auto & DomBox = gbox.get(key.getSub()).Dbox;
147 size_t patch_size = DomBox.getHigh(0) - DomBox.getLow(0) + 1;
149 size_t l = (size_t) ceil( (patch_size + rest_offset) / refinement[x]);
156 gkey.set_d(d, floor(gkey.get(d) / refinement[d]));
161 size_t offset = ginfo_image.
LinId(gkey);
162 file_stream.seekg(offset);
165 pixel_line.resize(l);
167 file_stream.read((
char*) & pixel_line[0], l);
172 for (
int k = 0; k < patch_size; ++k)
174 auto key = dom.get();
177 size_t i = (size_t) floor((k + rest_offset) / refinement[x]);
178 grid.template get<Phi_0>(key) = (double) pixel_line[i];
185 grid.template ghost_get<Phi_0>();
Header file containing help-functions that perform on OpenFPM-grids.
void load_pixel_onto_grid(grid_type &grid, std::string file_name, std::vector< int > &stack_dims)
Converts the pixel values stored in a binary file into doubles and loads them onto an OpenFPM grid.
std::vector< int > get_size(const std::string &path_to_file)
Read the number of pixels per dimension from a csv-file in order to create a grid with the same size.
This is a distributed grid.
static const unsigned int dims
Number of dimensions.
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const signed char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.