GoWebScan API
GoWebScanCal.h
Go to the documentation of this file.
1 /**
2 * @file GoWebScanCal.h
3 * @brief Declares a GoWebScanCal object.
4 *
5 * @internal
6 * Copyright (C) 2017-2026 by LMI Technologies Inc.
7 * Licensed under the MIT License.
8 * Redistributed files must retain the above copyright notice.
9 */
10 
11 #ifndef GO_WEB_SCAN_CAL_H
12 #define GO_WEB_SCAN_CAL_H
13 
15 #include <kApi/Data/kXml.h>
16 
17 /**
18 * @class GoWebScanCal
19 * @extends kObject
20 * @ingroup GoWebScanSdk-Calibration
21 * @brief Represents a container for the system calibration. The system calibration corrects
22 * for mounting differences between sensors and performs a flatfield correction for
23 * vision sensors. The calibration file contains Z and Y offsets per spot for profile
24 * and tracheid sensors, and Y offsets and gains (for each color channel) for vision
25 * sensors. All offsets are stored in hex to save space in the file. Additionally,
26 * the calibration file also stores the X offset per camera (in decimal). This is only
27 * used when detection of locators is enabled during vision calibration. The algorithm
28 * aligns cameras to the centers of holes in the calibration bars, and calculates the
29 * X offset accordingly. Non-vision systems will have an X offset of 0. The calibration
30 * also contains an X and Y reference (in decimal) which represents the system bias.
31 * This reference allows for aligning multiple systems to each other.
32 *
33 * The data for all sensors is stored in a single XML file, and this class handles
34 * reading and writing the file. For systems with vision, a vision sensor's calibration
35 * data is stored under the serial number of the connected profile sensor.
36 *
37 * For profile sensors, Z and Y offsets are stored in 4-digit hex per spot. For vision
38 * sensors, the Y offsets for the first and last column in the vision image are stored
39 * in 4-digit hex; when the calibration is loaded, the offsets are linearly interpolated
40 * to the full vision width. The vision gains are also sampled to a lower image
41 * resolution (8 x 64) to save space and are linearly interpolated to the larger vision
42 * image size when the calibration is loaded. For precision, the log of each gain is
43 * calculated and normalized to [0, 1] and scaled to [0, 255] prior to hex conversion
44 * and saving. The hex spot offsets of a particular type (e.g. profile Y offsets) are
45 * concatenated together and stored as a single text string. Vision gains of the
46 * downsampled image are concatenated together and stored as a single string for each
47 * row and each channel.
48 *
49 * When using the calibration, GoWebScanCal first converts and upsamples the offsets and
50 * gains. Calibration data is applied early in processing: offsets are applied after
51 * masking and reorienting input data and prior to resampling in X and Y. Vision gains
52 * are applied after reorienting input data and prior to demosaicing and resampling. X
53 * offsets are used when performing the X-axis layout in GoWebScanConfig.
54 *
55 * Internally, GoWebScanCal stores the offsets and gains for individual nodes (cameras)
56 * as GoWebScanCalNode objects.
57 *
58 * Refer to GoWebScanCalProcessor and GoWebScanCalProcessorNode for a description of the
59 * calibration processing algorithm.
60 * @see GoWebScanCalProcessor, GoWebScanCalProcessorNode
61 */
62 typedef kObject GoWebScanCal;
63 
64 // Forward declaration
65 typedef kObject GoWebScanCalNode;
66 
67 /**
68 * Constructs a GoWebScanCal object.
69 *
70 * @public @memberof GoWebScanCal
71 * @param cal Receives the constructed GoWebScanCal object.
72 * @param allocator Memory allocator (or kNULL for default).
73 * @return Operation status.
74 */
75 GoWebScanFx(kStatus) GoWebScanCal_Construct(GoWebScanCal* cal, kAlloc allocator);
76 
77 /**
78  * Constructs and loads a GoWebScanCal object from a saved XML file.
79  *
80  * @public @memberof GoWebScanCal
81  * @param cal Receives the constructed GoWebScanCal object.
82  * @param fileName Filename (including path). Expected to be an XML file.
83  * @param alloc Memory allocator (or kNULL for default).
84  * @return Operation status.
85  */
86 GoWebScanFx(kStatus) GoWebScanCal_Load(GoWebScanCal* cal, const kChar* fileName, kAlloc alloc);
87 
88 /**
89  * Writes and stores a GoWebScanCal object to a XML file.
90  *
91  * @public @memberof GoWebScanCal
92  * @param cal GoWebScanCal object.
93  * @param fileName Filename (including path). Expected to be an XML file. If the file does
94  * not exist, it will be created.
95  * @return Operation status.
96  */
97 GoWebScanFx(kStatus) GoWebScanCal_Store(GoWebScanCal cal, const kChar* fileName);
98 
99 /**
100 * Constructs and sets the values of a GoWebScanCal object from the given XML text.
101 *
102 * @public @memberof GoWebScanCal
103 * @param cal Receives the constructed GoWebScanCal object.
104 * @param str Text of a GoWebScan XML.
105 * @param alloc Memory allocator (or kNULL for default).
106 * @return Operation status.
107 */
108 GoWebScanFx(kStatus) GoWebScanCal_ImportFromText(GoWebScanCal* cal, const kChar* str, kAlloc alloc);
109 
110 /**
111 * Constructs and sets the values of a GoWebScanCal object from the given XML kString.
112 *
113 * @public @memberof GoWebScanCal
114 * @param cal Receives the constructed GoWebScanCal object.
115 * @param str kString containing the text of a GoWebScan XML.
116 * @param alloc Memory allocator (or kNULL for default).
117 * @return Operation status.
118 */
119 GoWebScanFx(kStatus) GoWebScanCal_ImportFromString(GoWebScanCal* cal, kString str, kAlloc alloc);
120 
121 /**
122 * Populates a kString with the text of a GoWebScanCal object.
123 *
124 * @public @memberof GoWebScanCal
125 * @param cal GoWebScanCal object.
126 * @param str kString to be populated with the GoWebScan XML text.
127 * @return Operation status.
128 */
130 
131 /**
132  * Constructs a calibration node object (GoWebScanCalNode) and adds it to the list of nodes. The node
133  * is given a unique ID based on its plane, system column, sensor ID, and bank ID (index of node with
134  * respect to the sensor).
135  *
136  * @public @memberof GoWebScanCal
137  * @param cal GoWebScanCal object.
138  * @param plane System plane.
139  * @param column System column index.
140  * @param deviceId Sensor ID. ID is of the connected profile sensor for vision systems.
141  * @param bankId Bank index.
142  * @param node Receives the constructed GoWebScanCalNode object.
143  * @return Operation status.
144  */
145 GoWebScanFx(kStatus) GoWebScanCal_AddNode(GoWebScanCal cal, GoWebScanSystemPlane plane, k32s column, k32s deviceId, k32s bankId, GoWebScanCalNode* node);
146 
147 /**
148  * Gets the number of nodes in the calibration.
149  *
150  * @public @memberof GoWebScanCal
151  * @param cal GoWebScanCal object.
152  * @return Node count.
153  */
154 GoWebScanFx(kSize) GoWebScanCal_NodeCount(GoWebScanCal cal);
155 
156 /**
157  * Gets the calibration node at a specified index in the system.
158  *
159  * @public @memberof GoWebScanCal
160  * @param cal GoWebScanCal object.
161  * @param index Node index.
162  * @return GoWebScanCalNode object representing the node's calibration.
163  */
164 GoWebScanFx(GoWebScanCalNode) GoWebScanCal_NodeAt(GoWebScanCal cal, kSize index);
165 
166 /**
167  * Finds and returns the calibration node with the specified device ID and bank ID.
168  *
169  * @public @memberof GoWebScanCal
170  * @param cal GoWebScanCal object.
171  * @param deviceId Sensor ID. ID is of the connected profile sensor for vision systems.
172  * @param bankId Bank index.
173  * @return GoWebScanCalNode object representing the node's calibration.
174  */
175 GoWebScanFx(GoWebScanCalNode) GoWebScanCal_FindNode(GoWebScanCal cal, k32s deviceId, k32s bankId);
176 
177 /**
178  * Gets the system Y reference in mils. This represents the Y-bias of the system and can be used
179  * to align multiple systems. Refer to GoWebScanSettings_SetCalYAdjustment() for how this should be
180  * applied by the user application.
181  *
182  * @public @memberof GoWebScanCal
183  * @param cal GoWebScanCal object.
184  * @return System Y reference (mils).
185  * @see GoWebScanSettings_SetCalYAdjustment
186  */
187 GoWebScanFx(k64s) GoWebScanCal_SystemYRef(GoWebScanCal cal);
188 
189 /**
190 * Sets the system Y reference in mils.
191 *
192 * @public @memberof GoWebScanCal
193 * @param cal GoWebScanCal object.
194 * @param yRef System Y reference (mils).
195 * @return Operation status.
196 */
197 GoWebScanFx(kStatus) GoWebScanCal_SetSystemYRef(GoWebScanCal cal, k64s yRef);
198 
199 /**
200 * Gets the system X reference in mils. This represents the X-bias of the system and can be used
201 * to align multiple systems. Refer to GoWebScanSettings_SetCalXAdjustment() for how this should be
202 * applied by the user application.
203 *
204 * @public @memberof GoWebScanCal
205 * @param cal GoWebScanCal object.
206 * @return System X reference (mils).
207 * @see GoWebScanSettings_SetCalXAdjustment
208 */
209 GoWebScanFx(k32s) GoWebScanCal_SystemXRef(GoWebScanCal cal);
210 
211 /**
212 * Sets the system X reference in mils.
213 *
214 * @public @memberof GoWebScanCal
215 * @param cal GoWebScanCal object.
216 * @param xRef System X reference (mils).
217 * @return Operation status.
218 */
219 GoWebScanFx(kStatus) GoWebScanCal_SetSystemXRef(GoWebScanCal cal, k32s xRef);
220 
221 #include <GoWebScanSdk/GoWebScanCal.x.h>
222 
223 #endif
GoWebScanCalNode GoWebScanCal_FindNode(GoWebScanCal cal, k32s deviceId, k32s bankId)
Finds and returns the calibration node with the specified device ID and bank ID.
kStatus GoWebScanCal_SetSystemYRef(GoWebScanCal cal, k64s yRef)
Sets the system Y reference in mils.
GoWebScanCalNode GoWebScanCal_NodeAt(GoWebScanCal cal, kSize index)
Gets the calibration node at a specified index in the system.
kStatus GoWebScanCal_ImportFromText(GoWebScanCal *cal, const kChar *str, kAlloc alloc)
Constructs and sets the values of a GoWebScanCal object from the given XML text.
Essential GoWebScan declarations.
k32s GoWebScanCal_SystemXRef(GoWebScanCal cal)
Gets the system X reference in mils.
kStatus GoWebScanCal_Load(GoWebScanCal *cal, const kChar *fileName, kAlloc alloc)
Constructs and loads a GoWebScanCal object from a saved XML file.
Represents a container for node-level system calibration data. Refer to GoWebScanCal for a descriptio...
kStatus GoWebScanCal_ImportFromString(GoWebScanCal *cal, kString str, kAlloc alloc)
Constructs and sets the values of a GoWebScanCal object from the given XML kString.
kSize GoWebScanCal_NodeCount(GoWebScanCal cal)
Gets the number of nodes in the calibration.
Represents the top or bottom plane of the system.
kStatus GoWebScanCal_Construct(GoWebScanCal *cal, kAlloc allocator)
Constructs a GoWebScanCal object.
Represents a container for the system calibration. The system calibration corrects for mounting diffe...
k64s GoWebScanCal_SystemYRef(GoWebScanCal cal)
Gets the system Y reference in mils.
kStatus GoWebScanCal_AddNode(GoWebScanCal cal, GoWebScanSystemPlane plane, k32s column, k32s deviceId, k32s bankId, GoWebScanCalNode *node)
Constructs a calibration node object (GoWebScanCalNode) and adds it to the list of nodes...
kStatus GoWebScanCal_SetSystemXRef(GoWebScanCal cal, k32s xRef)
Sets the system X reference in mils.
kStatus GoWebScanCal_Store(GoWebScanCal cal, const kChar *fileName)
Writes and stores a GoWebScanCal object to a XML file.
kStatus GoWebScanCal_ExportToString(GoWebScanCal cal, kString str)
Populates a kString with the text of a GoWebScanCal object.