Skip to content

Commit

Permalink
Improved XYZ-to-E57 example
Browse files Browse the repository at this point in the history
  • Loading branch information
cry-inc committed Aug 25, 2023
1 parent d236a57 commit a7e3479
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tools/xyz-to-e57/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* The first three values in each line must be X, Y and Z (as floating point values)
* and last three values must be integers between 0 and 255 for red, green and blue.
* Any additional columns will be ignored.
*
* X, Y and Z will be stored as Cartesian coordinates with 32 floarting points bits for each component.
* RGB colors will be stored with 8 integer bits for each component.
*/

use anyhow::{bail, Context, Result};
Expand Down Expand Up @@ -33,9 +36,9 @@ fn main() -> Result<()> {

let pc_guid = Uuid::new_v4().to_string();
let prototype = vec![
Record::CARTESIAN_X_F64,
Record::CARTESIAN_Y_F64,
Record::CARTESIAN_Z_F64,
Record::CARTESIAN_X_F32,
Record::CARTESIAN_Y_F32,
Record::CARTESIAN_Z_F32,
Record::COLOR_RED_U8,
Record::COLOR_GREEN_U8,
Record::COLOR_BLUE_U8,
Expand All @@ -53,18 +56,18 @@ fn main() -> Result<()> {
let parts: Vec<&str> = line.trim().split(' ').collect();
if parts.len() >= 6 {
// Parse XYZ ASCII data
let x: f64 = parts[0].parse().context("Failed to parse X value")?;
let y: f64 = parts[1].parse().context("Failed to parse X value")?;
let z: f64 = parts[2].parse().context("Failed to parse X value")?;
let x: f32 = parts[0].parse().context("Failed to parse X value")?;
let y: f32 = parts[1].parse().context("Failed to parse Y value")?;
let z: f32 = parts[2].parse().context("Failed to parse Z value")?;
let r: u8 = parts[3].parse().context("Failed to parse red value")?;
let g: u8 = parts[4].parse().context("Failed to parse red value")?;
let b: u8 = parts[5].parse().context("Failed to parse red value")?;
let g: u8 = parts[4].parse().context("Failed to parse green value")?;
let b: u8 = parts[5].parse().context("Failed to parse blue value")?;

// Create E57 point for inserting
let point = vec![
RecordValue::Double(x),
RecordValue::Double(y),
RecordValue::Double(z),
RecordValue::Single(x),
RecordValue::Single(y),
RecordValue::Single(z),
RecordValue::Integer(r as i64),
RecordValue::Integer(g as i64),
RecordValue::Integer(b as i64),
Expand Down

0 comments on commit a7e3479

Please sign in to comment.