mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-18 18:27:13 +02:00
starting work on ROI
This commit is contained in:
@ -13,9 +13,10 @@ RawFile::RawFile(const std::filesystem::path &fname, const std::string &mode)
|
||||
: m_master(fname) {
|
||||
m_mode = mode;
|
||||
if (mode == "r") {
|
||||
find_number_of_subfiles();
|
||||
n_subfile_parts = m_master.geometry().col * m_master.geometry().row;
|
||||
n_subfiles = find_number_of_subfiles(); //f0,f1...fn
|
||||
n_subfile_parts = m_master.geometry().col * m_master.geometry().row; // d0,d1...dn
|
||||
find_geometry();
|
||||
//update_geometry_from_roi();
|
||||
open_subfiles();
|
||||
} else {
|
||||
throw std::runtime_error(LOCATION +
|
||||
@ -107,27 +108,41 @@ bool RawFile::is_master_file(const std::filesystem::path &fpath) {
|
||||
return stem.find("_master_") != std::string::npos;
|
||||
}
|
||||
|
||||
void RawFile::find_number_of_subfiles() {
|
||||
int n_mod = 0;
|
||||
while (std::filesystem::exists(m_master.data_fname(0, ++n_mod)))
|
||||
int RawFile::find_number_of_subfiles() {
|
||||
int n_files = 0;
|
||||
// f0,f1...fn How many files is the data split into?
|
||||
while (std::filesystem::exists(m_master.data_fname(0, ++n_files)))
|
||||
;
|
||||
n_subfiles = n_mod;
|
||||
|
||||
#ifdef AARE_VERBOSE
|
||||
fmt::print("Found: {} subfiles\n", n_subfiles);
|
||||
#endif
|
||||
return n_files;
|
||||
}
|
||||
|
||||
void RawFile::find_geometry() {
|
||||
uint16_t r{};
|
||||
uint16_t c{};
|
||||
// for (size_t i = 0; i < n_subfile_parts; i++) {
|
||||
// for (size_t j = 0; j != n_subfiles; ++j) {
|
||||
// auto h = this->read_header(m_master.data_fname(i, j));
|
||||
// r = std::max(r, h.row);
|
||||
// c = std::max(c, h.column);
|
||||
|
||||
// positions.push_back({h.row, h.column});
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
std::vector<xy> module_position;
|
||||
|
||||
for (size_t i = 0; i < n_subfile_parts; i++) {
|
||||
for (size_t j = 0; j != n_subfiles; ++j) {
|
||||
auto h = this->read_header(m_master.data_fname(i, j));
|
||||
auto h = this->read_header(m_master.data_fname(i, 0));
|
||||
r = std::max(r, h.row);
|
||||
c = std::max(c, h.column);
|
||||
|
||||
positions.push_back({h.row, h.column});
|
||||
}
|
||||
xy pos = {h.row * m_master.pixels_y(), h.column* m_master.pixels_x()};
|
||||
module_position.emplace_back(pos);
|
||||
}
|
||||
|
||||
r++;
|
||||
@ -137,6 +152,10 @@ void RawFile::find_geometry() {
|
||||
m_cols = (c * m_master.pixels_x());
|
||||
|
||||
m_rows += static_cast<size_t>((r - 1) * cfg.module_gap_row);
|
||||
|
||||
for (size_t i=0; i < module_position.size(); i++){
|
||||
fmt::print("Module {} at position: ({},{})\n", i, module_position[i].row, module_position[i].col);
|
||||
}
|
||||
}
|
||||
|
||||
Frame RawFile::get_frame(size_t frame_index) {
|
||||
|
@ -143,6 +143,8 @@ ScanParameters RawMasterFile::scan_parameters() const {
|
||||
return m_scan_parameters;
|
||||
}
|
||||
|
||||
std::optional<ROI> RawMasterFile::roi() const { return m_roi; }
|
||||
|
||||
void RawMasterFile::parse_json(const std::filesystem::path &fpath) {
|
||||
std::ifstream ifs(fpath);
|
||||
json j;
|
||||
@ -240,6 +242,33 @@ void RawMasterFile::parse_json(const std::filesystem::path &fpath) {
|
||||
// not a scan
|
||||
}
|
||||
|
||||
try{
|
||||
ROI tmp_roi;
|
||||
auto obj = j.at("Receiver Roi");
|
||||
fmt::print("Receiver ROI: {}\n", obj.dump());
|
||||
tmp_roi.xmin = obj.at("xmin");
|
||||
tmp_roi.xmax = obj.at("xmax");
|
||||
tmp_roi.ymin = obj.at("ymin");
|
||||
tmp_roi.ymax = obj.at("ymax");
|
||||
|
||||
//if any of the values are set update the roi
|
||||
if (tmp_roi.xmin != 4294967295 || tmp_roi.xmax != 4294967295 ||
|
||||
tmp_roi.ymin != 4294967295 || tmp_roi.ymax != 4294967295) {
|
||||
m_roi = tmp_roi;
|
||||
}
|
||||
|
||||
|
||||
}catch (const json::out_of_range &e) {
|
||||
// leave the optional empty
|
||||
}
|
||||
|
||||
//if we have an roi we need to update the geometry for the subfiles
|
||||
if (m_roi){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Update detector type for Moench
|
||||
// TODO! How does this work with old .raw master files?
|
||||
#ifdef AARE_VERBOSE
|
||||
|
@ -61,16 +61,7 @@ size_t SubFile::get_part(std::byte *buffer, size_t frame_index) {
|
||||
}
|
||||
|
||||
}
|
||||
size_t SubFile::write_part(std::byte *buffer, DetectorHeader header, size_t frame_index) {
|
||||
if (frame_index > n_frames) {
|
||||
throw std::runtime_error("Frame number out of range");
|
||||
}
|
||||
fseek(fp, static_cast<int64_t>((sizeof(DetectorHeader) + bytes_per_part()) * frame_index), SEEK_SET);
|
||||
auto wc = fwrite(reinterpret_cast<char *>(&header), sizeof(header), 1, fp);
|
||||
wc += fwrite(buffer, bytes_per_part(), 1, fp);
|
||||
|
||||
return wc;
|
||||
}
|
||||
|
||||
size_t SubFile::frame_number(size_t frame_index) {
|
||||
DetectorHeader h{};
|
||||
|
Reference in New Issue
Block a user