Skip to content

Commit

Permalink
Support ply files with double as coordinate type.
Browse files Browse the repository at this point in the history
  • Loading branch information
spelufo committed Jun 4, 2024
1 parent 2a9b83d commit c5f49ad
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/io/ply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function load(fs::Stream{format"PLY_ASCII"}; facetype=GLTriangleFace, pointtype=
while !startswith(line, "end_header")
if startswith(line, "element vertex")
n_points = parse(Int, split(line)[3])
elseif startswith(line, "property float nx")
elseif startswith(line, "property float nx") || startswith(line, "property double nx")
has_normals = true
elseif startswith(line, "element face")
n_faces = parse(Int, split(line)[3])
Expand Down Expand Up @@ -140,11 +140,29 @@ function load(fs::Stream{format"PLY_BINARY"}; facetype=GLTriangleFace, pointtype
line = readline(io)

has_normals = false
has_doubles = Float32
xtype = Float32; ytype = Float32; ztype = Float32
nxtype = Float32; nytype = Float32; nztype = Float32
while !startswith(line, "end_header")
if startswith(line, "element vertex")
n_points = parse(Int, split(line)[3])
elseif startswith(line, "property float nx")
elseif startswith(line, "property double x")
xtype = Float64

Check warning on line 150 in src/io/ply.jl

View check run for this annotation

Codecov / codecov/patch

src/io/ply.jl#L150

Added line #L150 was not covered by tests
elseif startswith(line, "property double y")
ytype = Float64

Check warning on line 152 in src/io/ply.jl

View check run for this annotation

Codecov / codecov/patch

src/io/ply.jl#L152

Added line #L152 was not covered by tests
elseif startswith(line, "property double z")
ztype = Float64

Check warning on line 154 in src/io/ply.jl

View check run for this annotation

Codecov / codecov/patch

src/io/ply.jl#L154

Added line #L154 was not covered by tests
elseif startswith(line, "property float n")
has_normals = true

Check warning on line 156 in src/io/ply.jl

View check run for this annotation

Codecov / codecov/patch

src/io/ply.jl#L156

Added line #L156 was not covered by tests
elseif startswith(line, "property double nx")
has_normals = true
nxtype = Float64

Check warning on line 159 in src/io/ply.jl

View check run for this annotation

Codecov / codecov/patch

src/io/ply.jl#L158-L159

Added lines #L158 - L159 were not covered by tests
elseif startswith(line, "property double ny")
has_normals = true
nytype = Float64

Check warning on line 162 in src/io/ply.jl

View check run for this annotation

Codecov / codecov/patch

src/io/ply.jl#L161-L162

Added lines #L161 - L162 were not covered by tests
elseif startswith(line, "property double nz")
has_normals = true
nztype = Float64

Check warning on line 165 in src/io/ply.jl

View check run for this annotation

Codecov / codecov/patch

src/io/ply.jl#L164-L165

Added lines #L164 - L165 were not covered by tests
elseif startswith(line, "element face")
n_faces = parse(Int, split(line)[3])
elseif startswith(line, "property")
Expand All @@ -161,9 +179,9 @@ function load(fs::Stream{format"PLY_BINARY"}; facetype=GLTriangleFace, pointtype

# read the data
for i = 1:n_points
points[i] = pointtype(read(io, Float32), read(io, Float32), read(io, Float32))
points[i] = pointtype(read(io, xtype), read(io, ytype), read(io, ztype))
if has_normals
point_normals[i] = normalstype(read(io, Float32), read(io, Float32), read(io, Float32))
point_normals[i] = normalstype(read(io, nxtype), read(io, nytype), read(io, nztype))
end
end

Expand Down

0 comments on commit c5f49ad

Please sign in to comment.