-
Notifications
You must be signed in to change notification settings - Fork 0
/
StructureSet.py
60 lines (52 loc) · 2.16 KB
/
StructureSet.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
# -*- coding: utf-8 -*-
import logging
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
# own modules
import dcmreader
class StructureSet:
def __init__(self, dcm, contourNames = []):
""" read in structure Set
Arguments:
dcm pydicom object of rtstruct
origin image origin of corresponding CT
contourNames names of structures to be read in
Returns:
None
"""
self.logger = logging.getLogger("StructureSet")
self.UID = ['1.2.840.10008.5.1.4.1.1.481.3','RT Structure Set Storage']
self.PatientName = dcm.PatientName
self.nStructures = len(dcm.StructureSetROISequence)
self.structureNames = [dcm.StructureSetROISequence[iStructure].ROIName for iStructure in range(len(dcm.StructureSetROISequence))]
try: self.StructureSetName = dcm.StructureSetName
except: self.StructureSetName = ""
self.structures = dict()
self.dcm = dcm
if contourNames != []:
self.readStructures(contourNames)
def readStructures(self, structureNames):
""" read structures in RTSTRUCT
Arguments:
structureNames list of names of structures
"""
self.selected_structures = structureNames
for iStructure in structureNames:
structure = self.getStructure(self.dcm, iStructure)
if structure != -1:
self.structures[iStructure] = structure
def getStructure(self, dcm, structureName):
""" read in structure with its contour points
Arguments:
dcm pydicom object of rtstruct
structureName name of the structure
Returns:
structure structure object
"""
structure = -1
try:
self.structureNames.index(structureName)
structure = dcmreader.Structure(dcm, structure = {"index": self.structureNames.index(structureName), "name":structureName})
except ValueError:
self.logger.error("Could not find structure in structure set " + structureName)
return structure