GoWebScan API
 All Classes Files Functions Variables Typedefs Macros Modules Pages
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-2022 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 a calibration node object (GoWebScanCalNode) and adds it to the list of nodes. The node
101  * is given a unique ID based on its plane, system column, sensor ID, and bank ID (index of node with
102  * respect to the sensor).
103  *
104  * @public @memberof GoWebScanCal
105  * @param cal GoWebScanCal object.
106  * @param plane System plane.
107  * @param column System column index.
108  * @param deviceId Sensor ID. ID is of the connected profile sensor for vision systems.
109  * @param bankId Bank index.
110  * @param node Receives the constructed GoWebScanCalNode object.
111  * @return Operation status.
112  */
113 GoWebScanFx(kStatus) GoWebScanCal_AddNode(GoWebScanCal cal, GoWebScanSystemPlane plane, k32s column, k32s deviceId, k32s bankId, GoWebScanCalNode* node);
114 
115 /**
116  * Gets the number of nodes in the calibration.
117  *
118  * @public @memberof GoWebScanCal
119  * @param cal GoWebScanCal object.
120  * @return Node count.
121  */
122 GoWebScanFx(kSize) GoWebScanCal_NodeCount(GoWebScanCal cal);
123 
124 /**
125  * Gets the calibration node at a specified index in the system.
126  *
127  * @public @memberof GoWebScanCal
128  * @param cal GoWebScanCal object.
129  * @param index Node index.
130  * @return GoWebScanCalNode object representing the node's calibration.
131  */
132 GoWebScanFx(GoWebScanCalNode) GoWebScanCal_NodeAt(GoWebScanCal cal, kSize index);
133 
134 /**
135  * Finds and returns the calibration node with the specified device ID and bank ID.
136  *
137  * @public @memberof GoWebScanCal
138  * @param cal GoWebScanCal object.
139  * @param deviceId Sensor ID. ID is of the connected profile sensor for vision systems.
140  * @param bankId Bank index.
141  * @return GoWebScanCalNode object representing the node's calibration.
142  */
143 GoWebScanFx(GoWebScanCalNode) GoWebScanCal_FindNode(GoWebScanCal cal, k32s deviceId, k32s bankId);
144 
145 /**
146  * Gets the system Y reference in mils. This represents the Y-bias of the system and can be used
147  * to align multiple systems. Refer to GoWebScanSettings_SetCalYAdjustment() for how this should be
148  * applied by the user application.
149  *
150  * @public @memberof GoWebScanCal
151  * @param cal GoWebScanCal object.
152  * @return System Y reference (mils).
153  * @see GoWebScanSettings_SetCalYAdjustment
154  */
155 GoWebScanFx(k64s) GoWebScanCal_SystemYRef(GoWebScanCal cal);
156 
157 /**
158 * Sets the system Y reference in mils.
159 *
160 * @public @memberof GoWebScanCal
161 * @param cal GoWebScanCal object.
162 * @param yRef System Y reference (mils).
163 * @return Operation status.
164 */
165 GoWebScanFx(kStatus) GoWebScanCal_SetSystemYRef(GoWebScanCal cal, k64s yRef);
166 
167 /**
168 * Gets the system X reference in mils. This represents the X-bias of the system and can be used
169 * to align multiple systems. Refer to GoWebScanSettings_SetCalXAdjustment() for how this should be
170 * applied by the user application.
171 *
172 * @public @memberof GoWebScanCal
173 * @param cal GoWebScanCal object.
174 * @return System X reference (mils).
175 * @see GoWebScanSettings_SetCalXAdjustment
176 */
177 GoWebScanFx(k32s) GoWebScanCal_SystemXRef(GoWebScanCal cal);
178 
179 /**
180 * Sets the system X reference in mils.
181 *
182 * @public @memberof GoWebScanCal
183 * @param cal GoWebScanCal object.
184 * @param xRef System X reference (mils).
185 * @return Operation status.
186 */
187 GoWebScanFx(kStatus) GoWebScanCal_SetSystemXRef(GoWebScanCal cal, k32s xRef);
188 
189 #include <GoWebScanSdk/GoWebScanCal.x.h>
190 
191 #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.
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...
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.