Example #1
0
    def addRow(self, c):
        name = self.colorNode.GetColorName(c)
        lut = self.colorNode.GetLookupTable()
        rgb = lut.GetTableValue(c)
        brush = qt.QBrush()
        self.brushes.append(brush)
        color = qt.QColor()
        color.setRgb(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255)
        brush.setColor(color)

        # index
        item = qt.QStandardItem()
        item.setText(str(c))
        self.model.setItem(self.row, 0, item)
        self.items.append(item)
        # color
        item = qt.QStandardItem()
        item.setData(color, 1)
        self.model.setItem(self.row, 1, item)
        self.items.append(item)
        # name
        item = qt.QStandardItem()
        item.setText(self.colorNode.GetColorName(c))
        self.model.setItem(self.row, 2, item)
        self.items.append(item)
        self.row += 1
def _newItemPlaceholderItem(parent):
  palette = parent.palette
  color = qt.QColor(palette.text().color())
  color.setAlphaF(0.5)

  item = qt.QTreeWidgetItem()
  item.setText(0, "(New item)")
  item.setForeground(0, qt.QBrush(color))

  return item
Example #3
0
    def updateStructures(self, caller=None, event=None):
        """re-build the Structures frame
    - optional caller and event ignored (for use as vtk observer callback)
    """

        if self.setMergeButton.destroyed():
            """ TODO: here the python class still exists but the 
      Qt widgets are gone - need to figure out when to remove observers 
      and free python code - probably the destroyed() signal.
      """
            self.cleanup()
            return

        self.setMergeButton.setDisabled(not self.master)

        # reset to a fresh model
        self.brushes = []
        self.items = []
        self.structures = qt.QStandardItemModel()
        self.structuresView.setModel(self.structures)

        # if no merge volume exists, disable everything - else enable
        merge = self.mergeVolume()
        self.addStructureButton.setDisabled(not merge)
        self.deleteStructuresButton.setDisabled(not merge)
        self.mergeButton.setDisabled(not merge)
        self.splitButton.setDisabled(not merge)
        self.mergeAndBuildButton.setDisabled(not merge)
        self.replaceModels.setDisabled(not merge)
        if self.mergeValidCommand:
            # will be passed current
            self.mergeValidCommand(merge)

        if not merge:
            return

        colorNode = merge.GetDisplayNode().GetColorNode()
        lut = colorNode.GetLookupTable()

        masterName = self.master.GetName()
        slicer.mrmlScene.InitTraversal()
        vNode = slicer.mrmlScene.GetNextNodeByClass("vtkMRMLScalarVolumeNode")
        self.row = 0
        while vNode:
            vName = vNode.GetName()
            # match something like "CT-lung-label1"
            regexp = "%s-.*-label" % masterName
            if re.match(regexp, vName):
                # figure out what name it is
                # - account for the fact that sometimes a number will be added to the end of the name
                start = 1 + len(masterName)
                end = vName.rfind("-label")
                structureName = vName[start:end]
                structureIndex = colorNode.GetColorIndexByName(structureName)
                structureColor = lut.GetTableValue(structureIndex)[0:3]
                brush = qt.QBrush()
                self.brushes.append(brush)
                color = qt.QColor()
                color.setRgb(structureColor[0] * 255, structureColor[1] * 255,
                             structureColor[2] * 255)
                brush.setColor(color)

                # label index
                item = qt.QStandardItem()
                item.setEditable(False)
                item.setText(str(structureIndex))
                self.structures.setItem(self.row, 0, item)
                self.items.append(item)
                # label color
                item = qt.QStandardItem()
                item.setEditable(False)
                item.setData(color, 1)
                self.structures.setItem(self.row, 1, item)
                self.items.append(item)
                # structure name
                item = qt.QStandardItem()
                item.setEditable(False)
                item.setText(structureName)
                self.structures.setItem(self.row, 2, item)
                self.items.append(item)
                # volumeName name
                item = qt.QStandardItem()
                item.setEditable(False)
                item.setText(vName)
                self.structures.setItem(self.row, 3, item)
                self.items.append(item)
                # sort order
                item = qt.QStandardItem()
                item.setEditable(True)
                item.setText("")
                self.structures.setItem(self.row, 4, item)
                self.items.append(item)
                self.row += 1

            vNode = slicer.mrmlScene.GetNextNodeByClass(
                "vtkMRMLScalarVolumeNode")

        self.structuresView.setColumnWidth(0, 70)
        self.structuresView.setColumnWidth(1, 50)
        self.structuresView.setColumnWidth(2, 60)
        self.structuresView.setColumnWidth(3, 100)
        self.structuresView.setColumnWidth(4, 10)
        self.structures.setHeaderData(0, 1, "Number")
        self.structures.setHeaderData(1, 1, "Color")
        self.structures.setHeaderData(2, 1, "Name")
        self.structures.setHeaderData(3, 1, "Label Volume")
        self.structures.setHeaderData(4, 1, "Order")
        self.structuresView.setModel(self.structures)
Example #4
0
  def updateStructures(self,caller=None, event=None):
    """re-build the Structures frame
    - optional caller and event ignored (for use as vtk observer callback)
    """

    if slicer.mrmlScene.IsBatchProcessing():
      return

    if self.setMergeButton.destroyed():
      """ TODO: here the python class still exists but the
      Qt widgets are gone - need to figure out when to remove observers
      and free python code - probably the destroyed() signal.
      """
      self.cleanup()
      return

    self.setMergeButton.setDisabled(not self.master)

    # reset to a fresh model
    self.brushes = []
    self.items = []
    self.structures = qt.QStandardItemModel()
    self.structuresView.setModel(self.structures)

    # if no merge volume exists, disable everything - else enable
    merge = self.mergeVolume()
    self.addStructureButton.setDisabled(not merge)
    self.deleteStructuresButton.setDisabled(not merge)
    self.mergeButton.setDisabled(not merge)
    self.splitButton.setDisabled(not merge)
    self.mergeAndBuildButton.setDisabled(not merge)
    self.replaceModels.setDisabled(not merge)
    if self.mergeValidCommand:
      # will be passed current
      self.mergeValidCommand(merge)

    if not merge:
      return

    colorNode = merge.GetDisplayNode().GetColorNode()
    lut = colorNode.GetLookupTable()

    masterName = self.master.GetName()
    volumeNodes = self.structureVolumes()
    for vNode in volumeNodes:
      vName = vNode.GetName()
      # figure out what name it is
      # - account for the fact that sometimes a number will be added to the end of the name
      start = 1+len(masterName)
      end = vName.rfind("-label")
      structureName = vName[start:end]
      structureIndex = colorNode.GetColorIndexByName( structureName )
      structureColor = lut.GetTableValue(structureIndex)[0:3]
      brush = qt.QBrush()
      self.brushes.append(brush)
      color = qt.QColor()
      color.setRgb(structureColor[0]*255,structureColor[1]*255,structureColor[2]*255)
      brush.setColor(color)

      # label index
      item = qt.QStandardItem()
      item.setEditable(False)
      item.setText( "%03d"%int(structureIndex) )
      self.structures.setItem(self.row,0,item)
      self.items.append(item)
      # label color
      item = qt.QStandardItem()
      item.setEditable(False)
      item.setData(color,1)
      self.structures.setItem(self.row,1,item)
      self.items.append(item)
      # structure name
      item = qt.QStandardItem()
      item.setEditable(False)
      item.setText(structureName)
      self.structures.setItem(self.row,2,item)
      self.items.append(item)
      # volumeName name
      item = qt.QStandardItem()
      item.setEditable(False)
      item.setText(vName)
      self.structures.setItem(self.row,3,item)
      self.items.append(item)
      # sort order
      item = qt.QStandardItem()
      item.setEditable(True)
      item.setText("")
      self.structures.setItem(self.row,4,item)
      self.items.append(item)
      self.row += 1

    for i in range(5):
      self.structuresView.resizeColumnToContents(i)

    self.structures.setHeaderData(0,1,"Number")
    self.structures.setHeaderData(1,1,"Color")
    self.structures.setHeaderData(2,1,"Name")
    self.structures.setHeaderData(3,1,"Label Volume")
    self.structures.setHeaderData(4,1,"Order")
    self.structuresView.setModel(self.structures)
    self.structuresView.connect("activated(QModelIndex)", self.onStructuresClicked)
    self.structuresView.setProperty('SH_ItemView_ActivateItemOnSingleClick', 1)

    self.structureLabelNames = []
    rows = self.structures.rowCount()
    for row in xrange(rows):
      self.structureLabelNames.append(self.structures.item(row,2).text())