Exemple #1
0
    def __init__(self, cell):

        assert isinstance(cell, vtkUnitCellModule)
        self.cell = cell

        l0 = self.cell.get_characteristic_length()

        # Create VTK axes actor (not really a VTK actor though)
        self.vtk_ax = vtkAxesActor()
        self.vtk_ax.SetTipTypeToCone()
        self.vtk_ax.SetConeRadius(5e-2 * l0)
        self.vtk_ax.SetShaftTypeToCylinder()
        self.vtk_ax.SetCylinderRadius(5e-3 * l0)

        # Create VTK two-dimensional property
        p2d = vtkProperty2D()
        p2d.SetDisplayLocationToBackground()

        vtkModule.__init__(self, self.vtk_ax, p2d)

        # Create VTK text property and apply to axes
        vtk_textproperty = vtkTextProperty()
        vtk_textproperty.SetFontSize(14)
        vtk_textproperty.SetBold(True)
        vtk_textproperty.SetItalic(True)
        vtk_textproperty.SetShadow(True)
        vtk_textproperty.SetJustificationToRight()
        vtk_textproperty.SetVerticalJustificationToCentered()

        self.set_text_property(vtk_textproperty)
Exemple #2
0
    def __init__(self, cell):

        assert isinstance(cell, vtkUnitCellModule)
        self.cell = cell

        l0 = self.cell.get_characteristic_length()

        # Create VTK axes actor (not really a VTK actor though)
        self.vtk_ax = vtkAxesActor()
        self.vtk_ax.SetTipTypeToCone()
        self.vtk_ax.SetConeRadius(5e-2*l0)
        self.vtk_ax.SetShaftTypeToCylinder()
        self.vtk_ax.SetCylinderRadius(5e-3*l0)

        # Create VTK two-dimensional property
        p2d = vtkProperty2D()
        p2d.SetDisplayLocationToBackground()

        vtkModule.__init__(self, self.vtk_ax, p2d)

        # Create VTK text property and apply to axes
        vtk_textproperty = vtkTextProperty()
        vtk_textproperty.SetFontSize(14)
        vtk_textproperty.SetBold(True)
        vtk_textproperty.SetItalic(True)
        vtk_textproperty.SetShadow(True)
        vtk_textproperty.SetJustificationToRight()
        vtk_textproperty.SetVerticalJustificationToCentered()

        self.set_text_property(vtk_textproperty)
Exemple #3
0
    def _setup(self):
        """Set up this UI component.

        Creating the button actor used internally.

        """
        # This is highly inspired by
        # https://github.com/Kitware/VTK/blob/c3ec2495b183e3327820e927af7f8f90d34c3474/Interaction/Widgets/vtkBalloonRepresentation.cxx#L47

        self.texture_polydata = vtk.vtkPolyData()
        self.texture_points = vtk.vtkPoints()
        self.texture_points.SetNumberOfPoints(4)

        polys = vtk.vtkCellArray()
        polys.InsertNextCell(4)
        polys.InsertCellPoint(0)
        polys.InsertCellPoint(1)
        polys.InsertCellPoint(2)
        polys.InsertCellPoint(3)
        self.texture_polydata.SetPolys(polys)

        tc = vtk.vtkFloatArray()
        tc.SetNumberOfComponents(2)
        tc.SetNumberOfTuples(4)
        tc.InsertComponent(0, 0, 0.0)
        tc.InsertComponent(0, 1, 0.0)
        tc.InsertComponent(1, 0, 1.0)
        tc.InsertComponent(1, 1, 0.0)
        tc.InsertComponent(2, 0, 1.0)
        tc.InsertComponent(2, 1, 1.0)
        tc.InsertComponent(3, 0, 0.0)
        tc.InsertComponent(3, 1, 1.0)
        self.texture_polydata.GetPointData().SetTCoords(tc)

        texture_mapper = vtk.vtkPolyDataMapper2D()
        texture_mapper = set_input(texture_mapper, self.texture_polydata)

        button = vtk.vtkTexturedActor2D()
        button.SetMapper(texture_mapper)

        self.texture = vtk.vtkTexture()
        button.SetTexture(self.texture)

        button_property = vtk.vtkProperty2D()
        button_property.SetOpacity(1.0)
        button.SetProperty(button_property)
        self.actor = button

        # Add default events listener to the VTK actor.
        self.handle_events(self.actor)
Exemple #4
0
    def _setup(self):
        """Setup this UI Component.

        Return an image as a 2D actor with a specific position.

        Returns
        -------
        :class:`vtkTexturedActor2D`
        """
        self.texture_polydata = vtk.vtkPolyData()
        self.texture_points = vtk.vtkPoints()
        self.texture_points.SetNumberOfPoints(4)

        polys = vtk.vtkCellArray()
        polys.InsertNextCell(4)
        polys.InsertCellPoint(0)
        polys.InsertCellPoint(1)
        polys.InsertCellPoint(2)
        polys.InsertCellPoint(3)
        self.texture_polydata.SetPolys(polys)

        tc = vtk.vtkFloatArray()
        tc.SetNumberOfComponents(2)
        tc.SetNumberOfTuples(4)
        tc.InsertComponent(0, 0, 0.0)
        tc.InsertComponent(0, 1, 0.0)
        tc.InsertComponent(1, 0, 1.0)
        tc.InsertComponent(1, 1, 0.0)
        tc.InsertComponent(2, 0, 1.0)
        tc.InsertComponent(2, 1, 1.0)
        tc.InsertComponent(3, 0, 0.0)
        tc.InsertComponent(3, 1, 1.0)
        self.texture_polydata.GetPointData().SetTCoords(tc)

        texture_mapper = vtk.vtkPolyDataMapper2D()
        texture_mapper = set_input(texture_mapper, self.texture_polydata)

        image = vtk.vtkTexturedActor2D()
        image.SetMapper(texture_mapper)

        self.texture = vtk.vtkTexture()
        image.SetTexture(self.texture)

        image_property = vtk.vtkProperty2D()
        image_property.SetOpacity(1.0)
        image.SetProperty(image_property)
        self.actor = image

        # Add default events listener to the VTK actor.
        self.handle_events(self.actor)
Exemple #5
0
    def makeAxes(self, outline, outlinefilter):
        """ create axes """
        tprop = vtk.vtkTextProperty()
        tprop.SetColor(self.fgColor)
        tprop.ShadowOff()

        prop = vtk.vtkProperty2D()
        prop.SetColor(self.fgColor)

        zax = vtk.vtkCubeAxesActor()
        zax.SetBounds(outline.GetBounds()[0], outline.GetBounds()[1], outline.GetBounds()[2], outline.GetBounds()[3],
                      outline.GetBounds()[4], outline.GetBounds()[4])
        zax.SetDragable(False)
        zax.SetCamera(self.renderer.GetActiveCamera())
        zax.SetFlyModeToOuterEdges()
        zax.DrawXGridlinesOn()
        zax.DrawYGridlinesOn()
        zax.DrawZGridlinesOn()
        zax.SetXTitle('')
        zax.SetYTitle('')
        zax.SetZTitle('')
        zax.SetXAxisMinorTickVisibility(0)
        zax.SetYAxisMinorTickVisibility(0)
        zax.SetZAxisMinorTickVisibility(0)
        zax.SetXAxisLabelVisibility(0)
        zax.SetYAxisLabelVisibility(0)
        zax.SetZAxisLabelVisibility(0)

        axes = vtk.vtkCubeAxesActor2D()
        axes.SetDragable(False)
        axes.SetInputConnection(outlinefilter.GetOutputPort())

        axes.SetCamera(self.renderer.GetActiveCamera())
        axes.SetLabelFormat(self.config.LabelFormat())
        axes.SetFlyModeToOuterEdges()
        axes.SetFontFactor(self.fontFactor)
        axes.SetNumberOfLabels(self.config.NLabels())
        axes.SetXLabel(self.config.XLabel())
        axes.SetYLabel(self.config.YLabel())
        axes.SetZLabel(self.config.ZLabel())
        axes.SetRanges(self.out.GetBounds())
        axes.SetUseRanges(True)
        axes.SetProperty(prop)
        axes.SetAxisTitleTextProperty(tprop)
        axes.SetAxisLabelTextProperty(tprop)

        return zax, axes
Exemple #6
0
    def AddDataSet(self, xdata, ydata, dataSetId=None):
        xdata = numpy_to_vtk(numpy.asarray(xdata, dtype=numpy.double))
        ydata = numpy_to_vtk(numpy.asarray(ydata, dtype=numpy.double))
        if dataSetId is None:
            plotData = vtkXYPlotData()
            plotData.AddData(xdata, ydata)
            plotProperty = vtk.vtkProperty2D()
            plotProperty.SetColor(COLORMAP[len(self.dataSets) % 11]);
            self.actor.AddData(plotData, plotProperty)
            self.dataSets.append(plotData)
            self.dataSetProperties.append(plotProperty)
            dataSetId = len(self.dataSets) - 1
        else:
            self.dataSets[dataSetId].AddData(xdata, ydata)
            if self.dataSets[dataSetId].GetNumberOfKeyframes() > self.numKeyframes:
                self.numKeyframes = self.dataSets[dataSetId].GetNumberOfKeyframes()
            self.actor.CalculateDataRanges()
        self.Refresh()

        wx.PostEvent(self, PlotDataChangedEvent())

        return dataSetId
    def __init__(self, curveNode, sliceNode):
        VTKObservationMixin.__init__(self)

        self.glyphScale = 0.5

        self.intersectionPoints_XY = vtk.vtkPolyData()

        self.glyphSource = slicer.vtkMarkupsGlyphSource2D()
        self.glyphSource.SetGlyphType(
            slicer.vtkMarkupsGlyphSource2D.GlyphCrossDot)

        self.glypher = vtk.vtkGlyph2D()
        self.glypher.SetInputData(self.intersectionPoints_XY)
        self.glypher.SetScaleFactor(1.0)
        self.glypher.SetSourceConnection(self.glyphSource.GetOutputPort())

        self.mapper = vtk.vtkPolyDataMapper2D()
        self.mapper.SetInputConnection(self.glypher.GetOutputPort())
        self.mapper.ScalarVisibilityOff()
        mapperCoordinate = vtk.vtkCoordinate()
        mapperCoordinate.SetCoordinateSystemToDisplay()
        self.mapper.SetTransformCoordinate(mapperCoordinate)

        self.property = vtk.vtkProperty2D()
        self.property.SetColor(0.4, 1.0, 1.0)
        self.property.SetPointSize(3.)
        self.property.SetLineWidth(3.)
        self.property.SetOpacity(1.)

        self.actor = vtk.vtkActor2D()
        self.actor.SetMapper(self.mapper)
        self.actor.SetProperty(self.property)

        self.curveNode = curveNode
        self.sliceNode = sliceNode

        self.visibility = True
    def __init__(self):
        ActorFactory.ActorFactory.__init__(self)
        # used to be 14 but VTK44 doesn't render arial 14 properly
        fontSize = 12

        self._TextMapper = vtk.vtkTextMapper()
        self._TextMapper.SetInput(" ")

        self._TextProperty = self._TextMapper.GetTextProperty()
        self._TextProperty.SetFontSize(fontSize)
        self._TextProperty.SetFontFamilyToArial()
        self._TextProperty.BoldOff()
        self._TextProperty.ItalicOff()
        self._TextProperty.ShadowOff()
        self._TextProperty.SetColor(0.933, 0.505, 0)
        #self._TextProperty.SetColor(1, 1, 1)

        self._Input = None

        self._TextActor = vtk.vtkActor2D()
        self._TextActor.SetMapper(self._TextMapper)

        self._Position = "NW"
        self._Text = ""

        self._RectanglePoints = vtk.vtkPoints()
        self._RectanglePoints.SetNumberOfPoints(4)
        self._RectanglePoints.InsertPoint(0, 0, 0, 0)
        self._RectanglePoints.InsertPoint(1, 0, 0, 0)
        self._RectanglePoints.InsertPoint(2, 0, 0, 0)
        self._RectanglePoints.InsertPoint(3, 0, 0, 0)

        self._Rectangle = vtk.vtkPolygon()
        self._Rectangle.GetPointIds().SetNumberOfIds(4)
        self._Rectangle.GetPointIds().SetId(0, 0)
        self._Rectangle.GetPointIds().SetId(1, 1)
        self._Rectangle.GetPointIds().SetId(2, 2)
        self._Rectangle.GetPointIds().SetId(3, 3)

        self._RectangleGrid = vtk.vtkPolyData()
        self._RectangleGrid.Allocate(1, 1)
        self._RectangleGrid.InsertNextCell(
            self._Rectangle.GetCellType(), self._Rectangle.GetPointIds())
        self._RectangleGrid.SetPoints(self._RectanglePoints)

        self._RectangleOpacity = 0.65

        self._RectangleProperty = vtk.vtkProperty2D()
        self._RectangleProperty.SetColor(0, 0, 0)
        self._RectangleProperty.SetOpacity(self._RectangleOpacity)

        self._ActorRectangle = vtk.vtkActor2D()
        self._ActorRectangle.PickableOff()
        self._ActorRectangle.SetProperty(self._RectangleProperty)
        self._MapperRectangle = vtk.vtkPolyDataMapper2D()

        # VTK-6
        if vtk.vtkVersion().GetVTKMajorVersion() > 5:
            self._MapperRectangle.SetInputData(self._RectangleGrid)
        else:
            self._MapperRectangle.SetInput(self._RectangleGrid)

        self._ActorRectangle.SetMapper(self._MapperRectangle)