imageBrowser.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. import os
  2. import unittest
  3. from __main__ import vtk, qt, ctk, slicer
  4. from slicer.ScriptedLoadableModule import *
  5. import json
  6. import datetime
  7. import sys
  8. import nixModule
  9. import pathlib
  10. import chardet
  11. import re
  12. #
  13. # labkeySlicerPythonExtension
  14. #
  15. class imageBrowser(ScriptedLoadableModule):
  16. """Uses ScriptedLoadableModule base class, available at:
  17. https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
  18. """
  19. def __init__(self, parent):
  20. ScriptedLoadableModule.__init__(self, parent)
  21. self.parent.title = "image Browser"
  22. # TODO make this more human readable by adding spaces
  23. self.parent.categories = ["LabKey"]
  24. self.parent.dependencies = []
  25. self.parent.contributors = ["Andrej Studen (UL/FMF)"]
  26. # replace with "Firstname Lastname (Organization)"
  27. self.parent.helpText = """
  28. Interface to irAEMM files in LabKey
  29. """
  30. self.parent.acknowledgementText = """
  31. Developed within the medical physics research programme
  32. of the Slovenian research agency.
  33. """ # replace with organization, grant and thanks.
  34. #
  35. # labkeySlicerPythonExtensionWidget
  36. #
  37. class imageBrowserWidget(ScriptedLoadableModuleWidget):
  38. """Uses ScriptedLoadableModuleWidget base class, available at:
  39. https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
  40. """
  41. def setup(self):
  42. print("Setting up imageBrowserWidget")
  43. ScriptedLoadableModuleWidget.setup(self)
  44. # Instantiate and connect widgets ...
  45. self.logic=imageBrowserLogic(self)
  46. self.addInfoSection()
  47. self.addSetupSection()
  48. self.addPatientsSelector()
  49. def addInfoSection(self):
  50. #a python overview of json settings
  51. infoCollapsibleButton = ctk.ctkCollapsibleButton()
  52. infoCollapsibleButton.text = "Info"
  53. self.layout.addWidget(infoCollapsibleButton)
  54. infoLayout = qt.QFormLayout(infoCollapsibleButton)
  55. self.participantField=qt.QLabel("PatientId")
  56. infoLayout.addRow("Participant field:",self.participantField)
  57. self.ctField=qt.QLabel("ctResampled")
  58. infoLayout.addRow("Data field (CT):",self.ctField)
  59. self.petField=qt.QLabel("petResampled")
  60. infoLayout.addRow("Data field (PET):",self.petField)
  61. self.userField=qt.QLabel("Loading")
  62. infoLayout.addRow("User",self.userField)
  63. self.idField=qt.QLabel("Loading")
  64. infoLayout.addRow("ID",self.idField)
  65. #Add logic at some point
  66. #self.logic=imageBrowserLogic(self)
  67. def updatePatientList(self,ids):
  68. self.patientList.clear()
  69. for id in ids:
  70. self.patientList.addItem(id)
  71. def addPatientsSelector(self):
  72. #
  73. # Patients Area
  74. #
  75. patientsCollapsibleButton = ctk.ctkCollapsibleButton()
  76. patientsCollapsibleButton.text = "Patients"
  77. #don't add it yet
  78. self.layout.addWidget(patientsCollapsibleButton)
  79. patientsFormLayout = qt.QFormLayout(patientsCollapsibleButton)
  80. self.patientList=qt.QComboBox()
  81. self.patientList.currentIndexChanged.connect(self.onPatientListChanged)
  82. patientsFormLayout.addRow("Patient:",self.patientList)
  83. self.visitList=qt.QComboBox()
  84. self.visitList.currentIndexChanged.connect(self.onVisitListChanged)
  85. patientsFormLayout.addRow("Visit:",self.visitList)
  86. self.ctCode=qt.QLabel("ctCode")
  87. patientsFormLayout.addRow("CT:",self.ctCode)
  88. self.petCode=qt.QLabel("petCode")
  89. patientsFormLayout.addRow("PET:",self.petCode)
  90. self.patientLoad=qt.QPushButton("Load")
  91. self.patientLoad.clicked.connect(self.onPatientLoadButtonClicked)
  92. patientsFormLayout.addRow("Load patient",self.patientLoad)
  93. self.patientSave=qt.QPushButton("Save")
  94. self.patientSave.clicked.connect(self.onPatientSaveButtonClicked)
  95. patientsFormLayout.addRow("Save segmentation",self.patientSave)
  96. self.patientClear=qt.QPushButton("Clear")
  97. self.patientClear.clicked.connect(self.onPatientClearButtonClicked)
  98. patientsFormLayout.addRow("Clear patient",self.patientClear)
  99. self.keepCached=qt.QCheckBox("keep Cached")
  100. self.keepCached.setChecked(1)
  101. patientsFormLayout.addRow("Keep cached",self.keepCached)
  102. def addSetupSection(self):
  103. setupCollapsibleButton = ctk.ctkCollapsibleButton()
  104. setupCollapsibleButton.text = "Setup"
  105. self.layout.addWidget(setupCollapsibleButton)
  106. #Form layout (maybe one can think of more intuitive layouts)
  107. setupFormLayout = qt.QFormLayout(setupCollapsibleButton)
  108. self.serverList=qt.QComboBox()
  109. self.serverList.addItem('<Select>')
  110. self.serverList.addItem("astuden")
  111. self.serverList.currentIndexChanged.connect(self.onServerListChanged)
  112. setupFormLayout.addRow("Database:",self.serverList)
  113. self.setupList=qt.QComboBox()
  114. self.setupList.addItem('<Select>')
  115. self.setupList.addItem("limfomiPET_iBrowser.json")
  116. self.setupList.currentIndexChanged.connect(self.onSetupListChanged)
  117. setupFormLayout.addRow("Setup:",self.setupList)
  118. def addReviewSection(self):
  119. #
  120. # Review Area
  121. #
  122. reviewCollapsibleButton = ctk.ctkCollapsibleButton()
  123. reviewCollapsibleButton.text = "Review"
  124. self.layout.addWidget(reviewCollapsibleButton)
  125. self.reviewBoxLayout = qt.QVBoxLayout(reviewCollapsibleButton)
  126. self.reviewFormLayout = qt.QFormLayout()
  127. self.reviewSegment=qt.QComboBox()
  128. self.reviewSegment.currentIndexChanged.connect(\
  129. self.onReviewSegmentChanged)
  130. self.reviewFormLayout.addRow("Selected region:",self.reviewSegment)
  131. self.reviewResult=qt.QComboBox()
  132. sLabel="What do you think about the segmentation:"
  133. self.reviewFormLayout.addRow(sLabel,self.reviewResult)
  134. reviewOptions=['Select','Excellent','Minor deficiencies',\
  135. 'Major deficiencies','Unusable']
  136. for opt in reviewOptions:
  137. self.reviewResult.addItem(opt)
  138. self.aeResult=qt.QComboBox()
  139. aeLabel="Is organ suffering from adverse effect?"
  140. self.reviewFormLayout.addRow(aeLabel,self.aeResult)
  141. aeOptions=['Select','Yes','No']
  142. for opt in aeOptions:
  143. self.aeResult.addItem(opt)
  144. #self.aeResult.setCurrentIndex(0)
  145. self.updateReview=qt.QPushButton("Save")
  146. saLabel="Save segmentation and AE decision for current segment"
  147. self.reviewFormLayout.addRow(saLabel,self.updateReview)
  148. self.updateReview.clicked.connect(self.onUpdateReviewButtonClicked)
  149. self.reviewBoxLayout.addLayout(self.reviewFormLayout)
  150. submitFrame=qt.QGroupBox("Submit data")
  151. self.submitFormLayout=qt.QFormLayout()
  152. self.reviewComment=qt.QTextEdit("this is a test")
  153. self.submitFormLayout.addRow("Comments (optional)",self.reviewComment)
  154. self.submitReviewButton=qt.QPushButton("Submit")
  155. self.submitFormLayout.addRow("Submit to database",\
  156. self.submitReviewButton)
  157. self.submitReviewButton.clicked.connect(\
  158. self.onSubmitReviewButtonClicked)
  159. submitFrame.setLayout(self.submitFormLayout)
  160. submitFrame.setFlat(1)
  161. #submitFrame.setFrameShape(qt.QFrame.StyledPanel)
  162. #submitFrame.setFrameShadow(qt.QFrame.Sunken)
  163. submitFrame.setStyleSheet("background-color:rgba(220,215,180,45)")
  164. self.reviewBoxLayout.addWidget(submitFrame)
  165. def onSetupListChanged(self,i):
  166. status=self.logic.setConfig(self.setupList.currentText)
  167. try:
  168. if status['error']=='FILE NOT FOUND':
  169. print('File {} not found.'.format(self.setupList.currentText))
  170. return
  171. except KeyError:
  172. pass
  173. self.updatePatientList(status['ids'])
  174. self.onPatientListChanged(0)
  175. def onServerListChanged(self,i):
  176. status=self.logic.setServer(self.serverList.currentText)
  177. try:
  178. if status['error']=='KEY ERROR':
  179. self.serverList.setStyleSheet('background-color: violet')
  180. if status['error']=='ID ERROR':
  181. self.serverList.setStyleSheet('background-color: red')
  182. return
  183. except KeyError:
  184. pass
  185. self.idField.setText(status['id'])
  186. self.userField.setText(status['displayName'])
  187. self.serverList.setStyleSheet('background-color: green')
  188. def onPatientListChanged(self,i):
  189. idFilter={'variable':'PatientId',
  190. 'value':self.patientList.currentText,
  191. 'oper':'eq'}
  192. ds=self.logic.getDataset(dbFilter=[idFilter])
  193. seq=[int(row['SequenceNum']) for row in ds['rows']]
  194. self.visitList.clear()
  195. for s in seq:
  196. self.visitList.addItem("Visit "+str(s))
  197. self.onVisitListChanged(0)
  198. def onVisitListChanged(self,i):
  199. try:
  200. s=self.visitList.currentText.split(' ')[1]
  201. except IndexError:
  202. return
  203. print("Visit: Selected item: {}->{}".format(i,s))
  204. idFilter={'variable':'PatientId',\
  205. 'value':self.patientList.currentText,'oper':'eq'}
  206. sFilter={'variable':'SequenceNum','value':s,'oper':'eq'}
  207. ds=self.logic.getDataset(dbFilter=[idFilter,sFilter])
  208. if not len(ds['rows'])==1:
  209. print("Found incorrect number {} of matches for [{}]/[{}]".\
  210. format(len(ds['rows']),\
  211. self.patientList.currentText,s))
  212. row=ds['rows'][0]
  213. #copy row properties for data access
  214. self.currentRow=row
  215. self.petCode.setText(row[self.petField.text])
  216. self.ctCode.setText(row[self.ctField.text])
  217. #self.segmentationCode.setText(row[self.segmentationField.text])
  218. def onPatientLoadButtonClicked(self):
  219. print("Load")
  220. #delegate loading to logic
  221. self.logic.loadImages(self.currentRow,self.keepCached.isChecked())
  222. self.logic.loadSegmentation(self.currentRow)
  223. #self.logic.loadReview(self.currentRow)
  224. #self.logic.loadAE(self.currentRow)
  225. #self.onReviewSegmentChanged()
  226. def onReviewSegmentChanged(self):
  227. pass
  228. def onPatientClearButtonClicked(self):
  229. self.logic.clearVolumesAndSegmentations()
  230. def onPatientSaveButtonClicked(self):
  231. self.logic.saveSegmentation()
  232. def cleanup(self):
  233. pass
  234. def loadLibrary(name):
  235. #utility function to load nix library from git
  236. fwrapper=nixModule.getWrapper('nixWrapper.py')
  237. p=pathlib.Path(fwrapper)
  238. sys.path.append(str(p.parent))
  239. import nixWrapper
  240. return nixWrapper.loadLibrary(name)
  241. #
  242. # imageBrowserLogic
  243. #
  244. class imageBrowserLogic(ScriptedLoadableModuleLogic):
  245. """This class should implement all the actual
  246. computation done by your module. The interface
  247. should be such that other python code can import
  248. this class and make use of the functionality without
  249. requiring an instance of the Widget.
  250. Uses ScriptedLoadableModuleLogic base class, available at:
  251. https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
  252. """
  253. def __init__(self,parent=None):
  254. ScriptedLoadableModuleLogic.__init__(self, parent)
  255. print('imageBrowserLogic loading')
  256. if not parent==None:
  257. #use layout and data from parent widget
  258. self.parent=parent
  259. fhome=os.path.expanduser('~')
  260. fsetup=os.path.join(fhome,'.labkey','setup.json')
  261. try:
  262. with open(fsetup) as f:
  263. self.setup=json.load(f)
  264. except FileNotFoundError:
  265. self.setup={}
  266. try:
  267. pt=self.setup['paths']
  268. except KeyError:
  269. self.setup['paths']={}
  270. lName='labkeyInterface'
  271. loadLibrary(lName)
  272. import labkeyInterface
  273. import labkeyDatabaseBrowser
  274. import labkeyFileBrowser
  275. self.network=labkeyInterface.labkeyInterface()
  276. self.dbBrowser=labkeyDatabaseBrowser
  277. self.fBrowser=labkeyFileBrowser
  278. self.tempDir=os.path.join(os.path.expanduser('~'),'temp')
  279. if not os.path.isdir(self.tempDir):
  280. os.mkdir(self.tempDir)
  281. print('imageBrowserLogic setup complete')
  282. def setServer(self,serverName):
  283. #additional way of setting the labkey network interface
  284. #if no parent was provided in logic initialization (stand-alone mode)
  285. status={}
  286. fileName="NONE"
  287. if serverName=="astuden":
  288. fileName="astuden.json"
  289. if fileName=="NONE":
  290. print("No path was associated with server {}".format(serverName))
  291. status['error']='KEY ERROR'
  292. return status
  293. fconfig=os.path.join(os.path.expanduser('~'),'.labkey',fileName)
  294. self.network.init(fconfig)
  295. self.remoteId=self.network.getUserId()
  296. if self.remoteId==None:
  297. status['error']='ID ERROR'
  298. return status
  299. status['displayName']=self.remoteId['displayName']
  300. status['id']=self.remoteId['id']
  301. #reset db and fb (they are thin classes anyhow)
  302. self.db=self.dbBrowser.labkeyDB(self.network)
  303. self.fb=self.fBrowser.labkeyFileBrowser(self.network)
  304. return status
  305. def setConfig(self,configName):
  306. status={}
  307. fileName=os.path.join(os.path.expanduser('~'),'.labkey',configName)
  308. if not os.path.isfile(fileName):
  309. status['error']='FILE NOT FOUND'
  310. return status
  311. with open(fileName,'r') as f:
  312. self.isetup=json.load(f)
  313. #self.project=self.isetup['project']
  314. #"iPNUMMretro/Study"
  315. #self.schema='study'
  316. #self.dataset=self.isetup['query']
  317. ds=self.getDataset()
  318. ids=[row[self.isetup['participantField']] for row in ds['rows']]
  319. status['ids']=list(set(ids))
  320. return status
  321. def getDataset(self,name="Imaging",dbFilter=[]):
  322. dset=self.isetup['datasets'][name]
  323. project=dset['project']
  324. schema=dset['schema']
  325. query=dset['query']
  326. try:
  327. return self.db.selectRows(project,schema,query, \
  328. dbFilter,dset['view'])
  329. except KeyError:
  330. return self.db.selectRows(project,schema,query,dbFilter)
  331. def loadImage(self,iData):
  332. #unpack iData
  333. idx=iData['idx']
  334. path=iData['path']
  335. keepCached=iData['keepCached']
  336. dset=self.isetup['datasets'][iData['dataset']]
  337. localPath=os.path.join(self.tempDir,path[-1])
  338. if not os.path.isfile(localPath):
  339. #download from server
  340. remotePath=self.fb.formatPathURL(dset['project'],'/'.join(path))
  341. if not self.fb.entryExists(remotePath):
  342. print("Failed to get {}".format(remotePath))
  343. return
  344. self.fb.readFileToFile(remotePath,localPath)
  345. properties={}
  346. filetype='VolumeFile'
  347. #make sure segmentation gets loaded as a labelmap
  348. if idx=="Segmentation":
  349. filetype='SegmentationFile'
  350. #properties["labelmap"]=1
  351. self.volumeNode[idx]=slicer.util.loadNodeFromFile(localPath,
  352. filetype=filetype,properties=properties)
  353. if not keepCached:
  354. os.remove(localPath)
  355. def loadImages(self,row,keepCached):
  356. #fields={'ctResampled':True,'petResampled':False}
  357. fields={"CT":self.parent.ctField.text,\
  358. "PET":self.parent.petField.text}
  359. path=[self.isetup['imageDir'],row['patientCode'],row['visitCode']]
  360. relativePaths={x:path+[row[y]] for (x,y) in fields.items()}
  361. self.volumeNode={}
  362. for f in relativePaths:
  363. iData={'idx':f,'path':relativePaths[f],
  364. 'keepCached':keepCached,'dataset':'Imaging'}
  365. self.loadImage(iData)
  366. #mimic abdominalCT standardized window setting
  367. self.volumeNode['CT'].GetScalarVolumeDisplayNode().\
  368. SetWindowLevel(1400, -500)
  369. #set colormap for PET to PET-Heat (this is a verbatim setting from
  370. #the Volumes->Display->Lookup Table colormap identifier)
  371. self.volumeNode['PET'].GetScalarVolumeDisplayNode().\
  372. SetAndObserveColorNodeID(\
  373. slicer.util.getNode('PET-Heat').GetID())
  374. slicer.util.setSliceViewerLayers(background=self.volumeNode['CT'],\
  375. foreground=self.volumeNode['PET'],foregroundOpacity=0.5,fit=True)
  376. def loadSegmentation(self,row):
  377. userFilter={'variable':'User','value':'{}'.format(self.remoteId['id']),
  378. 'oper':'eq'}
  379. pField=self.isetup['participantField']
  380. idFilter={'variable':pField,'value':row[pField],'oper':'eq'}
  381. visitFilter={'variable':'visitCode','value':row['visitCode'],'oper':'eq'}
  382. ds=self.getDataset(name='SegmentationsMaster',
  383. dbFilter=[idFilter,visitFilter,userFilter])
  384. if len(ds['rows'])>1:
  385. print('Multiple segmentations found!')
  386. return
  387. if len(ds['rows'])==1:
  388. #update self.segmentationEntry
  389. self.segmentationEntry=ds['rows'][0]
  390. self.segmentationEntry['origin']='database'
  391. self.loadSegmentationFromEntry()
  392. return
  393. #create new segmentation
  394. self.createSegmentation(row)
  395. def getSegmentationPath(self):
  396. path=[self.isetup['imageDir'],
  397. self.segmentationEntry['patientCode'],
  398. self.segmentationEntry['visitCode']]
  399. path.append('Segmentations')
  400. return path
  401. def loadSegmentationFromEntry(self):
  402. #compile path
  403. entry=self.segmentationEntry
  404. path=self.getSegmentationPath()
  405. path.append(entry['latestFile'])
  406. iData={'idx':'Segmentation','path':path,
  407. 'keepCached':0,'dataset':'SegmentationsMaster'}
  408. self.loadImage(iData)
  409. def saveSegmentation(self):
  410. #get the latest key by adding an entry to SegmentationList
  411. copyFields=['ParticipantId','patientCode','visitCode','User']
  412. outRow={x:self.segmentationEntry[x] for x in copyFields}
  413. sList=self.isetup['datasets']['SegmentationsList']
  414. resp=self.db.modifyRows('insert',sList['project'],
  415. sList['schema'],sList['query'],[outRow])
  416. encoding=chardet.detect(resp)['encoding']
  417. respJSON=json.loads(resp.decode(encoding))
  418. outRow=respJSON['rows'][0]
  419. #print(outRow)
  420. #construct file name with known key
  421. uName=re.sub(' ','_',self.remoteId['displayName'])
  422. fName='Segmentation_{}-{}_{}_{}.nrrd'.format(
  423. self.segmentationEntry['patientCode'],
  424. self.segmentationEntry['visitCode'],
  425. uName,outRow['Key'])
  426. path=self.getSegmentationPath()
  427. path.append(fName)
  428. self.saveNode(self.volumeNode['Segmentation'],'SegmentationsMaster',path)
  429. #update SegmentationList with know file name
  430. outRow['Segmentation']=fName
  431. self.db.modifyRows('update',sList['project'],
  432. sList['schema'],sList['query'],[outRow])
  433. #update SegmentationsMaster
  434. self.segmentationEntry['latestFile']=fName
  435. self.segmentationEntry['version']=outRow['Key']
  436. des=self.isetup['datasets']['SegmentationsMaster']
  437. op='insert'
  438. if self.segmentationEntry['origin']=='database':
  439. op='update'
  440. self.db.modifyRows(op,des['project'],
  441. des['schema'],des['query'],[self.segmentationEntry])
  442. #since we loaded a version, origin should be set to dataset
  443. self.segmentationEntry['origin']='dataset'
  444. def saveNode(self,node,dataset,path):
  445. fName=path[-1]
  446. localPath=os.path.join(self.tempDir,fName)
  447. slicer.util.saveNode(node,localPath)
  448. dset=self.isetup['datasets'][dataset]
  449. #exclude file name when building directory structure
  450. remotePath=self.fb.buildPathURL(dset['project'],path[:-1])
  451. remotePath+='/'+fName
  452. self.fb.writeFileToFile(localPath,remotePath)
  453. #add entry to segmentation list
  454. def createSegmentation(self,entry):
  455. #create segmentation entry for database update
  456. #note that origin is not set to database
  457. copyFields=['ParticipantId','patientCode','visitCode','SequenceNum']
  458. self.segmentationEntry={x:entry[x] for x in copyFields}
  459. self.segmentationEntry['User']=self.remoteId['id']
  460. self.segmentationEntry['origin']='created'
  461. self.segmentationEntry['version']=-1111
  462. #create a segmentation node
  463. uName=re.sub(' ','_',self.remoteId['displayName'])
  464. segNode=slicer.vtkMRMLSegmentationNode()
  465. self.volumeNode['Segmentation']=segNode
  466. segNode.SetName('Segmentation_{}_{}_{}'.
  467. format(entry['patientCode'],entry['visitCode'],uName))
  468. slicer.mrmlScene.AddNode(segNode)
  469. segNode.CreateDefaultDisplayNodes()
  470. segNode.SetReferenceImageGeometryParameterFromVolumeNode(self.volumeNode['PET'])
  471. segNode.GetSegmentation().AddEmptySegment("Lesion","Lesion")
  472. def clearVolumesAndSegmentations(self):
  473. nodes=slicer.util.getNodesByClass("vtkMRMLVolumeNode")
  474. nodes.extend(slicer.util.getNodesByClass("vtkMRMLSegmentationNode"))
  475. res=[slicer.mrmlScene.RemoveNode(f) for f in nodes]
  476. #self.segmentationNode=None
  477. #self.reviewResult={}
  478. #self.aeList={}
  479. class imageBrowserTest(ScriptedLoadableModuleTest):
  480. """
  481. This is the test case for your scripted module.
  482. Uses ScriptedLoadableModuleTest base class, available at:
  483. https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
  484. """
  485. def setup(self):
  486. """ Do whatever is needed to reset the state - typically a scene clear will be enough.
  487. """
  488. slicer.mrmlScene.Clear(0)
  489. def runTest(self):
  490. """Run as few or as many tests as needed here.
  491. """
  492. self.setUp()
  493. self.test_irAEMMBrowser()
  494. def test_irAEMMBrowser(self):
  495. """ Ideally you should have several levels of tests. At the lowest level
  496. tests sould exercise the functionality of the logic with different inputs
  497. (both valid and invalid). At higher levels your tests should emulate the
  498. way the user would interact with your code and confirm that it still works
  499. the way you intended.
  500. One of the most important features of the tests is that it should alert other
  501. developers when their changes will have an impact on the behavior of your
  502. module. For example, if a developer removes a feature that you depend on,
  503. your test should break so they know that the feature is needed.
  504. """
  505. self.delayDisplay("Starting the test")
  506. #
  507. # first, get some data
  508. #