bb9f5c715f
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 9m55s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 10m28s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 8m56s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 11m47s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 13m7s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 12m31s
Build Packages / build:rpm (rocky8) (push) Successful in 12m59s
Build Packages / build:rpm (rocky9) (push) Successful in 14m5s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 15m30s
Build Packages / Generate python client (push) Successful in 1m18s
Build Packages / Build documentation (push) Successful in 1m3s
Build Packages / Create release (push) Has been skipped
Build Packages / build:rpm (ubuntu2404) (push) Successful in 10m8s
Build Packages / XDS test (durin plugin) (push) Successful in 9m16s
Build Packages / XDS test (neggia plugin) (push) Successful in 7m59s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 9m12s
Build Packages / DIALS test (push) Successful in 11m44s
Build Packages / Unit tests (push) Successful in 1h23m8s
This is an UNSTABLE release. The release has significant modifications and bug fixes, if things go wrong, it is better to revert to 1.0.0-rc.132. * Multiple small bug fixes scattered across the whole code base. (detected with GPT-5.4) * jfjoch_viewer: Improve image render performance Reviewed-on: #44 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch> Co-committed-by: Filip Leonarski <filip.leonarski@psi.ch>
172 lines
6.3 KiB
C++
172 lines
6.3 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "DetectorGeometryModular.h"
|
|
#include "JFJochException.h"
|
|
|
|
DetectorGeometryModular::DetectorGeometryModular(const std::vector<DetectorModuleGeometry> &in_modules, bool vertical_flip)
|
|
: modules(in_modules) {
|
|
if (modules.empty())
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Module number must be positive");
|
|
|
|
width = 0;
|
|
height = 0;
|
|
|
|
int64_t min_x = modules[0].GetMinX();
|
|
int64_t max_x = modules[0].GetMaxX();
|
|
int64_t min_y = modules[0].GetMinY();
|
|
int64_t max_y = modules[0].GetMaxY();
|
|
|
|
for (auto &m: modules) {
|
|
min_x = std::min<int64_t>(min_x, m.GetMinX());
|
|
max_x = std::max<int64_t>(max_x, m.GetMaxX());
|
|
min_y = std::min<int64_t>(min_y, m.GetMinY());
|
|
max_y = std::max<int64_t>(max_y, m.GetMaxY());
|
|
}
|
|
|
|
width = max_x - min_x + 1;
|
|
height = max_y - min_y + 1;
|
|
|
|
for (auto &m: modules)
|
|
m.Translate(-min_x, -min_y);
|
|
|
|
if (vertical_flip)
|
|
VerticalFlip();
|
|
}
|
|
|
|
DetectorGeometryModular::DetectorGeometryModular(int32_t nmodules, int32_t horizontal_stacking, int32_t gap_x,
|
|
int32_t gap_y, bool mirror_y) {
|
|
if (horizontal_stacking <= 0)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Horizontal stacking must be positive");
|
|
if (nmodules <= 0)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Module number must be positive");
|
|
if (gap_x < 0)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Gap x has to be non-negative");
|
|
if (gap_y < 0)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Gap y has to be non-negative");
|
|
if (nmodules < horizontal_stacking)
|
|
horizontal_stacking = nmodules;
|
|
|
|
width = horizontal_stacking * CONVERTED_MODULE_COLS + (horizontal_stacking - 1) * gap_x;
|
|
int64_t conv_lines = nmodules / horizontal_stacking + (nmodules % horizontal_stacking > 0 ? 1 : 0);
|
|
height = conv_lines * CONVERTED_MODULE_LINES + (conv_lines - 1) * gap_y;
|
|
|
|
for (int m = 0; m < nmodules; m++) {
|
|
int64_t module_x = m % horizontal_stacking;
|
|
int64_t module_y = m / horizontal_stacking;
|
|
|
|
int64_t x0 = module_x * (CONVERTED_MODULE_COLS + gap_x);
|
|
int64_t y0 = module_y * (CONVERTED_MODULE_LINES + gap_y);
|
|
|
|
DetectorModuleGeometry::Direction fast = DetectorModuleGeometry::Direction::Xpos;
|
|
DetectorModuleGeometry::Direction slow = DetectorModuleGeometry::Direction::Ypos;
|
|
|
|
DetectorModuleGeometry mgeom(x0,y0,fast, slow);
|
|
|
|
modules.emplace_back(mgeom);
|
|
}
|
|
|
|
if (mirror_y)
|
|
VerticalFlip();
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetModulesNum() const {
|
|
return modules.size();
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetWidth(bool geom_transformed) const {
|
|
if (geom_transformed)
|
|
return width;
|
|
else
|
|
return RAW_MODULE_COLS;
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetHeight(bool geom_transformed) const {
|
|
if (geom_transformed)
|
|
return height;
|
|
else
|
|
return RAW_MODULE_LINES * modules.size();
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetPixel0(int64_t m, bool geom_transformed) const {
|
|
if ((m < 0) || (m >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
if (geom_transformed)
|
|
return modules[m].GetPixel0_X() + width * modules[m].GetPixel0_Y();
|
|
else
|
|
return m * RAW_MODULE_SIZE;
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetX0(int64_t module_number) const {
|
|
if ((module_number < 0) || (module_number >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
return modules[module_number].GetPixel0_X();
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetY0(int64_t module_number) const {
|
|
if ((module_number < 0) || (module_number >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
return modules[module_number].GetPixel0_Y();
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetFastDirectionStep(int64_t m) const {
|
|
if ((m < 0) || (m >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
return GetDirectionStep(modules[m].GetFastAxis());
|
|
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetSlowDirectionStep(int64_t m) const {
|
|
if ((m < 0) || (m >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
return GetDirectionStep(modules[m].GetSlowAxis());
|
|
}
|
|
|
|
Coord DetectorGeometryModular::GetFastDirection(int64_t module_number) const {
|
|
if ((module_number < 0) || (module_number >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
|
|
return GetDirection(modules[module_number].GetFastAxis());
|
|
}
|
|
|
|
Coord DetectorGeometryModular::GetSlowDirection(int64_t module_number) const {
|
|
if ((module_number < 0) || (module_number >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
|
|
return GetDirection(modules[module_number].GetSlowAxis());
|
|
}
|
|
|
|
void DetectorGeometryModular::VerticalFlip() {
|
|
for (auto &m: modules)
|
|
m.VerticalFlip(height);
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetDirectionStep(DetectorModuleGeometry::Direction direction) const {
|
|
switch (direction) {
|
|
case DetectorModuleGeometry::Direction::Xneg:
|
|
return -1;
|
|
case DetectorModuleGeometry::Direction::Xpos:
|
|
return 1;
|
|
case DetectorModuleGeometry::Direction::Yneg:
|
|
return -width;
|
|
case DetectorModuleGeometry::Direction::Ypos:
|
|
return width;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
Coord DetectorGeometryModular::GetDirection(DetectorModuleGeometry::Direction direction) {
|
|
switch (direction) {
|
|
case DetectorModuleGeometry::Direction::Xneg:
|
|
return {-1, 0, 0};
|
|
case DetectorModuleGeometry::Direction::Yneg:
|
|
return { 0, -1, 0};
|
|
case DetectorModuleGeometry::Direction::Ypos:
|
|
return { 0, 1, 0};
|
|
default:
|
|
case DetectorModuleGeometry::Direction::Xpos:
|
|
return { 1, 0, 0};
|
|
}
|
|
}
|