allow no cells for ply
@@ -83,7 +83,7 @@ def read_buffer(f):
# assert that the first line reads `ply`
line = f.readline().decode("utf-8").strip()
if line != "ply":
- raise ReadError()
+ raise ReadError("Expected ply")
line = _fast_forward(f)
if line == "format ascii 1.0":
@@ -97,29 +97,32 @@ def read_buffer(f):
is_binary = True
endianness = "<"
+ # read header
line = _fast_forward(f)
- m = re.match("element vertex (\\d+)", line)
+ num_verts = 0
+ num_cells = 0
+ point_data_formats = []
+ point_data_names = []
+ cell_data_names = []
+ cell_data_dtypes = []
+ while line != "end_header":
+ if m := re.match("element vertex (\\d+)", line):
num_verts = int(m.groups()[0])
# read point data
- point_data_formats = []
- point_data_names = []
line = _fast_forward(f)
while line[:8] == "property":
m = re.match("property (.+) (.+)", line)
point_data_formats.append(m.groups()[0])
point_data_names.append(m.groups()[1])
line = _fast_forward(f)
-
- m = re.match("element face (\\d+)", line)
+ elif m := re.match("element face (\\d+)", line):
num_cells = int(m.groups()[0])
assert num_cells >= 0
# read property lists
line = _fast_forward(f)
- cell_data_names = []
- cell_data_dtypes = []
# read cell data
while line[:8] == "property":
if line[:13] == "property list":
@@ -131,9 +134,6 @@ def read_buffer(f):
cell_data_names.append(m.groups()[-1])
line = _fast_forward(f)
- if line != "end_header":
- raise ReadError()
-
if is_binary:
mesh = _read_binary(
f,
