1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
//! This module contains functionality for working with a compact file format for storing 3D point
//! data taken from a laser profile triangulation scanner. The format is simple and designed to be
//! similar to the intermediate representation produced by sensors in their raw output.
//!
//! The format is identified by the extension `.lptf3` and the header structured as follows:
//!
//! - bytes 0-5: magic number b"LPTF3" to identify the file type
//! - bytes 6-7: version number (currently 1)
//! - byte 8-9: data flags
//! - bit 0: Bytes per point coordinate (0=16 bit, 1=32 bit)
//! - bit 1: Color data present (0=none, 1=single uint8)
//! - byte 10: motion type
//! - 0: fixed y translation
//! - 1-255: not implemented
//!
//! After the header, the next set of bytes will depend on the motion type:
//!
//! - If the motion type is 0, the next four bytes will be a 32 bit uint representing the y
//! translation of the scanner per frame in nanometers.
//!
//! Following the motion type values, the file will contain a repeating sequence consisting of
//! a frame header and a variable number of point entries. The frame header consists of the
//! following 24 bytes:
//!
//! - bytes 0-3: frame number (uint32)
//! - bytes 4-7: number of points in the frame (uint32)
//! - bytes 8-11: x offset for all frame points in micrometers (int32)
//! - bytes 12-15: z offset for all frame points in micrometers (int32)
//! - bytes 16-19: x resolution for all frame points in nanometers (uint32)
//! - bytes 20-23: z resolution for all frame points in nanometers (uint32)
//!
//! Following the frame header, there will be the number of individual point entries specified
//! by the frame header. Each point entry consists of the following:
//!
//! - x coordinate (16 or 32-bit signed integer, depending on the data flags)
//! - z coordinate (16 or 32-bit signed integer, depending on the data flags)
//! - color (optional, 8-bit unsigned integer if color data is present)
//!
//! At the end of the point entries, there will be either another frame header or the end of the
//! file.
use crateMeshData3;
use crateload_downsample_filter_lptf3;
use crateload_lptf3_mesh_data_core;
use crate::;
use Path;
pub use *;
pub use Lptf3DsParams;
pub use Lptf3Loader;
pub use *;
/// The Lptf3Load enum defines the different ways to load data from a LPTF3 file, and is used to
/// pass these options to loading functions.
/// This trait defines the interface for uncertainty models that can be used when loading LPTF3
/// data from a file.
/// Quickly get the point distribution for the LPTF3 file, which returns a vector of point counts
/// for bins of the given size. For certain applications this is a quick way to heuristically check
/// if a scan of a known scene roughly matches the expected data.
///
/// # Arguments
///
/// * `file_path`:
/// * `bin_size`:
///
/// returns: Result<Vec<usize, Global>, Box<dyn Error, Global>>
///
/// # Examples
///
/// ```
///
/// ```
/// Read a lptf3 (Laser Profile Triangulation Format 3D) file and return a `PointCloud3`.
///
/// This function reads a LPTF3 file, which is a compact file format for storing 3D point data
/// taken from a laser profile triangulation scanner. The format is simple and compact, capable
/// of practically storing about 200k points (with an 8-bit color value each) per MB when using a
/// 16-bit coordinate format, or half that when using a 32-bit coordinate format.
///
/// There are a few different ways to load the data, controlled by the `Lptf3Load` enum:
/// - `Lptf3Load::All`: Load all points from the file.
/// - `Lptf3Load::TakeEveryN(n)`: Load every Nth row from the file. The loader will attempt to
/// roughly match the x spacing of the points to the gap distance between rows, resulting in a
/// grid-like point cloud with an approximately uniform point spacing when viewed from the
/// X-Y plane. This is a very fast method of retrieving a downsampled point cloud.
/// - `Lptf3Load::SmoothSample(params)`: Load the points using a downsampling filter, which
/// downsamples the point cloud similar to the `TakeEveryN` method, but also performs a gaussian
/// smoothing step using the full original cloud. This takes the longest time, but can remove
/// a significant amount of noise from the data by making use of an adjacency structure that
/// will be lost once the points are turned into a cloud.
///
/// # Attributes
///
/// If the file has a color channel it is expanded to grayscale and stored as `point_colors`. The
/// channel is a single 8-bit laser return intensity, not a true color.
///
/// # Arguments
///
/// * `file_path`: A path to the LPTF3 file to load.
/// * `load`: An enum specifying how to load the data from the file.
///
/// returns: `Result<PointCloud3>`
/// Read a lptf3 (Laser Profile Triangulation Format 3D) file and return a `MeshData3`.
///
/// This function reads a LPTF3 file, which is a compact file format for storing 3D point data
/// taken from a laser profile triangulation scanner. The format is simple and compact, capable
/// of practically storing about 200k points (with an 8-bit color value each) per MB when using a
/// 16-bit coordinate format, or half that when using a 32-bit coordinate format.
///
/// There are a few different ways to load the data, controlled by the `Lptf3Load` enum:
/// - `Lptf3Load::All`: Load all points from the file.
/// - `Lptf3Load::TakeEveryN(n)`: Load every Nth row from the file. The loader will attempt to
/// roughly match the x spacing of the points to the gap distance between rows, resulting in a
/// grid-like point cloud with an approximately uniform point spacing when viewed from the
/// X-Y plane. This is a very fast method of retrieving a downsampled point cloud.
/// - `Lptf3Load::SmoothSample(params)`: Load the points using a downsampling filter, which
/// downsamples the point cloud similar to the `TakeEveryN` method, but also performs a gaussian
/// smoothing step using the full original cloud. This takes the longest time, but can remove
/// a significant amount of noise from the data by making use of an adjacency structure that
/// will be lost once the points are turned into a cloud.
///
/// Once the points are loaded, they will be converted into a triangle mesh by connecting points in
/// adjacent rows with triangles that meet certain edge length criteria. The result is a fast mesh
/// that can be built using knowledge of the LPTF3's internal structure rather than having to rely
/// on more general techniques that can build meshes from arbitrary point clouds.
///
/// # Orphan Points
///
/// **Points which end up in no face are discarded.** The edge criteria reject the triangles around
/// a dropout or a depth discontinuity, and the first and last rows of a scan may have nothing to
/// join to, so a real scan always leaves some points unconnected. They are real measurements, but
/// they are not part of a surface, and what is being asked for here is a mesh.
///
/// The consequence is that the point buffer of the returned mesh is a *subset* of the points that
/// `load_lptf3` returns for the same file and load mode, in the same order but with gaps. Use
/// `load_lptf3` instead when every measured point matters. A scan which produces no faces at all,
/// such as a single row, returns an empty mesh rather than a bag of loose points.
///
/// # Attributes
///
/// Data which the sensor recorded alongside the geometry is carried onto the mesh rather than
/// discarded:
///
/// - If the file has a color channel, it is expanded to grayscale and stored as `point_colors`.
/// The channel is a single 8-bit laser return intensity, not a true color.
/// - If an uncertainty model is supplied, it is evaluated at every point and the results are
/// stored as `point_stdev`. A model returning a negative or non-finite value is an error, since
/// that is not a standard deviation.
///
/// Note that the uncertainty is evaluated at the *final* position of each point, so under
/// `Lptf3Load::SmoothSample` the model sees the smoothed coordinates. The model is also a function
/// of the sensor geometry alone, so it describes the inherent triangulation uncertainty of the
/// measurement and knows nothing about how much noise the smoothing removed.
///
/// # Arguments
///
/// * `file_path`: A path to the LPTF3 file to load.
/// * `load`: An enum specifying how to load the data from the file.
/// * `uncertainty`: An optional model of the sensor's measurement uncertainty. When supplied, the
/// standard deviation it predicts at each point is stored on the mesh as `point_stdev`.
///
/// returns: Result<MeshData3, Box<dyn Error, Global>>
/// Load every `take_every`th row of a file, returning the points and, if the file has a color
/// channel, one grayscale triple per point.
type LoadedPoints = ;
/// The same as `load_take_every` but running the gaussian downsampling filter, which flattens the
/// row structure the filter works over once it is done with it.
/// The rows of points recovered from a LPTF3 file, in the order they were scanned. Each inner
/// vector is one profile, sorted in ascending order by X coordinate.
///
/// When `colors` is `Some`, it has exactly the same row and column structure as `points`, so a
/// flattening of the two stays aligned element for element.