forked from andregouws/mrMeshPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp_Commands.py
executable file
·146 lines (104 loc) · 6.14 KB
/
mp_Commands.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/python
'''
Command module for mrMeshPy viewer
Commands and data are passed here from matab via the mrMeshPyServer.
Matlab sends a string in one transaction giving a command to the
visualisation module. This command either performs an explicit
function in the viewer (e.g. rotate the camera 90 degrees) or the
commnd describes the configuration/content of a large data chunk to
will be sent in the subsequent transaction so that we know how to
unpack the data, and how to process it (e.g. 70,000 floating point
numbers which are scalar values to show as an amplitude map.
Each command string is interpreted by the mp_commandInterpret module.
N.B. - currently command strings have a maximum length of 1024 bytes.
Commands are specifically ordered, semi-colon seperated strings which are
unpacked to describe what the user is trying to do / send from matlab.
Commands have a MINIMUM LENGTH of 6 arguments and have the following
structure and item order (zero-indexed)
0 - "cmd" -- always this, identifies it as a cmd :)
1-3 - place holders
4 - commandName - should match a command in mp_Commands file
5 - theMeshInstance - integer pointing to the the mesh window that we
want to operate on
6 onwards - commandArgs - a list of comma-separated pairs of arguments
to characterise the processing of the incoming data
blob or apply some settings to the viewport -
CAN BE EMPTY but must be set to []
Andre' Gouws 2017
'''
import vtk
import scipy.io #so we can read .mat files
import vtk
import vtk.util.numpy_support
from numpy import *
#local modules
from mp_setupVTKWindow import mrMeshVTKWindow
from mp_VTKRoutines import *
from mp_SendFunctions import *
debug = True
# master command handler
def run_mp_command(commandName, commandArgs, theMeshInstance, mainWindowUI, the_TCPserver):
if commandName == 'loadNewMesh':
mainWindowUI.statusbar.showMessage(' ... attempting to load new mesh ...')
# TODO - index will now be a new entry at the end of the exisitng .ui.vtkInstances list
newIndex = len(mainWindowUI.vtkInstances) #could be zero
# create an entry in the vtkDict to link the unique mesh ID to where it is stored
# in the vtkInstances list
mainWindowUI.vtkDict[theMeshInstance] = newIndex
# add a new tab with a new wVTK window
mrMeshVTKWindow(mainWindowUI, theMeshInstance, 'None')
mainWindowUI.tabWidget.setCurrentIndex(newIndex) #zero indexed
mainWindowUI.tabWidget.update()
#load data and generate the mesh
loadNewMesh(theMeshInstance, commandArgs, mainWindowUI, the_TCPserver)
mainWindowUI.statusbar.showMessage(' ... New mesh Loaded ...')
#the_TCPserver.socket.write(str('send useful message back here TODO'))
the_TCPserver.socket.write(str('1001'))
if debug: print mainWindowUI.vtkDict
elif commandName == 'smoothMesh':
mainWindowUI.statusbar.showMessage(' ... attempting to smooth mesh with id %s ...' %(theMeshInstance))
#load data and generate the mesh
err = smoothMesh(theMeshInstance, commandArgs, mainWindowUI, the_TCPserver)
if err == 0:
mainWindowUI.statusbar.showMessage(' ... Finished smoothing mesh with id %s ...' %(theMeshInstance))
the_TCPserver.socket.write(str('Mesh smooth complete'))
else:
mainWindowUI.statusbar.showMessage(' ... Error trying to smooth mesh with id %s ...' %(theMeshInstance))
the_TCPserver.socket.write(str('Mesh smooth failed'))
elif commandName == 'updateMeshData':
mainWindowUI.statusbar.showMessage(' ... updating mesh with id %s with current View settings ...' %(theMeshInstance))
#load data and send to the mesh
err = updateMeshData(theMeshInstance, commandArgs, mainWindowUI, the_TCPserver)
if err == 0:
mainWindowUI.statusbar.showMessage(' ... Finished: updated data for mesh id %s ...' %(theMeshInstance))
the_TCPserver.socket.write(str('Mesh update complete'))
else:
mainWindowUI.statusbar.showMessage(' ... Error trying to update mesh with id %s ...' %(theMeshInstance))
the_TCPserver.socket.write(str('Mesh update failed'))
elif commandName == 'checkMeshROI':
mainWindowUI.statusbar.showMessage(' ... MATLAB requested an ROI from mesh id %s ...' %(theMeshInstance))
#get roi data (if exists) and send to matlab
error = sendROIInfo(theMeshInstance, commandArgs, mainWindowUI, the_TCPserver) #returns 1 or 0
if error == 0:
mainWindowUI.statusbar.showMessage(' ... ROI ready to send to MATLAB from mesh id %s...' %(theMeshInstance))
else:
mainWindowUI.statusbar.showMessage(' ... No ROI to send to MATLAB from mesh id %s...' %(theMeshInstance))
the_TCPserver.socket.write(str('send useful message back here TODO'))
elif commandName == 'sendROIVertices':
mainWindowUI.statusbar.showMessage(' ... MATLAB requested an ROI from mesh id %s ...' %(theMeshInstance))
#get roi data (if exists) and send to matlab
error = sendROIVertices(theMeshInstance, commandArgs, mainWindowUI, the_TCPserver) #returns 1 or 0
if error == 0:
mainWindowUI.statusbar.showMessage(' ... ROI ready to send to MATLAB from mesh id %s...' %(theMeshInstance))
else:
mainWindowUI.statusbar.showMessage(' ... No ROI to send to MATLAB from mesh id %s...' %(theMeshInstance))
the_TCPserver.socket.write(str('send useful message back here TODO'))
elif commandName == 'rotateMeshAnimation':
mainWindowUI.statusbar.showMessage(' ... doing rotation animation ...')
#really just for testing initially
rotateMeshAnimation(theMeshInstance, commandArgs, mainWindowUI, the_TCPserver)
mainWindowUI.statusbar.showMessage(' ... Finished rotation animation ...')
the_TCPserver.socket.write(str('send useful message back here TODO'))
else:
print('mrMeshPy received a command it did not recognise')
the_TCPserver.socket.write(str('send cmd error message back here TODO'))