Skip to content

Commit

Permalink
Added tests for importing/exporting point clouds
Browse files Browse the repository at this point in the history
  • Loading branch information
elrnv committed Jul 9, 2024
1 parent 2737f77 commit 68321ad
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
17 changes: 17 additions & 0 deletions assets/point_cloud.vtk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# vtk DataFile Version 2.0
PointCloud example
ASCII

DATASET POLYDATA
POINTS 3 float
0 0 0 1 0 0 0 0 -1

VERTICES 3 6
1 0
1 1
1 2

POINT_DATA 3

CELL_DATA 3

1 change: 1 addition & 0 deletions assets/point_cloud.vtp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<VTKFile type="PolyData" version="1.0" byte_order="BigEndian" header_type="UInt64"><PolyData><Piece NumberOfPoints="3" NumberOfVerts="3"><Points><DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary" RangeMin="-1" RangeMax="1">AAAAAAAAACQAAAAAAAAAAAAAAAA/gAAAAAAAAAAAAAAAAAAAAAAAAL+AAAA=</DataArray></Points><Verts><DataArray type="UInt64" Name="connectivity" format="binary" RangeMin="0" RangeMax="2">AAAAAAAAABgAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAI=</DataArray><DataArray type="UInt64" Name="offsets" format="binary" RangeMin="1" RangeMax="3">AAAAAAAAABgAAAAAAAAAAQAAAAAAAAACAAAAAAAAAAM=</DataArray></Verts></Piece></PolyData></VTKFile>
23 changes: 23 additions & 0 deletions tests/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,3 +1105,26 @@ fn triangle_vtkidtype_test() {

test_b!(parse_be(in1) => out1);
}

#[test]
fn point_cloud() -> Result {
let in1 = include_bytes!("../assets/point_cloud.vtk");
let vtk = Vtk {
version: Version::new_legacy(2, 0),
byte_order: ByteOrder::BigEndian,
title: String::from("PointCloud example"),
file_path: None,
data: DataSet::inline(PolyDataPiece {
points: vec![0.0f32, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0].into(),
verts: Some(VertexNumbers::Legacy {
num_cells: 3,
vertices: vec![1, 0, 1, 1, 1, 2],
}),
data: Attributes::new(),
..Default::default()
}),
};
test_b!(parse_be(in1) => vtk);
test_b!(parse_be(Vec::<u8>::new().write_vtk(vtk.clone())?) => vtk);
Ok(())
}
27 changes: 27 additions & 0 deletions tests/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,33 @@ fn hexahedron_lzma_inline_binary() -> Result {
Ok(())
}

#[test]
fn point_cloud() -> Result {
init();
let vtk = Vtk {
version: Version::new_xml(1, 0),
byte_order: ByteOrder::BigEndian,
title: String::from("PointCloud example"),
file_path: None,
data: DataSet::inline(PolyDataPiece {
points: vec![0.0f32, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0].into(),
verts: Some(VertexNumbers::Legacy {
num_cells: 3,
vertices: vec![1, 0, 1, 1, 1, 2],
}),
data: Attributes::new(),
..Default::default()
}),
};
let path = "./assets/point_cloud.vtp";
let orig_vtkfile = vtkio::xml::VTKFile::import(path)?;
assert_eq!(
vtk.try_into_xml_format(vtkio::xml::Compressor::None, 0)?,
orig_vtkfile
); // Checks that compression is the same.
Ok(())
}

#[cfg(feature = "binary")]
#[test]
fn hexahedron_binary() -> Result {
Expand Down

0 comments on commit 68321ad

Please sign in to comment.