Commit 23bc2c04bec59b166c8877d0ab318c758b96cbb0

Authored by Andrey Zhdanov
Committed by GitHub
1 parent 5edcfb7d
Exists in master

Markers code cleanup (#364)

* Removed the legacy (.mks) marker loading code.

* minor cleanup
Showing 1 changed file with 7 additions and 75 deletions   Show diff stats
invesalius/gui/task_navigator.py
... ... @@ -504,14 +504,14 @@ class NeuronavigationPanel(wx.Panel):
504 504 Publisher.subscribe(self.OnStartNavigation, 'Start navigation')
505 505 Publisher.subscribe(self.OnStopNavigation, 'Stop navigation')
506 506  
507   - def LoadImageFiducials(self, marker_id, coord):
508   - fiducial = self.GetFiducialByAttribute(const.IMAGE_FIDUCIALS, 'label', marker_id)
  507 + def LoadImageFiducials(self, label, coord):
  508 + fiducial = self.GetFiducialByAttribute(const.IMAGE_FIDUCIALS, 'label', label)
509 509  
510 510 fiducial_index = fiducial['fiducial_index']
511 511 fiducial_name = fiducial['fiducial_name']
512 512  
513 513 if self.btns_set_fiducial[fiducial_index].GetValue():
514   - print("Fiducial {} already set, not resetting".format(marker_id))
  514 + print("Fiducial {} already set, not resetting".format(label))
515 515 return
516 516  
517 517 Publisher.sendMessage('Set image fiducial', fiducial_name=fiducial_name, coord=coord[0:3])
... ... @@ -1350,77 +1350,12 @@ class MarkersPanel(wx.Panel):
1350 1350 def OnLoadMarkers(self, evt):
1351 1351 filename = dlg.ShowLoadSaveDialog(message=_(u"Load markers"),
1352 1352 wildcard=const.WILDCARD_MARKER_FILES)
1353   -
1354   - def __legacy_load_markers(filename):
1355   - """Code for loading markers in the old .mks format. To be deprecated at some point."""
1356   - try:
1357   - count_line = self.lc.GetItemCount()
1358 1353  
1359   - # read lines from the file
1360   - with open(filename, 'r') as file:
1361   - reader = csv.reader(file, delimiter='\t')
1362   - content = [row for row in reader]
1363   -
1364   - # parse the lines and update the markers list
1365   - for line in content:
1366   - target = None
1367   - if len(line) > 8:
1368   - coord = [float(s) for s in line[:6]]
1369   - colour = [float(s) for s in line[6:9]]
1370   - size = float(line[9])
1371   - marker_id = line[10]
1372   -
1373   - if len(line) > 11:
1374   - seed = [float(s) for s in line[11:14]]
1375   - else:
1376   - seed = 3 * [0.]
1377   -
1378   - if len(line) >= 11:
1379   - for i in const.BTNS_IMG_MARKERS:
1380   - if marker_id in list(const.BTNS_IMG_MARKERS[i].values())[0]:
1381   - Publisher.sendMessage('Load image fiducials', marker_id=marker_id, coord=coord)
1382   - elif marker_id == 'TARGET':
1383   - target = count_line
1384   - else:
1385   - marker_id = '*'
1386   -
1387   - if len(line) == 15:
1388   - target_id = line[14]
1389   - else:
1390   - target_id = '*'
1391   - else:
1392   - # for compatibility with previous version without the extra seed and target columns
1393   - coord = float(line[0]), float(line[1]), float(line[2]), 0, 0, 0
1394   - colour = float(line[3]), float(line[4]), float(line[5])
1395   - size = float(line[6])
1396   -
1397   - seed = 3 * [0]
1398   - target_id = '*'
1399   -
1400   - if len(line) == 8:
1401   - marker_id = line[7]
1402   - for i in const.BTNS_IMG_MARKERS:
1403   - if marker_id in list(const.BTNS_IMG_MARKERS[i].values())[0]:
1404   - Publisher.sendMessage('Load image fiducials', marker_id=marker_id, coord=coord)
1405   - else:
1406   - marker_id = '*'
1407   -
1408   - self.CreateMarker(coord=coord, colour=colour, size=size,
1409   - label=marker_id, target_id=target_id, seed=seed)
1410   -
1411   - # if there are multiple TARGETS will set the last one
1412   - if target:
1413   - self.OnMenuSetTarget(target)
1414   -
1415   - count_line += 1
1416   - except:
1417   - wx.MessageBox(_("Invalid markers file."), _("InVesalius 3"))
1418   -
1419 1354 if not filename:
1420 1355 return
1421 1356  
1422 1357 if filename.lower().endswith('.mks'):
1423   - __legacy_load_markers(filename)
  1358 + wx.MessageBox(_(".mks files are no longer supported. Convert them to .mkss with the conversion tool."), _("InVesalius 3"))
1424 1359 return
1425 1360  
1426 1361 # Treat any extension othjer than .mks as 'new' format that has magick
... ... @@ -1502,12 +1437,9 @@ class MarkersPanel(wx.Panel):
1502 1437 if filename:
1503 1438 if self.list_coord:
1504 1439 with open(filename, 'w', newline='') as file:
1505   - if filename.lower().endswith('.mks'):
1506   - writer = csv.writer(file, delimiter='\t')
1507   - else:
1508   - file.writelines(['%s%i\n' % (const.MARKER_FILE_MAGICK_STRING, const.CURRENT_MARKER_FILE_VERSION)])
1509   - writer = csv.writer(file, dialect='markers_dialect')
1510   - writer.writerow(header_titles)
  1440 + file.writelines(['%s%i\n' % (const.MARKER_FILE_MAGICK_STRING, const.CURRENT_MARKER_FILE_VERSION)])
  1441 + writer = csv.writer(file, dialect='markers_dialect')
  1442 + writer.writerow(header_titles)
1511 1443  
1512 1444 writer.writerows(self.list_coord)
1513 1445  
... ...