[vtkusers] How to setup Parallel Coordinates?

Eric E. Monson emonson at cs.duke.edu
Sat Oct 16 14:09:51 EDT 2010


Hey Henry,

What version of VTK are you using? SetColumnVisibilityAll() is a fairly recent addition to the development version that you need to get with git and build yourself. Otherwise, the older standard way was just to set the column visibility of each one individually. (It used to default to only 10 columns visible, so if you wanted more than that you had to make sure to go through all of them manually.) Here's a chunk out of another piece of code that does this:

for ii in range(table.GetNumberOfColumns()):
    col_name = table.GetColumnName(ii)
    if not col_name.lower().endswith('_ids'):
        chart.SetColumnVisibility(col_name, True)

At the end I'll attach the example that I modified to send to you earlier. It has an AnnotationLink that watches for a change in selection and then prints out the selected IDs.

Let us know if you have any more problems,
-Eric

#==========================
# Translated to Python from [VTK]/Charts/Testing/Cxx/TestPCPlot.cxx

import vtk
import math
import vtk.util.numpy_support as VN

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

# 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
chart.SetAnnotationLink(annotationLink)

view.GetScene().AddItem(chart)

# Test charting with a few more points...
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)

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

def selectionCallback(caller, event):
        annSel = annotationLink.GetCurrentSelection()
        if annSel.GetNumberOfNodes() > 0:
                idxArr = annSel.GetNode(0).GetSelectionList()
                if idxArr.GetNumberOfTuples() > 0:
                        print VN.vtk_to_numpy(idxArr)

# Set up callback to update 3d render window when selections are changed in 
#       parallel coordinates view
annotationLink.AddObserver("AnnotationChangedEvent", selectionCallback)


view.ResetCamera()
view.Render()

# Start interaction event loop
view.GetInteractor().Start()



On Oct 16, 2010, at 1:49 PM, Henry wrote:

> Eric, It works! =DDD
> Thank you! :-D
> 
> "I have other examples which include setting column/axis visibility and getting the indices of selections that I can put up on the Wiki sometime." 
> I would be very happy with this. =]
> 
> I was trying to set visibilty and it doesn't work. 
> Example:
> 
> chart = vtk.vtkChartParallelCoordinates()
> chart.SetColumnVisibilityAll(False)
> 
> Python says:
> chart.SetColumnVisibilityAll(False)
> AttributeError: SetColumnVisibilityAll
> 
> I don't know if I am the problem or if the vtk+python is. Because all I try to do doesn't work. :s
> 
> Thank you
> Henry
> 
> 
> P.S. I'm trying to write in English, so sorry if I wrote wrong things. :)
> 
> 
> On Sat, Oct 16, 2010 at 10:06, Eric E. Monson <emonson at cs.duke.edu> wrote:
> Hey Henry,
> 
> After playing with it for a few minutes I'm starting to suspect that although vtkParallelCoordinatesRepresentation is supposed to accept a vtkTable as input, maybe there are some problems with that. The example from the Wiki uses a vtkImageData as input and plots its attributes.
> 
> What you might want to do is to switch to using the parallel coordinates chart from the newer VTK Charts. It doesn't have quite as many selection mode options, but it is very nice. Also, I know it's built to take a table as input for sure:
> 
> # ======
> import vtk
> 
> # 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)
> 
> reader = vtk.vtkDelimitedTextReader()
> reader.DetectNumericColumnsOn()
> reader.SetFieldDelimiterCharacters(" ")
> reader.SetHaveHeaders(True)
> reader.SetMaxRecords(100)
> reader.SetFileName("News.gbdiv")
> reader.Update()
> 
> chart.GetPlot(0).SetInput(reader.GetOutput())
> 
> view.ResetCamera()
> view.Render()
> 
> # Start interaction event loop
> view.GetInteractor().Start()
> # ======
> 
> I have other examples which include setting column/axis visibility and getting the indices of selections that I can put up on the Wiki sometime.
> 
> Talk to you later,
> -Eric
> 
> ------------------------------------------------------
> Eric E Monson
> Duke Visualization Technology Group
> 
> 
> On Oct 15, 2010, at 11:49 PM, Henry wrote:
> 
>> Hi! :-)
>> I'm having a problem and it's:
>> 
>> I'd like to plot parallel coordinates but I can't. The vtkParallelCoordinatesRepresentation can't get my data. It doesn't plot the rows.
>> 
>> I'm trying to be guided by the example of the wiki: http://www.vtk.org/Wiki/VTK/Examples/Python/Infovis/ParallelCoordinatesView
>> (The example works very well; my code doesn't)
>> 
>> My code is:
>> (...)
>> 
>> reader = vtkDelimitedTextReader()
>> reader.DetectNumericColumnsOn()
>> reader.SetFieldDelimiterCharacters(" ")
>> reader.SetHaveHeaders(True)
>> reader.SetMaxRecords(100)
>> reader.SetFileName(".\DataSets\News.gbdiv")
>> reader.Update()
>> #table = reader.GetOutput()
>> 
>> rep = vtk.vtkParallelCoordinatesRepresentation()
>> 
>> # I don't know why this don't work
>> 
>> rep.SetInputConnection(reader.GetOutputPort())  
>> 
>> #I have tried many ways to put my data in, but nothing works. another is:
>> #rep.SetInput(table)
>> 
>> rep.SetInputArrayToProcess(0,0,0,0,'all')
>> rep.SetInputArrayToProcess(1,0,0,0,'music')
>> rep.SetInputArrayToProcess(2,0,0,0,'entertainment')
>> rep.SetInputArrayToProcess(3,0,0,0,'health')
>> rep.SetInputArrayToProcess(4,0,0,0,'business')
>> rep.SetInputArrayToProcess(5,0,0,0,'sport')
>> rep.SetInputArrayToProcess(6,0,0,0,'science')
>> rep.SetInputArrayToProcess(7,0,0,0,'environment')
>> rep.SetInputArrayToProcess(8,0,0,0,'politics')
>> 
>> #Here is the same code in the example of the wiki
>> rep.SetUseCurves(0)    
>> rep.SetLineOpacity(0.5)
>> view.SetRepresentation(rep)
>> view.SetInspectMode(1)     
>> view.SetBrushModeToLasso()
>> view.SetBrushOperatorToReplace()
>> def ToggleInspectors(obj,event):
>>     if (view.GetInspectMode() == 0):
>>         view.SetInspectMode(1)
>>     else:
>>         view.SetInspectMode(0)
>> view.GetInteractor().AddObserver("UserEvent", ToggleInspectors)
>> view.GetRenderWindow().SetSize(1000,600)
>> view.ResetCamera()
>> view.Render()
>> view.GetInteractor().Start()
>> 
>> 
>> The data read by the reader is(each column,All, Music, Enter..., is a coordinate):
>> All Music Entertainment Health Business Sport Science Environment Politics
>> 2.02657807 0.86289549 0.31007752 1.10266160 0.92307692 0.27089783 0.98556846 0.45808520 0.11614402
>> 1.67774086 0.23969319 2.17054264 0.83650190 0.19230769 0.00000000 0.70397747 0.04580852 0.27100271
>> 1.16279070 0.14381592 0.10335917 0.41825095 0.73076923 0.34829721 0.35198874 0.22904260 0.61943477
>> (...)
>> 
>> 
>> What should I do to plot my data? What am I forgetting to? The reader get my data and the GetOutput() return a table. I've tried get some values by index and i'v got the right ones. But I can't plot it. =\
>> 
>> Thank you, 
>> :)
>> 
>> -- 
>> Henry
>> 
>> Bacharelado em Ciências de Computação - 2007
>> ICMC - USP - São Carlos
>> _______________________________________________
>> Powered by www.kitware.com
>> 
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>> 
>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101016/f591dddb/attachment.htm>


More information about the vtkusers mailing list