예제 #1
0
    def __init__(self):
        self._rendererScene = vtk.vtkRenderer()
        self._rendererScene.SetBackground(self.COLOR_BG)

        self._renderWindowScene = vtk.vtkRenderWindow()
        self._renderWindowScene.AddRenderer(self._rendererScene)
        self._renderWindowInteractor = vtk.vtkRenderWindowInteractor()
        self._renderWindowInteractor.SetRenderWindow(self._renderWindowScene)
        #self._interactorStyle = vtk.vtkInteractorStyleUnicam()
        self._interactorStyle = self.KeyPressInteractorStyle()
        self._interactorStyle.SetCamera(self._rendererScene.GetActiveCamera())
        self._interactorStyle.SetRenderer(self._rendererScene)
        self._interactorStyle.SetRenderWindow(self._renderWindowScene)

        self._contextViewPlotCurv = vtk.vtkContextView()
        self._contextViewPlotCurv.GetRenderer().SetBackground(
            self.COLOR_BG_PLOT)

        self._contextInteractorStyleCurv = self.KeyPressContextInteractorStyle(
        )
        self._contextInteractorStyleCurv.SetRenderWindow(
            self._contextViewPlotCurv.GetRenderWindow())

        self._chartXYCurv = vtk.vtkChartXY()
        self._contextViewPlotCurv.GetScene().AddItem(self._chartXYCurv)
        self._chartXYCurv.SetShowLegend(True)
        self._chartXYCurv.GetAxis(vtk.vtkAxis.LEFT).SetTitle("")
        self._chartXYCurv.GetAxis(vtk.vtkAxis.BOTTOM).SetTitle("")

        self._contextViewPlotTors = vtk.vtkContextView()
        self._contextViewPlotTors.GetRenderer().SetBackground(
            self.COLOR_BG_PLOT)

        self._contextInteractorStyleTors = self.KeyPressContextInteractorStyle(
        )
        self._contextInteractorStyleTors.SetRenderWindow(
            self._contextViewPlotTors.GetRenderWindow())

        self._chartXYTors = vtk.vtkChartXY()
        self._contextViewPlotTors.GetScene().AddItem(self._chartXYTors)
        self._chartXYTors.SetShowLegend(True)
        self._chartXYTors.GetAxis(vtk.vtkAxis.LEFT).SetTitle("")
        self._chartXYTors.GetAxis(vtk.vtkAxis.BOTTOM).SetTitle("")

        self._textActor = vtk.vtkTextActor()
        self._textActor.GetTextProperty().SetColor(self.COLOR_LENGTH)

        self._addedBSpline = False
def TestColorTransferFunction(int ,  char):
    # Set up a 2D scene, add an XY chart to it
    view = vtk.vtkContextView()
    view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
    view.GetRenderWindow().SetSize(400, 300)
    
    chart = vtk.vtkChartXY()
    chart.SetTitle('Chart')
    view.GetScene().AddItem(chart)
    
    colorTransferFunction = vtk.vtkColorTransferFunction()
    colorTransferFunction.AddHSVSegment(50.,0.,1.,1.,85.,0.3333,1.,1.)
    colorTransferFunction.AddHSVSegment(85.,0.3333,1.,1.,170.,0.6666,1.,1.)
    colorTransferFunction.AddHSVSegment(170.,0.6666,1.,1.,200.,0.,1.,1.)
    
    colorTransferFunction.Build()
    
    colorTransferItem = vtk.vtkColorTransferFunctionItem()
    colorTransferItem.SetColorTransferFunction(colorTransferFunction)
    chart.AddPlot(colorTransferItem)
    
    controlPointsItem = vtk.vtkColorTransferControlPointsItem()
    controlPointsItem.SetColorTransferFunction(colorTransferFunction)
    controlPointsItem.SetUserBounds(0., 255., 0., 1.)
    chart.AddPlot(controlPointsItem)
    
    # Finally render the scene and compare the image to a reference image
    view.GetRenderWindow().SetMultiSamples(1)
    if view.GetContext().GetDevice().IsA( "vtkOpenGLContextDevice2D") :
      view.GetInteractor().Initialize()
      view.GetInteractor().Start()
    else:
        print 'GL version 2 or higher is required.'
    
    return EXIT_SUCCESS
예제 #3
0
    def addPlot(self,_plotName,_style="Lines"):   # called directly from Steppable; add a (possibly more than one) plot to a plot window

        self.plotWindowInterfaceMutex.lock()
#        self.plotWindowMutex.lock()

#        return
#        print MODULENAME,'   addPlot():  _plotName= ',_plotName
#        import pdb; pdb.set_trace()
        
#        self.plotData[_plotName] = [array([],dtype=double),array([],dtype=double),False]  # 'array': from PyQt4.Qwt5.anynumpy import *
        
        self.chart = vtk.vtkChartXY()
#        self.chart.GetAxis(vtk.vtkAxis.LEFT).SetLogScale(True)
#        self.chart.GetAxis(vtk.vtkAxis.BOTTOM).SetLogScale(True)
#        self.numCharts += 1
        self.plotData[_plotName] = [self.chart]

        self.view = vtk.vtkContextView()
        self.ren = self.view.GetRenderer()
#        self.renWin = self.qvtkWidget.GetRenderWindow()
        self.renWin = self.pW.GetRenderWindow()
        self.renWin.AddRenderer(self.ren)

        # Create a table with some points in it
        self.table = vtk.vtkTable()

        self.arrX = vtk.vtkFloatArray()
        self.arrX.SetName("xarray")

        self.arrC = vtk.vtkFloatArray()
        self.arrC.SetName("yarray")

        numPoints = 5
        numPoints = 15
        inc = 7.5 / (numPoints - 1)

#        for i in range(0,numPoints):
#            self.arrX.InsertNextValue(i*inc)
#            self.arrC.InsertNextValue(math.cos(i * inc) + 0.0)

#        self.arrX.InsertNextValue(0.0)
#        self.arrC.InsertNextValue(0.0)
#        self.arrX.InsertNextValue(0.1)
#        self.arrC.InsertNextValue(0.1)

        self.table.AddColumn(self.arrX)
        self.table.AddColumn(self.arrC)

        # Now add the line plots with appropriate colors
        self.line = self.chart.AddPlot(0)
        self.line.SetInput(self.table,0,1)
        self.line.SetColor(0,0,255,255)
        self.line.SetWidth(1.0)


        self.view.GetRenderer().SetBackground([0.6,0.6,0.1])
        self.view.GetRenderer().SetBackground([1.0,1.0,1.0])
        self.view.GetScene().AddItem(self.chart)

        self.plotWindowInterfaceMutex.unlock()
예제 #4
0
    def testLinePlot(self):
        "Test if line plots can be built with python"

        # Set up a 2D scene, add an XY chart to it
        view = vtk.vtkContextView()
        view.GetRenderer().SetBackground(1.0,1.0,1.0)
        view.GetRenderWindow().SetSize(400,300)
        chart = vtk.vtkChartXY()
        view.GetScene().AddItem(chart)

        # Create a table with some points in it
        table = vtk.vtkTable()

        arrX = vtk.vtkFloatArray()
        arrX.SetName("X Axis")

        arrC = vtk.vtkFloatArray()
        arrC.SetName("Cosine")

        arrS = vtk.vtkFloatArray()
        arrS.SetName("Sine")

        arrS2 = vtk.vtkFloatArray()
        arrS2.SetName("Sine2")

        numPoints = 69
        inc = 7.5 / (numPoints - 1)

        for i in range(0,numPoints):
            arrX.InsertNextValue(i*inc)
            arrC.InsertNextValue(math.cos(i * inc) + 0.0)
            arrS.InsertNextValue(math.sin(i * inc) + 0.0)
            arrS2.InsertNextValue(math.sin(i * inc) + 0.5)

        table.AddColumn(arrX)
        table.AddColumn(arrC)
        table.AddColumn(arrS)
        table.AddColumn(arrS2)

        # Now add the line plots with appropriate colors
        line = chart.AddPlot(0)
        line.SetInput(table,0,1)
        line.SetColor(0,255,0,255)
        line.SetWidth(1.0)

        line = chart.AddPlot(0)
        line.SetInput(table,0,2)
        line.SetColor(255,0,0,255);
        line.SetWidth(5.0)

        line = chart.AddPlot(0)
        line.SetInput(table,0,3)
        line.SetColor(0,0,255,255);
        line.SetWidth(4.0)

        view.GetRenderWindow().SetMultiSamples(0)

        img_file = "TestLinePlot.png"
        vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
        vtk.test.Testing.interact()
예제 #5
0
    def testBarGraph(self):
        "Test if bar graphs can be built with python"

        # Set up a 2D scene, add an XY chart to it
        view = vtk.vtkContextView()
        view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
        view.GetRenderWindow().SetSize(400, 300)
        chart = vtk.vtkChartXY()
        view.GetScene().AddItem(chart)

        # Create a table with some points in it
        table = vtk.vtkTable()

        arrMonth = vtk.vtkIntArray()
        arrMonth.SetName("Month")

        arr2008 = vtk.vtkIntArray()
        arr2008.SetName("2008")

        arr2009 = vtk.vtkIntArray()
        arr2009.SetName("2009")

        arr2010 = vtk.vtkIntArray()
        arr2010.SetName("2010")

        numMonths = 12

        for i in range(0, numMonths):
            arrMonth.InsertNextValue(i + 1)
            arr2008.InsertNextValue(data_2008[i])
            arr2009.InsertNextValue(data_2009[i])
            arr2010.InsertNextValue(data_2010[i])

        table.AddColumn(arrMonth)
        table.AddColumn(arr2008)
        table.AddColumn(arr2009)
        table.AddColumn(arr2010)

        # Now add the line plots with appropriate colors
        line = chart.AddPlot(2)
        line.SetInputData(table, 0, 1)
        line.SetColor(0, 255, 0, 255)

        line = chart.AddPlot(2)
        line.SetInputData(table, 0, 2)
        line.SetColor(255, 0, 0, 255)

        line = chart.AddPlot(2)
        line.SetInputData(table, 0, 3)
        line.SetColor(0, 0, 255, 255)

        view.GetRenderWindow().SetMultiSamples(0)
        view.GetRenderWindow().Render()

        img_file = "TestBarGraph.png"
        vtk.test.Testing.compareImage(
            view.GetRenderWindow(),
            vtk.test.Testing.getAbsImagePath(img_file),
            threshold=25)
        vtk.test.Testing.interact()
예제 #6
0
def main():
    view = vtk.vtkContextView()
    view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
    view.GetRenderWindow().SetSize(400, 300)

    chart = vtk.vtkChartXY()
    view.GetScene().AddItem(chart)
    chart.SetShowLegend(True)

    table = vtk.vtkTable()

    arrX = vtk.vtkFloatArray()
    arrX.SetName('X Axis')

    arrC = vtk.vtkFloatArray()
    arrC.SetName('Cosine')

    arrS = vtk.vtkFloatArray()
    arrS.SetName('Sine')

    arrT = vtk.vtkFloatArray()
    arrT.SetName('Sine-Cosine')

    table.AddColumn(arrC)
    table.AddColumn(arrS)
    table.AddColumn(arrX)
    table.AddColumn(arrT)

    numPoints = 40

    inc = 7.5 / (numPoints - 1)
    table.SetNumberOfRows(numPoints)
    for i in range(numPoints):
        table.SetValue(i, 0, i * inc)
        table.SetValue(i, 1, math.cos(i * inc))
        table.SetValue(i, 2, math.sin(i * inc))
        table.SetValue(i, 3, math.sin(i * inc) - math.cos(i * inc))

    points = chart.AddPlot(vtk.vtkChart.POINTS)
    points.SetInputData(table, 0, 1)
    points.SetColor(0, 0, 0, 255)
    points.SetWidth(1.0)
    points.SetMarkerStyle(vtk.vtkPlotPoints.CROSS)

    points = chart.AddPlot(vtk.vtkChart.POINTS)
    points.SetInputData(table, 0, 2)
    points.SetColor(0, 0, 0, 255)
    points.SetWidth(1.0)
    points.SetMarkerStyle(vtk.vtkPlotPoints.PLUS)

    points = chart.AddPlot(vtk.vtkChart.POINTS)
    points.SetInputData(table, 0, 3)
    points.SetColor(0, 0, 255, 255)
    points.SetWidth(1.0)
    points.SetMarkerStyle(vtk.vtkPlotPoints.CIRCLE)

    view.GetRenderWindow().SetMultiSamples(0)
    view.GetInteractor().Initialize()
    view.GetInteractor().Start()
예제 #7
0
파일: TestBarGraph.py 프로젝트: kramarb/VTK
    def testBarGraph(self):
        "Test if bar graphs can be built with python"

        # Set up a 2D scene, add an XY chart to it
        view = vtk.vtkContextView()
        view.GetRenderer().SetBackground(1.0,1.0,1.0)
        view.GetRenderWindow().SetSize(400,300)
        chart = vtk.vtkChartXY()
        view.GetScene().AddItem(chart)

        # Create a table with some points in it
        table = vtk.vtkTable()

        arrMonth = vtk.vtkIntArray()
        arrMonth.SetName("Month")

        arr2008 = vtk.vtkIntArray()
        arr2008.SetName("2008")

        arr2009 = vtk.vtkIntArray()
        arr2009.SetName("2009")

        arr2010 = vtk.vtkIntArray()
        arr2010.SetName("2010")

        numMonths = 12

        for i in range(0,numMonths):
            arrMonth.InsertNextValue(i + 1)
            arr2008.InsertNextValue(data_2008[i])
            arr2009.InsertNextValue(data_2009[i])
            arr2010.InsertNextValue(data_2010[i])

        table.AddColumn(arrMonth)
        table.AddColumn(arr2008)
        table.AddColumn(arr2009)
        table.AddColumn(arr2010)

        # Now add the line plots with appropriate colors
        line = chart.AddPlot(2)
        line.SetInput(table,0,1)
        line.SetColor(0,255,0,255)

        line = chart.AddPlot(2)
        line.SetInput(table,0,2)
        line.SetColor(255,0,0,255);

        line = chart.AddPlot(2)
        line.SetInput(table,0,3)
        line.SetColor(0,0,255,255);

        view.GetRenderWindow().SetMultiSamples(0)
	view.GetRenderWindow().Render()

        img_file = "TestBarGraph.png"
        vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
        vtk.test.Testing.interact()
예제 #8
0
파일: plotter.py 프로젝트: trianam/voropath
    def __init__(self):
        self._rendererScene = vtk.vtkRenderer()
        self._rendererScene.SetBackground(self.COLOR_BG)

        self._renderWindowScene = vtk.vtkRenderWindow()
        self._renderWindowScene.AddRenderer(self._rendererScene)
        self._renderWindowInteractor = vtk.vtkRenderWindowInteractor()
        self._renderWindowInteractor.SetRenderWindow(self._renderWindowScene)
        #self._interactorStyle = vtk.vtkInteractorStyleUnicam()
        self._interactorStyle = self.KeyPressInteractorStyle()
        self._interactorStyle.SetCamera(self._rendererScene.GetActiveCamera())
        self._interactorStyle.SetRenderer(self._rendererScene)
        self._interactorStyle.SetRenderWindow(self._renderWindowScene)

        self._contextViewPlotCurv = vtk.vtkContextView()
        self._contextViewPlotCurv.GetRenderer().SetBackground(self.COLOR_BG_PLOT)

        self._contextInteractorStyleCurv = self.KeyPressContextInteractorStyle()
        self._contextInteractorStyleCurv.SetRenderWindow(self._contextViewPlotCurv.GetRenderWindow())
        
        self._chartXYCurv = vtk.vtkChartXY()
        self._contextViewPlotCurv.GetScene().AddItem(self._chartXYCurv)
        self._chartXYCurv.SetShowLegend(True)
        self._chartXYCurv.GetAxis(vtk.vtkAxis.LEFT).SetTitle("")
        self._chartXYCurv.GetAxis(vtk.vtkAxis.BOTTOM).SetTitle("")

        self._contextViewPlotTors = vtk.vtkContextView()
        self._contextViewPlotTors.GetRenderer().SetBackground(self.COLOR_BG_PLOT)

        self._contextInteractorStyleTors = self.KeyPressContextInteractorStyle()
        self._contextInteractorStyleTors.SetRenderWindow(self._contextViewPlotTors.GetRenderWindow())
        
        self._chartXYTors = vtk.vtkChartXY()
        self._contextViewPlotTors.GetScene().AddItem(self._chartXYTors)
        self._chartXYTors.SetShowLegend(True)
        self._chartXYTors.GetAxis(vtk.vtkAxis.LEFT).SetTitle("")
        self._chartXYTors.GetAxis(vtk.vtkAxis.BOTTOM).SetTitle("")

        self._textActor = vtk.vtkTextActor()
        self._textActor.GetTextProperty().SetColor(self.COLOR_LENGTH)

        self._addedBSpline = False
예제 #9
0
파일: graph_widget.py 프로젝트: ladisk/DyS
    def __init__(self, measure_obj=None, parent=None):
        """
        Constructor
        """
        super(GraphWidget, self).__init__(parent=parent)

        #   parent
        self._parent = parent

        # self.frame = QtGui.QFrame()
        #
        # self.vl = QtGui.QVBoxLayout()
        self.view = vtk.vtkContextView()
        self.view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
        # self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
        #
        # self.vl.addWidget(self.vtkWidget)

        self.view.SetInteractor(self.GetRenderWindow().GetInteractor())
        self.SetRenderWindow(self.view.GetRenderWindow())

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

        # self.frame.setLayout(self.vl)
        # self.setCentralWidget(self.frame)

        self.xy_data = vtk.vtkTable()
        self.arrX = vtk.vtkFloatArray()
        self.arrX.SetName("X Axis")
        self.xy_data.AddColumn(self.arrX)

        self.arrY = vtk.vtkFloatArray()
        self.arrY.SetName("Y value")
        self.xy_data.AddColumn(self.arrY)

        numPoints = 20
        inc = 7.5 / (numPoints - 1)
        self.xy_data.SetNumberOfRows(numPoints)
        for i in range(numPoints):
            self.xy_data.SetValue(i, 0, i * inc)
            self.xy_data.SetValue(i, 1, i * inc)

        # self.view = vtk.vtkContextView()
        # self.view.GetRenderer().SetBackground(1.0, 0.0, 1.0)
        #
        self.chart = vtk.vtkChartXY()
        self.chart.GetAxis(0).SetGridVisible(False)
        self.chart.GetAxis(1).SetGridVisible(False)

        self.view.GetScene().AddItem(self.chart)
        self.line = self.chart.AddPlot(vtk.vtkChart.LINE)
        self.line.SetInputData(self.xy_data, 0, 1)
예제 #10
0
def main():
    view = vtk.vtkContextView()
    table = vtk.vtkTable()
    arrMonth = vtk.vtkIntArray()
    arrMonth.SetName("Month")
    arr2008 = vtk.vtkIntArray()
    arr2008.SetName("2008")
    arr2009 = vtk.vtkIntArray()
    arr2009.SetName("2009")
    arr2010 = vtk.vtkIntArray()
    arr2010.SetName("2010")

    table.AddColumn(arrMonth)
    table.AddColumn(arr2008)
    table.AddColumn(arr2009)
    table.AddColumn(arr2010)

    table.SetNumberOfRows(12)
    for i in range(12):
        table.SetValue(i, 0, i + 1)
        table.SetValue(i, 1, data_2008[i])
        table.SetValue(i, 2, data_2009[i])
        table.SetValue(i, 3, data_2010[i])

    chart = vtk.vtkChartXY()

    line = chart.AddPlot(vtk.vtkChart.BAR)
    line.SetInputData(table, 0, 1)
    line.SetColor(0.0, 1.0, 0.0)

    line = chart.AddPlot(vtk.vtkChart.BAR)
    line.SetInputData(table, 0, 2)
    line.SetColor(1.0, 0.0, 0.0)

    line = chart.AddPlot(vtk.vtkChart.BAR)
    line.SetInputData(table, 0, 3)
    line.SetColor(0.0, 0.0, 1.0)

    view.GetScene().AddItem(chart)
    view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
    view.GetRenderWindow().SetSize(1200, 1000)
    view.GetRenderWindow().Render()

    winToImageFilter = vtk.vtkWindowToImageFilter()
    winToImageFilter.SetInput(view.GetRenderWindow())
    winToImageFilter.Update()

    writer = vtk.vtkPNGWriter()
    writer.SetFileName("./test.png")
    writer.SetInputData(winToImageFilter.GetOutput())
    writer.Write()
예제 #11
0
  def plot(self): 
    for (key, val) in self.props_name.items(): 
      print key, val 
    
      chart = vtk.vtkChartXY()
      self.view.GetScene().AddItem(chart);
    
      line = chart.AddPlot(vtk.vtkChart.LINE)
      line.SetInput(self.table, 0, 1);
      line.SetColor(0, 255, 0, 255);
      line.SetWidth(5.0);
      line.GetPen().SetLineType(1) 

    self.view.GetRenderWindow().SetMultiSamples(0);
    self.view.GetInteractor().Initialize()
    self.view.GetInteractor().Start()

    print "+Vtk_plot \'%s\'"
예제 #12
0
파일: Graph.py 프로젝트: aeslaughter/moose
    def __init__(self, *args, **kwargs):
        super(Graph, self).__init__(**kwargs)

        # Create a view actor, this is where the plots are displayed
        self._vtkchart = vtk.vtkChartXY()
        self._vtkview = vtk.vtkContextActor()
        self._vtkview.GetScene().AddItem(self._vtkchart)
        self._vtkrenderer.AddViewProp(self._vtkview)

        # vtkColorSeries for automatic line colors
        self._vtkcolorseries = None

        # Add the ChiggerPlot objects
        self._plots = []

        # Add the lines provided as arguments
        lines = self.getOption('lines') if self.isOptionValid('lines') else []
        lines.extend(args)
        self.setOption('lines', lines)
예제 #13
0
    def __init__(self, *args, **kwargs):
        super(Graph, self).__init__(**kwargs)

        # Create a view actor, this is where the plots are displayed
        self._vtkchart = vtk.vtkChartXY()
        self._vtkview = vtk.vtkContextActor()
        self._vtkview.GetScene().AddItem(self._vtkchart)
        self._vtkrenderer.AddViewProp(self._vtkview)

        # vtkColorSeries for automatic line colors
        self._vtkcolorseries = None

        # Add the ChiggerPlot objects
        self._plots = []

        # Add the lines provided as arguments
        lines = self.getOption('lines') if self.isOptionValid('lines') else []
        lines.extend(args)
        self.setOption('lines', lines)
예제 #14
0
    def __init__(self, parent = None):
        super(E_VolumeRenderingWidget, self).__init__(parent)
        self.setMaximumWidth(300)

        self.mainLayout = QVBoxLayout()
        self.mainLayout.setSpacing(0)        
        self.setLayout(self.mainLayout)

        self.m_widget = QVTKRenderWindowInteractor();
        self.m_widget.setMaximumHeight(100)
        self.m_widget.AddObserver('MouseMoveEvent', self.onMouseMove)
        self.m_widget.AddObserver('LeftButtonPressEvent', self.onLeftDown, 1.0)
        self.m_widget.AddObserver('LeftButtonReleaseEvent', self.onLeftUp, -1.0)
        self.m_widget.hide()
        self.m_bClicked = False

        self.m_view = vtk.vtkContextView()
        self.m_histogramChart  = vtk.vtkChartXY()

        self.Initialize()
예제 #15
0
    def plot(self):
        for (key, val) in self.props_name.items():
            if (val != 0):
                print "|_Vtk_plot.plot Y:\'%s\'" % key
                chart = vtk.vtkChartXY()
                self.view.GetScene().AddItem(chart)

                line = chart.AddPlot(vtk.vtkChart.LINE)
                line.SetInput(self.table, 0, val)
                line.SetColor(0, 255, 0, 255)
                line.SetWidth(5.0)
                line.GetPen().SetLineType(1)
            else:
                print "|_Vtk_plot.plot X:\'%s\'" % key

        self.view.GetRenderWindow().SetMultiSamples(0)
        self.view.GetInteractor().Initialize()
        self.view.GetInteractor().Start()

        print "|_Vtk_plot.plot ok!"
예제 #16
0
def PlotSelectedData(data, state, view, text_init):
    nb_sources = 0
    for i in range(data.GetPointData().GetNumberOfArrays()):
        if data.GetPointData().GetGlobalIds('Potentials-'+str(i)):
            nb_sources += 1
    view.GetRenderer().RemoveActor2D(text_init)
    chart = vtk.vtkChartXY()
    view.GetScene().RemoveItem(0)
    view.GetScene().AddItem(chart)
    chart.SetShowLegend(True)
    table = vtk.vtkTable()
    X = vtk.vtkDoubleArray(); X.SetName("X")
    if state:
        numPoints = data.GetNumberOfCells()
        chart.GetAxis(0).SetTitle('Current'); 
    else:
        numPoints = data.GetNumberOfPoints()
        chart.GetAxis(0).SetTitle('Potential'); 
    chart.GetAxis(0).SetRange(0,nb_sources)
    for j in range(nb_sources):
        X.InsertNextValue(j)
    table.AddColumn(X)
    for i in range(numPoints):
        Y = vtk.vtkDoubleArray()
        if state:
            Y.SetName("id"+str(data.GetCellData().GetGlobalIds('Indices').GetValue(i)))
        else:
            Y.SetName("id"+str(data.GetPointData().GetGlobalIds('Indices').GetValue(i)))
        for j in range(nb_sources):
            if state:
                Y.InsertNextValue(data.GetCellData().GetGlobalIds('Currents-'+str(j)).GetValue(i))
            else:
                Y.InsertNextValue(data.GetPointData().GetGlobalIds('Potentials-'+str(j)).GetValue(i))
        table.AddColumn(Y)
        # Now add the line plots
        line = chart.AddPlot(0)
        line.SetInput(table,0,i+1)
        line.SetColor(0,1,0)
        line.SetWidth(1.0)
    view.GetRenderWindow().Render()
예제 #17
0
    def __init__(self,_plotWindow=None):
        # PlotManagerSetup.PlotWindowInterfaceBase.__init__(self,_plotWindow)
        QtCore.QObject.__init__(self, None)
        print MODULENAME,' __init__():  _plotWindow=',_plotWindow
        if _plotWindow:
            self.plotWindow = _plotWindow
#            self.pW = self.plotWindow.plotWidget        
            self.pW = self.plotWindow.qvtkWidget        
            print MODULENAME,'PlotWindowInterface: __init__():  self.pW=',self.pW

        self.chart = vtk.vtkChartXY()
        self.plotData={}
        self.plotHistData={}
        self.plotDrawingObjects={}
        self.initSignalsAndSlots()
        self.plotWindowInterfaceMutex = QtCore.QMutex()
        self.dirtyFlagIndex=2 # this is the index of the flag that is used to signal whether the data has been modified or not
        self.autoLegendFlag=False
        self.legendSetFlag=False
        
        self.eraseAllFlag=False
        self.logScaleFlag=False
    def __init__(self, chart_frame):
        super(VTKChartWidget, self).__init__()
        vtk.vtkObject.GlobalWarningDisplayOff()

        self.line_colors = default_line_colors
        self.line_width = default_line_width
        self.line_types = default_line_types

        self._gui_callbacks = []

        self.chart_frame = chart_frame

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

        self.table = vtk.vtkTable()
        self.chart = vtk.vtkChartXY()
        self.chart_scene = vtk.vtkContextScene()
        self.chart_actor = vtk.vtkContextActor()
        self.chart_view = vtk.vtkContextView()

        self.chart_scene.AddItem(self.chart)
        self.chart_actor.SetScene(self.chart_scene)
        self.chart_view.SetScene(self.chart_scene)

        self.renderer.AddActor(self.chart_actor)
        self.chart_scene.SetRenderer(self.renderer)

        self.chart.SetShowLegend(True)
        legend = self.chart.GetLegend()
        legend.SetInline(False)
        legend.SetHorizontalAlignment(vtk.vtkChartLegend.RIGHT)
        legend.SetVerticalAlignment(vtk.vtkChartLegend.TOP)
        legend.SetLabelSize(20)
        title_prop = self.chart.GetTitleProperties()
        title_prop.SetFontSize(20)

        self.init_xy_data()
        self.set_up_view()
    def __init__(self, _plotWindow=None):
        # PlotManagerSetup.PlotWindowInterfaceBase.__init__(self,_plotWindow)
        QtCore.QObject.__init__(self, None)
        print MODULENAME, ' __init__():  _plotWindow=', _plotWindow
        if _plotWindow:
            self.plotWindow = _plotWindow
            #            self.pW = self.plotWindow.plotWidget
            self.pW = self.plotWindow.qvtkWidget
            print MODULENAME, 'PlotWindowInterface: __init__():  self.pW=', self.pW

        self.chart = vtk.vtkChartXY()
        self.plotData = {}
        self.plotHistData = {}
        self.plotDrawingObjects = {}
        self.initSignalsAndSlots()
        self.plotWindowInterfaceMutex = QtCore.QMutex()
        self.dirtyFlagIndex = 2  # this is the index of the flag that is used to signal whether the data has been modified or not
        self.autoLegendFlag = False
        self.legendSetFlag = False

        self.eraseAllFlag = False
        self.logScaleFlag = False
예제 #20
0
    def testStackedPlot(self):
        "Test if stacked plots can be built with python"

        # Set up a 2D scene, add an XY chart to it
        view = vtk.vtkContextView()
        view.GetRenderer().SetBackground(1.0,1.0,1.0)
        view.GetRenderWindow().SetSize(400,300)
        chart = vtk.vtkChartXY()
        view.GetScene().AddItem(chart)

        # Create a table with some data in it
        table = vtk.vtkTable()

        arrMonthLabels = vtk.vtkStringArray()
        arrMonthPositions = vtk.vtkDoubleArray()

        arrMonth = vtk.vtkIntArray()
        arrMonth.SetName("Month")

        arrBooks = vtk.vtkIntArray()
        arrBooks.SetName("Books")

        arrNew = vtk.vtkIntArray()
        arrNew.SetName("New / Popular")

        arrPeriodical = vtk.vtkIntArray()
        arrPeriodical.SetName("Periodical")

        arrAudiobook = vtk.vtkIntArray()
        arrAudiobook.SetName("Audiobook")

        arrVideo = vtk.vtkIntArray()
        arrVideo.SetName("Video")

        numMonths = 12

        for i in range(0,numMonths):
            arrMonthLabels.InsertNextValue(month_labels[i])
            arrMonthPositions.InsertNextValue(float(i))

            arrMonth.InsertNextValue(i)
            arrBooks.InsertNextValue(book[i])
            arrNew.InsertNextValue(new_popular[i])
            arrPeriodical.InsertNextValue(periodical[i])
            arrAudiobook.InsertNextValue(audiobook[i])
            arrVideo.InsertNextValue(video[i])

        table.AddColumn(arrMonth)
        table.AddColumn(arrBooks)
        table.AddColumn(arrNew)
        table.AddColumn(arrPeriodical)
        table.AddColumn(arrAudiobook)
        table.AddColumn(arrVideo)

        # Set up the X Labels
        chart.GetAxis(1).SetCustomTickPositions(arrMonthPositions, arrMonthLabels)
        chart.GetAxis(1).SetMaximum(11)
        chart.GetAxis(1).SetBehavior(vtk.vtkAxis.FIXED)

        chart.SetShowLegend(True)

        # Create the stacked plot
        stack = chart.AddPlot(3)
        stack.SetUseIndexForXSeries(True)
        stack.SetInputData(table)
        stack.SetInputArray(1,"Books")
        stack.SetInputArray(2,"New / Popular")
        stack.SetInputArray(3,"Periodical")
        stack.SetInputArray(4,"Audiobook")
        stack.SetInputArray(5,"Video")

        # Set up a nice color series
        colorSeries = vtk.vtkColorSeries()
        colorSeries.SetColorScheme(2)
        stack.SetColorSeries(colorSeries)

        view.GetRenderWindow().SetMultiSamples(0)
        view.GetRenderWindow().Render()

        img_file = "TestStackedPlot.png"
        vtk.test.Testing.compareImage(view.GetRenderWindow(),
                                      vtk.test.Testing.getAbsImagePath(img_file),
                                      threshold=25)
        vtk.test.Testing.interact()
예제 #21
0
    def testLinePlot(self):
        "Test if colored scatter plots can be built with python"

        # Set up a 2D scene, add an XY chart to it
        view = vtk.vtkContextView()
        view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
        view.GetRenderWindow().SetSize(400, 300)

        chart = vtk.vtkChartXY()
        chart.SetShowLegend(True)
        view.GetScene().AddItem(chart)

        # Create a table with some points in it
        arrX = vtk.vtkFloatArray()
        arrX.SetName("XAxis")

        arrC = vtk.vtkFloatArray()
        arrC.SetName("Cosine")

        arrS = vtk.vtkFloatArray()
        arrS.SetName("Sine")

        arrS2 = vtk.vtkFloatArray()
        arrS2.SetName("Tan")

        numPoints = 40
        inc = 7.5 / (numPoints-1)

        for i in range(numPoints):
            arrX.InsertNextValue(i * inc)
            arrC.InsertNextValue(math.cos(i * inc) + 0.0)
            arrS.InsertNextValue(math.sin(i * inc) + 0.0)
            arrS2.InsertNextValue(math.tan(i * inc) + 0.5)

        table = vtk.vtkTable()
        table.AddColumn(arrX)
        table.AddColumn(arrC)
        table.AddColumn(arrS)
        table.AddColumn(arrS2)

        # Generate a black-to-red lookup table with fixed alpha
        lut = vtk.vtkLookupTable()
        lut.SetValueRange(0.2, 1.0)
        lut.SetSaturationRange(1, 1)
        lut.SetHueRange(0,0)
        lut.SetRampToLinear()
        lut.SetRange(-1,1)
        lut.SetAlpha(0.75)
        lut.Build()

        # Generate a black-to-blue lookup table with alpha range
        lut2 = vtk.vtkLookupTable()
        lut2.SetValueRange(0.2, 1.0)
        lut2.SetSaturationRange(1, 1)
        lut2.SetHueRange(0.6667, 0.6667)
        lut2.SetAlphaRange(0.4, 0.8)
        lut2.SetRampToLinear()
        lut2.SetRange(-1,1)
        lut2.Build()

        # Add multiple line plots, setting the colors etc
        points0 = chart.AddPlot(vtk.vtkChart.POINTS)
        points0.SetInputData(table, 0, 1)
        points0.SetColor(0, 0, 0, 255)
        points0.SetWidth(1.0)
        points0.SetMarkerStyle(vtk.vtkPlotPoints.CROSS)

        points1 = chart.AddPlot(vtk.vtkChart.POINTS)
        points1.SetInputData(table, 0, 2)
        points1.SetColor(0, 0, 0, 255)
        points1.SetMarkerStyle(vtk.vtkPlotPoints.DIAMOND)
        points1.SetScalarVisibility(1)
        points1.SetLookupTable(lut)
        points1.SelectColorArray(1)

        points2 = chart.AddPlot(vtk.vtkChart.POINTS)
        points2.SetInputData(table, 0, 3)
        points2.SetColor(0, 0, 0, 255)
        points2.ScalarVisibilityOn()
        points2.SetLookupTable(lut2)
        points2.SelectColorArray("Cosine")
        points2.SetWidth(4.0)

        view.GetRenderWindow().SetMultiSamples(0)
        view.GetRenderWindow().Render()

        img_file = "TestScatterPlotColors.png"
        vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
        vtk.test.Testing.interact()
def main(argv):
    view = vtk.vtkContextView()
    view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
    view.GetRenderWindow().SetSize(1000, 400)

    global chart
    chart = vtk.vtkChartXY()
    view.GetScene().AddItem(chart)
    chart.SetShowLegend(False)
    chart.AutoAxesOn()
    chart.SetForceAxesToBounds(False)
    table = vtk.vtkTable()

    arrX = vtk.vtkFloatArray()
    arrX.SetName('X Axis')

    arrC = vtk.vtkFloatArray()
    arrC.SetName('Y Axis')

    table.AddColumn(arrX)
    table.AddColumn(arrC)

    table.SetNumberOfRows(2)
    table.SetValue(0, 0, -2.5)
    table.SetValue(0, 1, 0)

    table.SetValue(1, 0, 2.5)
    table.SetValue(1, 1, 1.4)

    points = chart.AddPlot(vtk.vtkChart.POINTS)
    points.SetInputData(table, 0, 1)
    points.SetColor(0, 0, 0, 255)
    points.SetWidth(1.0)
    points.SetMarkerStyle(vtk.vtkPlotPoints.CROSS)

    # define the stationary (gray) box
    global boxA
    boxA = vtk.vtkTable()
    boxAx = vtk.vtkFloatArray()
    boxAx.SetName('X Axis')

    boxAy = vtk.vtkFloatArray()
    boxAy.SetName('Y Axis')

    boxA.AddColumn(boxAx)
    boxA.AddColumn(boxAy)

    boxA.SetNumberOfRows(4)
    boxA.SetValue(0, 0, -0.5)
    boxA.SetValue(0, 1, 0.0)

    boxA.SetValue(1, 0, -0.5)
    boxA.SetValue(1, 1, 1)

    boxA.SetValue(2, 0, 0.5)
    boxA.SetValue(2, 1, 1.0)
    boxA.SetValue(3, 0, 0.5)
    boxA.SetValue(3, 1, 0)

    line0 = chart.AddPlot(vtk.vtkChart.LINE)
    line0.SetInputData(boxA, 0, 1)
    line0.SetColor(50, 50, 50, 255)
    line0.SetWidth(3.0)
    line0.GetPen().SetLineType(vtk.vtkPen.SOLID_LINE)
    line0.SetMarkerStyle(vtk.vtkPlotPoints.CIRCLE)

    # define the moving (red) box
    global boxB
    boxB = vtk.vtkTable()
    boxBx = vtk.vtkFloatArray()
    boxBx.SetName('X Axis')

    boxBy = vtk.vtkFloatArray()
    boxBy.SetName('Y Axis')

    boxB.AddColumn(boxBx)
    boxB.AddColumn(boxBy)

    boxB.SetNumberOfRows(4)
    boxB.SetValue(0, 0, -2.0)
    boxB.SetValue(0, 1, 0.0)

    boxB.SetValue(1, 0, -2.0)
    boxB.SetValue(1, 1, 1)

    boxB.SetValue(2, 0, -1.0)
    boxB.SetValue(2, 1, 1.0)
    boxB.SetValue(3, 0, -1.0)
    boxB.SetValue(3, 1, 0)

    line1 = chart.AddPlot(vtk.vtkChart.LINE)
    line1.SetInputData(boxB, 0, 1)
    line1.SetColor(255, 0, 0, 255)
    line1.SetWidth(3.0)
    line1.GetPen().SetLineType(vtk.vtkPen.SOLID_LINE)
    line1.SetMarkerStyle(vtk.vtkPlotPoints.CIRCLE)

    global boxC
    boxC = vtk.vtkTable()
    boxCx = vtk.vtkFloatArray()
    boxCx.SetName('X Axis')
    boxCy = vtk.vtkFloatArray()
    boxCy.SetName('Y Axis')
    boxC.SetNumberOfRows(3)
    boxC.AddColumn(boxCx)
    boxC.AddColumn(boxCy)
    boxC.SetNumberOfRows(3)

    boxC.SetValue(0, 0, 0)
    boxC.SetValue(0, 1, 0)
    boxC.SetValue(1, 0, 0)
    boxC.SetValue(1, 1, 0)
    boxC.SetValue(2, 0, 0)
    boxC.SetValue(2, 1, 0)

    line0 = chart.AddPlot(vtk.vtkChart.LINE)
    line0.SetInputData(boxC, 0, 1)
    line0.SetColor(50, 50, 255, 255)
    line0.SetWidth(3.0)
    line0.GetPen().SetLineType(vtk.vtkPen.SOLID_LINE)
    line0.SetMarkerStyle(vtk.vtkPlotPoints.CIRCLE)

    global boxD
    boxD = vtk.vtkTable()
    boxDx = vtk.vtkFloatArray()
    boxDx.SetName('X Axis')
    boxDy = vtk.vtkFloatArray()
    boxDy.SetName('Y Axis')
    boxD.AddColumn(boxDx)
    boxD.AddColumn(boxDy)
    boxD.SetNumberOfRows(130)

    line3 = chart.AddPlot(vtk.vtkChart.LINE)
    line3.SetInputData(boxD, 0, 1)
    line3.SetColor(50, 255, 0, 255)
    line3.SetWidth(3.0)
    line3.GetPen().SetLineType(vtk.vtkPen.SOLID_LINE)
    line3.SetMarkerStyle(vtk.vtkPlotPoints.CIRCLE)

    #create timerCallBack
    cb = vtkTimerCallback()
    view.GetRenderWindow().SetMultiSamples(0)
    view.GetInteractor().Initialize()
    view.GetInteractor().AddObserver('TimerEvent', cb.execute)
    timerId = view.GetInteractor().CreateRepeatingTimer(20)
    view.GetInteractor().Start()
예제 #23
0
def main():
    colors = vtk.vtkNamedColors()

    renwin = vtk.vtkRenderWindow()
    renwin.SetWindowName('MultiplePlots')
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renwin)

    # Setup the viewports
    grid_dimensions_x = 2
    grid_dimensions_y = 1
    renderer_sz_x = 320
    renderer_sz_y = 240
    renwin.SetSize(renderer_sz_x * grid_dimensions_x,
                   renderer_sz_y * grid_dimensions_y)

    viewports = list()
    for row in range(0, grid_dimensions_y):
        for col in range(0, grid_dimensions_x):
            # index = row * grid_dimensions_x + col

            # (xmin, ymin, xmax, ymax)
            viewports.append([
                float(col) / grid_dimensions_x,
                float(grid_dimensions_y - (row + 1)) / grid_dimensions_y,
                float(col + 1) / grid_dimensions_x,
                float(grid_dimensions_y - row) / grid_dimensions_y
            ])

    # Link the renderers to the viewports.
    left_renderer = vtk.vtkRenderer()
    left_renderer.SetBackground(colors.GetColor3d('AliceBlue'))
    left_renderer.SetViewport(viewports[0])
    renwin.AddRenderer(left_renderer)

    right_renderer = vtk.vtkRenderer()
    right_renderer.SetBackground(colors.GetColor3d('Lavender'))
    right_renderer.SetViewport(viewports[1])
    renwin.AddRenderer(right_renderer)

    # Create the charts.
    left_chart = vtk.vtkChartXY()
    left_chart_scene = vtk.vtkContextScene()
    left_chart_actor = vtk.vtkContextActor()

    left_chart_scene.AddItem(left_chart)
    left_chart_actor.SetScene(left_chart_scene)

    left_renderer.AddActor(left_chart_actor)
    left_chart_scene.SetRenderer(left_renderer)

    x_axis = left_chart.GetAxis(vtk.vtkAxis.BOTTOM)
    x_axis.GetGridPen().SetColor(colors.GetColor4ub("LightGrey"))
    x_axis.SetTitle('x')
    y_axis = left_chart.GetAxis(vtk.vtkAxis.LEFT)
    y_axis.GetGridPen().SetColor(colors.GetColor4ub("LightGrey"))
    y_axis.SetTitle('cos(x)')
    left_chart.GetBackgroundBrush().SetColorF(*colors.GetColor4d('MistyRose'))
    left_chart.GetBackgroundBrush().SetOpacityF(0.4)
    left_chart.SetTitle('Cosine')

    right_chart = vtk.vtkChartXY()
    right_chart_scene = vtk.vtkContextScene()
    right_chart_actor = vtk.vtkContextActor()

    right_chart_scene.AddItem(right_chart)
    right_chart_actor.SetScene(right_chart_scene)

    right_renderer.AddActor(right_chart_actor)
    right_chart_scene.SetRenderer(right_renderer)

    x_axis = right_chart.GetAxis(vtk.vtkAxis.BOTTOM)
    x_axis.GetGridPen().SetColor(colors.GetColor4ub("LightCyan"))
    x_axis.SetTitle('x')
    y_axis = right_chart.GetAxis(vtk.vtkAxis.LEFT)
    y_axis.GetGridPen().SetColor(colors.GetColor4ub("LightCyan"))
    y_axis.SetTitle('sin(x)')
    right_chart.GetBackgroundBrush().SetColorF(*colors.GetColor4d('Thistle'))
    right_chart.GetBackgroundBrush().SetOpacityF(0.4)
    right_chart.SetTitle('Sine')

    # Create the data.
    table = vtk.vtkTable()
    array_x = vtk.vtkFloatArray()
    array_x.SetName('X Axis')
    table.AddColumn(array_x)

    array_cos = vtk.vtkFloatArray()
    array_cos.SetName('Cosine')
    table.AddColumn(array_cos)

    array_sin = vtk.vtkFloatArray()
    array_sin.SetName('Sine')
    table.AddColumn(array_sin)

    # Fill in the table with some example values.
    num_points = 40
    inc = 7.5 / (num_points - 1.0)
    table.SetNumberOfRows(num_points)
    for i in range(num_points):
        table.SetValue(i, 0, i * inc)
        table.SetValue(i, 1, math.cos(i * inc))
        table.SetValue(i, 2, math.sin(i * inc))

    points = left_chart.AddPlot(vtk.vtkChart.POINTS)
    points.SetInputData(table, 0, 1)
    points.SetColor(*colors.GetColor4ub('Black'))
    points.SetWidth(1.0)
    points.SetMarkerStyle(vtk.vtkPlotPoints.CROSS)

    points = right_chart.AddPlot(vtk.vtkChart.POINTS)
    points.SetInputData(table, 0, 2)
    points.SetColor(*colors.GetColor4ub('Black'))
    points.SetWidth(1.0)
    points.SetMarkerStyle(vtk.vtkPlotPoints.PLUS)

    renwin.Render()
    iren.Initialize()
    iren.Start()
def generate_distance_plot():
    def add_spline(outline):
        outline['spline_params'] = sa.get_spline_params(outline['points'])[0]
        return outline

    bones = map(add_spline, lh.load_files('data/2D/registered-outline/2015-06-08'))
    class1bones = [ bone for bone in bones if bone['class'] == 2 ]
    class2bones = [ bone for bone in bones if bone['class'] == 3 ]
    class1outline = np.mean([sa.evaluate_spline(np.linspace(0, 1, 180, endpoint=False), s['spline_params']) for s in class1bones], axis=0)
    class2outline = np.mean([sa.evaluate_spline(np.linspace(0, 1, 180, endpoint=False), s['spline_params']) for s in class2bones], axis=0)
    total_mean = np.mean([sa.evaluate_spline(np.linspace(0, 1, 180, endpoint=False), s['spline_params']) for s in bones], axis=0)

    distances = np.linalg.norm(class1outline - class2outline, axis=1)
    angles = np.array([degrees(gh.cart2pol(ev[0], ev[1])[1]) for ev in total_mean])
    angles[angles[:] < 0] += 360

    limit_min, limit_max = get_axis_limits(distances)

    chart = vtk.vtkChartXY()
    chart.GetAxis(1).SetBehavior(vtk.vtkAxis.FIXED)
    chart.GetAxis(0).SetBehavior(vtk.vtkAxis.FIXED)
    chart.GetAxis(0).SetTitle('')
    chart.GetAxis(1).SetTitle('')
    chart.GetAxis(0).GetLabelProperties().SetFontSize(30)
    chart.GetAxis(1).GetLabelProperties().SetFontSize(30)
    chart.GetAxis(1).SetRange(0, 359)
    chart.GetAxis(0).SetRange(0, 1)
    chart_table = vtk.vtkTable()
    chart_angle_axis_array = vtk.vtkFloatArray()
    chart_angle_axis_array.SetName('Angle (degrees)')
    chart_metric_array = vtk.vtkFloatArray()
    chart_metric_array.SetName('Distance')
    chart_table.AddColumn(chart_angle_axis_array)
    chart_table.AddColumn(chart_metric_array)

    chart_line = chart.AddPlot(vtk.vtkChart.LINE)
    chart_line.SetColor(0, 0, 0, 255)
    chart_line.SetWidth(2)

    chart.GetAxis(0).SetGridVisible(False)
    chart.GetAxis(1).SetGridVisible(False)
    chart_line.SetWidth(5)

    chart_table.SetNumberOfRows(distances.shape[0])
    for i in range(distances.shape[0]):
        chart_table.SetValue(i, 0, angles[i])
        chart_table.SetValue(i, 1, distances[i])
    chart_line.SetInputData(chart_table, 0, 1)

    render_window = vtk.vtkRenderWindow()
    render_window.SetOffScreenRendering(1)
    render_window.SetSize(640, 360)

    tick_positions_x = vtk.vtkDoubleArray()
    tick_positions_y = vtk.vtkDoubleArray()
    for angle in [0, 90, 180, 270, 360]:
        tick_positions_x.InsertNextValue(angle)
    for height in [limit_min, floor(limit_max*100) / 100]:
        tick_positions_y.InsertNextValue(height)
    chart.GetAxis(0).SetRange(limit_min, limit_max)
    chart.GetAxis(0).SetCustomTickPositions(tick_positions_y)
    chart.GetAxis(1).SetRange(0, 360)
    chart.GetAxis(1).SetCustomTickPositions(tick_positions_x)
    chart.Update()

    graph_context = vtk.vtkContextView()
    graph_context.SetRenderWindow(render_window)

    graph_context.GetScene().AddItem(chart)

    exporter = vtk.vtkGL2PSExporter()
    exporter.SetRenderWindow(render_window)
    exporter.SetFileFormatToSVG()
    exporter.CompressOff()
    exporter.DrawBackgroundOff()
    exporter.SetFilePrefix(os.path.abspath('thesis/img/results/real/distances'))
    exporter.Write()

    render_window.Finalize()
예제 #25
0
  def setup(self):
    ScriptedLoadableModuleWidget.setup(self)

    self.imageData = None

    # Add a Qt timer, that fires every X ms (16.7ms = 60 FPS, 33ms = 30FPS)
    # Connect the timeout() signal of the qt timer to a function in this class that you will write
    self.timer = qt.QTimer()
    self.timer.connect('timeout()', self.OnTimerTimeout)
    self.timer.start(16.7)

    self.table = vtk.vtkTable()
    self.chart = vtk.vtkChartXY()
    self.line = self.chart.AddPlot(0)
    #self.chart.RecalculateBounds() 
    self.view = vtk.vtkContextView()

    # Instantiate and connect widgets ...
    #
    # Parameters Area
    #
    parametersCollapsibleButton = ctk.ctkCollapsibleButton()
    parametersCollapsibleButton.text = "Parameters"
    self.layout.addWidget(parametersCollapsibleButton)

    # Layout within the dummy collapsible button
    parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton)

    #
    # transform first peak selector
    #
    self.firstPeakTransformSelector = slicer.qMRMLNodeComboBox()
    self.firstPeakTransformSelector.nodeTypes = ["vtkMRMLLinearTransformNode"]
    self.firstPeakTransformSelector.selectNodeUponCreation = True
    self.firstPeakTransformSelector.addEnabled = False
    self.firstPeakTransformSelector.removeEnabled = False
    self.firstPeakTransformSelector.noneEnabled = True
    self.firstPeakTransformSelector.showHidden = False
    self.firstPeakTransformSelector.showChildNodeTypes = False
    self.firstPeakTransformSelector.setMRMLScene( slicer.mrmlScene )
    self.firstPeakTransformSelector.setToolTip( "Pick the transform for the first peak." )
    parametersFormLayout.addRow("First Peak Transform: ", self.firstPeakTransformSelector)
    
    #
    # transform second peak selector
    #
    self.secondPeakTransformSelector = slicer.qMRMLNodeComboBox()
    self.secondPeakTransformSelector.nodeTypes = ["vtkMRMLLinearTransformNode"]
    self.secondPeakTransformSelector.selectNodeUponCreation = True
    self.secondPeakTransformSelector.addEnabled = False
    self.secondPeakTransformSelector.removeEnabled = False
    self.secondPeakTransformSelector.noneEnabled = True
    self.secondPeakTransformSelector.showHidden = False
    self.secondPeakTransformSelector.showChildNodeTypes = False
    self.secondPeakTransformSelector.setMRMLScene( slicer.mrmlScene )
    self.secondPeakTransformSelector.setToolTip( "Pick the transform for the second peak." )
    parametersFormLayout.addRow("Second Peak Transform: ", self.secondPeakTransformSelector)
    
    #
    # transform third peak selector
    #
    self.thirdPeakTransformSelector = slicer.qMRMLNodeComboBox()
    self.thirdPeakTransformSelector.nodeTypes = ["vtkMRMLLinearTransformNode"]
    self.thirdPeakTransformSelector.selectNodeUponCreation = True
    self.thirdPeakTransformSelector.addEnabled = False
    self.thirdPeakTransformSelector.removeEnabled = False
    self.thirdPeakTransformSelector.noneEnabled = True
    self.thirdPeakTransformSelector.showHidden = False
    self.thirdPeakTransformSelector.showChildNodeTypes = False
    self.thirdPeakTransformSelector.setMRMLScene( slicer.mrmlScene )
    self.thirdPeakTransformSelector.setToolTip( "Pick the transform for the third peak." )
    parametersFormLayout.addRow("Third Peak Transform: ", self.thirdPeakTransformSelector)

    #
    # volume selector
    #
    self.imageSelector = slicer.qMRMLNodeComboBox()
    self.imageSelector.nodeTypes = ["vtkMRMLScalarVolumeNode"]
    self.imageSelector.selectNodeUponCreation = True
    self.imageSelector.addEnabled = False
    self.imageSelector.removeEnabled = False
    self.imageSelector.noneEnabled = True
    self.imageSelector.showHidden = False
    self.imageSelector.showChildNodeTypes = False
    self.imageSelector.setMRMLScene( slicer.mrmlScene )
    self.imageSelector.setToolTip( "Pick the image that is the oscilloscope signal." )
    parametersFormLayout.addRow("Signal Volume: ", self.imageSelector)

    #
    # threshold value
    #
    #self.imageThresholdSliderWidget = ctk.ctkSliderWidget()
    #self.imageThresholdSliderWidget.singleStep = 0.1
    #self.imageThresholdSliderWidget.minimum = -100
    #self.imageThresholdSliderWidget.maximum = 100
    #self.imageThresholdSliderWidget.value = 0.5
    #self.imageThresholdSliderWidget.setToolTip("Set threshold value for computing the output image. Voxels that have intensities lower than this value will set to zero.")
    #parametersFormLayout.addRow("Image threshold", self.imageThresholdSliderWidget)

    #
    # check box to trigger taking screen shots for later use in tutorials
    #
    #self.enableScreenshotsFlagCheckBox = qt.QCheckBox()
    #self.enableScreenshotsFlagCheckBox.checked = 0
    #self.enableScreenshotsFlagCheckBox.setToolTip("If checked, take screen shots for tutorials. Use Save Data to write them to disk.")
    #parametersFormLayout.addRow("Enable Screenshots", self.enableScreenshotsFlagCheckBox)

    #
    # Apply Button
    #
    self.runButton = qt.QPushButton("Run")
    self.runButton.toolTip = "Start visualization."
    self.runButton.enabled = True
    parametersFormLayout.addRow(self.runButton)

    # connections
    self.runButton.connect('clicked(bool)', self.onRunButton)
    self.imageSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.OnInputVolumeSelect)
    self.firstPeakTransformSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onFirstPeakSelect)
    self.secondPeakTransformSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onSecondPeakSelect)
    self.thirdPeakTransformSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onThirdPeakSelect)
    #self.outputSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onSelect)

    # Add vertical spacer
    self.layout.addStretch(1)
예제 #26
0
	def __init__(self, parent = None):
	
		# Number of slider divisions per integer value
		self.divs = 10

		# self.rot_method = 'alt_axis'
		self.rot_method = '111'
		# self.rot_method = 'simple'
		
		self.axis_rescale = False

		QtGui.QMainWindow.__init__(self, parent)
		self.ui = Ui_MainWindow()
		   
		# Set up a 2D scene, add an XY chart to it
		self.view = vtk.vtkContextView()
		self.view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
		
		self.ui.setupUi(self, self.view.GetRenderWindow())

		if self.rot_method == 'alt_axis':
			self.ui.comboBox.setCurrentIndex(0)
		elif self.rot_method == '111':
			self.ui.comboBox.setCurrentIndex(1)
		else:
			self.ui.comboBox.setCurrentIndex(2)
			
		style = vtk.vtkInteractorStyleRubberBand2D()
		self.view.GetInteractor().SetInteractorStyle(style)
		self.view.GetScene().SetInteractorStyle(style)
		# Need this additional command (plus above set style) for this class
		# self.view.SetInteractionModeTo2D()
		
		self.chart = vtk.vtkChartXY()
		self.chart.SetShowLegend(False)

		# Create a annotation link to access selection in parallel coordinates view
		annotationLink = vtk.vtkAnnotationLink()
		# If you don't set the FieldType explicitly it ends up as UNKNOWN (as of 21 Feb 2010)
		# See vtkSelectionNode doc for field and content type enum values
		annotationLink.GetCurrentSelection().GetNode(0).SetFieldType(1)     # Point
		annotationLink.GetCurrentSelection().GetNode(0).SetContentType(4)   # Indices
		# Connect the annotation link to the parallel coordinates representation
		self.chart.SetAnnotationLink(annotationLink)
		
		self.view.GetScene().AddItem(self.chart)		
		
		# Set up callback to update 3d render window when selections are changed in 
		#	parallel coordinates view
		annotationLink.AddObserver("AnnotationChangedEvent", self.selectionCallback)
						
		QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL("triggered()"), self.fileExit)
		QtCore.QObject.connect(self.ui.actionOpen, QtCore.SIGNAL("triggered()"), self.LoadData)
		QtCore.QObject.connect(self.ui.horizontalSlider, QtCore.SIGNAL("valueChanged(int)"), self.columnUpdate)
		QtCore.QObject.connect(self.ui.comboBox, QtCore.SIGNAL("currentIndexChanged(int)"), self.rotMethodChanged)
		
		self.LoadData()
		
		self.view.ResetCamera()
		self.ui.vtkWidget.GetRenderWindow().Render()
		self.view.GetInteractor().Start()
예제 #27
0
파일: vview.py 프로젝트: xhub/siconos
    xprecs = numpy_support.numpy_to_vtk(nprecs)

    xtime.SetName('time')
    xiters.SetName('iterations')
    xprecs.SetName('precisions')

    table = vtk.vtkTable()
    table.AddColumn(xtime)
    table.AddColumn(xiters)
    table.AddColumn(xprecs)
    #table.Dump()

    tview_iter = vtk.vtkContextView()
    tview_prec = vtk.vtkContextView()

    chart_iter = vtk.vtkChartXY()
    chart_prec = vtk.vtkChartXY()
    tview_iter.GetScene().AddItem(chart_iter)
    tview_prec.GetScene().AddItem(chart_prec)
    iter_plot = chart_iter.AddPlot(vtk.vtkChart.LINE)
    iter_plot.SetLabel('Solver iterations')
    iter_plot.GetXAxis().SetTitle('time')
    iter_plot.GetYAxis().SetTitle('iterations')

    prec_plot = chart_prec.AddPlot(vtk.vtkChart.LINE)
    prec_plot.SetLabel('Solver precisions')
    prec_plot.GetXAxis().SetTitle('time')
    prec_plot.GetYAxis().SetTitle('precisions')

    add_compatiblity_methods(iter_plot)
    add_compatiblity_methods(prec_plot)
예제 #28
0
        line1 = chart.AddPlot(vtk.vtkChart.LINE)
        line1.SetInput(table, 0, 1)
        #line1.GetPen().SetLineType(vtk.vtkPen.NO_PEN)
        #line1.SetMarkerStyle(vtk.vtkPlotPoints.PLUS)
        #line1.SetColor(150, 100, 0, 255)

if __name__ == "__main__":
	dirname, filename = os.path.split(sys.argv[1])
        _, _, k = filename.partition("-")
        l,_,_ = k.partition(".")

        view = vtk.vtkContextView()
        view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
        view.GetRenderWindow().SetSize(800, 600)
        chart = vtk.vtkChartXY()
        view.GetScene().AddItem(chart)

	chart.SetTitle("time = {}".format(int(l)))
	chart.GetAxis(0).SetTitle("Pressure")
	chart.GetAxis(1).SetTitle("Coordinate")

	reader = vtk.vtkXMLStructuredGridReader()
	reader.SetFileName(sys.argv[1])
	reader.Update()

	addPlot(chart, reader, "time = {}".format(int(l)))

        #chart.SetShowLegend(True)
        view.GetRenderWindow().SetMultiSamples(0)
예제 #29
0
    def testLinePlot(self):
        "Test if line plots can be built with python"

        # Set up a 2D scene, add an XY chart to it
        view = vtk.vtkContextView()
        view.GetRenderer().SetBackground(1.0,1.0,1.0)
        view.GetRenderWindow().SetSize(400,300)
        chart = vtk.vtkChartXY()
        view.GetScene().AddItem(chart)

        # Create a table with some points in it
        table = vtk.vtkTable()

        arrX = vtk.vtkFloatArray()
        arrX.SetName("X Axis")

        arrC = vtk.vtkFloatArray()
        arrC.SetName("Cosine")

        arrS = vtk.vtkFloatArray()
        arrS.SetName("Sine")

        arrS2 = vtk.vtkFloatArray()
        arrS2.SetName("Sine2")

        numPoints = 69
        inc = 7.5 / (numPoints - 1)

        for i in range(0,numPoints):
            arrX.InsertNextValue(i*inc)
            arrC.InsertNextValue(math.cos(i * inc) + 0.0)
            arrS.InsertNextValue(math.sin(i * inc) + 0.0)
            arrS2.InsertNextValue(math.sin(i * inc) + 0.5)

        table.AddColumn(arrX)
        table.AddColumn(arrC)
        table.AddColumn(arrS)
        table.AddColumn(arrS2)

        # Now add the line plots with appropriate colors
        line = chart.AddPlot(0)
        line.SetInput(table,0,1)
        line.SetColor(0,255,0,255)
        line.SetWidth(1.0)

        line = chart.AddPlot(0)
        line.SetInput(table,0,2)
        line.SetColor(255,0,0,255);
        line.SetWidth(5.0)

        line = chart.AddPlot(0)
        line.SetInput(table,0,3)
        line.SetColor(0,0,255,255);
        line.SetWidth(4.0)

        view.GetRenderWindow().SetMultiSamples(0)
	view.GetRenderWindow().Render()

        img_file = "TestLinePlot.png"
        vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
        vtk.test.Testing.interact()
예제 #30
0
    def __init__(self, parent=None):
#        QtGui.QFrame.__init__(self, parent)
#
##        self.plotWidget = CartesianPlot()
#        self.plotWidget = PlotWidget()
#        
#        self.parentWidget = parent
#        layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom)
#        layout.addWidget(self.plotWidget)
#        self.setLayout(layout)
#        self.resize(400, 400)
#        self.setMinimumSize(200, 200) #needs to be defined to resize smaller than 400x400


        QtGui.QFrame.__init__(self, parent)
        self.qvtkWidget = QVTKRenderWindowInteractor(self)   # a QWidget
        self.parentWidget = parent
        
#        self.lineEdit = QtGui.QLineEdit()
        
#        self.__initCrossSectionActions()
#        self.cstb = self.initCrossSectionToolbar()        
        
        layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom)
#        layout.addWidget(self.cstb)
        layout.addWidget(self.qvtkWidget)
        self.setLayout(layout)
        
        self.qvtkWidget.Initialize()
        self.qvtkWidget.Start()
        
#        self.ren = vtk.vtkRenderer()
#        self.renWin = self.qvtkWidget.GetRenderWindow()
#        self.renWin.AddRenderer(self.ren)
#        self.resize(300, 300)


        self.chart = vtk.vtkChartXY()
        self.view = vtk.vtkContextView()
        self.ren = self.view.GetRenderer()
        self.renWin = self.qvtkWidget.GetRenderWindow()
        self.renWin.AddRenderer(self.ren)

        # Create a table with some points in it
        table = vtk.vtkTable()

        arrX = vtk.vtkFloatArray()
        arrX.SetName("X Axis")

        arrC = vtk.vtkFloatArray()
        arrC.SetName("Cosine")

        numPoints = 20
        inc = 7.5 / (numPoints - 1)

        for i in range(0,numPoints):
            arrX.InsertNextValue(i*inc)
            arrC.InsertNextValue(math.cos(i * inc) + 0.0)

        table.AddColumn(arrX)
        table.AddColumn(arrC)

        # Now add the line plots with appropriate colors
        line = self.chart.AddPlot(0)
        line.SetInput(table,0,1)
        line.SetColor(0,0,255,255)
        line.SetWidth(2.0)
예제 #31
0
    def assignVolumeProperties(self, recomp=False):
        ''' Configures Transfer Functions for Volume Render. '''
        
        self.chart = vtk.vtkChartXY()
        
        # remove previous volume / scalarbar if there was one
        if self.actorVolume != None:
            self.renderer.RemoveActor(self.actorVolume)
            self.renderer.RemoveActor(self.scalarBar)
            
        if recomp:
            self.colorfunctions.clear()
            
        if self.curr_statistic not in self.colorfunctions.keys():
            self.colorfunctions[self.curr_statistic] = vtk.vtkColorTransferFunction()
            self.opacityfunctions[self.curr_statistic] = vtk.vtkPiecewiseFunction()
            cfn = self.colorfunctions[self.curr_statistic]
            ofn = self.opacityfunctions[self.curr_statistic]
            self.setColorOpacityDataPoints(cfn, ofn)
            self.opacityfunctions[self.curr_statistic].ClampingOn()
                    
        cfn = self.colorfunctions[self.curr_statistic]
        ofn = self.opacityfunctions[self.curr_statistic]
        
        self.__buildTransFuncChart(cfn, ofn)
        self.__buildScalarBar(self.curr_statistic)
        
        self.mapperVolume2 = vtk.vtkSmartVolumeMapper()
        img = self.images[self.curr_statistic]
        self.mapperVolume2.SetInputData( img )
        self.mapperVolume2.CroppingOff()
        self.addClippingPlanes(self.mapperVolume2, recomp)
        self.mapperVolume2.SetBlendModeToComposite()
        '''
        virtual void     SetBlendMode (int)
        void     SetBlendModeToComposite ()
        void     SetBlendModeToMaximumIntensity ()
        void     SetBlendModeToMinimumIntensity ()
        void     SetBlendModeToAdditive ()
        virtual int     GetBlendMode ()
        '''

        self.propVolume = vtk.vtkVolumeProperty()
        self.propVolume.ShadeOff()
        self.propVolume.SetColor(cfn)
        self.propVolume.SetScalarOpacity(ofn)
        #self.propVolume.SetInterpolationTypeToLinear()
        
        self.actorVolume = vtk.vtkVolume()
        self.actorVolume.SetMapper(self.mapperVolume2)
        self.actorVolume.SetProperty(self.propVolume)
        
        self.renderer.AddActor(self.actorVolume)
        self.renderer.AddActor(self.scalarBar)
        
        # set TF chart labels
        stat = self.curr_statistic
        if stat == 'Mean' or stat =='Var' or stat =='Min' or \
            stat =='Max' or stat =='NumSamples':
            self.setTFAxisLabels(self.curr_statistic, \
                                 self.curr_statistic, \
                                 self.curr_statistic)
        elif self.curr_statistic == 'Mean-Var':
            self.setTFAxisLabels(self.curr_statistic, \
                                 xlabel = 'Mean', \
                                 ylabel = '1.0 - Normalized Mean-Var')
        elif self.curr_statistic == 'Min-Var':
            self.setTFAxisLabels(self.curr_statistic, \
                                 xlabel = 'Min', \
                                 ylabel = '1.0 - Normalized Min-Var')
        elif self.curr_statistic == 'Max-Var':
            self.setTFAxisLabels(self.curr_statistic, \
                                 xlabel = 'Max', \
                                 ylabel = '1.0 - Normalized Max-Var')
예제 #32
0
        xprecs = numpy_support.numpy_to_vtk(nprecs)

        xtime.SetName('time')
        xiters.SetName('iterations')
        xprecs.SetName('precisions')

        table = vtk.vtkTable()
        table.AddColumn(xtime)
        table.AddColumn(xiters)
        table.AddColumn(xprecs)
        # table.Dump()

        tview_iter = vtk.vtkContextView()
        tview_prec = vtk.vtkContextView()

        chart_iter = vtk.vtkChartXY()
        chart_prec = vtk.vtkChartXY()
        tview_iter.GetScene().AddItem(chart_iter)
        tview_prec.GetScene().AddItem(chart_prec)
        iter_plot = chart_iter.AddPlot(vtk.vtkChart.LINE)
        iter_plot.SetLabel('Solver iterations')
        iter_plot.GetXAxis().SetTitle('time')
        iter_plot.GetYAxis().SetTitle('iterations')

        prec_plot = chart_prec.AddPlot(vtk.vtkChart.LINE)
        prec_plot.SetLabel('Solver precisions')
        prec_plot.GetXAxis().SetTitle('time')
        prec_plot.GetYAxis().SetTitle('precisions')

        add_compatiblity_methods(iter_plot)
        add_compatiblity_methods(prec_plot)
예제 #33
0
    def testStackedPlot(self):
        "Test if stacked plots can be built with python"

        # Set up a 2D scene, add an XY chart to it
        view = vtk.vtkContextView()
        view.GetRenderer().SetBackground(1.0,1.0,1.0)
        view.GetRenderWindow().SetSize(400,300)
        chart = vtk.vtkChartXY()
        view.GetScene().AddItem(chart)

        # Create a table with some points in it
        table = vtk.vtkTable()

        arrMonthLabels = vtk.vtkStringArray()
        arrMonthPositions = vtk.vtkDoubleArray()

        arrMonth = vtk.vtkIntArray()
        arrMonth.SetName("Month")

        arrBooks = vtk.vtkIntArray()
        arrBooks.SetName("Books")

        arrNew = vtk.vtkIntArray()
        arrNew.SetName("New / Popular")

        arrPeriodical = vtk.vtkIntArray()
        arrPeriodical.SetName("Periodical")

        arrAudiobook = vtk.vtkIntArray()
        arrAudiobook.SetName("Audiobook")

        arrVideo = vtk.vtkIntArray()
        arrVideo.SetName("Video")

        numMonths = 12

        for i in range(0,numMonths):
            arrMonthLabels.InsertNextValue(month_labels[i])
            arrMonthPositions.InsertNextValue(float(i));

            arrMonth.InsertNextValue(i)
            arrBooks.InsertNextValue(book[i])
            arrNew.InsertNextValue(new_popular[i])
            arrPeriodical.InsertNextValue(periodical[i])
            arrAudiobook.InsertNextValue(audiobook[i])
            arrVideo.InsertNextValue(video[i])

        table.AddColumn(arrMonth)
        table.AddColumn(arrBooks)
        table.AddColumn(arrNew)
        table.AddColumn(arrPeriodical)
        table.AddColumn(arrAudiobook)
        table.AddColumn(arrVideo)

        # Now add the line plots with appropriate colors

        chart.GetAxis(1).SetTickLabels(arrMonthLabels)
        chart.GetAxis(1).SetTickPositions(arrMonthPositions)
        chart.GetAxis(1).SetMaximum(11)

        # Books
        line = chart.AddPlot(3)
        line.SetInput(table,0,1)
        line.SetColor(120,120,254,255)

        # New / Popular
        line = chart.AddPlot(3)
        line.SetInput(table,0,2)
        line.SetColor(254,118,118,255)

        # Periodical
        line = chart.AddPlot(3)
        line.SetInput(table,0,3)
        line.SetColor(170,170,254,255)

        # Audiobook
        line = chart.AddPlot(3)
        line.SetInput(table,0,4)
        line.SetColor(91,91,254,255)

        # Video
        line = chart.AddPlot(3)
        line.SetInput(table,0,5)
        line.SetColor(253,158,158,255)

        view.GetRenderWindow().SetMultiSamples(0)
        #view.GetRenderWindow().GetInteractor().Start()

        img_file = "TestStackedPlot.png"
        img_file2 = "TestStackedPlot0Hidden.png"
        vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
        vtk.test.Testing.interact()
        chart.GetPlot(0).SetVisible(False)
        vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file2),threshold=25)
        vtk.test.Testing.interact()
예제 #34
0
    def testStackedPlot(self):
        "Test if stacked plots can be built with python"

        # Set up a 2D scene, add an XY chart to it
        view = vtk.vtkContextView()
        view.GetRenderer().SetBackground(1.0,1.0,1.0)
        view.GetRenderWindow().SetSize(400,300)
        chart = vtk.vtkChartXY()
        view.GetScene().AddItem(chart)

        # Create a table with some data in it
        table = vtk.vtkTable()

        arrMonthLabels = vtk.vtkStringArray()
        arrMonthPositions = vtk.vtkDoubleArray()

        arrMonth = vtk.vtkIntArray()
        arrMonth.SetName("Month")

        arrBooks = vtk.vtkIntArray()
        arrBooks.SetName("Books")

        arrNew = vtk.vtkIntArray()
        arrNew.SetName("New / Popular")

        arrPeriodical = vtk.vtkIntArray()
        arrPeriodical.SetName("Periodical")

        arrAudiobook = vtk.vtkIntArray()
        arrAudiobook.SetName("Audiobook")

        arrVideo = vtk.vtkIntArray()
        arrVideo.SetName("Video")

        numMonths = 12

        for i in range(0,numMonths):
            arrMonthLabels.InsertNextValue(month_labels[i])
            arrMonthPositions.InsertNextValue(float(i))

            arrMonth.InsertNextValue(i)
            arrBooks.InsertNextValue(book[i])
            arrNew.InsertNextValue(new_popular[i])
            arrPeriodical.InsertNextValue(periodical[i])
            arrAudiobook.InsertNextValue(audiobook[i])
            arrVideo.InsertNextValue(video[i])

        table.AddColumn(arrMonth)
        table.AddColumn(arrBooks)
        table.AddColumn(arrNew)
        table.AddColumn(arrPeriodical)
        table.AddColumn(arrAudiobook)
        table.AddColumn(arrVideo)

        # Set up the X Labels
        chart.GetAxis(1).SetCustomTickPositions(arrMonthPositions, arrMonthLabels)
        chart.GetAxis(1).SetMaximum(11)
        chart.GetAxis(1).SetBehavior(vtk.vtkAxis.FIXED)

        # Create the stacked plot
        stack = chart.AddPlot(3)
        stack.SetUseIndexForXSeries(True)
        stack.SetInputData(table)
        stack.SetInputArray(1,"Books")
        stack.SetInputArray(2,"New / Popular")
        stack.SetInputArray(3,"Periodical")
        stack.SetInputArray(4,"Audiobook")
        stack.SetInputArray(5,"Video")

        # Set up a nice color series
        colorSeries = vtk.vtkColorSeries()
        colorSeries.SetColorScheme(2)
        stack.SetColorSeries(colorSeries)

        view.GetRenderWindow().SetMultiSamples(0)
        view.GetRenderWindow().Render()

        img_file = "TestStackedPlot.png"
        vtk.test.Testing.compareImage(view.GetRenderWindow(),
                                      vtk.test.Testing.getAbsImagePath(img_file),
                                      threshold=25)
        vtk.test.Testing.interact()
예제 #35
0
    def testLinePlot(self):
        "Test if colored scatter plots can be built with python"

        # Set up a 2D scene, add an XY chart to it
        view = vtk.vtkContextView()
        view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
        view.GetRenderWindow().SetSize(400, 300)

        chart = vtk.vtkChartXY()
        chart.SetShowLegend(True)
        view.GetScene().AddItem(chart)

        # Create a table with some points in it
        arrX = vtk.vtkFloatArray()
        arrX.SetName("XAxis")

        arrC = vtk.vtkFloatArray()
        arrC.SetName("Cosine")

        arrS = vtk.vtkFloatArray()
        arrS.SetName("Sine")

        arrS2 = vtk.vtkFloatArray()
        arrS2.SetName("Tan")

        numPoints = 40
        inc = 7.5 / (numPoints-1)

        for i in range(numPoints):
            arrX.InsertNextValue(i * inc)
            arrC.InsertNextValue(math.cos(i * inc) + 0.0)
            arrS.InsertNextValue(math.sin(i * inc) + 0.0)
            arrS2.InsertNextValue(math.tan(i * inc) + 0.5)

        table = vtk.vtkTable()
        table.AddColumn(arrX)
        table.AddColumn(arrC)
        table.AddColumn(arrS)
        table.AddColumn(arrS2)

        # Generate a black-to-red lookup table with fixed alpha
        lut = vtk.vtkLookupTable()
        lut.SetValueRange(0.2, 1.0)
        lut.SetSaturationRange(1, 1)
        lut.SetHueRange(0,0)
        lut.SetRampToLinear()
        lut.SetRange(-1,1)
        lut.SetAlpha(0.75)
        lut.Build()

        # Generate a black-to-blue lookup table with alpha range
        lut2 = vtk.vtkLookupTable()
        lut2.SetValueRange(0.2, 1.0)
        lut2.SetSaturationRange(1, 1)
        lut2.SetHueRange(0.6667, 0.6667)
        lut2.SetAlphaRange(0.4, 0.8)
        lut2.SetRampToLinear()
        lut2.SetRange(-1,1)
        lut2.Build()

        # Add multiple line plots, setting the colors etc
        points0 = chart.AddPlot(vtk.vtkChart.POINTS)
        points0.SetInputData(table, 0, 1)
        points0.SetColor(0, 0, 0, 255)
        points0.SetWidth(1.0)
        points0.SetMarkerStyle(vtk.vtkPlotPoints.CROSS)

        points1 = chart.AddPlot(vtk.vtkChart.POINTS)
        points1.SetInputData(table, 0, 2)
        points1.SetColor(0, 0, 0, 255)
        points1.SetMarkerStyle(vtk.vtkPlotPoints.DIAMOND)
        points1.SetScalarVisibility(1)
        points1.SetLookupTable(lut)
        points1.SelectColorArray(1)

        points2 = chart.AddPlot(vtk.vtkChart.POINTS)
        points2.SetInputData(table, 0, 3)
        points2.SetColor(0, 0, 0, 255)
        points2.ScalarVisibilityOn()
        points2.SetLookupTable(lut2)
        points2.SelectColorArray("Cosine")
        points2.SetWidth(4.0)

        view.GetRenderWindow().SetMultiSamples(0)
        view.GetRenderWindow().Render()

        img_file = "TestScatterPlotColors.png"
        vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
        vtk.test.Testing.interact()
    def addPlot(
        self,
        _plotName,
        _style="Lines"
    ):  # called directly from Steppable; add a (possibly more than one) plot to a plot window

        self.plotWindowInterfaceMutex.lock()
        #        self.plotWindowMutex.lock()

        #        return
        #        print MODULENAME,'   addPlot():  _plotName= ',_plotName
        #        import pdb; pdb.set_trace()

        #        self.plotData[_plotName] = [array([],dtype=double),array([],dtype=double),False]  # 'array': from PyQt4.Qwt5.anynumpy import *

        self.chart = vtk.vtkChartXY()
        #        self.chart.GetAxis(vtk.vtkAxis.LEFT).SetLogScale(True)
        #        self.chart.GetAxis(vtk.vtkAxis.BOTTOM).SetLogScale(True)
        #        self.numCharts += 1
        self.plotData[_plotName] = [self.chart]

        self.view = vtk.vtkContextView()
        self.ren = self.view.GetRenderer()
        #        self.renWin = self.qvtkWidget.GetRenderWindow()
        self.renWin = self.pW.GetRenderWindow()
        self.renWin.AddRenderer(self.ren)

        # Create a table with some points in it
        self.table = vtk.vtkTable()

        self.arrX = vtk.vtkFloatArray()
        self.arrX.SetName("xarray")

        self.arrC = vtk.vtkFloatArray()
        self.arrC.SetName("yarray")

        numPoints = 5
        numPoints = 15
        inc = 7.5 / (numPoints - 1)

        #        for i in range(0,numPoints):
        #            self.arrX.InsertNextValue(i*inc)
        #            self.arrC.InsertNextValue(math.cos(i * inc) + 0.0)

        #        self.arrX.InsertNextValue(0.0)
        #        self.arrC.InsertNextValue(0.0)
        #        self.arrX.InsertNextValue(0.1)
        #        self.arrC.InsertNextValue(0.1)

        self.table.AddColumn(self.arrX)
        self.table.AddColumn(self.arrC)

        # Now add the line plots with appropriate colors
        self.line = self.chart.AddPlot(0)
        self.line.SetInput(self.table, 0, 1)
        self.line.SetColor(0, 0, 255, 255)
        self.line.SetWidth(1.0)

        self.view.GetRenderer().SetBackground([0.6, 0.6, 0.1])
        self.view.GetRenderer().SetBackground([1.0, 1.0, 1.0])
        self.view.GetScene().AddItem(self.chart)

        self.plotWindowInterfaceMutex.unlock()