예제 #1
0
def display_images(reader):
    image_viewer = vtk.vtkResliceImageViewer()
    image_viewer.SetInputData(reader.GetOutput())
    # image_viewer.SetInputConnection(reader.GetOutputPort())
    interactor = vtk.vtkRenderWindowInteractor()
    image_viewer.SetupInteractor(interactor)
    image_viewer.Render()
    image_viewer.GetRenderer().ResetCamera()
    image_viewer.Render()

    # Store the initial image size
    init_image_size = None
    init_image_size = interactor.GetSize()

    # Listener for left mouse button press:
    #   Gets mouse position in current window pixels and converts 
    #   them to pixel position based on initial image size,
    #   with the origin at the bottom left corner
    def on_left_mouse_button_press(obj, event):
        if(init_image_size != None):
            mouse_position = obj.GetEventPosition()
            current_image_size = obj.GetSize()
            posX = int(round(mouse_position[0] * init_image_size[0] / current_image_size[0]))
            posY = int(round(mouse_position[1] * init_image_size[1] / current_image_size[1]))
            print(posX,posY)
        return

    # Add left mouse button press observer
    interactor.AddObserver("LeftButtonPressEvent", on_left_mouse_button_press, 101.0)

    interactor.Start()
예제 #2
0
    def __init__(self, parent, iDim=0):
        super(Viewer2D, self).__init__(parent)
        interactor = QVTKRenderWindowInteractor(self)
        self.edgeActor = None

        self.trans = None  # Misalignment
        self.invTrans = None  # Inverse

        self.adjustment = vtk.vtkTransform()  # Move in front
        #self.adjustment.PostMultiply()

        self.iDim = iDim
        self.layout = QHBoxLayout(self)
        self.layout.addWidget(interactor)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.layout)

        self.viewer = vtk.vtkResliceImageViewer()
        self.viewer.SetupInteractor(interactor)
        self.viewer.SetRenderWindow(interactor.GetRenderWindow())
        # Disable interactor until data are present
        self.viewer.GetRenderWindow().GetInteractor().Disable()
        # Setup cursors and orientation of reslice image widget
        rep = self.viewer.GetResliceCursorWidget().GetRepresentation()
        rep.GetResliceCursorActor().GetCursorAlgorithm().SetReslicePlaneNormal(
            iDim)
        self.viewer.SetSliceOrientation(iDim)
        self.viewer.SetResliceModeToAxisAligned()
        self.interactor = interactor
예제 #3
0
def dicom_viewer(directory, slice_queue, mouse_move_event):
    filenames = vtk.vtkStringArray()
    for i, filename in enumerate(os.listdir(directory)):
        filenames.InsertNextValue(os.path.join(directory, filename))

    reader = vtk.vtkTIFFReader()
    reader.SetFileNames(filenames)
    reader.Update()

    image_viewer = vtk.vtkResliceImageViewer()
    image_viewer.SetInputData(reader.GetOutput())
    # image_viewer.SetInputConnection(reader.GetOutputPort())
    interactor = vtk.vtkRenderWindowInteractor()
    image_viewer.SetupInteractor(interactor)
    image_viewer.Render()
    image_viewer.GetRenderer().ResetCamera()
    image_viewer.Render()

    # Store the initial image size
    init_image_size = None
    init_image_size = interactor.GetSize()

    # def on_mouse_move(obj, event):
    #     mouse_queue.put(obj.GetEventPosition())
    #     mouse_move_event.set()
    #     return

    def on_scroll_wheel_move(obj, event):
        slice_queue.put(image_viewer.GetSlice())
        return

    # Listener for left mouse button press:
    #   Gets mouse position in current window pixels and converts
    #   them to pixel position based on initial image size,
    #   with the origin at the bottom left corner
    def on_left_mouse_button_press(obj, event):
        if (init_image_size != None):
            mouse_position = obj.GetEventPosition()
            current_image_size = obj.GetSize()
            posX = int(
                round(mouse_position[0] * init_image_size[0] /
                      current_image_size[0]))
            posY = int(
                round(mouse_position[1] * init_image_size[1] /
                      current_image_size[1]))
            print(posX, posY)
        return

    # Add left mouse button press observer
    interactor.AddObserver("LeftButtonPressEvent", on_left_mouse_button_press,
                           101.0)

    # interactor.AddObserver("MouseMoveEvent", on_mouse_move)
    interactor.AddObserver("MouseWheelForwardEvent", on_scroll_wheel_move,
                           100.0)
    interactor.AddObserver("MouseWheelBackwardEvent", on_scroll_wheel_move,
                           100.0)
    interactor.Start()
def DisplayImageData(data):
    viewer = vtk.vtkResliceImageViewer()
    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(viewer.GetRenderWindow())

    viewer.SetupInteractor(interactor)
    viewer.SetInputData(data)

    # calculate index of middle slice in the dicom image
    midSlice = viewer.GetSliceMax() / 2

    # set up reslice view properties
    viewer.SetSlice(midSlice)
    viewer.SetSliceOrientationToXY()
    viewer.GetRenderer().ResetCamera()
    viewer.Render()

    interactor.Start()
def DisplayImageData(data):
    viewer = vtk.vtkResliceImageViewer()
    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(viewer.GetRenderWindow())

    viewer.SetupInteractor(interactor)
    viewer.SetInputData(data)

    # calculate index of middle slice in the dicom image
    midSlice = viewer.GetSliceMax() / 2

    # set up reslice view properties
    viewer.SetSlice(midSlice)
    viewer.SetSliceOrientationToXY()
    viewer.GetRenderer().ResetCamera()
    viewer.Render()

    interactor.Start()
예제 #6
0
    def __init__(self, parent, iDim=0):
        super(Viewer2D, self).__init__(parent)
        interactor = QVTKRenderWindowInteractor(self)  # This is a QWidget
        self.contourActor = None  # Actor for contours

        self.trans = None  # Misalignment
        self.invTrans = None  # Inverse

        self.overlay = None  # Actor for segmentation contours
        self.wrongContourActor = None
        self.iDim = iDim  # Slice dimensions
        self.lastSize = (0, 0)  # Used for corner button
        self.buttonWidget = None
        self.cornerAnnotation = None
        self.buttonSize = 40.0
        layout = QHBoxLayout(self)
        layout.addWidget(interactor)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        self.adjustment = vtk.vtkTransform()  # Move in front

        self.viewer = vtk.vtkResliceImageViewer()
        self.viewer.SetupInteractor(interactor)
        self.viewer.SetRenderWindow(interactor.GetRenderWindow())

        # Must be done from start (no effect)
        #renderWindow = self.viewer.GetRenderWindow()
        #renderWindow.SetUseOffScreenBuffers(True)

        # Disable interactor until data are present
        self.viewer.GetRenderWindow().GetInteractor().Disable()

        # Setup cursors and orientation of reslice image widget
        rep = self.viewer.GetResliceCursorWidget().GetRepresentation()
        rep.GetResliceCursorActor().GetCursorAlgorithm().SetReslicePlaneNormal(
            iDim)
        self.viewer.SetSliceOrientation(iDim)
        self.viewer.SetResliceModeToAxisAligned()
        self.interactor = interactor

        self.interactor.AddObserver('KeyPressEvent', self.KeyPress, 1.0)
예제 #7
0
  def __init__(self, parent, iDim=0):
    super(Viewer2D, self).__init__(parent)
    interactor = QVTKRenderWindowInteractor(self)
    self.layout = QHBoxLayout(self)
    self.layout.addWidget(interactor)
    self.layout.setContentsMargins(0, 0, 0, 0)
    self.setLayout(self.layout)

    self.viewer = vtk.vtkResliceImageViewer()
    self.viewer.SetupInteractor(interactor)
    self.viewer.SetRenderWindow(interactor.GetRenderWindow())

    # Disable interactor until data are present
    # TODO: Do this after setting the interactor
    self.viewer.GetRenderWindow().GetInteractor().Disable()

    # Setup cursors and orientation of reslice image widget
    rep = self.viewer.GetResliceCursorWidget().GetRepresentation()
    rep.GetResliceCursorActor().GetCursorAlgorithm().SetReslicePlaneNormal(iDim)
    self.viewer.SetSliceOrientation(iDim)
    self.viewer.SetResliceModeToAxisAligned()
    self.interactor = interactor