Beispiel #1
0
    def __init__(self):

        # super(Cube, self).__init__(renderer)

        self.cube = vtk.vtkAnnotatedCubeActor()
        self.cube.SetXPlusFaceText('R')
        self.cube.SetXMinusFaceText('L')
        self.cube.SetYPlusFaceText('A')
        self.cube.SetYMinusFaceText('P')
        self.cube.SetZPlusFaceText('I')
        self.cube.SetZMinusFaceText('S')
        self.cube.SetXFaceTextRotation(180)
        self.cube.SetYFaceTextRotation(180)
        self.cube.SetZFaceTextRotation(-90)
        self.cube.SetFaceTextScale(0.65)
        self.cube.GetCubeProperty().SetColor(0.5, 1.0, 1.0)
        self.cube.GetTextEdgesProperty().SetLineWidth(1)
        self.cube.GetTextEdgesProperty().SetColor(0.18, 0.28, 0.23)
        self.cube.GetTextEdgesProperty().SetDiffuse(0)
        self.cube.GetTextEdgesProperty().SetAmbient(1)

        self.cube.GetXPlusFaceProperty().SetColor(1, 0, 0)
        self.cube.GetXPlusFaceProperty().SetInterpolationToFlat()
        self.cube.GetXMinusFaceProperty().SetColor(1, 0, 0)
        self.cube.GetXMinusFaceProperty().SetInterpolationToFlat()

        self.cube.GetYPlusFaceProperty().SetColor(0, 1, 0)
        self.cube.GetYPlusFaceProperty().SetInterpolationToFlat()
        self.cube.GetYMinusFaceProperty().SetColor(0, 1, 0)
        self.cube.GetYMinusFaceProperty().SetInterpolationToFlat()

        self.cube.GetZPlusFaceProperty().SetColor(0, 0, 1)
        self.cube.GetZPlusFaceProperty().SetInterpolationToFlat()
        self.cube.GetZMinusFaceProperty().SetColor(0, 0, 1)
        self.cube.GetZMinusFaceProperty().SetInterpolationToFlat()
    def FirstOpen(self):
        #create annotated cube anchor actor
        self.axesActor = vtk.vtkAnnotatedCubeActor()
        self.axesActor.SetXPlusFaceText('Right')
        self.axesActor.SetXMinusFaceText('Left')
        self.axesActor.SetYMinusFaceText('Front')
        self.axesActor.SetYPlusFaceText('Back')
        self.axesActor.SetZMinusFaceText('Bot')
        self.axesActor.SetZPlusFaceText('Top')
        self.axesActor.GetTextEdgesProperty().SetColor(.8, .8, .8)
        self.axesActor.GetZPlusFaceProperty().SetColor(.8, .8, .8)
        self.axesActor.GetZMinusFaceProperty().SetColor(.8, .8, .8)
        self.axesActor.GetXPlusFaceProperty().SetColor(.8, .8, .8)
        self.axesActor.GetXMinusFaceProperty().SetColor(.8, .8, .8)
        self.axesActor.GetYPlusFaceProperty().SetColor(.8, .8, .8)
        self.axesActor.GetYMinusFaceProperty().SetColor(.8, .8, .8)
        self.axesActor.GetTextEdgesProperty().SetLineWidth(2)
        self.axesActor.GetCubeProperty().SetColor(.2, .2, .2)
        self.axesActor.SetFaceTextScale(0.25)
        self.axesActor.SetZFaceTextRotation(90)

        #create orientation markers
        self.axes = vtk.vtkOrientationMarkerWidget()
        self.axes.SetOrientationMarker(self.axesActor)
        self.axes.SetInteractor(self.ModelView)
        self.axes.EnabledOn()
        self.axes.InteractiveOff()

        self.ui.Transform_groupbox.setEnabled(True)
 def __init__(self, parent = None):
     QtGui.QMainWindow.__init__(self, parent)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.ren = vtk.vtkRenderer()
     self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
     self.iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
     cube = vtk.vtkCubeSource()
     cube.SetXLength(200)
     cube.SetYLength(200)
     cube.SetZLength(200)
     cube.Update()
     cm = vtk.vtkPolyDataMapper()
     cm.SetInputConnection(cube.GetOutputPort())
     ca = vtk.vtkActor()
     ca.SetMapper(cm)
     self.ren.AddActor(ca)
     self.axesActor = vtk.vtkAnnotatedCubeActor();
     self.axesActor.SetXPlusFaceText('R')
     self.axesActor.SetXMinusFaceText('L')
     self.axesActor.SetYMinusFaceText('H')
     self.axesActor.SetYPlusFaceText('F')
     self.axesActor.SetZMinusFaceText('P')
     self.axesActor.SetZPlusFaceText('A')
     self.axesActor.GetTextEdgesProperty().SetColor(1,1,0)
     self.axesActor.GetTextEdgesProperty().SetLineWidth(2)
     self.axesActor.GetCubeProperty().SetColor(0,0,1)
     self.axes = vtk.vtkOrientationMarkerWidget()
     self.axes.SetOrientationMarker(self.axesActor)
     self.axes.SetInteractor(self.iren)
     self.axes.EnabledOn()
     self.axes.InteractiveOn()
     self.ren.ResetCamera()
Beispiel #4
0
    def __init__(self, vtk_filename=None, vtk_data=None):
        """
        Initiate Viwer

        Parameters
        ----------
        vtk_filename : str
            Input VTK filename
        """

        QDialog.__init__(self)
        self.initUI()

        ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(ren)
        iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        if vtk_filename is not None:
            # VTK file
            reader = vtk.vtkUnstructuredGridReader()
            reader.SetFileName(vtk_filename)
            reader.Update()
            vtkdata = reader.GetOutput()

        if vtk_data is not None:
            vtkdata = vtk_data

        # VTK surface
        surface = vtk.vtkDataSetSurfaceFilter()
        surface.SetInput(vtkdata)
        surface.Update()

        mapper = vtk.vtkDataSetMapper()
        mapper.SetInput(surface.GetOutput())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().EdgeVisibilityOff()
        # actor.GetProperty().SetEdgeColor(1,1,1)
        # actor.GetProperty().SetLineWidth(0.1)
        ren.AddActor(actor)

        # annot. cube
        axesActor = vtk.vtkAnnotatedCubeActor()
        axesActor.SetXPlusFaceText('R')
        axesActor.SetXMinusFaceText('L')
        axesActor.SetYMinusFaceText('H')
        axesActor.SetYPlusFaceText('F')
        axesActor.SetZMinusFaceText('A')
        axesActor.SetZPlusFaceText('P')
        axesActor.GetTextEdgesProperty().SetColor(1, 1, 0)
        axesActor.GetCubeProperty().SetColor(0, 0, 1)
        self.axes = vtk.vtkOrientationMarkerWidget()
        self.axes.SetOrientationMarker(axesActor)
        self.axes.SetInteractor(iren)
        self.axes.EnabledOn()
        self.axes.InteractiveOn()

        ren.ResetCamera()
        iren.Initialize()
Beispiel #5
0
def MakeAnnotatedCubeActor(colors):
    """
  :param colors: Used to determine the cube color.
  :return: The annotated cube actor.
  """
    # A cube with labeled faces.
    cube = vtk.vtkAnnotatedCubeActor()
    # Interchange R and L for RAS, this is LPS
    # Interchange A and P for RAS

    cube.SetXPlusFaceText('L')  # Right
    cube.SetXMinusFaceText('R')  # Left
    cube.SetYPlusFaceText('P')  # Anterior
    cube.SetYMinusFaceText('A')  # Posterior

    cube.SetZPlusFaceText('S')  # Superior/Cranial
    cube.SetZMinusFaceText('I')  # Inferior/Caudal
    cube.SetFaceTextScale(0.5)
    cube.GetCubeProperty().SetColor(colors.GetColor3d('Gainsboro'))

    cube.GetTextEdgesProperty().SetColor(colors.GetColor3d('LightSlateGray'))

    # Change the vector text colors.
    cube.GetXPlusFaceProperty().SetColor(colors.GetColor3d('Tomato'))
    cube.GetXMinusFaceProperty().SetColor(colors.GetColor3d('Tomato'))

    cube.GetYPlusFaceProperty().SetColor(colors.GetColor3d('SeaGreen'))
    cube.GetYMinusFaceProperty().SetColor(colors.GetColor3d('SeaGreen'))
    cube.GetZPlusFaceProperty().SetColor(colors.GetColor3d('DeepSkyBlue'))
    cube.GetZMinusFaceProperty().SetColor(colors.GetColor3d('DeepSkyBlue'))

    cube.SetZFaceTextRotation(90)

    return cube
Beispiel #6
0
def loadTestVTKWindow(parentUI):

    cube = vtk.vtkCubeSource()
    cube.SetXLength(200)
    cube.SetYLength(200)
    cube.SetZLength(200)
    cube.Update()
    cm = vtk.vtkPolyDataMapper()
    cm.SetInputConnection(cube.GetOutputPort())
    ca = vtk.vtkActor()
    ca.SetMapper(cm)
    parentUI.vtkInstances[-1].ren.AddActor(ca)

    axesActor = vtk.vtkAnnotatedCubeActor()
    axesActor.SetXPlusFaceText('R')
    axesActor.SetXMinusFaceText('L')
    axesActor.SetYMinusFaceText('H')
    axesActor.SetYPlusFaceText('F')
    axesActor.SetZMinusFaceText('P')
    axesActor.SetZPlusFaceText('A')
    axesActor.GetTextEdgesProperty().SetColor(1, 1, 0)
    axesActor.GetTextEdgesProperty().SetLineWidth(2)
    axesActor.GetCubeProperty().SetColor(0, 0, 1)
    axes = vtk.vtkOrientationMarkerWidget()
    axes.SetOrientationMarker(axesActor)
    axes.SetInteractor(parentUI.vtkInstances[-1].iren)

    parentUI.vtkInstances[-1].ren.ResetCamera()
    parentUI.vtkInstances[-1].iren.Start()
Beispiel #7
0
    def ShowOrientationCube(self):
        cube = vtk.vtkAnnotatedCubeActor()
        cube.GetXMinusFaceProperty().SetColor(1,0,0)
        cube.GetXPlusFaceProperty().SetColor(1,0,0)
        cube.GetYMinusFaceProperty().SetColor(0,1,0)
        cube.GetYPlusFaceProperty().SetColor(0,1,0)
        cube.GetZMinusFaceProperty().SetColor(0,0,1)
        cube.GetZPlusFaceProperty().SetColor(0,0,1)
        cube.GetTextEdgesProperty().SetColor(0,0,0)

        # anatomic labelling
        cube.SetXPlusFaceText ("A")
        cube.SetXMinusFaceText("P")
        cube.SetYPlusFaceText ("L")
        cube.SetYMinusFaceText("R")
        cube.SetZPlusFaceText ("S")
        cube.SetZMinusFaceText("I")

        axes = vtk.vtkAxesActor()
        axes.SetShaftTypeToCylinder()
        axes.SetTipTypeToCone()
        axes.SetXAxisLabelText("X")
        axes.SetYAxisLabelText("Y")
        axes.SetZAxisLabelText("Z")
        #axes.SetNormalizedLabelPosition(.5, .5, .5)

        orientation_widget = vtk.vtkOrientationMarkerWidget()
        orientation_widget.SetOrientationMarker(cube)
        orientation_widget.SetViewport(0.85,0.85,1.0,1.0)
        #orientation_widget.SetOrientationMarker(axes)
        orientation_widget.SetInteractor(self.interactor)
        orientation_widget.SetEnabled(1)
        orientation_widget.On()
        orientation_widget.InteractiveOff()
Beispiel #8
0
    def __init__(self):

        # super(Cube, self).__init__(renderer)

        self.cube = vtk.vtkAnnotatedCubeActor()
        self.cube.SetXPlusFaceText('R')
        self.cube.SetXMinusFaceText('L')
        self.cube.SetYPlusFaceText('A')
        self.cube.SetYMinusFaceText('P')
        self.cube.SetZPlusFaceText('I')
        self.cube.SetZMinusFaceText('S')
        self.cube.SetXFaceTextRotation(180)
        self.cube.SetYFaceTextRotation(180)
        self.cube.SetZFaceTextRotation(-90)
        self.cube.SetFaceTextScale(0.65)
        self.cube.GetCubeProperty().SetColor(0.5, 1.0, 1.0)
        self.cube.GetTextEdgesProperty().SetLineWidth(1)
        self.cube.GetTextEdgesProperty().SetColor(0.18, 0.28, 0.23)
        self.cube.GetTextEdgesProperty().SetDiffuse(0)
        self.cube.GetTextEdgesProperty().SetAmbient(1)

        self.cube.GetXPlusFaceProperty().SetColor(1, 0, 0)
        self.cube.GetXPlusFaceProperty().SetInterpolationToFlat()
        self.cube.GetXMinusFaceProperty().SetColor(1, 0, 0)
        self.cube.GetXMinusFaceProperty().SetInterpolationToFlat()

        self.cube.GetYPlusFaceProperty().SetColor(0, 1, 0)
        self.cube.GetYPlusFaceProperty().SetInterpolationToFlat()
        self.cube.GetYMinusFaceProperty().SetColor(0, 1, 0)
        self.cube.GetYMinusFaceProperty().SetInterpolationToFlat()

        self.cube.GetZPlusFaceProperty().SetColor(0, 0, 1)
        self.cube.GetZPlusFaceProperty().SetInterpolationToFlat()
        self.cube.GetZMinusFaceProperty().SetColor(0, 0, 1)
        self.cube.GetZMinusFaceProperty().SetInterpolationToFlat()
Beispiel #9
0
    def ShowOrientationCube(self):
        cube = vtk.vtkAnnotatedCubeActor()
        cube.GetXMinusFaceProperty().SetColor(1,0,0)
        cube.GetXPlusFaceProperty().SetColor(1,0,0)
        cube.GetYMinusFaceProperty().SetColor(0,1,0)
        cube.GetYPlusFaceProperty().SetColor(0,1,0)
        cube.GetZMinusFaceProperty().SetColor(0,0,1)
        cube.GetZPlusFaceProperty().SetColor(0,0,1)
        cube.GetTextEdgesProperty().SetColor(0,0,0)

        # anatomic labelling
        cube.SetXPlusFaceText ("A")
        cube.SetXMinusFaceText("P")
        cube.SetYPlusFaceText ("L")
        cube.SetYMinusFaceText("R")
        cube.SetZPlusFaceText ("S")
        cube.SetZMinusFaceText("I")

        axes = vtk.vtkAxesActor()
        axes.SetShaftTypeToCylinder()
        axes.SetTipTypeToCone()
        axes.SetXAxisLabelText("X")
        axes.SetYAxisLabelText("Y")
        axes.SetZAxisLabelText("Z")
        #axes.SetNormalizedLabelPosition(.5, .5, .5)

        orientation_widget = vtk.vtkOrientationMarkerWidget()
        orientation_widget.SetOrientationMarker(cube)
        orientation_widget.SetViewport(0.85,0.85,1.0,1.0)
        #orientation_widget.SetOrientationMarker(axes)
        orientation_widget.SetInteractor(self.interactor)
        orientation_widget.SetEnabled(1)
        orientation_widget.On()
        orientation_widget.InteractiveOff()
Beispiel #10
0
def create_axes_orientation_box(line_width=1, text_scale=0.366667,
                                edge_color='black', x_color='lightblue',
                                y_color='seagreen', z_color='tomato',
                                x_face_color=(255, 0, 0),
                                y_face_color=(0, 255, 0),
                                z_face_color=(0, 0, 255),
                                color_box=False):
    """Create a Box axes orientation widget with labels.
    """
    axes_actor = vtk.vtkAnnotatedCubeActor()
    axes_actor.SetFaceTextScale(text_scale)
    axes_actor.SetXPlusFaceText("X+")
    axes_actor.SetXMinusFaceText("X-")
    axes_actor.SetYPlusFaceText("Y+")
    axes_actor.SetYMinusFaceText("Y-")
    axes_actor.SetZPlusFaceText("Z+")
    axes_actor.SetZMinusFaceText("Z-")
    axes_actor.GetTextEdgesProperty().SetColor(parse_color(edge_color))
    axes_actor.GetTextEdgesProperty().SetLineWidth(line_width)
    axes_actor.GetXPlusFaceProperty().SetColor(parse_color(x_color))
    axes_actor.GetXMinusFaceProperty().SetColor(parse_color(x_color))
    axes_actor.GetYPlusFaceProperty().SetColor(parse_color(y_color))
    axes_actor.GetYMinusFaceProperty().SetColor(parse_color(y_color))
    axes_actor.GetZPlusFaceProperty().SetColor(parse_color(z_color))
    axes_actor.GetZMinusFaceProperty().SetColor(parse_color(z_color))

    if color_box:
        # Hide the cube so we can color each face
        axes_actor.GetCubeProperty().SetOpacity(0)

        cube = pyvista.Cube()
        cube.clear_arrays() # remove normals
        face_colors = np.array([x_face_color,
                                x_face_color,
                                y_face_color,
                                y_face_color,
                                z_face_color,
                                z_face_color,
                               ], dtype=np.uint8)

        cube.cell_arrays['face_colors'] = face_colors

        cube_mapper = vtk.vtkPolyDataMapper()
        cube_mapper.SetInputData(cube)
        cube_mapper.SetColorModeToDirectScalars()
        cube_mapper.Update()

        cube_actor = vtk.vtkActor()
        cube_actor.SetMapper(cube_mapper)
        cube_actor.GetProperty().BackfaceCullingOn()

        prop_assembly = vtk.vtkPropAssembly()
        prop_assembly.AddPart(axes_actor)
        prop_assembly.AddPart(cube_actor)
        actor = prop_assembly
    else:
        actor = axes_actor

    return actor
def main():
    colors = vtk.vtkNamedColors()

    # colors.SetColor('bkg', [0.2, 0.3, 0.7, 1.0])

    # create a rendering window and renderer
    ren = vtk.vtkRenderer()
    ren_win = vtk.vtkRenderWindow()
    ren_win.AddRenderer(ren)
    ren_win.SetWindowName('OrientationMarkerWidget')

    # create a renderwindowinteractor
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(ren_win)

    cube = vtk.vtkCubeSource()
    cube.SetXLength(200)
    cube.SetYLength(200)
    cube.SetZLength(200)
    cube.Update()
    cm = vtk.vtkPolyDataMapper()
    cm.SetInputConnection(cube.GetOutputPort())
    ca = vtk.vtkActor()
    ca.SetMapper(cm)
    ca.GetProperty().SetColor(colors.GetColor3d("BurlyWood"))
    ca.GetProperty().EdgeVisibilityOn()
    ca.GetProperty().SetEdgeColor(colors.GetColor3d("Red"))

    # assign actor to the renderer
    ren.AddActor(ca)
    ren.SetBackground(colors.GetColor3d('CornflowerBlue'))

    axes_actor = vtk.vtkAnnotatedCubeActor()
    axes_actor.SetXPlusFaceText('L')
    axes_actor.SetXMinusFaceText('R')
    axes_actor.SetYMinusFaceText('I')
    axes_actor.SetYPlusFaceText('S')
    axes_actor.SetZMinusFaceText('P')
    axes_actor.SetZPlusFaceText('A')
    axes_actor.GetTextEdgesProperty().SetColor(colors.GetColor3d("Yellow"))
    axes_actor.GetTextEdgesProperty().SetLineWidth(2)
    axes_actor.GetCubeProperty().SetColor(colors.GetColor3d("Blue"))
    axes = vtk.vtkOrientationMarkerWidget()
    axes.SetOrientationMarker(axes_actor)
    axes.SetInteractor(iren)
    axes.EnabledOn()
    axes.InteractiveOn()
    ren.ResetCamera()

    # enable user interface interactor
    iren.Initialize()
    ren_win.Render()
    ren.GetActiveCamera().Azimuth(45)
    ren.GetActiveCamera().Elevation(30)
    ren_win.Render()
    iren.Start()
Beispiel #12
0
    def __init__(self, vtk_filename):
        """
        Initiate Viwer

        Parameters
        ----------
        vtk_filename : str
            Input VTK filename
        """

        QDialog.__init__(self)
        self.initUI()
        
        ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(ren)
        iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        # VTK file
        reader = vtk.vtkUnstructuredGridReader()
        reader.SetFileName(vtk_filename)
        reader.Update()

        # VTK surface
        surface=vtk.vtkDataSetSurfaceFilter()
        surface.SetInput(reader.GetOutput())
        surface.Update()

        mapper = vtk.vtkDataSetMapper()
        mapper.SetInput(surface.GetOutput())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().EdgeVisibilityOn()
        actor.GetProperty().SetEdgeColor(1,1,1)
        actor.GetProperty().SetLineWidth(0.5)
        ren.AddActor(actor)

        # annot. cube
        axesActor = vtk.vtkAnnotatedCubeActor();
        axesActor.SetXPlusFaceText('R')
        axesActor.SetXMinusFaceText('L')
        axesActor.SetYMinusFaceText('H')
        axesActor.SetYPlusFaceText('F')
        axesActor.SetZMinusFaceText('A')
        axesActor.SetZPlusFaceText('P')
        axesActor.GetTextEdgesProperty().SetColor(1,1,0)
        axesActor.GetCubeProperty().SetColor(0,0,1)
        self.axes = vtk.vtkOrientationMarkerWidget()
        self.axes.SetOrientationMarker(axesActor)
        self.axes.SetInteractor(iren)
        self.axes.EnabledOn()
        self.axes.InteractiveOn()

        ren.ResetCamera()
        iren.Initialize()
Beispiel #13
0
 def createCubeOrientation(self):
     self._cubeOrientationActor = vtk.vtkAnnotatedCubeActor()
     self._cubeOrientationActor.SetXPlusFaceText(QtGui.QApplication.translate("ImagePlane", 
                                                  "L", 
                                                  None, 
                                                  QtGui.QApplication.UnicodeUTF8))      
     self._cubeOrientationActor.SetXMinusFaceText(QtGui.QApplication.translate("ImagePlane", 
                                                  "R", 
                                                  None, 
                                                  QtGui.QApplication.UnicodeUTF8))
     self._cubeOrientationActor.SetYPlusFaceText(QtGui.QApplication.translate("ImagePlane", 
                                                  "P", 
                                                  None, 
                                                  QtGui.QApplication.UnicodeUTF8))
     self._cubeOrientationActor.SetYMinusFaceText(QtGui.QApplication.translate("ImagePlane", 
                                                  "A", 
                                                  None, 
                                                  QtGui.QApplication.UnicodeUTF8))
     self._cubeOrientationActor.SetZPlusFaceText(QtGui.QApplication.translate("ImagePlane", 
                                                  "S", 
                                                  None, 
                                                  QtGui.QApplication.UnicodeUTF8))
     self._cubeOrientationActor.SetZMinusFaceText(QtGui.QApplication.translate("ImagePlane", 
                                                  "I", 
                                                  None, 
                                                  QtGui.QApplication.UnicodeUTF8))
     self._cubeOrientationActor.SetZFaceTextRotation(90)
     self._cubeOrientationActor.SetFaceTextScale(0.67)
     
     property = self._cubeOrientationActor.GetXPlusFaceProperty()
     property.SetColor(0, 0, 1)
     property = self._cubeOrientationActor.GetXMinusFaceProperty()
     property.SetColor(0, 0, 1)
     property = self._cubeOrientationActor.GetYPlusFaceProperty()
     property.SetColor(0, 1, 0)
     property = self._cubeOrientationActor.GetYMinusFaceProperty()
     property.SetColor(0, 1, 0)
     property = self._cubeOrientationActor.GetZPlusFaceProperty()
     property.SetColor(1, 0, 0)
     property = self._cubeOrientationActor.GetZMinusFaceProperty()
     property.SetColor(1, 0, 0)
     
     self._cubeOrientationActor.SetTextEdgesVisibility(1)
     self._cubeOrientationActor.SetCubeVisibility(1)
     self._cubeOrientationActor.SetFaceTextVisibility(1)
     
     self.orientationWidget = vtk.vtkOrientationMarkerWidget()    
     self.orientationWidget.SetInteractor(self._interactor)
     self.orientationWidget.SetViewport(0.85, 0.85, 1, 1)
     self.orientationWidget.SetOrientationMarker(self._cubeOrientationActor)
     self.orientationWidget.SetEnabled(1)
     self.orientationWidget.InteractiveOff()
     
     self.orientationWidget.On();
def main():
    colors = vtk.vtkNamedColors()

    colors.SetColor('bkg', [0.2, 0.3, 0.7, 1.0])

    # create a rendering window and renderer
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)

    # create a renderwindowinteractor
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    cube = vtk.vtkCubeSource()
    cube.SetXLength(200)
    cube.SetYLength(200)
    cube.SetZLength(200)
    cube.Update()
    cm = vtk.vtkPolyDataMapper()
    cm.SetInputConnection(cube.GetOutputPort())
    ca = vtk.vtkActor()
    ca.SetMapper(cm)
    ca.GetProperty().SetColor(colors.GetColor3d("BurlyWood"))

    # assign actor to the renderer
    ren.AddActor(ca)
    ren.SetBackground(colors.GetColor3d('bkg'))

    axesActor = vtk.vtkAnnotatedCubeActor()
    axesActor.SetXPlusFaceText('R')
    axesActor.SetXMinusFaceText('L')
    axesActor.SetYMinusFaceText('H')
    axesActor.SetYPlusFaceText('F')
    axesActor.SetZMinusFaceText('P')
    axesActor.SetZPlusFaceText('A')
    axesActor.GetTextEdgesProperty().SetColor(colors.GetColor3d("Yellow"))
    axesActor.GetTextEdgesProperty().SetLineWidth(2)
    axesActor.GetCubeProperty().SetColor(colors.GetColor3d("Blue"))
    axes = vtk.vtkOrientationMarkerWidget()
    axes.SetOrientationMarker(axesActor)
    axes.SetInteractor(iren)
    axes.EnabledOn()
    axes.InteractiveOn()
    ren.ResetCamera()

    # enable user interface interactor
    iren.Initialize()
    renWin.Render()
    ren.GetActiveCamera().SetPosition(-151.5, 540.1, 364.0)
    ren.GetActiveCamera().SetViewUp(0.2, 0.6, -0.8)
    renWin.Render()
    iren.Start()
    def __init__(self):
        '''
        Constructor
        '''
        vtkPythonViewImage.__init__(self)
        
#        texture mapper in 3D: vtkVolumeMapper
        self.__VolumeMapper = None
#        texture mapper in 3D: vtkVolumeTextureMapper3D
        self.__VolumeTextureMapper = vtk.vtkVolumeTextureMapper3D()
#        volume ray cast mapper vtkFixedPointVolumeRayCastMapper
        self.__VolumeRayCastMapper = vtk.vtkFixedPointVolumeRayCastMapper()
#        volume property: vtkVolumeProperty
        self.__VolumeProperty = vtk.vtkVolumeProperty()
#        volume actor: vtkVolume
        self.__VolumeActor = vtk.vtkVolume()
#        opacity transfer function: vtkPiecewiseFunction
        self.__OpacityFunction = vtk.vtkPiecewiseFunction()
#        color transfer function: vtkColorTransferFunction
        self.__ColorFunction = vtk.vtkColorTransferFunction()
        
#        vtkProp3DCollection
        self.__PhantomCollection = vtk.vtkProp3DCollection()
#        blender: vtkImageBlend
        self.__Blender = None
        
#        image 3D cropping box callback: vtkImage3DCroppingBoxCallback
        self.__Callback = vtkPythonImage3DCroppingBoxCallback()
#        box widget: vtkOrientedBoxWidget
#        self.__BoxWidget = vtkOrientedBoxWidget()    # Now I could not wrap vtkOrientedBoxWidget
        self.__BoxWidget = vtk.vtkBoxWidget()
#        vtkPlane widget: vtkPlaneWidget
        self.__PlaneWidget = vtk.vtkPlaneWidget()
#        annotated cube actor: vtkAnnotatedCubeActor, vtkOrientationMarkerWidget
        self.__Cube = vtk.vtkAnnotatedCubeActor()
        self.__Marker = vtk.vtkOrientationMarkerWidget()
        
        self.SetupVolumeRendering()
        self.SetupWidgets()
        
        self.ShowAnnotationsOn()
        self.getTextProperty().SetColor(0, 0, 0)
        self.SetBackground(0.9, 0.9, 0.9) # white
        
        self.__FirstRender = 1
        self.__RenderingMode = self.PLANAR_RENDERING
        self.__VRQuality = 1
        
        self.__InteractorStyleSwitcher = None
Beispiel #16
0
    def __init__(self, rwi):

        self._orientation_widget = vtk.vtkOrientationMarkerWidget()
        self._orientation_widget.SetInteractor(rwi)

        # we'll use this if there is no orientation metadata
        # just a thingy with x-y-z indicators
        self._axes_actor = vtk.vtkAxesActor()

        # we'll use this if there is orientation metadata
        self._annotated_cube_actor = aca = vtk.vtkAnnotatedCubeActor()

        # configure the thing with better colours and no stupid edges
        #aca.TextEdgesOff()
        aca.GetXMinusFaceProperty().SetColor(1, 0, 0)
        aca.GetXPlusFaceProperty().SetColor(1, 0, 0)
        aca.GetYMinusFaceProperty().SetColor(0, 1, 0)
        aca.GetYPlusFaceProperty().SetColor(0, 1, 0)
        aca.GetZMinusFaceProperty().SetColor(0, 0, 1)
        aca.GetZPlusFaceProperty().SetColor(0, 0, 1)
Beispiel #17
0
    def __init__(self, rwi):


        self._orientation_widget = vtk.vtkOrientationMarkerWidget()
        self._orientation_widget.SetInteractor(rwi)

        # we'll use this if there is no orientation metadata
        # just a thingy with x-y-z indicators
        self._axes_actor = vtk.vtkAxesActor()

        # we'll use this if there is orientation metadata
        self._annotated_cube_actor = aca = vtk.vtkAnnotatedCubeActor()

        # configure the thing with better colours and no stupid edges 
        #aca.TextEdgesOff()
        aca.GetXMinusFaceProperty().SetColor(1,0,0)
        aca.GetXPlusFaceProperty().SetColor(1,0,0)
        aca.GetYMinusFaceProperty().SetColor(0,1,0)
        aca.GetYPlusFaceProperty().SetColor(0,1,0)
        aca.GetZMinusFaceProperty().SetColor(0,0,1)
        aca.GetZPlusFaceProperty().SetColor(0,0,1)
Beispiel #18
0
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.widget = self.ui.vtkWidget
        self.ren = vtk.vtkRenderer()
        renwin = self.widget.GetRenderWindow()
        renwin.AddRenderer(self.ren)
        iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()

        cube = vtk.vtkCubeSource()
        cube.SetXLength(200)
        cube.SetYLength(200)
        cube.SetZLength(200)
        cube.Update()
        cm = vtk.vtkPolyDataMapper()
        cm.SetInputConnection(cube.GetOutputPort())
        ca = vtk.vtkActor()
        ca.SetMapper(cm)
        self.ren.AddActor(ca)

        if 1:  # AnnotatedCubeActor
            self.axesActor = vtk.vtkAnnotatedCubeActor()
            self.axesActor.SetXPlusFaceText('R')
            self.axesActor.SetXMinusFaceText('L')
            self.axesActor.SetYMinusFaceText('H')
            self.axesActor.SetYPlusFaceText('F')
            self.axesActor.SetZMinusFaceText('P')
            self.axesActor.SetZPlusFaceText('A')
            self.axesActor.GetTextEdgesProperty().SetColor(1, 1, 0)
            self.axesActor.GetTextEdgesProperty().SetLineWidth(2)
            self.axesActor.GetCubeProperty().SetColor(0, 0, 1)
            self.axes = vtk.vtkOrientationMarkerWidget()
            self.axes.SetOrientationMarker(self.axesActor)
            self.axes.SetInteractor(iren)
            self.axes.EnabledOn()
            self.axes.InteractiveOn()

        self.ren.ResetCamera()
iren.SetRenderWindow(renWin)
 
cube = vtk.vtkCubeSource()
cube.SetXLength(200)
cube.SetYLength(200)
cube.SetZLength(200)
cube.Update()
cm = vtk.vtkPolyDataMapper()
cm.SetInputConnection(cube.GetOutputPort())
ca = vtk.vtkActor()
ca.SetMapper(cm)
 
# assign actor to the renderer
ren.AddActor(ca)
 
axesActor = vtk.vtkAnnotatedCubeActor();
axesActor.SetXPlusFaceText('R')
axesActor.SetXMinusFaceText('L')
axesActor.SetYMinusFaceText('H')
axesActor.SetYPlusFaceText('F')
axesActor.SetZMinusFaceText('P')
axesActor.SetZPlusFaceText('A')
axesActor.GetTextEdgesProperty().SetColor(1,1,0)
axesActor.GetTextEdgesProperty().SetLineWidth(2)
axesActor.GetCubeProperty().SetColor(0,0,1)
axes = vtk.vtkOrientationMarkerWidget()
axes.SetOrientationMarker(axesActor)
axes.SetInteractor(iren)
axes.EnabledOn()
axes.InteractiveOn()
ren.ResetCamera()
Beispiel #20
0
def addAxes(axtype=None, c=None):
    """Draw axes on scene. Available axes types:

    :param int axtype:

          - 0,  no axes,
          - 1,  draw three gray grid walls
          - 2,  show cartesian axes from (0,0,0)
          - 3,  show positive range of cartesian axes from (0,0,0)
          - 4,  show a triad at bottom left
          - 5,  show a cube at bottom left
          - 6,  mark the corners of the bounding box
          - 7,  draw a simple ruler at the bottom of the window
          - 8,  show the ``vtkCubeAxesActor`` object
          - 9,  show the bounding box outLine
          - 10, show three circles representing the maximum bounding box
    """
    vp = settings.plotter_instance
    if axtype is not None:
        vp.axes = axtype  # overrride

    r = vp.renderers.index(vp.renderer)

    if not vp.axes:
        return

    if c is None:  # automatic black or white
        c = (0.9, 0.9, 0.9)
        if numpy.sum(vp.renderer.GetBackground()) > 1.5:
            c = (0.1, 0.1, 0.1)

    if not vp.renderer:
        return

    if vp.axes_exist[r]:
        return

    # calculate max actors bounds
    bns = []
    for a in vp.actors:
        if a and a.GetPickable():
            b = a.GetBounds()
            if b:
                bns.append(b)
    if len(bns):
        max_bns = numpy.max(bns, axis=0)
        min_bns = numpy.min(bns, axis=0)
        vbb = (min_bns[0], max_bns[1], min_bns[2], max_bns[3], min_bns[4],
               max_bns[5])
    else:
        vbb = vp.renderer.ComputeVisiblePropBounds()
        max_bns = vbb
        min_bns = vbb
    sizes = (max_bns[1] - min_bns[0], max_bns[3] - min_bns[2],
             max_bns[5] - min_bns[4])

    ############################################################
    if vp.axes == 1 or vp.axes == True:  # gray grid walls
        nd = 4  # number of divisions in the smallest axis
        off = -0.04  # label offset
        step = numpy.min(sizes) / nd
        if not step:
            # bad proportions, use vtkCubeAxesActor
            vp.addAxes(axtype=8, c=c)
            vp.axes = 1
            return

        rx, ry, rz = numpy.rint(sizes / step).astype(int)
        if max([rx / ry, ry / rx, rx / rz, rz / rx, ry / rz, rz / ry]) > 15:
            # bad proportions, use vtkCubeAxesActor
            vp.addAxes(axtype=8, c=c)
            vp.axes = 1
            return

        gxy = shapes.Grid(pos=(0.5, 0.5, 0),
                          normal=[0, 0, 1],
                          bc=None,
                          resx=rx,
                          resy=ry)
        gxz = shapes.Grid(pos=(0.5, 0, 0.5),
                          normal=[0, 1, 0],
                          bc=None,
                          resx=rz,
                          resy=rx)
        gyz = shapes.Grid(pos=(0, 0.5, 0.5),
                          normal=[1, 0, 0],
                          bc=None,
                          resx=rz,
                          resy=ry)
        gxy.alpha(0.06).wire(False).color(c).lineWidth(1)
        gxz.alpha(0.04).wire(False).color(c).lineWidth(1)
        gyz.alpha(0.04).wire(False).color(c).lineWidth(1)

        xa = shapes.Line([0, 0, 0], [1, 0, 0], c=c, lw=1)
        ya = shapes.Line([0, 0, 0], [0, 1, 0], c=c, lw=1)
        za = shapes.Line([0, 0, 0], [0, 0, 1], c=c, lw=1)

        xt, yt, zt, ox, oy, oz = [None] * 6
        if vp.xtitle:
            xtitle = vp.xtitle
            if min_bns[0] <= 0 and max_bns[1] > 0:  # mark x origin
                ox = shapes.Cube([-min_bns[0] / sizes[0], 0, 0],
                                 side=0.008,
                                 c=c)
            if len(vp.xtitle) == 1:  # add axis length info
                xtitle = vp.xtitle + " /" + utils.precision(sizes[0], 4)
            wpos = [1 - (len(vp.xtitle) + 1) / 40, off, 0]
            xt = shapes.Text(xtitle,
                             pos=wpos,
                             normal=(0, 0, 1),
                             s=0.025,
                             c=c,
                             justify="bottom-right")

        if vp.ytitle:
            if min_bns[2] <= 0 and max_bns[3] > 0:  # mark y origin
                oy = shapes.Cube([0, -min_bns[2] / sizes[1], 0],
                                 side=0.008,
                                 c=c)
            yt = shapes.Text(vp.ytitle,
                             pos=(0, 0, 0),
                             normal=(0, 0, 1),
                             s=0.025,
                             c=c,
                             justify="bottom-right")
            if len(vp.ytitle) == 1:
                wpos = [off, 1 - (len(vp.ytitle) + 1) / 40, 0]
                yt.pos(wpos)
            else:
                wpos = [off * 0.7, 1 - (len(vp.ytitle) + 1) / 40, 0]
                yt.rotateZ(90).pos(wpos)

        if vp.ztitle:
            if min_bns[4] <= 0 and max_bns[5] > 0:  # mark z origin
                oz = shapes.Cube([0, 0, -min_bns[4] / sizes[2]],
                                 side=0.008,
                                 c=c)
            zt = shapes.Text(vp.ztitle,
                             pos=(0, 0, 0),
                             normal=(1, -1, 0),
                             s=0.025,
                             c=c,
                             justify="bottom-right")
            if len(vp.ztitle) == 1:
                wpos = [off * 0.6, off * 0.6, 1 - (len(vp.ztitle) + 1) / 40]
                zt.rotate(90, (1, -1, 0)).pos(wpos)
            else:
                wpos = [off * 0.3, off * 0.3, 1 - (len(vp.ztitle) + 1) / 40]
                zt.rotate(180, (1, -1, 0)).pos(wpos)

        acts = [gxy, gxz, gyz, xa, ya, za, xt, yt, zt, ox, oy, oz]
        for a in acts:
            if a:
                a.PickableOff()
        aa = Assembly(acts)
        aa.pos(min_bns[0], min_bns[2], min_bns[4])
        aa.SetScale(sizes)
        aa.PickableOff()
        vp.renderer.AddActor(aa)
        vp.axes_exist[r] = aa

    elif vp.axes == 2 or vp.axes == 3:
        vbb = vp.renderer.ComputeVisiblePropBounds()  # to be double checked
        xcol, ycol, zcol = "db", "dg", "dr"
        s = 1
        alpha = 1
        centered = False
        x0, x1, y0, y1, z0, z1 = vbb
        dx, dy, dz = x1 - x0, y1 - y0, z1 - z0
        aves = numpy.sqrt(dx * dx + dy * dy + dz * dz) / 2
        x0, x1 = min(x0, 0), max(x1, 0)
        y0, y1 = min(y0, 0), max(y1, 0)
        z0, z1 = min(z0, 0), max(z1, 0)

        if vp.axes == 3:
            if x1 > 0:
                x0 = 0
            if y1 > 0:
                y0 = 0
            if z1 > 0:
                z0 = 0

        dx, dy, dz = x1 - x0, y1 - y0, z1 - z0
        acts = []
        if x0 * x1 <= 0 or y0 * z1 <= 0 or z0 * z1 <= 0:  # some ranges contain origin
            zero = shapes.Sphere(r=aves / 120 * s, c="k", alpha=alpha, res=10)
            acts += [zero]

        if len(vp.xtitle) and dx > aves / 100:
            xl = shapes.Cylinder([[x0, 0, 0], [x1, 0, 0]],
                                 r=aves / 250 * s,
                                 c=xcol,
                                 alpha=alpha)
            xc = shapes.Cone(pos=[x1, 0, 0],
                             c=xcol,
                             alpha=alpha,
                             r=aves / 100 * s,
                             height=aves / 25 * s,
                             axis=[1, 0, 0],
                             res=10)
            wpos = [
                x1 - (len(vp.xtitle) + 1) * aves / 40 * s, -aves / 25 * s, 0
            ]  # aligned to arrow tip
            if centered:
                wpos = [(x0 + x1) / 2 - len(vp.xtitle) / 2 * aves / 40 * s,
                        -aves / 25 * s, 0]
            xt = shapes.Text(vp.xtitle,
                             pos=wpos,
                             normal=(0, 0, 1),
                             s=aves / 40 * s,
                             c=xcol)
            acts += [xl, xc, xt]

        if len(vp.ytitle) and dy > aves / 100:
            yl = shapes.Cylinder([[0, y0, 0], [0, y1, 0]],
                                 r=aves / 250 * s,
                                 c=ycol,
                                 alpha=alpha)
            yc = shapes.Cone(pos=[0, y1, 0],
                             c=ycol,
                             alpha=alpha,
                             r=aves / 100 * s,
                             height=aves / 25 * s,
                             axis=[0, 1, 0],
                             res=10)
            wpos = [
                -aves / 40 * s, y1 - (len(vp.ytitle) + 1) * aves / 40 * s, 0
            ]
            if centered:
                wpos = [
                    -aves / 40 * s,
                    (y0 + y1) / 2 - len(vp.ytitle) / 2 * aves / 40 * s, 0
                ]
            yt = shapes.Text(vp.ytitle,
                             pos=(0, 0, 0),
                             normal=(0, 0, 1),
                             s=aves / 40 * s,
                             c=ycol)
            yt.rotate(90, [0, 0, 1]).pos(wpos)
            acts += [yl, yc, yt]

        if len(vp.ztitle) and dz > aves / 100:
            zl = shapes.Cylinder([[0, 0, z0], [0, 0, z1]],
                                 r=aves / 250 * s,
                                 c=zcol,
                                 alpha=alpha)
            zc = shapes.Cone(pos=[0, 0, z1],
                             c=zcol,
                             alpha=alpha,
                             r=aves / 100 * s,
                             height=aves / 25 * s,
                             axis=[0, 0, 1],
                             res=10)
            wpos = [
                -aves / 50 * s, -aves / 50 * s,
                z1 - (len(vp.ztitle) + 1) * aves / 40 * s
            ]
            if centered:
                wpos = [
                    -aves / 50 * s, -aves / 50 * s,
                    (z0 + z1) / 2 - len(vp.ztitle) / 2 * aves / 40 * s
                ]
            zt = shapes.Text(vp.ztitle,
                             pos=(0, 0, 0),
                             normal=(1, -1, 0),
                             s=aves / 40 * s,
                             c=zcol)
            zt.rotate(180, (1, -1, 0)).pos(wpos)
            acts += [zl, zc, zt]
        for a in acts:
            a.PickableOff()
        ass = Assembly(acts)
        ass.PickableOff()
        vp.renderer.AddActor(ass)
        vp.axes_exist[r] = ass

    elif vp.axes == 4:
        axact = vtk.vtkAxesActor()
        axact.SetShaftTypeToCylinder()
        axact.SetCylinderRadius(0.03)
        axact.SetXAxisLabelText(vp.xtitle)
        axact.SetYAxisLabelText(vp.ytitle)
        axact.SetZAxisLabelText(vp.ztitle)
        axact.GetXAxisShaftProperty().SetColor(0, 0, 1)
        axact.GetZAxisShaftProperty().SetColor(1, 0, 0)
        axact.GetXAxisTipProperty().SetColor(0, 0, 1)
        axact.GetZAxisTipProperty().SetColor(1, 0, 0)
        bc = numpy.array(vp.renderer.GetBackground())
        if numpy.sum(bc) < 1.5:
            lc = (1, 1, 1)
        else:
            lc = (0, 0, 0)
        axact.GetXAxisCaptionActor2D().GetCaptionTextProperty().BoldOff()
        axact.GetYAxisCaptionActor2D().GetCaptionTextProperty().BoldOff()
        axact.GetZAxisCaptionActor2D().GetCaptionTextProperty().BoldOff()
        axact.GetXAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff()
        axact.GetYAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff()
        axact.GetZAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff()
        axact.GetXAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
        axact.GetYAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
        axact.GetZAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
        axact.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetColor(lc)
        axact.GetYAxisCaptionActor2D().GetCaptionTextProperty().SetColor(lc)
        axact.GetZAxisCaptionActor2D().GetCaptionTextProperty().SetColor(lc)
        axact.PickableOff()
        icn = addIcon(axact, size=0.1)
        vp.axes_exist[r] = icn

    elif vp.axes == 5:
        axact = vtk.vtkAnnotatedCubeActor()
        axact.GetCubeProperty().SetColor(0.75, 0.75, 0.75)
        axact.SetTextEdgesVisibility(0)
        axact.SetFaceTextScale(0.4)
        axact.GetXPlusFaceProperty().SetColor(colors.getColor("b"))
        axact.GetXMinusFaceProperty().SetColor(colors.getColor("db"))
        axact.GetYPlusFaceProperty().SetColor(colors.getColor("g"))
        axact.GetYMinusFaceProperty().SetColor(colors.getColor("dg"))
        axact.GetZPlusFaceProperty().SetColor(colors.getColor("r"))
        axact.GetZMinusFaceProperty().SetColor(colors.getColor("dr"))
        axact.PickableOff()
        icn = addIcon(axact, size=0.06)
        vp.axes_exist[r] = icn

    elif vp.axes == 6:
        ocf = vtk.vtkOutlineCornerFilter()
        ocf.SetCornerFactor(0.1)
        largestact, sz = None, -1
        for a in vp.actors:
            if a.GetPickable():
                b = a.GetBounds()
                d = max(b[1] - b[0], b[3] - b[2], b[5] - b[4])
                if sz < d:
                    largestact = a
                    sz = d
        if isinstance(largestact, Assembly):
            ocf.SetInputData(largestact.getActor(0).GetMapper().GetInput())
        else:
            ocf.SetInputData(largestact.polydata())
        ocf.Update()
        ocMapper = vtk.vtkHierarchicalPolyDataMapper()
        ocMapper.SetInputConnection(0, ocf.GetOutputPort(0))
        ocActor = vtk.vtkActor()
        ocActor.SetMapper(ocMapper)
        bc = numpy.array(vp.renderer.GetBackground())
        if numpy.sum(bc) < 1.5:
            lc = (1, 1, 1)
        else:
            lc = (0, 0, 0)
        ocActor.GetProperty().SetColor(lc)
        ocActor.PickableOff()
        vp.renderer.AddActor(ocActor)
        vp.axes_exist[r] = ocActor

    elif vp.axes == 7:
        # draws a simple ruler at the bottom of the window
        ls = vtk.vtkLegendScaleActor()
        ls.RightAxisVisibilityOff()
        ls.TopAxisVisibilityOff()
        ls.LegendVisibilityOff()
        ls.LeftAxisVisibilityOff()
        ls.GetBottomAxis().SetNumberOfMinorTicks(1)
        ls.GetBottomAxis().GetProperty().SetColor(c)
        ls.GetBottomAxis().GetLabelTextProperty().SetColor(c)
        ls.GetBottomAxis().GetLabelTextProperty().BoldOff()
        ls.GetBottomAxis().GetLabelTextProperty().ItalicOff()
        ls.GetBottomAxis().GetLabelTextProperty().ShadowOff()
        ls.PickableOff()
        vp.renderer.AddActor(ls)
        vp.axes_exist[r] = ls

    elif vp.axes == 8:
        ca = vtk.vtkCubeAxesActor()
        ca.SetBounds(vbb)
        if vp.camera:
            ca.SetCamera(vp.camera)
        else:
            ca.SetCamera(vp.renderer.GetActiveCamera())
        ca.GetXAxesLinesProperty().SetColor(c)
        ca.GetYAxesLinesProperty().SetColor(c)
        ca.GetZAxesLinesProperty().SetColor(c)
        for i in range(3):
            ca.GetLabelTextProperty(i).SetColor(c)
            ca.GetTitleTextProperty(i).SetColor(c)
        ca.SetTitleOffset(5)
        ca.SetFlyMode(3)
        ca.SetXTitle(vp.xtitle)
        ca.SetYTitle(vp.ytitle)
        ca.SetZTitle(vp.ztitle)
        if vp.xtitle == "":
            ca.SetXAxisVisibility(0)
            ca.XAxisLabelVisibilityOff()
        if vp.ytitle == "":
            ca.SetYAxisVisibility(0)
            ca.YAxisLabelVisibilityOff()
        if vp.ztitle == "":
            ca.SetZAxisVisibility(0)
            ca.ZAxisLabelVisibilityOff()
        ca.PickableOff()
        vp.renderer.AddActor(ca)
        vp.axes_exist[r] = ca
        return

    elif vp.axes == 9:
        src = vtk.vtkCubeSource()
        src.SetXLength(vbb[1] - vbb[0])
        src.SetYLength(vbb[3] - vbb[2])
        src.SetZLength(vbb[5] - vbb[4])
        src.Update()
        ca = Actor(src.GetOutput(), c=c, alpha=0.5, wire=1)
        ca.pos((vbb[0] + vbb[1]) / 2, (vbb[3] + vbb[2]) / 2,
               (vbb[5] + vbb[4]) / 2)
        ca.PickableOff()
        vp.renderer.AddActor(ca)
        vp.axes_exist[r] = ca

    elif vp.axes == 10:
        x0 = (vbb[0] + vbb[1]) / 2, (vbb[3] + vbb[2]) / 2, (vbb[5] +
                                                            vbb[4]) / 2
        rx, ry, rz = (vbb[1] - vbb[0]) / 2, (vbb[3] - vbb[2]) / 2, (vbb[5] -
                                                                    vbb[4]) / 2
        rm = max(rx, ry, rz)
        xc = shapes.Disc(x0, (0, 0, 1),
                         r1=rm,
                         r2=rm,
                         c='lr',
                         bc=None,
                         res=1,
                         resphi=72)
        yc = shapes.Disc(x0, (0, 1, 0),
                         r1=rm,
                         r2=rm,
                         c='lg',
                         bc=None,
                         res=1,
                         resphi=72)
        zc = shapes.Disc(x0, (1, 0, 0),
                         r1=rm,
                         r2=rm,
                         c='lb',
                         bc=None,
                         res=1,
                         resphi=72)
        xc.clean().alpha(0.2).wire().lineWidth(2.5).PickableOff()
        yc.clean().alpha(0.2).wire().lineWidth(2.5).PickableOff()
        zc.clean().alpha(0.2).wire().lineWidth(2.5).PickableOff()
        ca = xc + yc + zc
        ca.PickableOff()
        vp.renderer.AddActor(ca)
        vp.axes_exist[r] = ca

    else:
        colors.printc('~bomb Keyword axes must be in range [0-10].', c=1)
        colors.printc('''
  ~target Available axes types:
  0 = no axes,
  1 = draw three gray grid walls
  2 = show cartesian axes from (0,0,0)
  3 = show positive range of cartesian axes from (0,0,0)
  4 = show a triad at bottom left
  5 = show a cube at bottom left
  6 = mark the corners of the bounding box
  7 = draw a simple ruler at the bottom of the window
  8 = show the vtkCubeAxesActor object
  9 = show the bounding box outline
  10 = show three circles representing the maximum bounding box
  ''',
                      c=1,
                      bold=0)

    if not vp.axes_exist[r]:
        vp.axes_exist[r] = True
    return
    def vtkCube(self, data_matrix=None):

        # We begin by creating the data we want to render.
        # For this tutorial, we create a 3D-image containing three overlaping cubes.
        # This data can of course easily be replaced by data from a medical CT-scan or anything else three dimensional.
        # The only limit is that the data must be reduced to unsigned 8 bit or 16 bit integers.
        #data_matrix = zeros([75, 75, 75], dtype=uint8)
        #data_matrix[0:35, 0:35, 0:35] = 50
        #data_matrix[25:55, 25:55, 25:55] = 100
        #data_matrix[45:74, 45:74, 45:74] = 150

        # For VTK to be able to use the data, it must be stored as a VTK-image. This can be done by the vtkImageImport-class which
        # imports raw data and stores it.
        dataImporter = vtk.vtkImageImport()
        # The preaviusly created array is converted to a string of chars and imported.
        data_string = data_matrix.tostring()
        dataImporter.CopyImportVoidPointer(data_string, len(data_string))
        # The type of the newly imported data is set to unsigned char (uint8)
        dataImporter.SetDataScalarTypeToUnsignedChar()
        # Because the data that is imported only contains an intensity value (it isnt RGB-coded or someting similar), the importer
        # must be told this is the case.
        dataImporter.SetNumberOfScalarComponents(1)
        # The following two functions describe how the data is stored and the dimensions of the array it is stored in. For this
        # simple case, all axes are of length 75 and begins with the first element. For other data, this is probably not the case.
        # I have to admit however, that I honestly dont know the difference between SetDataExtent() and SetWholeExtent() although
        # VTK complains if not both are used.
        dataImporter.SetDataExtent(0, 9, 0, 9, 0, 9)
        dataImporter.SetWholeExtent(0, 9, 0, 9, 0, 9)
        #dataImporter.SetDataExtent(0, 74, 0, 74, 0, 74)
        #dataImporter.SetWholeExtent(0, 74, 0, 74, 0, 74)

        # The following class is used to store transparencyv-values for later retrival. In our case, we want the value 0 to be
        # completly opaque whereas the three different cubes are given different transperancy-values to show how it works.
        alphaChannelFunc = vtk.vtkPiecewiseFunction()
        alphaChannelFunc.AddPoint(0, 0.6)
        alphaChannelFunc.AddPoint(33, 0.2)
        alphaChannelFunc.AddPoint(66, 0.1)
        alphaChannelFunc.AddPoint(100, 0.01)

        # Gradient opacity
        # other way: misfit 0 is anti opacity
        volumeGradientOpacity = vtk.vtkPiecewiseFunction()
        volumeGradientOpacity.AddPoint(70, 1.0)
        volumeGradientOpacity.AddPoint(50, 0.5)
        volumeGradientOpacity.AddPoint(20, 0.0)

        # This class stores color data and can create color tables from a few color points. For this demo, we want the three cubes
        # to be of the colors red green and blue.
        colorFunc = vtk.vtkColorTransferFunction()
        colorFunc.AddRGBPoint(00, 1.0, 0.0, 0.0)
        colorFunc.AddRGBPoint(30, 0.0, 1.0, 0.0)
        colorFunc.AddRGBPoint(60, 0.0, 0.0, 1.0)

        # The preavius two classes stored properties. Because we want to apply these properties to the volume we want to render,
        # we have to store them in a class that stores volume prpoperties.
        volumeProperty = vtk.vtkVolumeProperty()
        volumeProperty.SetColor(colorFunc)
        volumeProperty.SetScalarOpacity(alphaChannelFunc)
        volumeProperty.SetGradientOpacity(volumeGradientOpacity)
        volumeProperty.SetInterpolationTypeToLinear()
        volumeProperty.ShadeOff()
        volumeProperty.SetAmbient(0.1)
        volumeProperty.SetDiffuse(0.6)
        volumeProperty.SetSpecular(0.2)

        # This class describes how the volume is rendered (through ray tracing).
        compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
        # We can finally create our volume. We also have to specify the data for it, as well as how the data will be rendered.
        volumeMapper = vtk.vtkVolumeRayCastMapper()
        volumeMapper.SetVolumeRayCastFunction(compositeFunction)
        volumeMapper.SetInputConnection(dataImporter.GetOutputPort())

        # The class vtkVolume is used to pair the preaviusly declared volume as well as the properties to be used when rendering that volume.
        volume = vtk.vtkVolume()
        volume.SetMapper(volumeMapper)
        volume.SetProperty(volumeProperty)

        # Text am Nullpunkt
        atext = vtk.vtkVectorText()
        atext.SetText("(0,0,0)")
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInputConnection(atext.GetOutputPort())
        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetScale(10, 10, 10)
        textActor.AddPosition(0, -0.1, 78)

        # Cube to give some orientation
        # (from http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/OrientationMarkerWidget)

        axesActor = vtk.vtkAnnotatedCubeActor()
        axesActor.SetXPlusFaceText('N')
        axesActor.SetXMinusFaceText('S')
        axesActor.SetYMinusFaceText('W')
        axesActor.SetYPlusFaceText('E')
        axesActor.SetZMinusFaceText('D')
        axesActor.SetZPlusFaceText('U')
        axesActor.GetTextEdgesProperty().SetColor(1, 1, 0)
        axesActor.GetTextEdgesProperty().SetLineWidth(2)
        axesActor.GetCubeProperty().SetColor(0, 0, 1)

        # With almost everything else ready, its time to initialize the renderer and window, as well as creating a method for exiting the application
        renderer = vtk.vtkRenderer()
        renderWin = vtk.vtkRenderWindow()
        renderWin.AddRenderer(renderer)
        renderInteractor = vtk.vtkRenderWindowInteractor()
        renderInteractor.SetRenderWindow(renderWin)

        axes = vtk.vtkOrientationMarkerWidget()
        axes.SetOrientationMarker(axesActor)
        axes.SetInteractor(renderInteractor)
        axes.EnabledOn()
        axes.InteractiveOn()
        renderer.ResetCamera()

        # We add the volume to the renderer ...
        renderer.AddVolume(volume)
        # ... set background color to white ...
        renderer.SetBackground(0.7, 0.7, 0.7)
        # ... and set window size.
        renderWin.SetSize(400, 400)

        # Fuege Text am Nullpunkt hinzu:
        renderer.AddActor(textActor)

        # A simple function to be called when the user decides to quit the application.
        def exitCheck(obj, event):
            if obj.GetEventPending() != 0:
                obj.SetAbortRender(1)

        # Tell the application to use the function as an exit check.
        renderWin.AddObserver("AbortCheckEvent", exitCheck)

        renderInteractor.Initialize()
        # Because nothing will be rendered without any input, we order the first render manually before control is handed over to the main-loop.
        renderWin.Render()
        renderInteractor.Start()
Beispiel #22
0
    def CreateMarker(self):
        # Create a composite orientation marker using
        # vtkAnnotatedCubeActor and vtkAxesActor.
        #
        cube = vtkAnnotatedCubeActor()
        cube.SetXPlusFaceText("R")
        cube.SetXMinusFaceText("L")
        cube.SetYPlusFaceText("A")
        cube.SetYMinusFaceText("P")
        cube.SetZPlusFaceText("I")
        cube.SetZMinusFaceText("S")
        cube.SetXFaceTextRotation(0)
        cube.SetYFaceTextRotation(0)
        cube.SetZFaceTextRotation(-90)
        cube.SetFaceTextScale(0.65)

        prop = cube.GetCubeProperty()
        prop.SetColor(0.5, 1, 1)

        prop = cube.GetTextEdgesProperty()
        prop.SetLineWidth(1)
        prop.SetDiffuse(0)
        prop.SetAmbient(1)
        prop.SetColor(0.18, 0.28, 0.23)

        for axis, colour in (('X', (0,0,1)),
                             ('Y', (0,1,0)),
                             ('Z', (1,0,0))):
            for orient in ('Plus', 'Minus'):
                prop = getattr(cube, 'Get'+axis+orient+'FaceProperty')()
                prop.SetColor(*colour)
                prop.SetInterpolationToFlat()
                continue
            continue

        axes = vtkAxesActor()
        axes.SetShaftTypeToCylinder()
        axes.SetXAxisLabelText("x")
        axes.SetYAxisLabelText("y")
        axes.SetZAxisLabelText("z")
        axes.SetTotalLength(1.5, 1.5, 1.5)

        tpropx = vtkTextProperty()
        tpropx.ItalicOn()
        tpropx.ShadowOn()
        tpropx.SetFontFamilyToTimes()
        axes.GetXAxisCaptionActor2D().SetCaptionTextProperty(tpropx)
        tpropy = vtkTextProperty()
        tpropy.ShallowCopy(tpropx)
        axes.GetYAxisCaptionActor2D().SetCaptionTextProperty(tpropy)
        tpropz = vtkTextProperty()
        tpropz.ShallowCopy(tpropx)
        axes.GetZAxisCaptionActor2D().SetCaptionTextProperty(tpropz)

        # Combine the two actors into one with vtkPropAssembly ...
        #
        assembly = vtkPropAssembly()
        assembly.AddPart(axes)
        assembly.AddPart(cube)

        # Add the composite marker to the widget.  The widget
        # should be kept in non-interactive mode and the aspect
        # ratio of the render window taken into account explicitly, 
        # since the widget currently does not take this into 
        # account in a multi-renderer environment.
        # 
        marker = vtkOrientationMarkerWidget()
        marker.SetOutlineColor(0.93, 0.57, 0.13)
        marker.SetOrientationMarker(assembly)
        marker.SetViewport(0.0, 0.0, 0.15, 0.3)
        self.OrientationMarker = marker
        return
    def vtkCube(self, data_matrix=None):

        # We begin by creating the data we want to render.
        # For this tutorial, we create a 3D-image containing three overlaping cubes.
        # This data can of course easily be replaced by data from a medical CT-scan or anything else three dimensional.
        # The only limit is that the data must be reduced to unsigned 8 bit or 16 bit integers.
        #data_matrix = zeros([75, 75, 75], dtype=uint8)
        #data_matrix[0:35, 0:35, 0:35] = 50
        #data_matrix[25:55, 25:55, 25:55] = 100
        #data_matrix[45:74, 45:74, 45:74] = 150

        # For VTK to be able to use the data, it must be stored as a VTK-image. This can be done by the vtkImageImport-class which
        # imports raw data and stores it.
        dataImporter = vtk.vtkImageImport()
        # The preaviusly created array is converted to a string of chars and imported.
        data_string = data_matrix.tostring()
        dataImporter.CopyImportVoidPointer(data_string, len(data_string))
        # The type of the newly imported data is set to unsigned char (uint8)
        dataImporter.SetDataScalarTypeToUnsignedChar()
        # Because the data that is imported only contains an intensity value (it isnt RGB-coded or someting similar), the importer
        # must be told this is the case.
        dataImporter.SetNumberOfScalarComponents(1)
        # The following two functions describe how the data is stored and the dimensions of the array it is stored in. For this
        # simple case, all axes are of length 75 and begins with the first element. For other data, this is probably not the case.
        # I have to admit however, that I honestly dont know the difference between SetDataExtent() and SetWholeExtent() although
        # VTK complains if not both are used.
        dataImporter.SetDataExtent(0, 9, 0, 9, 0, 9)
        dataImporter.SetWholeExtent(0, 9, 0, 9, 0, 9)
        #dataImporter.SetDataExtent(0, 74, 0, 74, 0, 74)
        #dataImporter.SetWholeExtent(0, 74, 0, 74, 0, 74)

        # The following class is used to store transparencyv-values for later retrival. In our case, we want the value 0 to be
        # completly opaque whereas the three different cubes are given different transperancy-values to show how it works.
        alphaChannelFunc = vtk.vtkPiecewiseFunction()
        alphaChannelFunc.AddPoint(0, 0.6)
        alphaChannelFunc.AddPoint(33, 0.2)
        alphaChannelFunc.AddPoint(66, 0.1)
        alphaChannelFunc.AddPoint(100, 0.01)

        # Gradient opacity
        # other way: misfit 0 is anti opacity
        volumeGradientOpacity = vtk.vtkPiecewiseFunction()
        volumeGradientOpacity.AddPoint(70,   1.0)
        volumeGradientOpacity.AddPoint(50,  0.5)
        volumeGradientOpacity.AddPoint(20, 0.0)

        # This class stores color data and can create color tables from a few color points. For this demo, we want the three cubes
        # to be of the colors red green and blue.
        colorFunc = vtk.vtkColorTransferFunction()
        colorFunc.AddRGBPoint(00, 1.0, 0.0, 0.0)
        colorFunc.AddRGBPoint(30, 0.0, 1.0, 0.0)
        colorFunc.AddRGBPoint(60, 0.0, 0.0, 1.0)

        # The preavius two classes stored properties. Because we want to apply these properties to the volume we want to render,
        # we have to store them in a class that stores volume prpoperties.
        volumeProperty = vtk.vtkVolumeProperty()
        volumeProperty.SetColor(colorFunc)
        volumeProperty.SetScalarOpacity(alphaChannelFunc)
        volumeProperty.SetGradientOpacity(volumeGradientOpacity)
        volumeProperty.SetInterpolationTypeToLinear()
        volumeProperty.ShadeOff()
        volumeProperty.SetAmbient(0.1)
        volumeProperty.SetDiffuse(0.6)
        volumeProperty.SetSpecular(0.2)

        # This class describes how the volume is rendered (through ray tracing).
        compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
        # We can finally create our volume. We also have to specify the data for it, as well as how the data will be rendered.
        volumeMapper = vtk.vtkVolumeRayCastMapper()
        volumeMapper.SetVolumeRayCastFunction(compositeFunction)
        volumeMapper.SetInputConnection(dataImporter.GetOutputPort())

        # The class vtkVolume is used to pair the preaviusly declared volume as well as the properties to be used when rendering that volume.
        volume = vtk.vtkVolume()
        volume.SetMapper(volumeMapper)
        volume.SetProperty(volumeProperty)

        # Text am Nullpunkt
        atext = vtk.vtkVectorText()
        atext.SetText("(0,0,0)")
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInputConnection(atext.GetOutputPort())
        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetScale(10, 10, 10)
        textActor.AddPosition(0, -0.1, 78)

        # Cube to give some orientation 
        # (from http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/OrientationMarkerWidget)

        axesActor = vtk.vtkAnnotatedCubeActor();
        axesActor.SetXPlusFaceText('N')
        axesActor.SetXMinusFaceText('S')
        axesActor.SetYMinusFaceText('W')
        axesActor.SetYPlusFaceText('E')
        axesActor.SetZMinusFaceText('D')
        axesActor.SetZPlusFaceText('U')
        axesActor.GetTextEdgesProperty().SetColor(1,1,0)
        axesActor.GetTextEdgesProperty().SetLineWidth(2)
        axesActor.GetCubeProperty().SetColor(0,0,1)

        # With almost everything else ready, its time to initialize the renderer and window, as well as creating a method for exiting the application
        renderer = vtk.vtkRenderer()
        renderWin = vtk.vtkRenderWindow()
        renderWin.AddRenderer(renderer)
        renderInteractor = vtk.vtkRenderWindowInteractor()
        renderInteractor.SetRenderWindow(renderWin)

        axes = vtk.vtkOrientationMarkerWidget()
        axes.SetOrientationMarker(axesActor)
        axes.SetInteractor(renderInteractor)
        axes.EnabledOn()
        axes.InteractiveOn()
        renderer.ResetCamera()

        # We add the volume to the renderer ...
        renderer.AddVolume(volume)
        # ... set background color to white ...
        renderer.SetBackground(0.7,0.7,0.7)
        # ... and set window size.
        renderWin.SetSize(400, 400)

        # Fuege Text am Nullpunkt hinzu:
        renderer.AddActor(textActor)
        
        # A simple function to be called when the user decides to quit the application.
        def exitCheck(obj, event):
            if obj.GetEventPending() != 0:
                obj.SetAbortRender(1)

        # Tell the application to use the function as an exit check.
        renderWin.AddObserver("AbortCheckEvent", exitCheck)

        renderInteractor.Initialize()
        # Because nothing will be rendered without any input, we order the first render manually before control is handed over to the main-loop.
        renderWin.Render()
        renderInteractor.Start()
Beispiel #24
0
    def setDataset(self):
        self.ParcelationNumpy = nib.load(
            self.parcelation_filename).get_data().astype(np.uint8)
        self.TemplateNumpy = nib.load(
            self.template_filename).get_data().astype(np.uint8)

        img1 = nib.load(self.parcelation_filename)
        img2 = nib.load(self.template_filename)

        hdr1 = img1.header
        hdr2 = img2.header

        a1 = hdr1['pixdim'][1:4]
        a2 = hdr2['pixdim'][1:4]

        self.ParcelationNumpy.shape

        self.PixX = 1
        self.PixY = 1
        self.PixZ = 1

        self.ParcelationReader = vtk.vtkImageImport()
        self.ParcelationReader = copy.deepcopy(self.ParcelationNumpy)
        self.StrParcelationNumpy = str(self.ParcelationNumpy)

        self.ParcelationReader.SetImportVoidPointer(
            self.StrParcelationNumpy,
            len(self.StrParcelationNumpy) * 32)

        self.ParcelationReader.SetDataScalarTypeToUnsignedChar()

        print np.shape(self.ParcelationNumpy)
        x, y, z = np.shape(self.ParcelationNumpy)
        self.ParcelationReader.SetDataExtent(0, x - 1, 0, y - 1, 0, z - 1)
        self.ParcelationReader.SetWholeExtent(0, x - 1, 0, y - 1, 0, z - 1)

        self.TemplateReader = vtk.vtkImageImport()
        self.StrTemplateNumpy = str(self.TemplateNumpy)
        self.TemplateReader.CopyImportVoidPointer(self.StrTemplateNumpy,
                                                  len(self.StrTemplateNumpy))
        self.TemplateReader.SetDataScalarTypeToUnsignedChar()

        x, y, z = np.shape(self.TemplateNumpy)
        self.TemplateReader.SetDataExtent(0, x - 1, 0, y - 1, 0, z - 1)
        self.TemplateReader.SetWholeExtent(0, x - 1, 0, y - 1, 0, z - 1)

        if vtk.VTK_MAJOR_VERSION <= 5:
            self.ParcelationReader = vtk.vtkNIFTIImageReader()
        else:
            self.ParcelationReader = vtk.vtkNIFTIImageReader()

        self.ParcelationReader.SetFileName(self.parcelation_filename)
        self.ParcelationNumpy = nib.load(
            self.parcelation_filename).get_data().astype(np.uint8)
        self.ParcelationReader.Update()

        self.TemplateReader = vtk.vtkNIFTIImageReader()
        self.TemplateReader.SetFileName(self.template_filename)

        self.TemplateNumpy = nib.load(
            self.template_filename).get_data().astype(np.uint8)
        self.TemplateReader.Update()

        self.Templatedmc = vtk.vtkDiscreteMarchingCubes()
        self.dmc = vtk.vtkDiscreteMarchingCubes()

        self.TemplateMapper = vtk.vtkPolyDataMapper()
        self.mapper2 = vtk.vtkPolyDataMapper()
        self.outline = vtk.vtkOutlineFilter()

        self.TemplateActor = vtk.vtkActor()
        self.OutlineActor = vtk.vtkActor()

        self.renderer = vtk.vtkRenderer()
        self.renderer.SetBackground(1, 1, 1)

        self.renderWin = vtk.vtkRenderWindow()
        self.renderWin.AddRenderer(self.renderer)

        self.axes2 = vtk.vtkCubeAxesActor2D()
        self.axes3 = vtk.vtkCubeAxesActor2D()

        self.colorData = vtk.vtkUnsignedCharArray()
        self.colorData.SetName('colors')  # Any name will work here.
        self.colorData.SetNumberOfComponents(3)

        self.TextProperty = vtk.vtkTextProperty()
        self.TextProperty.SetColor(0, 0, 0)
        self.TextProperty.SetFontSize(100)

        self.axesActor = vtk.vtkAnnotatedCubeActor()
        self.axes = vtk.vtkOrientationMarkerWidget()

        self.renderInteractor = QVTKRenderWindowInteractor(self,
                                                           rw=self.renderWin)
        self.BoxLayoutView.addWidget(self.renderInteractor)

        self.picker = vtk.vtkCellPicker()
        self.template_data = None
Beispiel #25
0
def vtk_show(_renderer, window_name='VTK Show Window',
             width=640, height=480, has_picker=False):
    """
    Show the vtkRenderer in an vtkRenderWindow
    Only support ONE vtkRenderer
    :return: No return value
    """
    # render_window = vtk.vtkRenderWindow()
    render_window.AddRenderer(_renderer)
    render_window.SetSize(width, height)
    render_window.Render()
    # It works only after Render() is called
    render_window.SetWindowName(window_name)

    # iren = vtk.vtkRenderWindowInteractor()
    # iren.SetRenderWindow(render_window)

    interactor_style = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(interactor_style)

    # Add an Annoted Cube with Arrows
    cube = vtk.vtkAnnotatedCubeActor()
    cube.SetXPlusFaceText('R')
    cube.SetXMinusFaceText('L')
    cube.SetYPlusFaceText('A')
    cube.SetYMinusFaceText('P')
    cube.SetZPlusFaceText('I')
    cube.SetZMinusFaceText('S')
    cube.SetXFaceTextRotation(180)
    cube.SetYFaceTextRotation(180)
    cube.SetZFaceTextRotation(-90)
    cube.SetFaceTextScale(0.65)
    cube.GetCubeProperty().SetColor(0.5, 1.0, 1.0)
    cube.GetTextEdgesProperty().SetLineWidth(1)
    cube.GetTextEdgesProperty().SetColor(0.18, 0.28, 0.23)
    cube.GetTextEdgesProperty().SetDiffuse(0)
    cube.GetTextEdgesProperty().SetAmbient(1)

    cube.GetXPlusFaceProperty().SetColor(1, 0, 0)
    cube.GetXPlusFaceProperty().SetInterpolationToFlat()
    cube.GetXMinusFaceProperty().SetColor(1, 0, 0)
    cube.GetXMinusFaceProperty().SetInterpolationToFlat()

    cube.GetYPlusFaceProperty().SetColor(0, 1, 0)
    cube.GetYPlusFaceProperty().SetInterpolationToFlat()
    cube.GetYMinusFaceProperty().SetColor(0, 1, 0)
    cube.GetYMinusFaceProperty().SetInterpolationToFlat()

    cube.GetZPlusFaceProperty().SetColor(0, 0, 1)
    cube.GetZPlusFaceProperty().SetInterpolationToFlat()
    cube.GetZMinusFaceProperty().SetColor(0, 0, 1)
    cube.GetZMinusFaceProperty().SetInterpolationToFlat()

    text_property = vtk.vtkTextProperty()
    text_property.ItalicOn()
    text_property.ShadowOn()
    text_property.BoldOn()
    text_property.SetFontFamilyToTimes()
    text_property.SetColor(1, 0, 0)

    text_property_2 = vtk.vtkTextProperty()
    text_property_2.ShallowCopy(text_property)
    text_property_2.SetColor(0, 1, 0)
    text_property_3 = vtk.vtkTextProperty()
    text_property_3.ShallowCopy(text_property)
    text_property_3.SetColor(0, 0, 1)

    axes = vtk.vtkAxesActor()
    axes.SetShaftTypeToCylinder()
    axes.SetXAxisLabelText('X')
    axes.SetYAxisLabelText('Y')
    axes.SetZAxisLabelText('Z')
    axes.SetTotalLength(1.5, 1.5, 1.5)
    axes.GetXAxisCaptionActor2D().SetCaptionTextProperty(text_property)
    axes.GetYAxisCaptionActor2D().SetCaptionTextProperty(text_property_2)
    axes.GetZAxisCaptionActor2D().SetCaptionTextProperty(text_property_3)

    assembly = vtk.vtkPropAssembly()
    assembly.AddPart(axes)
    assembly.AddPart(cube)

    marker = vtk.vtkOrientationMarkerWidget()
    marker.SetOutlineColor(0.93, 0.57, 0.13)
    marker.SetOrientationMarker(assembly)
    marker.SetViewport(0.0, 0.0, 0.15, 0.3)
    marker.SetInteractor(iren)
    marker.EnabledOn()
    marker.InteractiveOn()

    # Add a x-y-z coordinate to the original point
    axes_coor = vtk.vtkAxes()
    axes_coor.SetOrigin(0, 0, 0)
    mapper_axes_coor = vtk.vtkPolyDataMapper()
    mapper_axes_coor.SetInputConnection(axes_coor.GetOutputPort())
    actor_axes_coor = vtk.vtkActor()
    actor_axes_coor.SetMapper(mapper_axes_coor)
    _renderer.AddActor(actor_axes_coor)

    # Add an original point and text
    add_point(_renderer, color=[0, 1, 0], radius=2)
    add_text(_renderer, position=[0, 0, 0], text="Origin",
             color=[0, 1, 0], scale=2)

    _renderer.ResetCamera()  # Coorperate with vtkFollower

    # iren.Initialize()  # will be called by Start() autometically
    if has_picker:
        iren.AddObserver('MouseMoveEvent', MoveCursor)
    iren.Start()
Beispiel #26
0
    def __init__(self, render_window_interactor, widget,config=None):

        # render_window_interactor.Initialize()
        # render_window_interactor.Start()
        self.configure(config)
        self.iren = render_window_interactor
        self.ren_win = render_window_interactor.GetRenderWindow()
        self.ren = vtk.vtkRenderer()
        self.ren.GradientBackgroundOn()
        self.ren.SetBackground2(self.BACKGROUND2)
        self.ren.SetBackground(self.BACKGROUND1)
        self.ren.SetUseDepthPeeling(1)
        self.ren_win.SetMultiSamples(0)
        self.ren_win.AlphaBitPlanesOn()
        self.ren.SetOcclusionRatio(0.1)
        self.ren_win.AddRenderer(self.ren)

        self.iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())

        self.light = vtk.vtkLight()
        self.ren.AddLight(self.light)
        self.light.SetLightTypeToSceneLight()
        self.light.SetPositional(0)


        self.light2 = vtk.vtkLight()
        self.ren.AddLight(self.light2)
        self.light2.SetLightTypeToSceneLight()
        self.light2.SetPositional(0)

        self.light3 = vtk.vtkLight()
        self.ren.AddLight(self.light3)
        self.light3.SetLightTypeToSceneLight()
        self.light3.SetPositional(0)

        self.picker = vtk.vtkCellPicker()
        self.picker.SetTolerance(0.0005)
        self.iren.SetPicker(self.picker)

        self.experiment = None
        self.__cylinder_actors = {}
        self.__line_actors = {}
        self.__cone_actors = {}
        self.__cone_sources = {}
        self.__error_triple = None
        self.__temp_sample = None
        self.__highlighted_actors = []

        #orientation axes
        axes_actor = vtk.vtkAnnotatedCubeActor()
        axes_actor.SetXPlusFaceText("R")
        axes_actor.SetXMinusFaceText("L")
        axes_actor.SetYPlusFaceText("P")
        axes_actor.SetYMinusFaceText("I ")
        axes_actor.SetZPlusFaceText("B")
        axes_actor.SetZMinusFaceText("F")

        axes_actor.GetTextEdgesProperty().SetColor(1, 1, 1)
        axes_actor.GetTextEdgesProperty().SetLineWidth(2)
        axes_actor.GetCubeProperty().SetColor(0.3, 0.3, 0.3)
        axes_actor.SetTextEdgesVisibility(1)
        axes_actor.SetFaceTextVisibility(0)

        axes_actor.SetZFaceTextRotation(90)
        axes_actor.SetXFaceTextRotation(-90)

        axes = vtk.vtkOrientationMarkerWidget()
        axes.SetOrientationMarker(axes_actor)
        axes.SetViewport(0.01, 0.01, 0.2, 0.2)

        self.axes = axes
        self.axes_actor = axes_actor


        self.axes.SetInteractor(self.iren)
        self.axes.EnabledOn()
        self.axes.InteractiveOff()

        self.__widget = widget

        if self.SHADOWS:
            opaque_sequence = vtk.vtkSequencePass()
            passes2 = vtk.vtkRenderPassCollection()
            opaque = vtk.vtkOpaquePass()
            lights = vtk.vtkLightsPass()
            peeling = vtk.vtkDepthPeelingPass()
            translucent = vtk.vtkTranslucentPass()
            peeling.SetTranslucentPass(translucent)
            passes2.AddItem(lights)
            passes2.AddItem(opaque)
            opaque_sequence.SetPasses(passes2)

            opaque_camera_pass = vtk.vtkCameraPass()
            opaque_camera_pass.SetDelegatePass(opaque_sequence)

            shadow_baker = vtk.vtkShadowMapBakerPass()
            shadow_baker.SetOpaquePass(opaque_camera_pass)

            shadow_baker.SetResolution(2**12)
            shadow_baker.SetPolygonOffsetFactor(3.1)
            shadow_baker.SetPolygonOffsetUnits(10.0)

            shadows = vtk.vtkShadowMapPass()
            shadows.SetShadowMapBakerPass(shadow_baker)

            shadows.SetOpaquePass(opaque_sequence)

            seq = vtk.vtkSequencePass()
            passes = vtk.vtkRenderPassCollection()
            seq.SetPasses(passes)
            passes.AddItem(shadow_baker)
            passes.AddItem(shadows)

            passes.AddItem(lights)
            passes.AddItem(peeling)
            passes.AddItem(vtk.vtkVolumetricPass())

            cameraP = vtk.vtkCameraPass()
            cameraP.SetDelegatePass(seq)
            self.ren.SetPass(cameraP)
Beispiel #27
0
def display(image, image_pos_pat, image_ori_pat):
	global xMin, xMax, yMin, yMax, zMin, zMax, xSpacing, ySpacing, zSpacing, interactor, actions, reslice, interactorStyle
	# The box widget observes the events invoked by the render window
	# interactor.  These events come from user interaction in the render
	# window.
	# boxWidget = vtk.vtkBoxWidget()
	# boxWidget.SetInteractor(iren1)
	# boxWidget.SetPlaceFactor(1)
	
	# Initialize Image orienation
	IO = matrix(	[[0, 0,-1, 0],
			[1, 0, 0, 0],
			[0,-1, 0, 0],
			[0, 0, 0, 1]])
	# Assign the 6-Image orientation patient coordinates (from Dicomtags)
	IO[0,0] = image_ori_pat[0]; IO[1,0] = image_ori_pat[1]; IO[2,0] = image_ori_pat[2]; 
	IO[0,1] = image_ori_pat[3]; IO[1,1] = image_ori_pat[4]; IO[2,1] = image_ori_pat[5]; 
	
	# obtain thrid column as the cross product of column 1 y 2
	IO_col1 = [image_ori_pat[0], image_ori_pat[1], image_ori_pat[2]]
	IO_col2 = [image_ori_pat[3], image_ori_pat[4], image_ori_pat[5]]
	IO_col3 = cross(IO_col1, IO_col2)
	
	# assign column 3	
	IO[0,2] = IO_col3[0]; IO[1,2] = IO_col3[1]; IO[2,2] = IO_col3[2]; 
	
	IP =  array([0, 0, 0, 1]) # Initialization Image Position
	IP[0] = image_pos_pat[0]; IP[1] = image_pos_pat[1]; IP[2] = image_pos_pat[2];  
	IO[0,3] = image_pos_pat[0]; IO[1,3] = image_pos_pat[1]; IO[2,3] = image_pos_pat[2]
	
	print "image_pos_pat :"
	print image_pos_pat
	print "image_ori_pat:"
	print image_ori_pat
	
	origin = IP*IO.I
	print "Volume Origin:"
	print origin[0,0], origin[0,1], origin[0,2]
	
	# Create matrix 4x4
	DICOM_mat = vtk.vtkMatrix4x4();
	DICOM_mat.SetElement(0, 0, IO[0,0])
	DICOM_mat.SetElement(0, 1, IO[0,1])
	DICOM_mat.SetElement(0, 2, IO[0,2])
	DICOM_mat.SetElement(0, 3, IO[0,3])
	
	DICOM_mat.SetElement(1, 0, IO[1,0])
	DICOM_mat.SetElement(1, 1, IO[1,1])
	DICOM_mat.SetElement(1, 2, IO[1,2])
	DICOM_mat.SetElement(1, 3, IO[1,3])
	
	DICOM_mat.SetElement(2, 0, IO[2,0])
	DICOM_mat.SetElement(2, 1, IO[2,1])
	DICOM_mat.SetElement(2, 2, IO[2,2])
	DICOM_mat.SetElement(2, 3, IO[2,3])
	
	DICOM_mat.SetElement(3, 0, IO[3,0])
	DICOM_mat.SetElement(3, 1, IO[3,1])
	DICOM_mat.SetElement(3, 2, IO[3,2])
	DICOM_mat.SetElement(3, 3, IO[3,3])
	#DICOM_mat.Invert()
	
	# Set up the axes	
	transform = vtk.vtkTransform()
	transform.Concatenate(DICOM_mat)
	transform.Update()
	
	# Set up the cube (set up the translation back to zero	
	DICOM_mat_cube = vtk.vtkMatrix4x4();
	DICOM_mat_cube.DeepCopy(DICOM_mat)
	DICOM_mat_cube.SetElement(0, 3, 0)
	DICOM_mat_cube.SetElement(1, 3, 0)
	DICOM_mat_cube.SetElement(2, 3, 0)
		
	transform_cube = vtk.vtkTransform()
	transform_cube.Concatenate(DICOM_mat_cube)
	transform_cube.Update()
	
	##########################
	# Calculate the center of the volume
	(xMin, xMax, yMin, yMax, zMin, zMax) = image.GetWholeExtent()
	(xSpacing, ySpacing, zSpacing) = image.GetSpacing()
	(x0, y0, z0) = image.GetOrigin()
	
	center = [x0 + xSpacing * 0.5 * (xMin + xMax),
		  y0 + ySpacing * 0.5 * (yMin + yMax),
		  z0 + zSpacing * 0.5 * (zMin + zMax)]
	
	# Matrices for axial, coronal, sagittal, oblique view orientations
	axial = vtk.vtkMatrix4x4()
	axial.DeepCopy((1, 0, 0, center[0],
			0, 1, 0, center[1],
			0, 0, 1, center[2],
			0, 0, 0, 1))
	
	coronal = vtk.vtkMatrix4x4()
	coronal.DeepCopy((1, 0, 0, center[0],
			  0, 0, 1, center[1],
			  0,-1, 0, center[2],
			  0, 0, 0, 1))
	
	sagittal = vtk.vtkMatrix4x4()
	sagittal.DeepCopy((0, 0,-1, center[0],
			   1, 0, 0, center[1],
			   0,-1, 0, center[2],
			   0, 0, 0, 1))
	
	oblique = vtk.vtkMatrix4x4()
	oblique.DeepCopy((1, 0, 0, center[0],
			  0, 0.866025, -0.5, center[1],
			  0, 0.5, 0.866025, center[2],
			  0, 0, 0, 1))
	
	# Extract a slice in the desired orientation
	reslice = vtk.vtkImageReslice()
	reslice.SetInput(image)
	reslice.SetOutputDimensionality(2)
	reslice.SetResliceAxes(sagittal)
	reslice.SetInterpolationModeToLinear()
	
	# Create a greyscale lookup table
	table = vtk.vtkLookupTable()
	table.SetRange(0, 2000) # image intensity range
	table.SetValueRange(0.0, 1.0) # from black to white
	table.SetSaturationRange(0.0, 0.0) # no color saturation
	table.SetRampToLinear()
	table.Build()
	
	# Map the image through the lookup table
	color = vtk.vtkImageMapToColors()
	color.SetLookupTable(table)
	color.SetInputConnection(reslice.GetOutputPort())

	# Display the image
	actor = vtk.vtkImageActor()
	actor.GetMapper().SetInputConnection(color.GetOutputPort())

	renderer1 = vtk.vtkRenderer()
	renderer1.AddActor(actor)
	################
	    
	
	# set up cube actor with Orientation(R-L, A-P, S-O) using transform_cube
	# Set up to ALS (+X=A, +Y=S, +Z=L) source:
	cube = vtk.vtkAnnotatedCubeActor()
	cube.SetXPlusFaceText( "S" );
	cube.SetXMinusFaceText( "I" );
	cube.SetYPlusFaceText( "L" );
	cube.SetYMinusFaceText( "R" );
	cube.SetZPlusFaceText( "A" );
	cube.SetZMinusFaceText( "P" );
	cube.SetFaceTextScale( 0.5 );
	cube.GetAssembly().SetUserTransform( transform_cube );
		
	# Set UP the axes
	axes2 = vtk.vtkAxesActor()
	axes2.SetShaftTypeToCylinder();
	#axes2.SetUserTransform( transform_cube );		 
	axes2.SetTotalLength( 1.5, 1.5, 1.5 );
	axes2.SetCylinderRadius( 0.500 * axes2.GetCylinderRadius() );
	axes2.SetConeRadius( 1.025 * axes2.GetConeRadius() );
	axes2.SetSphereRadius( 1.500 * axes2.GetSphereRadius() );

	tprop2 = axes2.GetXAxisCaptionActor2D()
	tprop2.GetCaptionTextProperty();

	assembly = vtk.vtkPropAssembly();
	assembly.AddPart( axes2 );
	assembly.AddPart( cube );
	
	widget = vtk.vtkOrientationMarkerWidget();
	widget.SetOutlineColor( 0.9300, 0.5700, 0.1300 );
	widget.SetOrientationMarker( assembly );
	widget.SetInteractor( iren1 );
	widget.SetViewport( 0.0, 0.0, 0.4, 0.4 );
	widget.SetEnabled( 1 );
	widget.InteractiveOff();
			
	# Set Up Camera view
	renderer1.SetBackground(0.0, 0.0, 0.0)
	camera = renderer1.GetActiveCamera()

	# bounds and initialize camera
	b = image.GetBounds()
	renderer1.ResetCamera(b)	
	renderer1.ResetCameraClippingRange()
	camera.SetViewUp(0.0,-1.0,0.0)
	camera.Azimuth(315)
	
	# Create a text property for both cube axes
	tprop = vtk.vtkTextProperty()
	tprop.SetColor(1, 1, 1)
	tprop.ShadowOff()
	
	# Create a vtkCubeAxesActor2D.  Use the outer edges of the bounding box to
	# draw the axes.  Add the actor to the renderer.
	axes = vtk.vtkCubeAxesActor2D()
	axes.SetInput(image)
	axes.SetCamera(renderer1.GetActiveCamera())
	axes.SetLabelFormat("%6.4g")
	axes.SetFlyModeToOuterEdges()
	axes.SetFontFactor(1.2)
	axes.SetAxisTitleTextProperty(tprop)
	axes.SetAxisLabelTextProperty(tprop)      
	renderer1.AddViewProp(axes)
	
	############
	# Place the interactor initially. The input to a 3D widget is used to
	# initially position and scale the widget. The "EndInteractionEvent" is
  	# observed which invokes the SelectPolygons callback.
    	# boxWidget.SetInput(image)
	# boxWidget.PlaceWidget()
	# boxWidget.AddObserver("InteractionEvent", SelectPolygons)
	# boxWidget.On()
	# Initizalize
	# Set up the interaction
	interactorStyle = vtk.vtkInteractorStyleImage()
	interactor = vtk.vtkRenderWindowInteractor()
	interactor.SetInteractorStyle(interactorStyle)
	renWin1.SetInteractor(interactor)
	renWin1.Render()
	
	renderer1.Render()
	interactor.Start()
	renderer1.RemoveViewProp(axes)
						
	return transform_cube, zImagePlaneWidget.GetSliceIndex()
def MakeAnnotatedCubeActor(colors):
    # Annotated Cube setup
    annotated_cube = vtk.vtkAnnotatedCubeActor()
    annotated_cube.SetFaceTextScale(0.366667)

    # Anatomic labeling
    annotated_cube.SetXPlusFaceText('X+')
    annotated_cube.SetXMinusFaceText('X-')
    annotated_cube.SetYPlusFaceText('Y+')
    annotated_cube.SetYMinusFaceText('Y-')
    annotated_cube.SetZPlusFaceText('Z+')
    annotated_cube.SetZMinusFaceText('Z-')

    # Change the vector text colors
    annotated_cube.GetTextEdgesProperty().SetColor(colors.GetColor3d('Black'))
    annotated_cube.GetTextEdgesProperty().SetLineWidth(1)

    annotated_cube.GetXPlusFaceProperty().SetColor(
        colors.GetColor3d('Turquoise'))
    annotated_cube.GetXMinusFaceProperty().SetColor(
        colors.GetColor3d('Turquoise'))
    annotated_cube.GetYPlusFaceProperty().SetColor(colors.GetColor3d('Mint'))
    annotated_cube.GetYMinusFaceProperty().SetColor(colors.GetColor3d('Mint'))
    annotated_cube.GetZPlusFaceProperty().SetColor(colors.GetColor3d('Tomato'))
    annotated_cube.GetZMinusFaceProperty().SetColor(
        colors.GetColor3d('Tomato'))
    annotated_cube.SetXFaceTextRotation(90)
    annotated_cube.SetYFaceTextRotation(180)
    annotated_cube.SetZFaceTextRotation(-90)
    # Make the annotated cube transparent
    annotated_cube.GetCubeProperty().SetOpacity(0)

    # Colored faces cube setup
    cube_source = vtk.vtkCubeSource()
    cube_source.Update()

    face_colors = vtk.vtkUnsignedCharArray()
    face_colors.SetNumberOfComponents(3)
    face_x_plus = colors.GetColor3ub('Red')
    face_x_minus = colors.GetColor3ub('Green')
    face_y_plus = colors.GetColor3ub('Blue')
    face_y_minus = colors.GetColor3ub('Yellow')
    face_z_plus = colors.GetColor3ub('Cyan')
    face_z_minus = colors.GetColor3ub('Magenta')
    face_colors.InsertNextTypedTuple(face_x_minus)
    face_colors.InsertNextTypedTuple(face_x_plus)
    face_colors.InsertNextTypedTuple(face_y_minus)
    face_colors.InsertNextTypedTuple(face_y_plus)
    face_colors.InsertNextTypedTuple(face_z_minus)
    face_colors.InsertNextTypedTuple(face_z_plus)

    cube_source.GetOutput().GetCellData().SetScalars(face_colors)
    cube_source.Update()

    cube_mapper = vtk.vtkPolyDataMapper()
    cube_mapper.SetInputData(cube_source.GetOutput())
    cube_mapper.Update()

    cube_actor = vtk.vtkActor()
    cube_actor.SetMapper(cube_mapper)

    # Assemble the colored cube and annotated cube texts into a composite prop.
    prop_assembly = vtk.vtkPropAssembly()
    prop_assembly.AddPart(annotated_cube)
    prop_assembly.AddPart(cube_actor)
    return prop_assembly
Beispiel #29
0
 def visualize(self, images, image_pos_pat, image_ori_pat, sub, postS, interact=True):
     '''Display and render volumes, reference frames, actors and widgets'''
     if(sub):
         #subtract volumes based on indicated postS            
         # define image based on subtraction of postS -preS
         image = self.subImage(images, postS)
     else:
         image = images[postS]            
          
     # Proceed to build reference frame for display objects based on DICOM coords   
     [self.transformed_image, transform_cube] = self.dicomTransform(image, image_pos_pat, image_ori_pat)
     
     # get info from image before visualization
     self.dims = self.transformed_image.GetDimensions()
     print "Image Dimensions"
     print self.dims
     self.T1spacing = self.transformed_image.GetSpacing()
     print "Image Spacing"
     print self.T1spacing
     self.T1origin = self.transformed_image.GetOrigin()
     print "Image Origin"
     print self.T1origin
     self.T1extent = list(self.transformed_image.GetExtent())
     print "Image Extent"
     print self.T1extent
         
     # Set up ortogonal planes
     self.xImagePlaneWidget.SetInputData( self.transformed_image )
     self.xImagePlaneWidget.SetPlaneOrientationToXAxes()
     self.xImagePlaneWidget.SetSliceIndex(0)
     self.yImagePlaneWidget.SetInputData( self.transformed_image )
     self.yImagePlaneWidget.SetPlaneOrientationToYAxes()
     self.yImagePlaneWidget.SetSliceIndex(0)
     self.zImagePlaneWidget.SetInputData( self.transformed_image )
     self.zImagePlaneWidget.SetPlaneOrientationToZAxes()
     self.zImagePlaneWidget.SetSliceIndex(0)
         
     self.xImagePlaneWidget.On()
     self.yImagePlaneWidget.On()
     self.zImagePlaneWidget.On()
     
     # set up cube actor with Orientation(A-P, S-I, L-R) using transform_cube
     # Set up to ALS (+X=A, +Y=S, +Z=L) source:
     cube = vtk.vtkAnnotatedCubeActor()
     cube.SetXPlusFaceText( "L" );
     cube.SetXMinusFaceText( "R" );
     cube.SetYPlusFaceText( "A" );
     cube.SetYMinusFaceText( "P" );
     cube.SetZPlusFaceText( "S" );
     cube.SetZMinusFaceText( "I" );
     cube.SetFaceTextScale( 0.5 );
     cube.GetAssembly().SetUserTransform( transform_cube );
         
     # Set UP the axes
     axes2 = vtk.vtkAxesActor()
     axes2.SetShaftTypeToCylinder();
     #axes2.SetUserTransform( transform_cube );         
     axes2.SetTotalLength( 1.5, 1.5, 1.5 );
     axes2.SetCylinderRadius( 0.500 * axes2.GetCylinderRadius() );
     axes2.SetConeRadius( 1.025 * axes2.GetConeRadius() );
     axes2.SetSphereRadius( 1.500 * axes2.GetSphereRadius() );
 
     tprop2 = axes2.GetXAxisCaptionActor2D()
     tprop2.GetCaptionTextProperty();
 
     assembly = vtk.vtkPropAssembly();
     assembly.AddPart( axes2 );
     assembly.AddPart( cube );
     
     widget = vtk.vtkOrientationMarkerWidget();
     widget.SetOutlineColor( 0.9300, 0.5700, 0.1300 );
     widget.SetOrientationMarker( assembly );
     widget.SetInteractor( self.iren1 );
     widget.SetViewport( 0.0, 0.0, 0.4, 0.4 );
     widget.SetEnabled( 1 );
     widget.InteractiveOff();
                 
     # Create a text property for both cube axes
     tprop = vtk.vtkTextProperty()
     tprop.SetColor(1, 1, 1)
     tprop.ShadowOff()
     
     # Create a vtkCubeAxesActor2D.  Use the outer edges of the bounding box to
     # draw the axes.  Add the actor to the renderer.
     axes = vtk.vtkCubeAxesActor2D()
     axes.SetInputData(self.transformed_image)
     axes.SetCamera(self.renderer1.GetActiveCamera())
     axes.SetLabelFormat("%6.4g")
     axes.SetFlyModeToOuterEdges()
     axes.SetFontFactor(1.2)
     axes.SetAxisTitleTextProperty(tprop)
     axes.SetAxisLabelTextProperty(tprop)      
     self.renderer1.AddViewProp(axes)
     
     ############
     # bounds and initialize camera
     bounds = self.transformed_image.GetBounds()
     self.renderer1.ResetCamera(bounds)    
     self.renderer1.ResetCameraClippingRange()
     self.camera.SetViewUp(0.0,-1.0,0.0)
     self.camera.Azimuth(315)
     
     # Initizalize
     self.renWin1.Modified()
     self.renWin1.Render()
     self.renderer1.Render()
     
     if(interact==True):
         interactor = self.renWin1.GetInteractor()
         interactor.Start()
                         
     return
Beispiel #30
0
    def CreateMarker(self):
        # Create a composite orientation marker using
        # vtkAnnotatedCubeActor and vtkAxesActor.
        #
        cube = vtkAnnotatedCubeActor()
        cube.SetXPlusFaceText("R")
        cube.SetXMinusFaceText("L")
        cube.SetYPlusFaceText("A")
        cube.SetYMinusFaceText("P")
        cube.SetZPlusFaceText("I")
        cube.SetZMinusFaceText("S")
        cube.SetXFaceTextRotation(0)
        cube.SetYFaceTextRotation(0)
        cube.SetZFaceTextRotation(-90)
        cube.SetFaceTextScale(0.65)

        prop = cube.GetCubeProperty()
        prop.SetColor(0.5, 1, 1)

        prop = cube.GetTextEdgesProperty()
        prop.SetLineWidth(1)
        prop.SetDiffuse(0)
        prop.SetAmbient(1)
        prop.SetColor(0.18, 0.28, 0.23)

        for axis, colour in (('X', (0, 0, 1)), ('Y', (0, 1, 0)), ('Z', (1, 0,
                                                                        0))):
            for orient in ('Plus', 'Minus'):
                prop = getattr(cube, 'Get' + axis + orient + 'FaceProperty')()
                prop.SetColor(*colour)
                prop.SetInterpolationToFlat()
                continue
            continue

        axes = vtkAxesActor()
        axes.SetShaftTypeToCylinder()
        axes.SetXAxisLabelText("x")
        axes.SetYAxisLabelText("y")
        axes.SetZAxisLabelText("z")
        axes.SetTotalLength(1.5, 1.5, 1.5)

        tpropx = vtkTextProperty()
        tpropx.ItalicOn()
        tpropx.ShadowOn()
        tpropx.SetFontFamilyToTimes()
        axes.GetXAxisCaptionActor2D().SetCaptionTextProperty(tpropx)
        tpropy = vtkTextProperty()
        tpropy.ShallowCopy(tpropx)
        axes.GetYAxisCaptionActor2D().SetCaptionTextProperty(tpropy)
        tpropz = vtkTextProperty()
        tpropz.ShallowCopy(tpropx)
        axes.GetZAxisCaptionActor2D().SetCaptionTextProperty(tpropz)

        # Combine the two actors into one with vtkPropAssembly ...
        #
        assembly = vtkPropAssembly()
        assembly.AddPart(axes)
        assembly.AddPart(cube)

        # Add the composite marker to the widget.  The widget
        # should be kept in non-interactive mode and the aspect
        # ratio of the render window taken into account explicitly,
        # since the widget currently does not take this into
        # account in a multi-renderer environment.
        #
        marker = vtkOrientationMarkerWidget()
        marker.SetOutlineColor(0.93, 0.57, 0.13)
        marker.SetOrientationMarker(assembly)
        marker.SetViewport(0.0, 0.0, 0.15, 0.3)
        self.OrientationMarker = marker
        return
Beispiel #31
0
    def __init__(self, module_manager):
        # call base constructor
        ModuleBase.__init__(self, module_manager)
        ColourDialogMixin.__init__(
            self, module_manager.get_module_view_parent_window())
        self._numDataInputs = self.NUM_INPUTS
        # use list comprehension to create list keeping track of inputs
        self._inputs = [{
            'Connected': None,
            'inputData': None,
            'vtkActor': None,
            'ipw': None
        } for i in range(self._numDataInputs)]
        # then the window containing the renderwindows
        self.threedFrame = None

        # the renderers corresponding to the render windows
        self._threedRenderer = None

        self._outline_source = vtk.vtkOutlineSource()
        om = vtk.vtkPolyDataMapper()
        om.SetInputConnection(self._outline_source.GetOutputPort())
        self._outline_actor = vtk.vtkActor()
        self._outline_actor.SetMapper(om)
        self._cube_axes_actor2d = vtk.vtkCubeAxesActor2D()
        self._cube_axes_actor2d.SetFlyModeToOuterEdges()
        #self._cube_axes_actor2d.SetFlyModeToClosestTriad()

        # use box widget for VOI selection
        self._voi_widget = vtk.vtkBoxWidget()
        # we want to keep it aligned with the cubic volume, thanks
        self._voi_widget.SetRotationEnabled(0)
        self._voi_widget.AddObserver('InteractionEvent',
                                     self.voiWidgetInteractionCallback)
        self._voi_widget.AddObserver('EndInteractionEvent',
                                     self.voiWidgetEndInteractionCallback)
        self._voi_widget.NeedsPlacement = True

        # also create the VTK construct for actually extracting VOI from data
        #self._extractVOI = vtk.vtkExtractVOI()
        self._currentVOI = 6 * [0]

        # set the whole UI up!
        self._create_window()

        # our interactor styles (we could add joystick or something too)
        self._cInteractorStyle = vtk.vtkInteractorStyleTrackballCamera()

        # set the default
        self.threedFrame.threedRWI.SetInteractorStyle(self._cInteractorStyle)

        rwi = self.threedFrame.threedRWI
        rwi.Unbind(wx.EVT_MOUSEWHEEL)
        rwi.Bind(wx.EVT_MOUSEWHEEL, self._handler_mousewheel)

        # initialise our sliceDirections, this will also setup the grid and
        # bind all slice UI events
        self.sliceDirections = sliceDirections(self,
                                               self.controlFrame.sliceGrid)

        self.selectedPoints = selectedPoints(self,
                                             self.controlFrame.pointsGrid)

        # we now have a wx.ListCtrl, let's abuse it
        self._tdObjects = tdObjects(self, self.controlFrame.objectsListGrid)

        self._implicits = implicits(self, self.controlFrame.implicitsGrid)

        # setup orientation widget stuff
        # NB NB NB: we switch interaction with this off later
        # (InteractiveOff()), thus disabling direct translation and
        # scaling.  If we DON'T do this, interaction with software
        # raycasters are greatly slowed down.
        self._orientation_widget = vtk.vtkOrientationMarkerWidget()

        self._annotated_cube_actor = aca = vtk.vtkAnnotatedCubeActor()
        #aca.TextEdgesOff()

        aca.GetXMinusFaceProperty().SetColor(1, 0, 0)
        aca.GetXPlusFaceProperty().SetColor(1, 0, 0)
        aca.GetYMinusFaceProperty().SetColor(0, 1, 0)
        aca.GetYPlusFaceProperty().SetColor(0, 1, 0)
        aca.GetZMinusFaceProperty().SetColor(0, 0, 1)
        aca.GetZPlusFaceProperty().SetColor(0, 0, 1)

        self._axes_actor = vtk.vtkAxesActor()

        self._orientation_widget.SetInteractor(self.threedFrame.threedRWI)
        self._orientation_widget.SetOrientationMarker(self._axes_actor)
        self._orientation_widget.On()

        # make sure interaction is off; when on, interaction with
        # software raycasters is greatly slowed down!
        self._orientation_widget.InteractiveOff()
iren.SetRenderWindow(renWin)

cube = vtk.vtkCubeSource()
cube.SetXLength(200)
cube.SetYLength(200)
cube.SetZLength(200)
cube.Update()
cm = vtk.vtkPolyDataMapper()
cm.SetInputConnection(cube.GetOutputPort())
ca = vtk.vtkActor()
ca.SetMapper(cm)

# assign actor to the renderer
ren.AddActor(ca)

axesActor = vtk.vtkAnnotatedCubeActor()
axesActor.SetXPlusFaceText('R')
axesActor.SetXMinusFaceText('L')
axesActor.SetYMinusFaceText('H')
axesActor.SetYPlusFaceText('F')
axesActor.SetZMinusFaceText('P')
axesActor.SetZPlusFaceText('A')
axesActor.GetTextEdgesProperty().SetColor(1, 1, 0)
axesActor.GetTextEdgesProperty().SetLineWidth(2)
axesActor.GetCubeProperty().SetColor(0, 0, 1)
axes = vtk.vtkOrientationMarkerWidget()
axes.SetOrientationMarker(axesActor)
axes.SetInteractor(iren)
axes.EnabledOn()
axes.InteractiveOn()
ren.ResetCamera()
Beispiel #33
0
def create_axes_orientation_box(
    line_width=1,
    text_scale=0.366667,
    edge_color='black',
    x_color=None,
    y_color=None,
    z_color=None,
    xlabel='X',
    ylabel='Y',
    zlabel='Z',
    x_face_color='red',
    y_face_color='green',
    z_face_color='blue',
    color_box=False,
    label_color=None,
    labels_off=False,
    opacity=0.5,
):
    """Create a Box axes orientation widget with labels."""
    if x_color is None:
        x_color = rcParams['axes']['x_color']
    if y_color is None:
        y_color = rcParams['axes']['y_color']
    if z_color is None:
        z_color = rcParams['axes']['z_color']
    if edge_color is None:
        edge_color = rcParams['edge_color']
    axes_actor = vtk.vtkAnnotatedCubeActor()
    axes_actor.SetFaceTextScale(text_scale)
    if xlabel is not None:
        axes_actor.SetXPlusFaceText(f"+{xlabel}")
        axes_actor.SetXMinusFaceText(f"-{xlabel}")
    if ylabel is not None:
        axes_actor.SetYPlusFaceText(f"+{ylabel}")
        axes_actor.SetYMinusFaceText(f"-{ylabel}")
    if zlabel is not None:
        axes_actor.SetZPlusFaceText(f"+{zlabel}")
        axes_actor.SetZMinusFaceText(f"-{zlabel}")
    axes_actor.SetFaceTextVisibility(not labels_off)
    axes_actor.SetTextEdgesVisibility(False)
    # axes_actor.GetTextEdgesProperty().SetColor(parse_color(edge_color))
    # axes_actor.GetTextEdgesProperty().SetLineWidth(line_width)
    axes_actor.GetXPlusFaceProperty().SetColor(parse_color(x_color))
    axes_actor.GetXMinusFaceProperty().SetColor(parse_color(x_color))
    axes_actor.GetYPlusFaceProperty().SetColor(parse_color(y_color))
    axes_actor.GetYMinusFaceProperty().SetColor(parse_color(y_color))
    axes_actor.GetZPlusFaceProperty().SetColor(parse_color(z_color))
    axes_actor.GetZMinusFaceProperty().SetColor(parse_color(z_color))

    axes_actor.GetCubeProperty().SetOpacity(opacity)
    # axes_actor.GetCubeProperty().SetEdgeColor(parse_color(edge_color))
    axes_actor.GetCubeProperty().SetEdgeVisibility(True)
    axes_actor.GetCubeProperty().BackfaceCullingOn()
    if opacity < 1.0:
        # Hide the text edges
        axes_actor.GetTextEdgesProperty().SetOpacity(0)

    if color_box:
        # Hide the cube so we can color each face
        axes_actor.GetCubeProperty().SetOpacity(0)
        axes_actor.GetCubeProperty().SetEdgeVisibility(False)

        cube = pyvista.Cube()
        cube.clear_arrays()  # remove normals
        face_colors = np.array([
            parse_color(x_face_color),
            parse_color(x_face_color),
            parse_color(y_face_color),
            parse_color(y_face_color),
            parse_color(z_face_color),
            parse_color(z_face_color),
        ])
        face_colors = (face_colors * 255).astype(np.uint8)
        cube.cell_arrays['face_colors'] = face_colors

        cube_mapper = vtk.vtkPolyDataMapper()
        cube_mapper.SetInputData(cube)
        cube_mapper.SetColorModeToDirectScalars()
        cube_mapper.Update()

        cube_actor = vtk.vtkActor()
        cube_actor.SetMapper(cube_mapper)
        cube_actor.GetProperty().BackfaceCullingOn()
        cube_actor.GetProperty().SetOpacity(opacity)

        prop_assembly = vtk.vtkPropAssembly()
        prop_assembly.AddPart(axes_actor)
        prop_assembly.AddPart(cube_actor)
        actor = prop_assembly
    else:
        actor = axes_actor

    update_axes_label_color(actor, label_color)

    return actor
Beispiel #34
0
 def visualize(self, images, image_pos_pat, image_ori_pat, sub, postS, interact):
     '''Display and render volumes, reference frames, actors and widgets'''
     if(sub):
         #subtract volumes based on indicated postS            
         # define image based on subtraction of postS -preS
         image = self.subImage(images, postS)
     else:
         image = images[postS]            
          
     # Proceed to build reference frame for display objects based on DICOM coords   
     [self.transformed_image, transform_cube] = self.dicomTransform(image, image_pos_pat, image_ori_pat)
     
     # get info from image before visualization
     self.transformed_image.UpdateInformation()
     self.dims = self.transformed_image.GetDimensions()
     print "Image Dimensions"
     print self.dims
     self.T1spacing = self.transformed_image.GetSpacing()
     print "Image Spacing"
     print self.T1spacing
     self.T1origin = self.transformed_image.GetOrigin()
     print "Image Origin"
     print self.T1origin
     self.T1extent = list(self.transformed_image.GetWholeExtent())
     print "Image Extent"
     print self.T1extent
         
     # Set up ortogonal planes
     self.xImagePlaneWidget.SetInput( self.transformed_image )
     self.xImagePlaneWidget.SetPlaneOrientationToXAxes()
     self.xImagePlaneWidget.SetSliceIndex(0)
     self.yImagePlaneWidget.SetInput( self.transformed_image )
     self.yImagePlaneWidget.SetPlaneOrientationToYAxes()
     self.yImagePlaneWidget.SetSliceIndex(0)
     self.zImagePlaneWidget.SetInput( self.transformed_image )
     self.zImagePlaneWidget.SetPlaneOrientationToZAxes()
     self.zImagePlaneWidget.SetSliceIndex(0)
         
     self.xImagePlaneWidget.On()
     self.yImagePlaneWidget.On()
     self.zImagePlaneWidget.On()
     
     # set up cube actor with Orientation(A-P, S-I, L-R) using transform_cube
     # Set up to ALS (+X=A, +Y=S, +Z=L) source:
     cube = vtk.vtkAnnotatedCubeActor()
     cube.SetXPlusFaceText( "L" );
     cube.SetXMinusFaceText( "R" );
     cube.SetYPlusFaceText( "A" );
     cube.SetYMinusFaceText( "P" );
     cube.SetZPlusFaceText( "S" );
     cube.SetZMinusFaceText( "I" );
     cube.SetFaceTextScale( 0.5 );
     cube.GetAssembly().SetUserTransform( transform_cube );
         
     # Set UP the axes
     axes2 = vtk.vtkAxesActor()
     axes2.SetShaftTypeToCylinder();
     #axes2.SetUserTransform( transform_cube );         
     axes2.SetTotalLength( 1.5, 1.5, 1.5 );
     axes2.SetCylinderRadius( 0.500 * axes2.GetCylinderRadius() );
     axes2.SetConeRadius( 1.025 * axes2.GetConeRadius() );
     axes2.SetSphereRadius( 1.500 * axes2.GetSphereRadius() );
 
     tprop2 = axes2.GetXAxisCaptionActor2D()
     tprop2.GetCaptionTextProperty();
 
     assembly = vtk.vtkPropAssembly();
     assembly.AddPart( axes2 );
     assembly.AddPart( cube );
     
     widget = vtk.vtkOrientationMarkerWidget();
     widget.SetOutlineColor( 0.9300, 0.5700, 0.1300 );
     widget.SetOrientationMarker( assembly );
     widget.SetInteractor( self.iren1 );
     widget.SetViewport( 0.0, 0.0, 0.4, 0.4 );
     widget.SetEnabled( 1 );
     widget.InteractiveOff();
                 
     # Create a text property for both cube axes
     tprop = vtk.vtkTextProperty()
     tprop.SetColor(1, 1, 1)
     tprop.ShadowOff()
     
     # Create a vtkCubeAxesActor2D.  Use the outer edges of the bounding box to
     # draw the axes.  Add the actor to the renderer.
     axes = vtk.vtkCubeAxesActor2D()
     axes.SetInput(self.transformed_image)
     axes.SetCamera(self.renderer1.GetActiveCamera())
     axes.SetLabelFormat("%6.4g")
     axes.SetFlyModeToOuterEdges()
     axes.SetFontFactor(1.2)
     axes.SetAxisTitleTextProperty(tprop)
     axes.SetAxisLabelTextProperty(tprop)      
     self.renderer1.AddViewProp(axes)
     
     ############
     # bounds and initialize camera
     bounds = self.transformed_image.GetBounds()
     self.renderer1.ResetCamera(bounds)    
     self.renderer1.ResetCameraClippingRange()
     self.camera.SetViewUp(0.0,-1.0,0.0)
     self.camera.Azimuth(315)
     
     # Initizalize
     self.renWin1.Modified()
     self.renWin1.Render()
     self.renderer1.Render()
     
     if(interact==True):
         interactor = self.renWin1.GetInteractor()
         interactor.Start()
                         
     return
Beispiel #35
0
    def __init__(self, vtk_filename=None, vtk_data=None):
        """
        Initiate Viwer

        Parameters
        ----------
        vtk_filename : str
            Input VTK filename
        """

        QDialog.__init__(self)
        self.initUI()

        ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(ren)
        iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        if vtk_filename is not None:
            # VTK file
            reader = vtk.vtkUnstructuredGridReader()
            reader.SetFileName(vtk_filename)
            reader.Update()
            vtkdata = reader.GetOutput()

        if vtk_data is not None:
            vtkdata = vtk_data

        # VTK surface
        surface = vtk.vtkDataSetSurfaceFilter()
        surface.SetInputData(vtkdata)
        # surface.SetInput(vtkdata)
        surface.Update()

        mapper = vtk.vtkDataSetMapper()
        mapper.SetInputData(surface.GetOutput())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        # actor.GetProperty().EdgeVisibilityOff()
        actor.GetProperty().SetEdgeColor(1, 0.0, 1)
        actor.GetProperty().SetDiffuseColor(1, 0.0, 1.0)
        actor.GetProperty().SetAmbientColor(1, 0.0, 1)
        actor.GetProperty().SetLineWidth(0.1)
        # import pdb; pdb.set_trace()
        # actor.GetProperty().SetColor(1, 0, 1)
        actor.GetProperty().SetOpacity(0.3)

        ren.AddActor(actor)

        # annot. cube
        axesActor = vtk.vtkAnnotatedCubeActor()
        axesActor.SetXPlusFaceText('R')
        axesActor.SetXMinusFaceText('L')
        axesActor.SetYMinusFaceText('H')
        axesActor.SetYPlusFaceText('F')
        axesActor.SetZMinusFaceText('A')
        axesActor.SetZPlusFaceText('P')
        axesActor.GetTextEdgesProperty().SetColor(1, 0, 0)
        axesActor.GetCubeProperty().SetColor(0, 0, 1)
        self.axes = vtk.vtkOrientationMarkerWidget()
        self.axes.SetOrientationMarker(axesActor)
        self.axes.SetInteractor(iren)
        self.axes.EnabledOn()
        self.axes.InteractiveOn()

        ren.SetBackground(0.5, 0.5, 0.5)
        ren.ResetCamera()
        iren.Initialize()
Beispiel #36
0
    def __init__(self, module_manager):
        # call base constructor
        ModuleBase.__init__(self, module_manager)
        ColourDialogMixin.__init__(
            self, module_manager.get_module_view_parent_window())
        self._numDataInputs = self.NUM_INPUTS
        # use list comprehension to create list keeping track of inputs
        self._inputs = [{'Connected' : None, 'inputData' : None,
                         'vtkActor' : None, 'ipw' : None}
                       for i in range(self._numDataInputs)]
        # then the window containing the renderwindows
        self.threedFrame = None

        # the renderers corresponding to the render windows
        self._threedRenderer = None

        self._outline_source = vtk.vtkOutlineSource()
        om = vtk.vtkPolyDataMapper()
        om.SetInputConnection(self._outline_source.GetOutputPort())
        self._outline_actor = vtk.vtkActor()
        self._outline_actor.SetMapper(om)
        self._cube_axes_actor2d = vtk.vtkCubeAxesActor2D()
        self._cube_axes_actor2d.SetFlyModeToOuterEdges()
        #self._cube_axes_actor2d.SetFlyModeToClosestTriad()


        # use box widget for VOI selection
        self._voi_widget = vtk.vtkBoxWidget()
        # we want to keep it aligned with the cubic volume, thanks
        self._voi_widget.SetRotationEnabled(0)
        self._voi_widget.AddObserver('InteractionEvent',
                                     self.voiWidgetInteractionCallback)
        self._voi_widget.AddObserver('EndInteractionEvent',
                                     self.voiWidgetEndInteractionCallback)
        self._voi_widget.NeedsPlacement = True

        # also create the VTK construct for actually extracting VOI from data
        #self._extractVOI = vtk.vtkExtractVOI()
        self._currentVOI = 6 * [0]

        # set the whole UI up!
        self._create_window()

        # our interactor styles (we could add joystick or something too)
        self._cInteractorStyle = vtk.vtkInteractorStyleTrackballCamera()


        # set the default
        self.threedFrame.threedRWI.SetInteractorStyle(self._cInteractorStyle)
        
        rwi = self.threedFrame.threedRWI
        rwi.Unbind(wx.EVT_MOUSEWHEEL)
        rwi.Bind(wx.EVT_MOUSEWHEEL, self._handler_mousewheel)        

        # initialise our sliceDirections, this will also setup the grid and
        # bind all slice UI events
        self.sliceDirections = sliceDirections(
            self, self.controlFrame.sliceGrid)

        self.selectedPoints = selectedPoints(
            self, self.controlFrame.pointsGrid)

        # we now have a wx.ListCtrl, let's abuse it
        self._tdObjects = tdObjects(self,
                                    self.controlFrame.objectsListGrid)

        self._implicits = implicits(self,
                                    self.controlFrame.implicitsGrid)


        # setup orientation widget stuff
        # NB NB NB: we switch interaction with this off later
        # (InteractiveOff()), thus disabling direct translation and
        # scaling.  If we DON'T do this, interaction with software 
        # raycasters are greatly slowed down.
        self._orientation_widget = vtk.vtkOrientationMarkerWidget()
        
        self._annotated_cube_actor = aca = vtk.vtkAnnotatedCubeActor()
        #aca.TextEdgesOff()

        aca.GetXMinusFaceProperty().SetColor(1,0,0)
        aca.GetXPlusFaceProperty().SetColor(1,0,0)
        aca.GetYMinusFaceProperty().SetColor(0,1,0)
        aca.GetYPlusFaceProperty().SetColor(0,1,0)
        aca.GetZMinusFaceProperty().SetColor(0,0,1)
        aca.GetZPlusFaceProperty().SetColor(0,0,1)
        
        self._axes_actor = vtk.vtkAxesActor()

        self._orientation_widget.SetInteractor(
            self.threedFrame.threedRWI)
        self._orientation_widget.SetOrientationMarker(
            self._axes_actor)
        self._orientation_widget.On()
       
        # make sure interaction is off; when on, interaction with
        # software raycasters is greatly slowed down!
        self._orientation_widget.InteractiveOff()