@@ -74,23 +74,54 @@ void Panel::update(Matrix3d d) {
7474}
7575
7676Panel::Panel (json panel_data) {
77+ // We can either get an explicit origin or beam centre and distance
78+ std::vector<std::string> required_keys = {
79+ " fast_axis" , " slow_axis" , " pixel_size" , " image_size" ,
80+ " trusted_range" , " type" , " name" , " thickness" ,
81+ " raw_image_offset" , " gain" , " pedestal" , " px_mm_strategy" };
82+ for (const auto &key : required_keys) {
83+ if (panel_data.find (key) == panel_data.end ()) {
84+ throw std::invalid_argument (
85+ " Key " + key + " is missing from the input detector panel JSON" );
86+ }
87+ }
7788 Vector3d fast{{panel_data[" fast_axis" ][0 ], panel_data[" fast_axis" ][1 ],
7889 panel_data[" fast_axis" ][2 ]}};
7990 Vector3d slow{{panel_data[" slow_axis" ][0 ], panel_data[" slow_axis" ][1 ],
8091 panel_data[" slow_axis" ][2 ]}};
81- Vector3d origin{{panel_data[" origin" ][0 ], panel_data[" origin" ][1 ],
82- panel_data[" origin" ][2 ]}};
83- Matrix3d d_matrix{{fast[0 ], slow[0 ], origin[0 ]},
84- {fast[1 ], slow[1 ], origin[1 ]},
85- {fast[2 ], slow[2 ], origin[2 ]}};
86- origin_ = origin;
92+ fast.normalize ();
93+ slow.normalize ();
8794 fast_axis_ = fast;
8895 slow_axis_ = slow;
89- normal_ = fast_axis_.cross (slow_axis_);
90- d_ = d_matrix;
91- D_ = d_.inverse ();
9296 pixel_size_ = {{panel_data[" pixel_size" ][0 ], panel_data[" pixel_size" ][1 ]}};
9397 image_size_ = {{panel_data[" image_size" ][0 ], panel_data[" image_size" ][1 ]}};
98+ Matrix3d d_matrix;
99+
100+ if (panel_data.contains (" beam_center" ) && panel_data.contains (" distance" )) {
101+ double distance = panel_data[" distance" ];
102+ std::array<double , 2 > beam_center = panel_data[" beam_center" ];
103+ origin_ = {0 ., 0 ., -1.0 * distance};
104+ origin_ -= beam_center[0 ] * pixel_size_[0 ] * fast_axis_;
105+ origin_ -= beam_center[1 ] * pixel_size_[1 ] * slow_axis_;
106+ normal_ = fast_axis_.cross (slow_axis_);
107+ d_matrix << fast_axis_[0 ], slow_axis_[0 ], origin_[0 ], fast_axis_[1 ],
108+ slow_axis_[1 ], origin_[1 ], fast_axis_[2 ], slow_axis_[2 ], origin_[2 ];
109+ } else {
110+ if (!panel_data.contains (" origin" )) {
111+ throw std::invalid_argument (" Detector panel JSON must contain either "
112+ " origin or beam_center + distance" );
113+ }
114+ origin_ = Vector3d{{panel_data[" origin" ][0 ], panel_data[" origin" ][1 ],
115+ panel_data[" origin" ][2 ]}};
116+ d_matrix << fast[0 ], slow[0 ], origin_[0 ], fast[1 ], slow[1 ], origin_[1 ],
117+ fast[2 ], slow[2 ], origin_[2 ];
118+ // origin_ = origin;
119+ normal_ = fast_axis_.cross (slow_axis_);
120+ }
121+
122+ d_ = d_matrix;
123+ D_ = d_.inverse ();
124+
94125 image_size_mm_ = {
95126 {image_size_[0 ] * pixel_size_[0 ], image_size_[1 ] * pixel_size_[1 ]}};
96127 trusted_range_ = {
@@ -200,10 +231,12 @@ const std::map<std::string, Vector3d> axis_map = {
200231 {" -x" , Vector3d (-1.0 , 0.0 , 0.0 )},
201232 {" y" , Vector3d (0.0 , 1.0 , 0.0 )},
202233 {" -y" , Vector3d (0.0 , -1.0 , 0.0 )}};
203- Panel::Panel (double distance, std::array<double , 2 > beam_center,
204- std::array<double , 2 > pixel_size, std::array<int , 2 > image_size,
205- const std::string &fast_axis, const std::string &slow_axis,
206- double thickness, double mu)
234+
235+ Panel::Panel (double distance, // units mm
236+ std::array<double , 2 > beam_center, // units px
237+ std::array<double , 2 > pixel_size, // units mm
238+ std::array<int , 2 > image_size, const std::string &fast_axis,
239+ const std::string &slow_axis, double thickness, double mu)
207240 : pixel_size_(pixel_size), image_size_(image_size), thickness_(thickness),
208241 mu_(mu) {
209242 if (valid_axes.find (fast_axis) == valid_axes.end ()) {
0 commit comments