-
Notifications
You must be signed in to change notification settings - Fork 2
/
ImodContour.py
executable file
·47 lines (41 loc) · 1.47 KB
/
ImodContour.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import struct
class ImodContour(object):
def __init__(self,
fid = None,
nPoints = 0,
flags = 0,
type = 0,
iSurface = 0,
points = [],
pointSizes = [],
size_set = 0,
**kwargs):
self.__dict__.update(kwargs)
self.__dict__.update(locals())
self.size_vals = []
if self.fid:
self.read_file()
def read_file(self):
fid = self.fid
self.nPoints = struct.unpack('>l', fid.read(4))[0]
self.flags = struct.unpack('>l', fid.read(4))[0]
self.type = struct.unpack('>l', fid.read(4))[0]
self.iSurface = struct.unpack('>l', fid.read(4))[0]
self.points = struct.unpack('>{0}f'.format(3 * self.nPoints),
fid.read(12 * self.nPoints))
# Read the next data chunk. If it is SIZE, then set size_set to one and
# read the values from the binary file. If not, seek back and continue.
datatype = fid.read(4)
if datatype == 'SIZE':
self.size_set = 1
psize = struct.unpack('>l', fid.read(4))[0]
for i in range(0, psize, 4):
self.size_vals.append(struct.unpack('>f', fid.read(4))[0])
else:
fid.seek(-4, 1)
return self
def dump(self):
from collections import OrderedDict as od
for key, value in od(sorted(self.__dict__.items())).iteritems():
print key, value
print "\n"