Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions dx2/detector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,28 @@ Matrix3d Panel::get_d_matrix() const { return d_; }
Matrix3d Panel::get_D_matrix() const { return D_; }

std::optional<std::array<double, 2>>
Panel::get_ray_intersection(const Vector3d &s1) const {
Panel::get_ray_intersection_unbounded(const Vector3d &s1) const {
// Project s₁ into panel frame: v = D·s₁
// v[2] is the depth component; reject rays travelling away from the panel
Vector3d v = D_ * s1;
if (v[2] <= 0) {
return {};
}
std::array<double, 2> pxy;
pxy[0] = v[0] / v[2];
pxy[1] = v[1] / v[2];
/** Check if the coordinate is invalid */
if (pxy[0] < 0 || pxy[1] < 0 || pxy[0] > image_size_mm_[0] ||
pxy[1] > image_size_mm_[1]) {
return std::array<double, 2>{v[0] / v[2], v[1] / v[2]}; // in mm, unbounded
}

std::optional<std::array<double, 2>>
Panel::get_ray_intersection(const Vector3d &s1) const {
// Use unbounded projection, then clip to the physical panel extent
auto pxy = get_ray_intersection_unbounded(s1);
if (!pxy) {
return {};
}
if ((*pxy)[0] < 0 || (*pxy)[1] < 0 || (*pxy)[0] > image_size_mm_[0] ||
(*pxy)[1] > image_size_mm_[1]) {
return {};
}
return pxy; // in mmm
return pxy; // in mm
}

std::array<double, 2> Panel::px_to_mm(double x, double y) const {
Expand Down
2 changes: 2 additions & 0 deletions include/dx2/detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Panel {
Vector3d get_lab_coord(double x_mm, double y_mm) const;
std::optional<std::array<double, 2>>
get_ray_intersection(const Vector3d &s1) const;
std::optional<std::array<double, 2>>
get_ray_intersection_unbounded(const Vector3d &s1) const;
std::array<double, 2> get_pixel_size() const;
json to_json() const;
Vector3d get_origin() const;
Expand Down
2 changes: 1 addition & 1 deletion include/dx2/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ using Eigen::Vector3d;

double angle_between_vectors_degrees(Vector3d v1, Vector3d v2);

std::string ersatz_uuid4();
std::string ersatz_uuid4();
Loading