Exemple #1
0
  def mergeStructures(self,label="all"):
    """merge the named or all structure labels into the master label"""

    merge = self.mergeVolume()
    if not merge:
      return

    rows = self.structures.rowCount()

    # check that structures are all the same size as the merge volume
    dims = merge.GetImageData().GetDimensions()
    for row in xrange(rows):
      structureName = self.structures.item(row,2).text()
      structureVolume = self.structureVolume( structureName )
      if not structureVolume:
        mergeName = merge.GetName()
        self.errorDialog( "Merge Aborted: No image data for volume node %s."%(structureName) )
        return
      if structureVolume.GetImageData().GetDimensions() != dims:
        mergeName = merge.GetName()
        self.errorDialog( "Merge Aborted: Volume %s does not have the same dimensions as the target merge volume.  Use the Resample Scalar/Vector/DWI module to resample.  Use %s as the Reference Volume and select Nearest Neighbor (nn) Interpolation Type."%(structureName,mergeName) )
        return

    # check that user really wants to merge
    rows = self.structures.rowCount()
    for row in xrange(rows):
      structureName = self.structures.item(row,2).text()
      structureVolume = self.structureVolume( structureName)
      if structureVolume.GetImageData().GetMTime() < merge.GetImageData().GetMTime():
        mergeName = merge.GetName()
        self.errorDialog( "Note: Merge volume has been modified more recently than structure volumes.\nCreating backup copy as %s-backup"%mergeName )
        self.volumesLogic.CloneVolume( slicer.mrmlScene, merge, mergeName+"-backup" )

    #
    # find the Image Label Combine
    # - call Enter to be sure GUI has been built
    #
    combiner = slicer.vtkImageLabelCombine()

    #
    # iterate through structures merging into merge volume
    #
    for row in xrange(rows):
      structureName = self.structures.item(row,2).text()
      structureVolume = self.structureVolume( structureName )

      if row == 0:
        # first row, just copy into merge volume
        merge.GetImageData().DeepCopy( structureVolume.GetImageData() )
        continue

      combiner.SetInput1( merge.GetImageData() )
      combiner.SetInput2( structureVolume.GetImageData() )
      self.statusText( "Merging $structureName..." )
      combiner.Update()
      merge.GetImageData().DeepCopy( combiner.GetOutput() )

    # mark all volumes as modified so we will be able to tell if the 
    # merged volume gets edited after these
    for row in xrange(rows):
      structureName = self.structures.item(row,2).text()
      structureVolume = self.structureVolume( structureName )
      structureVolume.GetImageData().Modified()

    selectionNode = self.applicationLogic.GetSelectionNode()
    selectionNode.SetReferenceActiveVolumeID( self.master.GetID() )
    selectionNode.SetReferenceActiveLabelVolumeID( merge.GetID() )
    self.applicationLogic.PropagateVolumeSelection()

    self.statusText( "Finished merging." )
Exemple #2
0
    def mergeStructures(self, label="all"):
        """merge the named or all structure labels into the master label"""

        merge = self.mergeVolume()
        if not merge:
            return

        rows = self.structures.rowCount()

        # check that structures are all the same size as the merge volume
        dims = merge.GetImageData().GetDimensions()
        for row in xrange(rows):
            structureName = self.structures.item(row, 2).text()
            structureVolume = self.structureVolume(structureName)
            if not structureVolume:
                mergeName = merge.GetName()
                self.errorDialog(
                    "Merge Aborted: No image data for volume node %s." %
                    (structureName))
                return
            if structureVolume.GetImageData().GetDimensions() != dims:
                mergeName = merge.GetName()
                self.errorDialog(
                    "Merge Aborted: Volume %s does not have the same dimensions as the target merge volume.  Use the Resample Scalar/Vector/DWI module to resample.  Use %s as the Reference Volume and select Nearest Neighbor (nn) Interpolation Type."
                    % (structureName, mergeName))
                return

        # check that user really wants to merge
        rows = self.structures.rowCount()
        for row in xrange(rows):
            structureName = self.structures.item(row, 2).text()
            structureVolume = self.structureVolume(structureName)
            if structureVolume.GetImageData().GetMTime() < merge.GetImageData(
            ).GetMTime():
                mergeName = merge.GetName()
                self.errorDialog(
                    "Note: Merge volume has been modified more recently than structure volumes.\nCreating backup copy as %s-backup"
                    % mergeName)
                self.volumesLogic.CloneVolume(slicer.mrmlScene, merge,
                                              mergeName + "-backup")

        #
        # find the Image Label Combine
        # - call Enter to be sure GUI has been built
        #
        combiner = slicer.vtkImageLabelCombine()

        #
        # iterate through structures merging into merge volume
        #
        for row in xrange(rows):
            structureName = self.structures.item(row, 2).text()
            structureVolume = self.structureVolume(structureName)

            if row == 0:
                # first row, just copy into merge volume
                merge.GetImageData().DeepCopy(structureVolume.GetImageData())
                continue

            combiner.SetInput1(merge.GetImageData())
            combiner.SetInput2(structureVolume.GetImageData())
            self.statusText("Merging $structureName...")
            combiner.Update()
            merge.GetImageData().DeepCopy(combiner.GetOutput())

        # mark all volumes as modified so we will be able to tell if the
        # merged volume gets edited after these
        for row in xrange(rows):
            structureName = self.structures.item(row, 2).text()
            structureVolume = self.structureVolume(structureName)
            structureVolume.GetImageData().Modified()

        selectionNode = self.applicationLogic.GetSelectionNode()
        selectionNode.SetReferenceActiveVolumeID(self.master.GetID())
        selectionNode.SetReferenceActiveLabelVolumeID(merge.GetID())
        self.applicationLogic.PropagateVolumeSelection(0)

        self.statusText("Finished merging.")