-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix_slicer_markup.py
59 lines (52 loc) · 2.02 KB
/
fix_slicer_markup.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
# Load Packages
import sys
import os
import json
class pointNormalPlane(object):
"""
Class to represent point-Normal plane (that can be written to and from a .json file)
:param origin: list [x,y,z] with origin coordinates (float or int)
:param normal: list [a,b,c] with normal components (float or int)
:param orientation: 3-character string (e.g. 'RAS','LPS','LPI')
:param filename: string ending in .json
:param space: 'SCT_image' or 'anatomical'
"""
def __init__(self,origin,normal,orientation,space='SCT_image'):
self.origin = origin
self.normal = normal
self.orientation = orientation
self.space = space
@classmethod
def fromJsonFile(cls,filename):
with open(filename, "r") as f:
data=f.read()
dict_tmp=json.loads(data)
return(pointNormalPlane(origin=dict_tmp['origin'],normal=dict_tmp['normal'],orientation=dict_tmp['orientation'],space=dict_tmp['space']))
def write_plane_json(self,filename):
new_plane_dict_json = json.dumps(self.__dict__)
if (filename.endswith('json')):
with open(filename, "w") as f:
f.write(new_plane_dict_json)
else:
with open(f'{filename}.json', "w") as f:
f.write(new_plane_dict_json)
fname_in = sys.argv[1]
plane=pointNormalPlane.fromJsonFile(sys.argv[1])
print(plane.normal)
print(plane.origin)
slicer.util.loadScene('../../../input/2022-11-16-Scene.mrml')
input_Node = getNode("input-pointNormal-Plane-markup")
print(f'input plane normal: {input_Node.GetNormal()}')
print(f'input plane normal: {input_Node.GetOrigin()}')
print('\n')
input_Node.SetNormal(plane.normal)
input_Node.SetOrigin(plane.origin)
print('New plane values:')
print(f'new plane normal: {input_Node.GetNormal()}')
print(f'new plane origin: {input_Node.GetOrigin()}')
myStorageNode = input_Node.CreateDefaultStorageNode()
filename=f'markup_{fname_in}'
myStorageNode.SetFileName(filename)
myStorageNode.WriteData(input_Node)
myStorageNode.UnRegister(None)
sys.exit(0)