[vtkusers] Updating parallel coordinates using vtkchartsparallelcoordinates

aedeegee dasgupta.aritra at gmail.com
Fri May 24 17:31:46 EDT 2013


I am trying to update the parallel coordinates view by deleting a column and
having parallel coordinates to be rendered without the deleted columns. I am
implementing a callback function (selfDeleteCallBack) that is invoked on the
right click of the mouse. But the program crashes on the right click.

On printing diagnostic statements, I can see that the program knows which
columns are deleted, but does not re-render parallel coordinates with the
subset of the columns.

Here is the script:

import vtk 
import math 
import random 

# 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(600,300) 

chart = vtk.vtkChartParallelCoordinates() 
view.GetScene().AddItem(chart) 

# Test charting with a few more points... 
numPoints = 100 
numCats = 8 
inc = 7.5 / (numPoints-1) 

# Create arrays that will end up as table columns 
arrX = vtk.vtkFloatArray() 
arrX.SetName("XAxis") 
arrX.SetNumberOfComponents(1) 
arrX.SetNumberOfTuples(numPoints) 
arrC = vtk.vtkFloatArray() 
arrC.SetName("Cosine") 
arrC.SetNumberOfComponents(1) 
arrC.SetNumberOfTuples(numPoints) 
arrS = vtk.vtkFloatArray() 
arrS.SetName("Sine") 
arrS.SetNumberOfComponents(1) 
arrS.SetNumberOfTuples(numPoints) 
arrS2 = vtk.vtkFloatArray() 
arrS2.SetName("GaussRand") 
arrS2.SetNumberOfComponents(1) 
arrS2.SetNumberOfTuples(numPoints) 

arrCat = vtk.vtkIntArray() 
arrCat.SetName("Category_ids") 
arrCat.SetNumberOfComponents(1) 
arrCat.SetNumberOfTuples(numPoints) 

# For some reason table.SetValue() is not wrapped 
# so need to build arrays and then add as columns 
# Would be more elegant to use numpy, but wanted to keep it out for now... 
for i in range(numPoints): 
        arrX.SetTuple1(i, i * inc) 
        arrC.SetTuple1(i, math.cos(i * inc) + 0.0) 
        arrS.SetTuple1(i, math.sin(i * inc) + 0.0) 
        arrS2.SetTuple1(i, random.gauss(0,1)) 
        arrCat.SetTuple1(i, int(float(numCats)*float(i)/float(numPoints))) 

# Create a table with some points in it... 
table = vtk.vtkTable() 
table.AddColumn(arrX) 
table.AddColumn(arrC) 
# table.AddColumn(arrS2) 
table.AddColumn(arrS) 
table.AddColumn(arrCat) 

cl = [] 
cl.append([float(cc)/255.0 for cc in [27, 158, 119]])	# Colorbrewer Dark2 
cl.append([float(cc)/255.0 for cc in [217, 95, 2]]) 
cl.append([float(cc)/255.0 for cc in [117, 112, 179]]) 
cl.append([float(cc)/255.0 for cc in [231, 41, 138]]) 
cl.append([float(cc)/255.0 for cc in [102, 166, 30]]) 
cl.append([float(cc)/255.0 for cc in [230, 171, 2]]) 
cl.append([float(cc)/255.0 for cc in [166, 118, 29]]) 
cl.append([float(cc)/255.0 for cc in [102, 102, 102]]) 

lut = vtk.vtkLookupTable() 
lutNum = len(cl) 
lut.SetNumberOfTableValues(lutNum) 
lut.Build() 
for ii,cc in enumerate(cl): 
        lut.SetTableValue(ii,cc[0],cc[1],cc[2],1.0) 
lut.SetRange(0,numCats-1) 

chart.GetPlot(0).SetInput(table) 
chart.GetPlot(0).SetScalarVisibility(1) 
chart.GetPlot(0).SetLookupTable(lut) 
chart.GetPlot(0).SelectColorArray("Category_ids") 
# chart.GetAxis(0).GetPen().SetColor(0,0,0,50) 
chart.GetPlot(0).GetPen().SetOpacityF(0.5) 
chart.GetPlot(0).GetPen().SetWidth(2) 

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


#This is the callback function to remove a column and re-render the parallel
coordinates without the removed column.

def selfDeleteCallback(iren, strObj):

        axisClicked = None  
        column = None   
        for id in range(chart.GetNumberOfAxes()):
           if iren.GetEventPosition()[0] >
chart.GetAxis(id).GetPoint1()[0]-10 and \
              iren.GetEventPosition()[0] <=
chart.GetAxis(id).GetPoint1()[0]+10:
               
                axisClicked = chart.GetAxis(id)

                table.RemoveColumn(id)
                print "Number of columns", table.GetNumberOfColumns()
                table.Modified()
                view.GetInteractor().Render()


# Start interaction event loop 
view.GetInteractor().AddObserver("RightButtonPressEvent",
selfDeleteCallback)
view.GetInteractor().Start() 



--
View this message in context: http://vtk.1045678.n5.nabble.com/Updating-parallel-coordinates-using-vtkchartsparallelcoordinates-tp5720991.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list