当前位置: 首页>>代码示例>>Python>>正文


Python EditUtil.markVolumeNodeAsModified方法代码示例

本文整理汇总了Python中EditUtil.EditUtil.markVolumeNodeAsModified方法的典型用法代码示例。如果您正苦于以下问题:Python EditUtil.markVolumeNodeAsModified方法的具体用法?Python EditUtil.markVolumeNodeAsModified怎么用?Python EditUtil.markVolumeNodeAsModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EditUtil.EditUtil的用法示例。


在下文中一共展示了EditUtil.markVolumeNodeAsModified方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: paintPixel

# 需要导入模块: from EditUtil import EditUtil [as 别名]
# 或者: from EditUtil.EditUtil import markVolumeNodeAsModified [as 别名]
  def paintPixel(self, x, y):
    """
    paint with a single pixel (in label space)
    """
    sliceLogic = self.sliceWidget.sliceLogic()
    labelLogic = sliceLogic.GetLabelLayer()
    labelNode = labelLogic.GetVolumeNode()
    labelImage = labelNode.GetImageData()

    if not labelNode:
      # if there's no label, we can't paint
      return

    xyToIJK = labelLogic.GetXYToIJKTransform()
    ijkFloat = xyToIJK.TransformDoublePoint( (x, y, 0) )
    ijk = []
    for e in ijkFloat:
      try:
        index = int(round(e))
      except ValueError:
        return
      ijk.append(index)
    dims = labelImage.GetDimensions()
    for e,d in zip(ijk,dims): # clamp to volume extent
      if e < 0 or e >= d:
        return

    parameterNode = EditUtil.getParameterNode()
    paintLabel = int(parameterNode.GetParameter("label"))
    labelImage.SetScalarComponentFromFloat(ijk[0],ijk[1],ijk[2],0, paintLabel)
    EditUtil.markVolumeNodeAsModified(labelNode)
开发者ID:filipemanuel1,项目名称:Slicer,代码行数:33,代码来源:PaintEffect.py

示例2: updateLabel

# 需要导入模块: from EditUtil import EditUtil [as 别名]
# 或者: from EditUtil.EditUtil import markVolumeNodeAsModified [as 别名]
  def updateLabel(self,value):
    if not self.fm:
      return
    self.fm.show(value)
    self.fm.Modified()
    self.fm.Update()

    EditUtil.getLabelImage().DeepCopy(self.fm.GetOutput())
    EditUtil.getLabelImage().Modified()

    EditUtil.markVolumeNodeAsModified(self.sliceLogic.GetLabelLayer().GetVolumeNode())
开发者ID:kingofpanda,项目名称:Slicer,代码行数:13,代码来源:FastMarchingEffect.py

示例3: split

# 需要导入模块: from EditUtil import EditUtil [as 别名]
# 或者: from EditUtil.EditUtil import markVolumeNodeAsModified [as 别名]
  def split(self):
    """split the merge volume into individual structures"""

    self.statusText( "Splitting..." )
    merge = self.merge
    if not merge:
      return
    colorNode = merge.GetDisplayNode().GetColorNode()

    accum = vtk.vtkImageAccumulate()
    if vtk.VTK_MAJOR_VERSION <= 5:
      accum.SetInput(merge.GetImageData())
    else:
      accum.SetInputConnection(merge.GetImageDataConnection())
    accum.Update()
    lo = int(accum.GetMin()[0])
    hi = int(accum.GetMax()[0])

    # TODO: pending resolution of bug 1822, run the thresholding
    # in single threaded mode to avoid data corruption observed on mac release
    # builds
    thresholder = vtk.vtkImageThreshold()
    thresholder.SetNumberOfThreads(1)
    for i in xrange(lo,hi+1):
      self.statusText( "Splitting label %d..."%i )
      if vtk.VTK_MAJOR_VERSION <= 5:
        thresholder.SetInput( merge.GetImageData() )
      else:
        thresholder.SetInputConnection( merge.GetImageDataConnection() )
      thresholder.SetInValue( i )
      thresholder.SetOutValue( 0 )
      thresholder.ReplaceInOn()
      thresholder.ReplaceOutOn()
      thresholder.ThresholdBetween( i, i )
      thresholder.SetOutputScalarType( merge.GetImageData().GetScalarType() )
      thresholder.Update()
      if thresholder.GetOutput().GetScalarRange() != (0.0, 0.0):
        labelName = colorNode.GetColorName(i)
        self.statusText( "Creating structure volume %s..."%labelName )
        structureVolume = self.structureVolume( labelName )
        if not structureVolume:
          self.addStructure( i, "noEdit" )
        structureVolume = self.structureVolume( labelName )
        structureVolume.GetImageData().DeepCopy( thresholder.GetOutput() )
        EditUtil.markVolumeNodeAsModified(structureVolume)

    self.statusText( "Finished splitting." )
开发者ID:kevinwangcanada,项目名称:Slicer,代码行数:49,代码来源:LabelStructureListWidget.py

示例4: paintApply

# 需要导入模块: from EditUtil import EditUtil [as 别名]
# 或者: from EditUtil.EditUtil import markVolumeNodeAsModified [as 别名]
  def paintApply(self):
    if self.paintCoordinates != []:
      if self.undoRedo:
        self.undoRedo.saveState()

    for xy in self.paintCoordinates:
      if self.pixelMode:
        self.paintPixel(xy[0], xy[1])
      else:
        self.paintBrush(xy[0], xy[1])
    self.paintCoordinates = []
    self.paintFeedback()

    # TODO: workaround for new pipeline in slicer4
    # - editing image data of the calling modified on the node
    #   does not pull the pipeline chain
    # - so we trick it by changing the image data first
    sliceLogic = self.sliceWidget.sliceLogic()
    labelLogic = sliceLogic.GetLabelLayer()
    labelNode = labelLogic.GetVolumeNode()
    EditUtil.markVolumeNodeAsModified(labelNode)
开发者ID:filipemanuel1,项目名称:Slicer,代码行数:23,代码来源:PaintEffect.py

示例5: fastMarching

# 需要导入模块: from EditUtil import EditUtil [as 别名]
# 或者: from EditUtil.EditUtil import markVolumeNodeAsModified [as 别名]
  def fastMarching(self,percentMax):

    self.fm = None
    # allocate a new filter each time March is hit
    bgImage = EditUtil.getBackgroundImage()
    labelImage = EditUtil.getLabelImage()

    # collect seeds
    if vtk.VTK_MAJOR_VERSION <= 5:
      dim = bgImage.GetWholeExtent()
    else:
      dim = bgImage.GetDimensions()
      print dim
    # initialize the filter
    self.fm = slicer.vtkPichonFastMarching()
    scalarRange = bgImage.GetScalarRange()
    depth = scalarRange[1]-scalarRange[0]

    # this is more or less arbitrary; large depth values will bring the
    # algorithm to the knees
    scaleValue = 0
    shiftValue = 0

    if depth>300:
      scaleValue = 300./depth
    if scalarRange[0] < 0:
      shiftValue = scalarRange[0]*-1

    if scaleValue or shiftValue:
      rescale = vtk.vtkImageShiftScale()
      if vtk.VTK_MAJOR_VERSION <= 5:
        rescale.SetInput(bgImage)
      else:
        rescale.SetInputData(bgImage)
      rescale.SetScale(scaleValue)
      rescale.SetShift(shiftValue)
      rescale.Update()
      bgImage = rescale.GetOutput()
      scalarRange = bgImage.GetScalarRange()
      depth = scalarRange[1]-scalarRange[0]

    print('Input scalar range: '+str(depth))
    if vtk.VTK_MAJOR_VERSION <= 5:
      self.fm.init(dim[1]+1, dim[3]+1, dim[5]+1, depth, 1, 1, 1)
    else:
      self.fm.init(dim[0], dim[1], dim[2], depth, 1, 1, 1)

    caster = vtk.vtkImageCast()
    caster.SetOutputScalarTypeToShort()
    if vtk.VTK_MAJOR_VERSION <= 5:
      caster.SetInput(bgImage)
      caster.Update()
      self.fm.SetInput(caster.GetOutput())
    else:
      caster.SetInputData(bgImage)
      self.fm.SetInputConnection(caster.GetOutputPort())

    # self.fm.SetOutput(labelImage)

    if vtk.VTK_MAJOR_VERSION <= 5:
      npoints = int((dim[1]+1)*(dim[3]+1)*(dim[5]+1)*percentMax/100.)
    else:
      npoints = int(dim[0]*dim[1]*dim[2]*percentMax/100.)

    self.fm.setNPointsEvolution(npoints)
    print('Setting active label to '+str(EditUtil.getLabel()))
    self.fm.setActiveLabel(EditUtil.getLabel())

    nSeeds = self.fm.addSeedsFromImage(labelImage)
    if nSeeds == 0:
      return 0

    self.fm.Modified()
    self.fm.Update()

    # TODO: need to call show() twice for data to be updated
    self.fm.show(1)
    self.fm.Modified()
    self.fm.Update()

    self.fm.show(1)
    self.fm.Modified()
    self.fm.Update()

    self.undoRedo.saveState()

    EditUtil.getLabelImage().DeepCopy(self.fm.GetOutput())
    EditUtil.markVolumeNodeAsModified(self.sliceLogic.GetLabelLayer().GetVolumeNode())
    # print('FastMarching output image: '+str(output))
    print('FastMarching march update completed')

    return npoints
开发者ID:kingofpanda,项目名称:Slicer,代码行数:94,代码来源:FastMarchingEffect.py

示例6: applyImageMask

# 需要导入模块: from EditUtil import EditUtil [as 别名]
# 或者: from EditUtil.EditUtil import markVolumeNodeAsModified [as 别名]

#.........这里部分代码省略.........
    if not backgroundImage: return
    labelLogic = self.sliceLogic.GetLabelLayer()
    labelNode = labelLogic.GetVolumeNode()
    if not labelNode: return
    labelImage = labelNode.GetImageData()
    if not labelImage: return

    #
    # at this point, the mask vtkImageData contains a rasterized
    # version of the polygon and now needs to be added to the label
    # image
    #

    # store a backup copy of the label map for undo
    # (this happens in it's own thread, so it is cheap)
    if self.undoRedo:
      self.undoRedo.saveState()

    #
    # get the mask bounding box in ijk coordinates
    # - get the xy bounds
    # - transform to ijk
    # - clamp the bounds to the dimensions of the label image
    #

    xlo, xhi, ylo, yhi, zlo, zhi = bounds
    labelLogic = self.sliceLogic.GetLabelLayer()
    xyToIJK = labelLogic.GetXYToIJKTransform()
    tlIJK = xyToIJK.TransformDoublePoint( (xlo, yhi, 0) )
    trIJK = xyToIJK.TransformDoublePoint( (xhi, yhi, 0) )
    blIJK = xyToIJK.TransformDoublePoint( (xlo, ylo, 0) )
    brIJK = xyToIJK.TransformDoublePoint( (xhi, ylo, 0) )

    # do the clamping of the four corners
    dims = labelImage.GetDimensions()
    tl = [0,] * 3
    tr = [0,] * 3
    bl = [0,] * 3
    br = [0,] * 3
    corners = ((tlIJK, tl),(trIJK, tr),(blIJK, bl),(brIJK, br))
    for corner,clampedCorner in corners:
      for d in xrange(3):
        clamped = int(round(corner[d]))
        if clamped < 0: clamped = 0
        if clamped >= dims[d]: clamped = dims[d]-1
        clampedCorner[d] = clamped

    #
    # get the ijk to ras matrices including transforms
    # (use the maskToRAS calculated above)
    #

    labelLogic = self.sliceLogic.GetLabelLayer()
    labelNode = labelLogic.GetVolumeNode()
    backgroundLogic = self.sliceLogic.GetLabelLayer()
    backgroundNode = backgroundLogic.GetVolumeNode()

    backgroundIJKToRAS = self.getIJKToRASMatrix(backgroundNode)
    labelIJKToRAS = self.getIJKToRASMatrix(labelNode)

    #
    # create an exract image for undo if it doesn't exist yet.
    #

    if not self.extractImage:
      self.extractImage = vtk.vtkImageData()

    parameterNode = EditUtil.getParameterNode()
    paintLabel = int(parameterNode.GetParameter("label"))
    paintOver = int(parameterNode.GetParameter("LabelEffect,paintOver"))
    paintThreshold = int(parameterNode.GetParameter("LabelEffect,paintThreshold"))
    paintThresholdMin = float(
        parameterNode.GetParameter("LabelEffect,paintThresholdMin"))
    paintThresholdMax = float(
        parameterNode.GetParameter("LabelEffect,paintThresholdMax"))

    #
    # set up the painter class and let 'r rip!
    #
    self.painter.SetBackgroundImage( backgroundImage )
    self.painter.SetBackgroundIJKToWorld( backgroundIJKToRAS )
    self.painter.SetWorkingImage( labelImage )
    self.painter.SetWorkingIJKToWorld( labelIJKToRAS )
    self.painter.SetMaskImage( mask )
    self.painter.SetExtractImage( self.extractImage )
    self.painter.SetReplaceImage(None)
    self.painter.SetMaskIJKToWorld( maskIJKToRAS )
    self.painter.SetTopLeft(tl)
    self.painter.SetTopRight(tr)
    self.painter.SetBottomLeft(bl)
    self.painter.SetBottomRight(br)

    self.painter.SetPaintLabel( paintLabel )
    self.painter.SetPaintOver( paintOver )
    self.painter.SetThresholdPaint( paintThreshold )
    self.painter.SetThresholdPaintRange( paintThresholdMin, paintThresholdMax )

    self.painter.Paint()

    EditUtil.markVolumeNodeAsModified(labelNode)
开发者ID:lassoan,项目名称:Slicer,代码行数:104,代码来源:LabelEffect.py


注:本文中的EditUtil.EditUtil.markVolumeNodeAsModified方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。