Skip to content

Commit dc5c6d2

Browse files
committed
Remove extra copy from PLY import, move cube to LFS
1 parent d1152ed commit dc5c6d2

File tree

2 files changed

+45
-96
lines changed

2 files changed

+45
-96
lines changed

data/cube.ply

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,3 @@
1-
ply
2-
format ascii 1.0
3-
comment Created by Blender 2.82 (sub 7) - www.blender.org, source file: ''
4-
element vertex 24
5-
property float x
6-
property float y
7-
property float z
8-
property float nx
9-
property float ny
10-
property float nz
11-
property float s
12-
property float t
13-
element face 12
14-
property list uchar uint vertex_indices
15-
end_header
16-
-1.000000 1.000000 1.000000 0.000000 0.000000 1.000000 0.875000 0.500000
17-
1.000000 -1.000000 1.000000 0.000000 0.000000 1.000000 0.625000 0.750000
18-
1.000000 1.000000 1.000000 0.000000 0.000000 1.000000 0.625000 0.500000
19-
1.000000 -1.000000 1.000000 0.000000 -1.000000 0.000000 0.625000 0.750000
20-
-1.000000 -1.000000 -1.000000 0.000000 -1.000000 0.000000 0.375000 1.000000
21-
1.000000 -1.000000 -1.000000 0.000000 -1.000000 0.000000 0.375000 0.750000
22-
-1.000000 -1.000000 1.000000 -1.000000 0.000000 0.000000 0.625000 0.000000
23-
-1.000000 1.000000 -1.000000 -1.000000 0.000000 0.000000 0.375000 0.250000
24-
-1.000000 -1.000000 -1.000000 -1.000000 0.000000 0.000000 0.375000 0.000000
25-
1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000 0.375000 0.500000
26-
-1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000 0.125000 0.750000
27-
-1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000 0.125000 0.500000
28-
1.000000 1.000000 1.000000 1.000000 0.000000 -0.000000 0.625000 0.500000
29-
1.000000 -1.000000 -1.000000 1.000000 0.000000 -0.000000 0.375000 0.750000
30-
1.000000 1.000000 -1.000000 1.000000 0.000000 -0.000000 0.375000 0.500000
31-
-1.000000 1.000000 1.000000 0.000000 1.000000 -0.000000 0.625000 0.250000
32-
1.000000 1.000000 -1.000000 0.000000 1.000000 -0.000000 0.375000 0.500000
33-
-1.000000 1.000000 -1.000000 0.000000 1.000000 -0.000000 0.375000 0.250000
34-
-1.000000 -1.000000 1.000000 0.000000 -0.000000 1.000000 0.875000 0.750000
35-
-1.000000 -1.000000 1.000000 0.000000 -1.000000 0.000000 0.625000 1.000000
36-
-1.000000 1.000000 1.000000 -1.000000 0.000000 0.000000 0.625000 0.250000
37-
1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000 0.375000 0.750000
38-
1.000000 -1.000000 1.000000 1.000000 0.000000 0.000000 0.625000 0.750000
39-
1.000000 1.000000 1.000000 0.000000 1.000000 -0.000000 0.625000 0.500000
40-
3 0 1 2
41-
3 3 4 5
42-
3 6 7 8
43-
3 9 10 11
44-
3 12 13 14
45-
3 15 16 17
46-
3 0 18 1
47-
3 3 19 4
48-
3 6 20 7
49-
3 9 21 10
50-
3 12 22 13
51-
3 15 23 16
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:ac47713c37cd6e8bdddce5fd026f617d64f7a7cfdfb8194cd8bb40740db8ec73
3+
size 2219

splashsurf/src/io/ply_format.rs

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -69,52 +69,49 @@ pub fn surface_mesh_from_ply<R: Real, P: AsRef<Path>>(
6969
.get("vertex")
7070
.ok_or(anyhow!("PLY file is missing a 'vertex' element"))?;
7171

72-
let vertices_normals: Vec<(Vector3<_>, Vector3<_>)> = vertices_normals
73-
.into_iter()
74-
.map(|e| {
75-
let vertex = (
76-
e.get("x").unwrap(),
77-
e.get("y").unwrap(),
78-
e.get("z").unwrap(),
79-
e.get("nx").unwrap(),
80-
e.get("ny").unwrap(),
81-
e.get("nz").unwrap(),
82-
);
83-
84-
let v = match vertex {
85-
(
86-
Property::Float(x),
87-
Property::Float(y),
88-
Property::Float(z),
89-
Property::Float(nx),
90-
Property::Float(ny),
91-
Property::Float(nz),
92-
) => (
93-
Vector3::new(
94-
R::from_f32(*x).unwrap(),
95-
R::from_f32(*y).unwrap(),
96-
R::from_f32(*z).unwrap(),
97-
),
98-
Vector3::new(
99-
R::from_f32(*nx).unwrap(),
100-
R::from_f32(*ny).unwrap(),
101-
R::from_f32(*nz).unwrap(),
102-
),
72+
let mut vertices = Vec::with_capacity(vertices_normals.len());
73+
let mut normals = Vec::with_capacity(vertices_normals.len());
74+
75+
for e in vertices_normals {
76+
let vertex = (
77+
e.get("x").unwrap(),
78+
e.get("y").unwrap(),
79+
e.get("z").unwrap(),
80+
e.get("nx").unwrap(),
81+
e.get("ny").unwrap(),
82+
e.get("nz").unwrap(),
83+
);
84+
85+
let (vertex, normal) = match vertex {
86+
(
87+
Property::Float(x),
88+
Property::Float(y),
89+
Property::Float(z),
90+
Property::Float(nx),
91+
Property::Float(ny),
92+
Property::Float(nz),
93+
) => (
94+
Vector3::new(
95+
R::from_f32(*x).unwrap(),
96+
R::from_f32(*y).unwrap(),
97+
R::from_f32(*z).unwrap(),
10398
),
104-
_ => {
105-
return Err(anyhow!(
106-
"Vertex properties have wrong PLY data type (expected float)"
107-
))
108-
}
109-
};
110-
111-
Ok(v)
112-
})
113-
.map(|vn| vn.unwrap())
114-
.collect();
99+
Vector3::new(
100+
R::from_f32(*nx).unwrap(),
101+
R::from_f32(*ny).unwrap(),
102+
R::from_f32(*nz).unwrap(),
103+
),
104+
),
105+
_ => {
106+
return Err(anyhow!(
107+
"Vertex properties have wrong PLY data type (expected float)"
108+
))
109+
}
110+
};
115111

116-
let vertices: Vec<Vector3<_>> = vertices_normals.iter().map(|vn| vn.0.clone()).collect();
117-
let normals: Vec<Vector3<_>> = vertices_normals.iter().map(|vn| vn.1.clone()).collect();
112+
vertices.push(vertex);
113+
normals.push(normal);
114+
}
118115

119116
let faces = ply
120117
.payload
@@ -167,7 +164,7 @@ pub mod test {
167164
use super::*;
168165

169166
#[test]
170-
fn test_convert_cube() -> Result<(), anyhow::Error> {
167+
fn test_read_ply_cube() -> Result<(), anyhow::Error> {
171168
let input_file = Path::new("../data/cube.ply");
172169

173170
let mesh: MeshWithData<f32, _> = surface_mesh_from_ply(input_file).with_context(|| {

0 commit comments

Comments
 (0)