2017-12-12 39 views
2

파이썬을 사용하여 3DSlicer에서 확장 프로그래밍을 시도하고 있습니다. 온라인으로 a tutorial가 있습니다. 불행히도 세 번째 예제 스크립트 "HelloSharpen"에 문제가 있습니다. 나는 그들이했던 똑같은 일을했다하지만 난이 오류 : 나는 그들이 VTK의 최신 버전이 변경된 것을 읽을 수 있기 때문에 "GetImage"및 "Update"에 대한 VTK가 변경됩니다.

Traceback (most recent call last): 
    File "C:/Users/johan/Desktop/HelloPythonSlicer4/helloPython/code/HelloSharpen.py", line 105, in onApply 
    laplacian.SetInput(inputVolume.GetImageData()) 
AttributeError: 'vtkImagingGeneralPython.vtkImageLaplacian' object has no attribute 'SetInput' 

내가 laplacian.SetInputData(inputVolume.GetImageData())laplacian.SetInput(inputVolume.GetImageData())을 변경하여이 문제를 해결했다. 내가 실행하려고하면

그러나 새로운 오류가 제공이 :

Traceback (most recent call last): 
    File "C:/Users/johan/Desktop/HelloPythonSlicer4/helloPython/code/HelloSharpen.py", line 107, in onApply 
    laplacian.GetOutput().Update() 
AttributeError: 'vtkCommonDataModelPython.vtkImageData' object has no attribute 'Update' 

그들이 또한 최신 버전이 변경된 경우 laplacian.GetOutput().Update()입니다 일으키는 문제 때문에 내가 인터넷에서 무언가를 찾으려고 것으로 보인다 VTK의. 그러나 나는 아무것도 발견 할 수 없었다. 이 "UpdateData"로 변경하려고했지만이 작동하지 않습니다. 그들은 또한 이것을 바꾸 었는지 알고 있습니까? 그렇다면 대체해야 할 것이 무엇인지 알고 있습니까?

여기에 "HelloSharpen"의 전체 코드입니다 :

from __main__ import vtk, qt, ctk, slicer 

# 
# HelloSharpen 
# 

class HelloSharpen: 
    def __init__(self, parent): 
    parent.title = "Hello Python Part D - Sharpen" 
    parent.categories = ["Examples"] 
    parent.dependencies = [] 
    parent.contributors = ["Jean-Christophe Fillion-Robin (Kitware)", 
          "Steve Pieper (Isomics)", 
          "Sonia Pujol (BWH)"] # replace with "Firstname Lastname (Org)" 
    parent.helpText = """ 
    Example of scripted loadable extension for the HelloSharpen tutorial. 
    """ 
    parent.acknowledgementText = """ 
    This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc., 
Steve Pieper, Isomics, Inc., and Sonia Pujol, Brigham and Women's Hospital and was 
partially funded by NIH grant 3P41RR013218-12S1 (NAC) and is part of the National Alliance 
for Medical Image Computing (NA-MIC), funded by the National Institutes of Health through the 
NIH Roadmap for Medical Research, Grant U54 EB005149.""" # replace with organization, grant and thanks. 
    self.parent = parent 

# 
# qHelloPythonWidget 
# 

class HelloSharpenWidget: 
    def __init__(self, parent = None): 
    if not parent: 
     self.parent = slicer.qMRMLWidget() 
     self.parent.setLayout(qt.QVBoxLayout()) 
     self.parent.setMRMLScene(slicer.mrmlScene) 
    else: 
     self.parent = parent 
    self.layout = self.parent.layout() 
    if not parent: 
     self.setup() 
     self.parent.show() 

    def setup(self): 
    # Collapsible button 
    self.laplaceCollapsibleButton = ctk.ctkCollapsibleButton() 
    self.laplaceCollapsibleButton.text = "Sharpen Operator" 
    self.layout.addWidget(self.laplaceCollapsibleButton) 

    # Layout within the laplace collapsible button 
    self.laplaceFormLayout = qt.QFormLayout(self.laplaceCollapsibleButton) 

    # 
    # the volume selectors 
    # 
    self.inputFrame = qt.QFrame(self.laplaceCollapsibleButton) 
    self.inputFrame.setLayout(qt.QHBoxLayout()) 
    self.laplaceFormLayout.addWidget(self.inputFrame) 
    self.inputSelector = qt.QLabel("Input Volume: ", self.inputFrame) 
    self.inputFrame.layout().addWidget(self.inputSelector) 
    self.inputSelector = slicer.qMRMLNodeComboBox(self.inputFrame) 
    self.inputSelector.nodeTypes = (("vtkMRMLScalarVolumeNode"), "") 
    self.inputSelector.addEnabled = False 
    self.inputSelector.removeEnabled = False 
    self.inputSelector.setMRMLScene(slicer.mrmlScene) 
    self.inputFrame.layout().addWidget(self.inputSelector) 

    self.outputFrame = qt.QFrame(self.laplaceCollapsibleButton) 
    self.outputFrame.setLayout(qt.QHBoxLayout()) 
    self.laplaceFormLayout.addWidget(self.outputFrame) 
    self.outputSelector = qt.QLabel("Output Volume: ", self.outputFrame) 
    self.outputFrame.layout().addWidget(self.outputSelector) 
    self.outputSelector = slicer.qMRMLNodeComboBox(self.outputFrame) 
    self.outputSelector.nodeTypes = (("vtkMRMLScalarVolumeNode"), "") 
    self.outputSelector.setMRMLScene(slicer.mrmlScene) 
    self.outputFrame.layout().addWidget(self.outputSelector) 

    self.sharpen = qt.QCheckBox("Sharpen", self.laplaceCollapsibleButton) 
    self.sharpen.toolTip = "When checked, subtract laplacian from input volume" 
    self.sharpen.checked = True 
    self.laplaceFormLayout.addWidget(self.sharpen) 


    # Apply button 
    laplaceButton = qt.QPushButton("Apply") 
    laplaceButton.toolTip = "Run the Laplace or Sharpen Operator." 
    self.laplaceFormLayout.addWidget(laplaceButton) 
    laplaceButton.connect('clicked(bool)', self.onApply) 

    # Add vertical spacer 
    self.layout.addStretch(1) 

    # Set local var as instance attribute 
    self.laplaceButton = laplaceButton 

    def onApply(self): 
    inputVolume = self.inputSelector.currentNode() 
    outputVolume = self.outputSelector.currentNode() 
    if not (inputVolume and outputVolume): 
     qt.QMessageBox.critical(
      slicer.util.mainWindow(), 
      'Sharpen', 'Input and output volumes are required for Laplacian') 
     return 
    # run the filter 
    laplacian = vtk.vtkImageLaplacian() 
    laplacian.SetInputData(inputVolume.GetImageData()) 
    laplacian.SetDimensionality(3) 
    laplacian.GetOutput().Update() 
    ijkToRAS = vtk.vtkMatrix4x4() 
    inputVolume.GetIJKToRASMatrix(ijkToRAS) 
    outputVolume.SetIJKToRASMatrix(ijkToRAS) 
    outputVolume.SetAndObserveImageData(laplacian.GetOutput()) 

    # optionally subtract laplacian from original image 
    if self.sharpen.checked: 
     parameters = {} 
     parameters['inputVolume1'] = inputVolume.GetID() 
     parameters['inputVolume2'] = outputVolume.GetID() 
     parameters['outputVolume'] = outputVolume.GetID() 
     slicer.cli.run(slicer.modules.subtractscalarvolumes, None, parameters, wait_for_completion=True) 

    selectionNode = slicer.app.applicationLogic().GetSelectionNode() 
    selectionNode.SetReferenceActiveVolumeID(outputVolume.GetID()) 
    slicer.app.applicationLogic().PropagateVolumeSelection(0) 

답변

2

TL은, DRlaplacian.Update()로 변경 laplacian.GetOutput().Update().

설명 : this 링크 당으로 요약 VTK 6에 도입 된 주요 변화, VTK의 최신 버전 분리 한 알고리즘과 두 개의 서로 다른 클래스 계층의 데이터가 있었다. 최신 버전의 VTK에서 함수는 vtkAlgorithm 클래스에서 파생 된 객체에서만 호출 할 수 있습니다. vtkImageLaplacianhere의 상속 다이어그램을 볼 수 있으며 실제로는 vtkAlgorithm 클래스에서 파생됩니다. 따라서 laplacian.Update()이 작동합니다.

이름에서 알 수 있듯이 vtkImageData은 데이터 개체입니다. laplacian.GetOutput()vtkImageData 개체를 반환하기 때문에 Update() 함수를 호출 할 수 없으므로 오류가 발생합니다.

+0

정말 고마워요! – Ineedhelpbecauseiamstupid