-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmat_demo.py
More file actions
executable file
·77 lines (59 loc) · 2.13 KB
/
mat_demo.py
File metadata and controls
executable file
·77 lines (59 loc) · 2.13 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
import Geo
# Import the matlab module only after you have imported
# MATLAB Compiler SDK generated Python modules.
import matlab
import redis
import json
# Connect to Redis server
r = redis.Redis(host='localhost', port=6379, db=0)
# Add items to the queue
queue_name = 'matlab_data'
# filename = 'data/bent_pipe_closed_lr.off'
filename = 'data/spot_rr.off'
def load_off_file(filename):
with open(filename, 'r') as file:
if 'OFF' != file.readline().strip():
raise ValueError('Not a valid OFF header')
n_verts, n_faces, _ = map(int, file.readline().strip().split(' '))
vertices = []
for _ in range(n_verts):
vertices.extend(map(float, file.readline().strip().split(' ')))
vertices = [vertices[i:i + 3] for i in range(0, len(vertices), 3)]
faces = []
for _ in range(n_faces):
face = list(map(int, file.readline().strip().split(' ')))
faces.append(face[1:])
return vertices, faces
try:
my_Geo = Geo.initialize()
except Exception as e:
print('Error initializing Geo package\\n:{}'.format(e))
exit(1)
try:
vertices, faces = load_off_file(filename)
vIn = matlab.double(vertices)
# Adjust indices from 0-based to 1-based
faces_matlab = [[index + 1 for index in face] for face in faces]
fIn = matlab.double(faces_matlab)
x0In = matlab.double([2273], size=(1, 1))
given_vf_facesIn = matlab.double([4736, 2703], size=(1, 2))
given_vf_valsIn = matlab.double([1.6256, 1.6952, -0.3518, 0.3193, -0.6234, 0.0335], size=(2, 3))
u_vfaOut = my_Geo.geo(vIn, fIn, x0In, given_vf_facesIn, given_vf_valsIn)
print(u_vfaOut, sep='\\n')
print("Dimensions of u_vfaOut:", u_vfaOut.size)
print("val: ", u_vfaOut[0])
gd = []
for elem in u_vfaOut:
gd.append(elem[0])
print("Dimensions of gd:", len(gd))
data = {
'vertices': vertices,
'faces': faces,
'u_vfaOut': gd
}
data_json = json.dumps(data)
r.lpush(queue_name, data_json)
except Exception as e:
print('Error occurred during program execution\\n:{}'.format(e))
my_Geo.terminate()