#include "FileFactory.hpp" #include "File.hpp" #include "RawFileFactory.hpp" #include "JsonFileFactory.hpp" #include FileFactory* FileFactory::get_factory(std::filesystem::path fpath, uint16_t bitdepth){ // check if file exists if(!std::filesystem::exists(fpath)){ throw std::runtime_error("File does not exist"); } if(fpath.extension() == ".raw"){ std::cout<<"Loading raw file"<base_path = fpath.parent_path(); file->base_name = fpath.stem(); file->ext = fpath.extension(); auto pos = file->base_name.rfind("_"); file->findex = std::stoi(file->base_name.substr(pos + 1)); pos = file->base_name.find("_master_"); file->base_name.erase(pos); } template Header FileFactory::read_header(const std::filesystem::path &fname) { Header h{}; FILE *fp = fopen(fname.c_str(), "r"); if (!fp) throw std::runtime_error( fmt::format("Could not open: {} for reading", fname.c_str())); size_t rc = fread(reinterpret_cast(&h), sizeof(h), 1, fp); fclose(fp); if (rc != 1) throw std::runtime_error("Could not read header from file"); return h; } void FileFactory::find_geometry(File* file) { uint16_t r{}; uint16_t c{}; for (int i = 0; i != file->n_subfiles; ++i) { auto h = this->read_header(file->data_fname(i, 0)); r = std::max(r, h.row); c = std::max(c, h.column); file->positions.push_back({h.row, h.column}); } r++; c++; file->rows = r * file->subfile_rows; file->cols = c * file->subfile_cols; file->rows += (r - 1) * file->cfg.module_gap_row; }