in shapenet/utils/binvox_torch.py [0:0]
def _read_binvox_header(f):
# First line of the header should be "#binvox 1"
line = f.readline().strip()
if line != b"#binvox 1":
raise ValueError("Invalid header (line 1)")
# Second line of the header should be "dim [int] [int] [int]"
# and all three int should be the same
line = f.readline().strip()
if not line.startswith(b"dim "):
raise ValueError("Invalid header (line 2)")
dims = line.split(b" ")
try:
dims = [int(d) for d in dims[1:]]
except ValueError:
raise ValueError("Invalid header (line 2)")
if len(dims) != 3 or dims[0] != dims[1] or dims[0] != dims[2]:
raise ValueError("Invalid header (line 2)")
size = dims[0]
# Third line of the header should be "translate [float] [float] [float]"
line = f.readline().strip()
if not line.startswith(b"translate "):
raise ValueError("Invalid header (line 3)")
translation = line.split(b" ")
if len(translation) != 4:
raise ValueError("Invalid header (line 3)")
try:
translation = tuple(float(t) for t in translation[1:])
except ValueError:
raise ValueError("Invalid header (line 3)")
# Fourth line of the header should be "scale [float]"
line = f.readline().strip()
if not line.startswith(b"scale "):
raise ValueError("Invalid header (line 4)")
line = line.split(b" ")
if not len(line) == 2:
raise ValueError("Invalid header (line 4)")
scale = float(line[1])
# Fifth line of the header should be "data"
line = f.readline().strip()
if not line == b"data":
raise ValueError("Invalid header (line 5)")
return size, translation, scale