4
4
# --------------------------------------------------
5
5
# Header IO
6
6
7
- @enum Format Format_ascii Format_binary_little Format_binary_big
8
-
9
7
function ply_type (type_name)
10
8
if type_name == " char" || type_name == " int8" ; return Int8
11
9
elseif type_name == " short" || type_name == " int16" ; return Int16
@@ -141,9 +139,10 @@ function write_header_field(stream::IO, comment::PlyComment)
141
139
println (stream, prefix, comment. comment)
142
140
end
143
141
144
- function write_header (ply, stream:: IO , ascii )
142
+ function write_header (ply, stream:: IO , format = ply . format )
145
143
println (stream, " ply" )
146
- if ascii
144
+ _check_native_endian (format)
145
+ if format == Format_ascii
147
146
println (stream, " format ascii 1.0" )
148
147
else
149
148
endianness = _host_is_little_endian ? " little" : " big"
@@ -309,6 +308,13 @@ function write_binary_values(stream::IO, elen, props::ArrayProperty{T}...) where
309
308
end
310
309
end
311
310
311
+ function _check_native_endian (format)
312
+ if _host_is_little_endian && format == Format_binary_big
313
+ error (" Reading big endian ply on little endian host is not implemented" )
314
+ elseif ! _host_is_little_endian && format == Format_binary_little
315
+ error (" Reading little endian ply on big endian host is not implemented" )
316
+ end
317
+ end
312
318
313
319
# -------------------------------------------------------------------------------
314
320
# High level IO for complete files
@@ -321,13 +327,7 @@ be a file name or an open stream.
321
327
"""
322
328
function load_ply (io:: IO )
323
329
elements, format, comments = read_header (io)
324
- if format != Format_ascii
325
- if _host_is_little_endian && format != Format_binary_little
326
- error (" Reading big endian ply on little endian host is not implemented" )
327
- elseif ! _host_is_little_endian && format != Format_binary_big
328
- error (" Reading little endian ply on big endian host is not implemented" )
329
- end
330
- end
330
+ _check_native_endian (format)
331
331
for element in elements
332
332
for prop in element. properties
333
333
resize! (prop, length (element))
@@ -338,11 +338,11 @@ function load_ply(io::IO)
338
338
read_ascii_value! (io, prop, i)
339
339
end
340
340
end
341
- else # format == Format_binary_little
341
+ else
342
342
read_binary_values! (io, length (element), element. properties... )
343
343
end
344
344
end
345
- Ply (elements, comments)
345
+ Ply (format, elements, comments)
346
346
end
347
347
348
348
function load_ply (file_name:: AbstractString )
@@ -359,10 +359,14 @@ Save data from `Ply` data structure into `file` which may be a filename or an
359
359
open stream. The file will be native endian binary, unless the keyword
360
360
argument `ascii` is set to `true`.
361
361
"""
362
- function save_ply (ply, stream:: IO ; ascii:: Bool = false )
363
- write_header (ply, stream, ascii)
362
+ function save_ply (ply, stream:: IO ; ascii= nothing )
363
+ format = ascii === nothing ? ply. format :
364
+ ascii ? Format_ascii :
365
+ _host_is_little_endian ? Format_binary_little :
366
+ Format_binary_big
367
+ write_header (ply, stream, format)
364
368
for element in ply
365
- if ascii
369
+ if format == Format_ascii
366
370
for i= 1 : length (element)
367
371
for (j,property) in enumerate (element. properties)
368
372
if j != 1
0 commit comments