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"
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
{
54 struct HklHolderConfig
*config
;
55 HklGeometry
*geometry
;
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
);
74 const HklFactory
*factory
;
76 darray_parameter axes
;
77 darray_holder holders
;
78 const HklGeometryOperations
*ops
;
81 static inline 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 inline 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 inline HklVector
hkl_geometry_ki_get_real(const HklGeometry
*self
)
97 hkl_source_compute_ki(&self
->source
, &ki
);
102 static inline HklVector
hkl_geometry_kf_get_real(const HklGeometry
*self
,
103 UNUSED
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
);
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 extern const HklGeometryOperations 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");
129 HKL_GEOMETRY_ERROR_AXIS_GET
, /* can not get the axis */
130 HKL_GEOMETRY_ERROR_AXIS_SET
, /* can not set the axis */
133 struct _HklGeometryList
135 HklGeometryListMultiplyFunction multiply
;
136 struct list_head items
;
140 struct _HklGeometryListItem
142 struct list_node list
;
143 HklGeometry
*geometry
;
150 extern HklParameter
*hkl_holder_add_rotation(HklHolder
*self
,
152 double x
, double y
, double z
,
153 const HklUnit
*punit
);
155 extern HklParameter
*hkl_holder_add_rotation_with_origin(HklHolder
*self
,
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
,
163 double x
, double y
, double z
,
164 const HklUnit
*punit
);
166 extern HklVector
hkl_holder_transformation_apply(const HklHolder
*self
,
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
,
186 /* internally require do not use the hkl_geometry_axis_get */
187 extern HklParameter
*hkl_geometry_get_axis_by_name(HklGeometry
*self
,
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
);
246 #endif /* __HKL_GEOMETRY_PRIVATE_H__ */