[contrib][haskell] PyFAI.Detector
[hkl.git] / hkl / hkl-geometry-private.h
blobadec8211ccaf8522a0fa32138877eaf175557bdb
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-2017 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_GEOMETRY_PRIVATE_H__
23 #define __HKL_GEOMETRY_PRIVATE_H__
25 #include <stddef.h> // for size_t
26 #include <stdio.h> // for FILE
27 #include "hkl-parameter-private.h" // for darray_parameter
28 #include "hkl-quaternion-private.h" // for _HklQuaternion
29 #include "hkl-source-private.h" // for HklSource
30 #include "hkl-vector-private.h" // for HklQuaternion
31 #include "hkl.h" // for HklGeometry, etc
32 #include "hkl/ccan/darray/darray.h" // for darray
33 #include "hkl/ccan/list/list.h"
35 G_BEGIN_DECLS
37 #define HKL_HOLDER_SAMPLE_IDX 0
38 #define HKL_HOLDER_DETECTOR_IDX 1
40 typedef struct _HklHolder HklHolder;
42 typedef void (* HklGeometryListMultiplyFunction) (HklGeometryList *self,
43 HklGeometryListItem *item);
45 typedef darray(HklHolder *) darray_holder;
47 struct HklHolderConfig {
48 int gc;
49 size_t *idx;
50 size_t len;
53 struct _HklHolder {
54 struct HklHolderConfig *config;
55 HklGeometry *geometry;
56 HklQuaternion q;
59 typedef struct _HklGeometryOperations HklGeometryOperations;
61 struct _HklGeometryOperations
63 HklHolder* (*sample_holder_get) (const HklGeometry *self, const HklSample *sample);
65 HklHolder* (*detector_holder_get) (const HklGeometry *self, const HklDetector *detector);
67 HklVector (*ki_get) (const HklGeometry *geometry);
69 HklVector (*kf_get) (const HklGeometry *self, const HklDetector *detector);
72 struct _HklGeometry
74 const HklFactory *factory;
75 HklSource source;
76 darray_parameter axes;
77 darray_holder holders;
78 const HklGeometryOperations *ops;
81 static HklHolder *hkl_geometry_sample_holder_get_real(const HklGeometry *self,
82 UNUSED const HklSample *sample)
84 return darray_item(self->holders, HKL_HOLDER_SAMPLE_IDX);
87 static HklHolder *hkl_geometry_detector_holder_get_real(const HklGeometry *self,
88 UNUSED const HklDetector *detector)
90 return darray_item(self->holders, HKL_HOLDER_DETECTOR_IDX);
93 static HklVector hkl_geometry_ki_get_real(const HklGeometry *self)
95 HklVector ki;
97 hkl_source_compute_ki(&self->source, &ki);
99 return ki;
102 static HklVector hkl_geometry_kf_get_real(const HklGeometry *self,
103 const HklDetector *detector)
105 HklVector kf = {{HKL_TAU / self->source.wave_length, 0, 0}};
106 HklHolder *detector_holder = darray_item(self->holders, HKL_HOLDER_DETECTOR_IDX);
108 hkl_vector_rotated_quaternion(&kf, &detector_holder->q);
110 return kf;
113 #define HKL_GEOMETRY_OPERATIONS_DEFAULTS \
114 .sample_holder_get = hkl_geometry_sample_holder_get_real, \
115 .detector_holder_get = hkl_geometry_detector_holder_get_real, \
116 .ki_get = hkl_geometry_ki_get_real, \
117 .kf_get = hkl_geometry_kf_get_real
119 static HklGeometryOperations hkl_geometry_operations_defaults = {HKL_GEOMETRY_OPERATIONS_DEFAULTS};
121 #define HKL_GEOMETRY_ERROR hkl_geometry_error_quark ()
123 static inline GQuark hkl_geometry_error_quark (void)
125 return g_quark_from_static_string ("hkl-geometry-error-quark");
128 typedef enum {
129 HKL_GEOMETRY_ERROR_AXIS_GET, /* can not get the axis */
130 HKL_GEOMETRY_ERROR_AXIS_SET, /* can not set the axis */
131 } HklGeometryError;
133 struct _HklGeometryList
135 HklGeometryListMultiplyFunction multiply;
136 struct list_head items;
137 size_t n_items;
140 struct _HklGeometryListItem
142 struct list_node list;
143 HklGeometry *geometry;
146 /*************/
147 /* HklHolder */
148 /*************/
150 extern HklParameter *hkl_holder_add_rotation(HklHolder *self,
151 char const *name,
152 double x, double y, double z,
153 const HklUnit *punit);
155 extern HklParameter *hkl_holder_add_rotation_with_origin(HklHolder *self,
156 const char *name,
157 double x, double y, double z,
158 double ox, double oy, double oz,
159 const HklUnit *punit);
161 extern HklParameter *hkl_holder_add_translation(HklHolder *self,
162 char const *name,
163 double x, double y, double z,
164 const HklUnit *punit);
166 extern HklVector hkl_holder_transformation_apply(const HklHolder *self,
167 const HklVector *v);
169 /***************/
170 /* HklGeometry */
171 /***************/
173 extern HklGeometry *hkl_geometry_new(const HklFactory *factory,
174 const HklGeometryOperations *ops);
176 extern int hkl_geometry_init_geometry(HklGeometry *self,
177 const HklGeometry *src);
179 extern HklHolder *hkl_geometry_add_holder(HklGeometry *self);
181 extern void hkl_geometry_update(HklGeometry *self);
183 extern int hkl_geometry_get_axis_idx_by_name(const HklGeometry *self,
184 const char *name);
186 /* internally require do not use the hkl_geometry_axis_get */
187 extern HklParameter *hkl_geometry_get_axis_by_name(HklGeometry *self,
188 const char *name);
190 extern double hkl_geometry_distance(const HklGeometry *self,
191 const HklGeometry *ref);
193 extern double hkl_geometry_distance_orthodromic(const HklGeometry *self,
194 const HklGeometry *ref);
196 extern int hkl_geometry_closest_from_geometry_with_range(HklGeometry *self,
197 const HklGeometry *ref);
199 extern int hkl_geometry_is_valid(const HklGeometry *self);
201 extern int hkl_geometry_is_valid_range(const HklGeometry *self);
203 extern HklHolder *hkl_geometry_sample_holder_get(const HklGeometry *self, const HklSample *sample);
205 extern HklHolder *hkl_geometry_detector_holder_get(const HklGeometry *self, const HklDetector *detector);
207 extern HklVector hkl_geometry_ki_get(const HklGeometry *self);
209 extern HklVector hkl_geometry_kf_get(const HklGeometry *self,
210 const HklDetector *detector);
212 /*******************/
213 /* HklGeometryList */
214 /*******************/
216 extern HklGeometryList *hkl_geometry_list_new(void);
218 extern HklGeometryList *hkl_geometry_list_new_copy(const HklGeometryList *self);
220 extern void hkl_geometry_list_add(HklGeometryList *self, const HklGeometry *geometry);
222 extern void hkl_geometry_list_reset(HklGeometryList *self);
224 extern void hkl_geometry_list_sort(HklGeometryList *self, HklGeometry *ref);
226 extern void hkl_geometry_list_fprintf(FILE *f, const HklGeometryList *self);
228 extern void hkl_geometry_list_multiply(HklGeometryList *self);
230 extern void hkl_geometry_list_multiply_from_range(HklGeometryList *self);
232 extern void hkl_geometry_list_remove_invalid(HklGeometryList *self);
234 /***********************/
235 /* HklGeometryListItem */
236 /***********************/
238 extern HklGeometryListItem *hkl_geometry_list_item_new(const HklGeometry *geometry);
240 extern HklGeometryListItem *hkl_geometry_list_item_new_copy(const HklGeometryListItem *self);
242 extern void hkl_geometry_list_item_free(HklGeometryListItem *self);
244 G_END_DECLS
246 #endif /* __HKL_GEOMETRY_PRIVATE_H__ */