Skip to content

Commit

Permalink
Fixed bug to allow reading E57 files without data3D or images2D tags …
Browse files Browse the repository at this point in the history
…and added more tests for files generated by las2e57 tool with point attribute extension
  • Loading branch information
cry-inc committed Apr 1, 2024
1 parent 83581af commit 72441e9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
16 changes: 6 additions & 10 deletions src/images.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::error::Converter;
use crate::xml;
use crate::{Blob, DateTime, Error, Result, Transform};
use roxmltree::{Document, Node};
Expand Down Expand Up @@ -70,16 +69,13 @@ impl Image {
}

pub(crate) fn vec_from_document(document: &Document) -> Result<Vec<Self>> {
let images2d_node = document
.descendants()
.find(|n| n.has_tag_name("images2D"))
.invalid_err("Cannot find 'images2D' tag in XML document")?;

let mut images = Vec::new();
for n in images2d_node.children() {
if n.has_tag_name("vectorChild") && n.attribute("type") == Some("Structure") {
let image = Self::from_node(&n)?;
images.push(image);
if let Some(images2d_node) = document.descendants().find(|n| n.has_tag_name("images2D")) {
for n in images2d_node.children() {
if n.has_tag_name("vectorChild") && n.attribute("type") == Some("Structure") {
let image = Self::from_node(&n)?;
images.push(image);
}
}
}
Ok(images)
Expand Down
15 changes: 6 additions & 9 deletions src/pointcloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ pub struct PointCloud {

impl PointCloud {
pub(crate) fn vec_from_document(document: &Document) -> Result<Vec<Self>> {
let data3d_node = document
.descendants()
.find(|n| n.has_tag_name("data3D"))
.invalid_err("Cannot find 'data3D' tag in XML document")?;

let mut pointclouds = Vec::new();
for n in data3d_node.children() {
if n.has_tag_name("vectorChild") && n.attribute("type") == Some("Structure") {
let pointcloud = Self::from_node(&n)?;
pointclouds.push(pointcloud);
if let Some(data3d_node) = document.descendants().find(|n| n.has_tag_name("data3D")) {
for n in data3d_node.children() {
if n.has_tag_name("vectorChild") && n.attribute("type") == Some("Structure") {
let pointcloud = Self::from_node(&n)?;
pointclouds.push(pointcloud);
}
}
}
Ok(pointclouds)
Expand Down
Binary file added testdata/las2e57_no_images_tag.e57
Binary file not shown.
43 changes: 41 additions & 2 deletions tests/reader_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use e57::{
CartesianCoordinate, E57Reader, ImageFormat, Point, Projection, RawValues, Record, RecordName,
RecordValue, Result, SphericalCoordinate,
CartesianCoordinate, E57Reader, ImageFormat, Point, Projection, RawValues, Record,
RecordDataType, RecordName, RecordValue, Result, SphericalCoordinate,
};
use std::fs::File;

Expand Down Expand Up @@ -630,3 +630,42 @@ fn scaled_integer_intensity() {
assert_eq!(p[1][4].to_i64(&proto[4].data_type).unwrap(), 0);
}
}

#[test]
fn no_images_tag() {
let e57 = E57Reader::from_file("testdata/las2e57_no_images_tag.e57").unwrap();
assert_eq!(e57.images().len(), 0);
}

#[test]
fn las2e57() {
let mut e57 = E57Reader::from_file("testdata/las2e57_no_images_tag.e57").unwrap();

// Extension should be detected
let extentions = e57.extensions();
assert_eq!(extentions.len(), 1);
assert_eq!(extentions[0].namespace, "las");

// Point cloud prototype should contain LAS record
let pcs = e57.pointclouds();
assert_eq!(pcs.len(), 1);
let pc = pcs.first().unwrap();
assert!(matches!(
pc.prototype[5].data_type,
RecordDataType::Integer { min: 0, max: 65535 }
));
assert_eq!(
pc.prototype[5].name,
RecordName::Unknown {
namespace: String::from("las"),
name: String::from("pointSourceId")
}
);

// Reading all the LAS record values should work
let iter = e57.pointcloud_raw(pc).unwrap();
let points = iter.collect::<Result<Vec<RawValues>>>().unwrap();
assert_eq!(points.len(), pc.records as usize);
let point = points.first().unwrap().clone();
assert_eq!(point[5], RecordValue::Integer(1));
}

0 comments on commit 72441e9

Please sign in to comment.