indentation
[hkl.git] / binoculars / hkl-binoculars.h
blob4bbc586e91dc21c8d4c798cdf14c2dcb9e07e438
1 /* This file is part of the hkl library.
3 * The hkl library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * The hkl library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2003-2022 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
22 #ifndef __HKL_BINOCULARS_H__
23 #define __HKL_BINOCULARS_H__
25 #include "hkl.h"
26 #include "stdint.h"
28 G_BEGIN_DECLS
30 /****************/
31 /* 2D detectors */
32 /****************/
34 typedef enum _HklBinocularsDetectorEnum
36 HKL_BINOCULARS_DETECTOR_IMXPAD_S140 = 0,
37 HKL_BINOCULARS_DETECTOR_XPAD_FLAT_CORRECTED,
38 HKL_BINOCULARS_DETECTOR_IMXPAD_S70,
39 HKL_BINOCULARS_DETECTOR_DECTRIS_EIGER1M,
40 HKL_BINOCULARS_DETECTOR_UFXC,
41 HKL_BINOCULARS_DETECTOR_MERLIN,
42 HKL_BINOCULARS_DETECTOR_MERLIN_MEDIPIX_3RX_QUAD,
43 /* Add new your detectors here */
44 HKL_BINOCULARS_DETECTOR_NUM_DETECTORS,
45 } HklBinocularsDetectorEnum;
47 HKLAPI extern int hkl_binoculars_detector_2d_number_of_detectors(void);
49 HKLAPI extern const char *hkl_binoculars_detector_2d_name_get(HklBinocularsDetectorEnum n);
51 HKLAPI extern void hkl_binoculars_detector_2d_shape_get(HklBinocularsDetectorEnum n,
52 int *width, int *height);
54 HKLAPI extern double *hkl_binoculars_detector_2d_coordinates_get(HklBinocularsDetectorEnum n);
56 HKLAPI extern void hkl_binoculars_detector_2d_coordinates_save(HklBinocularsDetectorEnum n,
57 const char *fname);
59 HKLAPI extern uint8_t *hkl_binoculars_detector_2d_mask_get(HklBinocularsDetectorEnum n);
61 HKLAPI extern uint8_t *hkl_binoculars_detector_2d_mask_load(HklBinocularsDetectorEnum n,
62 const char *filename);
64 HKLAPI extern void hkl_binoculars_detector_2d_mask_save(HklBinocularsDetectorEnum n,
65 const char *fname);
67 HKLAPI extern void hkl_binoculars_detector_2d_sixs_calibration(HklBinocularsDetectorEnum n,
68 double *arr,
69 int width, int height,
70 int ix0, int iy0, double sdd,
71 double detrot);
73 HKLAPI extern uint32_t *hkl_binoculars_detector_2d_fake_image_uint32(HklBinocularsDetectorEnum n,
74 size_t *n_pixels);
76 /***********/
77 /* Limits */
78 /***********/
80 typedef struct _HklBinocularsAxisLimits HklBinocularsAxisLimits;
82 HKLAPI extern void hkl_binoculars_axis_limits_free(HklBinocularsAxisLimits *self);
84 HKLAPI extern HklBinocularsAxisLimits *hkl_binoculars_axis_limits_new(const ptrdiff_t *min,
85 const ptrdiff_t *max);
87 /********/
88 /* Axis */
89 /********/
91 typedef struct _HklBinocularsAxis HklBinocularsAxis;
93 HKLAPI extern double *hkl_binoculars_axis_array(const HklBinocularsAxis *self);
96 /*********/
97 /* Space */
98 /*********/
100 typedef struct _HklBinocularsSpace HklBinocularsSpace;
102 typedef enum _HklBinocularsSurfaceOrientationEnum
104 HKL_BINOCULARS_SURFACE_ORIENTATION_VERTICAL = 0,
105 HKL_BINOCULARS_SURFACE_ORIENTATION_HORIZONTAL,
106 /* Add new your detectors here */
107 HKL_BINOCULARS_SURFACE_ORIENTATION_NUM_ORIENTATION,
108 } HklBinocularsSurfaceOrientationEnum;
111 HKLAPI extern HklBinocularsSpace *hkl_binoculars_space_new(size_t n_indexes_0,
112 size_t n_axes);
114 HKLAPI extern void hkl_binoculars_space_free(HklBinocularsSpace *self);
116 /********/
117 /* Cube */
118 /********/
120 typedef struct _HklBinocularsCube HklBinocularsCube;
122 HKLAPI extern void hkl_binoculars_cube_free(HklBinocularsCube *self);
124 HKLAPI extern HklBinocularsCube *hkl_binoculars_cube_new(size_t n_spaces,
125 const HklBinocularsSpace *const *spaces);
127 HKLAPI extern HklBinocularsCube *hkl_binoculars_cube_new_empty(void);
129 HKLAPI extern HklBinocularsCube *hkl_binoculars_cube_new_empty_from_cube(const HklBinocularsCube *src);
131 HKLAPI extern HklBinocularsCube *hkl_binoculars_cube_new_copy(const HklBinocularsCube *src);
133 HKLAPI extern HklBinocularsCube *hkl_binoculars_cube_new_from_space(const HklBinocularsSpace *space);
135 HKLAPI extern HklBinocularsCube *hkl_binoculars_cube_new_merge(const HklBinocularsCube *cube1,
136 const HklBinocularsCube *cube2);
139 HKLAPI extern void hkl_binoculars_cube_add_space(HklBinocularsCube *self,
140 const HklBinocularsSpace *space);
142 HKLAPI extern void hkl_binoculars_cube_save_hdf5(const char *fn,
143 const HklBinocularsCube *self);
145 HKLAPI extern void hkl_binoculars_cube_fprintf(FILE *f, const HklBinocularsCube *self);
147 /***************/
148 /* Projections */
149 /***************/
151 /* class RealSpace(backend.ProjectionBase): */
152 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
153 /* pixels = pdataframe.pixels */
154 /* P = pdataframe.P */
155 /* timestamp = pdataframe.timestamp */
157 /* if P is not None: */
158 /* pixels_ = numpy.tensordot(P, pixels, axes=1) */
159 /* else: */
160 /* pixels_ = pixels */
161 /* x = pixels_[1] */
162 /* y = pixels_[2] */
163 /* if timestamp is not None: */
164 /* z = numpy.ones_like(x) * timestamp */
165 /* else: */
166 /* z = pixels_[0] */
168 /* return (x, y, z) */
170 /* def get_axis_labels(self): */
171 /* return ("x", "y", "z") */
174 /* class Pixels(backend.ProjectionBase): */
175 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
176 /* pixels = pdataframe.pixels */
178 /* return numpy.meshgrid( */
179 /* numpy.arange(pixels[0].shape[1]), numpy.arange(pixels[0].shape[0]) */
180 /* ) */
182 /* def get_axis_labels(self) -> Tuple[str]: */
183 /* return "x", "y" */
186 /* class QxQyIndexProjection(QxQyQzProjection): */
187 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
188 /* timestamp = pdataframe.timestamp */
190 /* qx, qy, qz = super(QxQyIndexProjection, self).project(index, pdataframe) */
191 /* return qx, qy, numpy.ones_like(qx) * timestamp */
193 /* def get_axis_labels(self) -> Tuple[str]: */
194 /* return "Qx", "Qy", "t" */
197 /* class QxQzIndexProjection(QxQyQzProjection): */
198 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
199 /* timestamp = pdataframe.timestamp */
201 /* qx, qy, qz = super(QxQzIndexProjection, self).project(index, pdataframe) */
202 /* return qx, qz, numpy.ones_like(qx) * timestamp */
204 /* def get_axis_labels(self) -> Tuple[str]: */
205 /* return "Qx", "Qz", "t" */
208 /* class QyQzIndexProjection(QxQyQzProjection): */
209 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
210 /* timestamp = pdataframe.timestamp */
212 /* qx, qy, qz = super(QyQzIndexProjection, self).project(index, pdataframe) */
213 /* return qy, qz, numpy.ones_like(qy) * timestamp */
215 /* def get_axis_labels(self) -> Tuple[str]: */
216 /* return "Qy", "Qz", "t" */
219 /* class QparQperIndexProjection(QparQperProjection): */
220 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
221 /* timestamp = pdataframe.timestamp */
223 /* qpar, qper = super(QparQperIndexProjection, self).project(index, pdataframe) */
224 /* return qpar, qper, numpy.ones_like(qpar) * timestamp */
226 /* def get_axis_labels(self) -> Tuple[str]: */
227 /* return "Qpar", "Qper", "t" */
230 /* class Stereo(QxQyQzProjection): */
231 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
232 /* qx, qy, qz = super(Stereo, self).project(index, pdataframe) */
233 /* q = numpy.sqrt(qx * qx + qy * qy + qz * qz) */
234 /* ratio = qz + q */
235 /* xp = qx / ratio */
236 /* yp = qy / ratio */
237 /* return q, xp, yp */
239 /* def get_axis_labels(self) -> Tuple[str]: */
240 /* return "Q", "xp", "yp" */
243 /* class QzPolarProjection(QxQyQzProjection): */
244 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
245 /* qx, qy, qz = super(QzPolarProjection, self).project(index, pdataframe) */
246 /* phi = numpy.rad2deg(numpy.arctan2(qx, qy)) */
247 /* q = numpy.sqrt(qx * qx + qy * qy + qz * qz) */
248 /* return phi, q, qz */
250 /* def get_axis_labels(self) -> Tuple[str]: */
251 /* return "Phi", "Q", "Qz" */
254 /* class QyPolarProjection(QxQyQzProjection): */
255 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
256 /* qx, qy, qz = super(QyPolarProjection, self).project(index, pdataframe) */
257 /* phi = numpy.rad2deg(numpy.arctan2(qz, qx)) */
258 /* q = numpy.sqrt(qx * qx + qy * qy + qz * qz) */
259 /* return phi, q, qy */
261 /* def get_axis_labels(self) -> Tuple[str]: */
262 /* return "Phi", "Q", "Qy" */
265 /* class QxPolarProjection(QxQyQzProjection): */
266 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
267 /* qx, qy, qz = super(QxPolarProjection, self).project(index, pdataframe) */
268 /* phi = numpy.rad2deg(numpy.arctan2(qz, -qy)) */
269 /* q = numpy.sqrt(qx * qx + qy * qy + qz * qz) */
270 /* return phi, q, qx */
272 /* def get_axis_labels(self) -> Tuple[str]: */
273 /* return "Phi", "Q", "Qx" */
276 /* class QIndex(Stereo): */
277 /* def project(self, index: int, pdataframe: PDataFrame) -> Tuple[ndarray]: */
278 /* timestamp = pdataframe.timestamp */
280 /* q, qx, qy = super(QIndex, self).project(index, pdataframe) */
281 /* return q, numpy.ones_like(q) * timestamp */
283 /* def get_axis_labels(self) -> Tuple[str]: */
284 /* return "Q", "Index" */
286 /* angles */
288 #define HKL_BINOCULARS_SPACE_ANGLES_DECL(image_t) \
289 void hkl_binoculars_space_angles_ ## image_t (HklBinocularsSpace *space, \
290 const HklGeometry *geometry, \
291 const image_t *image, \
292 size_t n_pixels, \
293 double weight, \
294 const double *pixels_coordinates, \
295 size_t pixels_coordinates_ndim, \
296 const size_t *pixels_coordinates_dims, \
297 const double *resolutions, \
298 size_t n_resolutions, \
299 const uint8_t *masked, \
300 const HklBinocularsAxisLimits **limits, \
301 size_t n_limits, \
302 const char *sample_axis)
304 HKLAPI extern HKL_BINOCULARS_SPACE_ANGLES_DECL(int32_t);
305 HKLAPI extern HKL_BINOCULARS_SPACE_ANGLES_DECL(uint16_t);
306 HKLAPI extern HKL_BINOCULARS_SPACE_ANGLES_DECL(uint32_t);
308 /* qparqper */
310 #define HKL_BINOCULARS_SPACE_QPARQPER_DECL(image_t) \
311 void hkl_binoculars_space_qparqper_ ## image_t (HklBinocularsSpace *space, \
312 const HklGeometry *geometry, \
313 const image_t *image, \
314 size_t n_pixels, \
315 double weight, \
316 const double *pixels_coordinates, \
317 size_t pixels_coordinates_ndim, \
318 const size_t *pixels_coordinates_dims, \
319 const double *resolutions, \
320 size_t n_resolutions, \
321 const uint8_t *masked, \
322 HklBinocularsSurfaceOrientationEnum surf, \
323 const HklBinocularsAxisLimits **limits, \
324 size_t n_limits)
326 HKLAPI extern HKL_BINOCULARS_SPACE_QPARQPER_DECL(int32_t);
327 HKLAPI extern HKL_BINOCULARS_SPACE_QPARQPER_DECL(uint16_t);
328 HKLAPI extern HKL_BINOCULARS_SPACE_QPARQPER_DECL(uint32_t);
330 /* qxqyqz */
332 #define HKL_BINOCULARS_SPACE_QXQYQZ_DECL(image_t) \
333 void hkl_binoculars_space_qxqyqz_ ## image_t (HklBinocularsSpace *space, \
334 const HklGeometry *geometry, \
335 const image_t *image, \
336 size_t n_pixels, \
337 double weight, \
338 const double *pixels_coordinates, \
339 size_t pixels_coordinates_ndim, \
340 const size_t *pixels_coordinates_dims, \
341 const double *resolutions, \
342 size_t n_resolutions, \
343 const uint8_t *masked, \
344 HklBinocularsSurfaceOrientationEnum surf, \
345 const HklBinocularsAxisLimits **limits, \
346 size_t n_limits)
348 HKLAPI extern HKL_BINOCULARS_SPACE_QXQYQZ_DECL(int32_t);
349 HKLAPI extern HKL_BINOCULARS_SPACE_QXQYQZ_DECL(uint16_t);
350 HKLAPI extern HKL_BINOCULARS_SPACE_QXQYQZ_DECL(uint32_t);
352 /* hkl */
354 #define HKL_BINOCULARS_SPACE_HKL_DECL(image_t) \
355 void hkl_binoculars_space_hkl_ ## image_t (HklBinocularsSpace *space, \
356 const HklGeometry *geometry, \
357 const HklSample *sample, \
358 const image_t *image, \
359 size_t n_pixels, \
360 double weight, \
361 const double *pixels_coordinates, \
362 size_t pixels_coordinates_ndim, \
363 const size_t *pixels_coordinates_dims, \
364 const double *resolutions, \
365 size_t n_resolutions, \
366 const uint8_t *masked, \
367 const HklBinocularsAxisLimits **limits, \
368 size_t n_limits)
370 HKLAPI extern HKL_BINOCULARS_SPACE_HKL_DECL(int32_t);
371 HKLAPI extern HKL_BINOCULARS_SPACE_HKL_DECL(uint16_t);
372 HKLAPI extern HKL_BINOCULARS_SPACE_HKL_DECL(uint32_t);
374 G_END_DECLS
376 #endif