[vtk-developers] ChartParallelCoordinates data switching

Eric E. Monson emonson at cs.duke.edu
Tue Sep 28 10:45:29 EDT 2010


Hey Marcus,

In my application I was switching the data in a parallel coordinates chart and noticed that there are problems (and no intuitive solution) if you swap out the data to a new set which has less axes/columns. If you just do a chart.GetPlot(0).SetInput(table) with a new table that has less columns than the previous one you get a Segmentation Fault. (I'll put a short python script at the end that demonstrates this.) 

You can get around it by first turning off the visibility of all the current axes, since the plot relies on the column visibility data for its updating routines. (To see that this seems to work, set the if(False) to if(True) in the script.)

In my custom version I just added a SetAllColumnsInvisible() method, which just does a this->VisibleColumns->SetNumberOfTuples(0); (plus a Modified and Update), and if I call this before resetting the data in the plot it seems to work fine. This name won't help people, though, since it's not obvious that you'd need to call this before swapping the data...

So, I don't have the ideal solution, just one that's working for me, but I thought I'd bring this to your attention since it seems like something that should be addressed at some point.

Talk to you later,
-Eric

------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group


=================================================
# This version illustrates a Segmentation Fault when switching to 
# a new data table that has less columns than the original

import vtk
import math

# 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)

numPoints = 200
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("Tan")
arrS2.SetNumberOfComponents(1)
arrS2.SetNumberOfTuples(numPoints)

# Fill the arrays with data
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, math.tan(i * inc) + 0.5)

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

chart.GetPlot(0).SetInput(table)

view.ResetCamera()
view.Render()

# * * * *
# Set this to "if (True):" to see the program not crash
# * * * *
if (False):
	for ii in range(table.GetNumberOfColumns()):
		t_name = table.GetColumnName(ii)
		chart.SetColumnVisibility(t_name, False)

# Create a new table with less columns than the first
table2 = vtk.vtkTable()
table2.AddColumn(arrX)
table2.AddColumn(arrC)
table2.AddColumn(arrS)

chart.GetPlot(0).SetInput(table2)
view.Render()

view.GetInteractor().Start()





More information about the vtk-developers mailing list