[vtkusers] Selection Problem with VtkChartParallelCoordinates

Eric E. Monson emonson at cs.duke.edu
Tue Jul 24 16:06:05 EDT 2012


Hey Weimin,

(I'm doing this with VTK 5.10, so hopefully it's similar enough to the current dev…)

First, selections in VTK take a bit of getting used to. Here's an explanation of some of it that Jeff Baumes wrote a while back:

http://www.kitware.com/media/html/SelectionsInVTK.html

Then there is also the vtkAnnotationLink, which contains a selection, and is used to pass selections between (originally InfoVis) views. You can look at some of the examples and tests linked off of the doc page:

http://www.vtk.org/doc/nightly/html/classvtkAnnotationLink.html

You can make selections in a parallel coordinates (PC) chart by creating an index selection and putting it in the chart's annotation link. The PC chart only seems to be set up to do selections by Index, so if your ID array (table column) is always going to match up with the row index, then life can be simpler for you. You can just set up an annotation link into your PC chart and then create a vtkIdTypeArray containing the ID you want to select, and put that in 

annotationLink->GetCurrentSelection()->GetNode(0)->SetSelectionList(idArray);

If your IDs are not always going to match up with the row indices, then the only way I can figure out how to make the correct selection is to create a vtkSelection and vtkSelectionNode which will select by PedigreeIds (or GlobalIds), and then when you put the ID you want in the SelectionList for that selection node, then use vtkConvertSelection, passing this pedigree id selection along with your table (where you've set the ID array as the pedigree ids) and convert the selection to an Index selection. You can then pass this "converted to index" selection into your PC chart annotation link and it will select the proper line in your plot.

I know that's confusing. Maybe someone else can pipe in with a simpler way or a more clear explanation. I'm attaching a Python example that shows the method. Notice that the ID array in my table contains non-sequential IDs that don't start at 0 like the Index does. But, when I choose pedigree id 4020, the proper line is selected (and highlighted) in the chart, even though there is no line or table row with index 4020, but there is a matching pedigree ID.

(Sorry if Python isn't best for you – I already has an example that was close, and it's easier for me to play there.)

Good luck,
-Eric

· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
Eric E Monson
Duke Visualization Technology Group



=================================================

# 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()
annotationLink.GetCurrentSelection().GetNode(0).SetFieldType(1)     # Point
annotationLink.GetCurrentSelection().GetNode(0).SetContentType(4)   # 1 = GlobalIds, 2 = PedigreeIds, 4 = Indices

# Connect the annotation link to the parallel coordinates representation
# PCoords chart only seems to actually highlight with Index content
#   even if the table has Pedigree or Global IDs...
chart.SetAnnotationLink(annotationLink)

# Create another vtkSelection to allow Pedigree IDs selections (conversion to Index later)
pedIdSel = vtk.vtkSelection()
pedIdNode = vtk.vtkSelectionNode()
pedIdNode.SetFieldType(1)
pedIdNode.SetContentType(2)
pedIdSel.AddNode(pedIdNode)

view.GetScene().AddItem(chart)

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

# Create arrays that will end up as table columns
arrP = vtk.vtkIntArray()
arrP.SetName('ID')
arrX = vtk.vtkFloatArray()
arrX.SetName("XAxis")
arrC = vtk.vtkFloatArray()
arrC.SetName("Cosine")
arrS = vtk.vtkFloatArray()
arrS.SetName("Sine")

# 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):
	arrP.InsertNextValue(2*i+4000)
	arrX.InsertNextValue(i * inc)
	arrC.InsertNextValue(math.cos(i * inc) + 0.0)
	arrS.InsertNextValue(math.sin(i * inc) + 0.0)

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

# Set ID as the PedigreeIds so can select by those later
table.GetRowData().SetActivePedigreeIds('ID')

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 do something when selections are changed in parallel coordinates view
annotationLink.AddObserver("AnnotationChangedEvent", selectionCallback)

# Fill selection with pedigree IDs
ped_id_array = vtk.vtkIdTypeArray()
ped_id_array.SetName('ID')
ped_id_array.InsertNextValue(4020)

# Apply the selection to the PedigreeIds selection node
pedIdNode.SetSelectionList(ped_id_array)

# Convert pedigree ids to index selection for PC view highlighting
cs = vtk.vtkConvertSelection()
idxSel = cs.ToIndexSelection(pedIdSel, table)

# Set that index selection to the annotation link for PC chart selection
# Note: This will fire the AnnotationChangedEvent
annotationLink.SetCurrentSelection(idxSel)

view.ResetCamera()
view.Render()

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



On Jul 23, 2012, at 12:22 PM, Weimin Li wrote:

> Hi Dear all,
>  
> I have now a question about how to select a single line in a VtkChartParellelCoordinates view.
>  
> I am using the vtk nightly version, Qt 4.8.2 and VS 2008.
>  
> And the question is:
> My first column of the input VtkTable for VtkChartParallelCoordinates is an ID Column. Now I want to select a single line or multi-lines in the ChartParallelCoordinates view by giving the ID number.
>  
> Is there anybody knows how to solve this? That would be great! Thanks a lot!
>  
>  
> ________________________________________________
> Dipl.-Ing. Weimin Li
> Junior Reseacher / Industrial X-ray Computed Tomography
>  
> FH OÖ Forschungs- & Entwicklungs GmbH
> Stelzhamerstraße 23 
> 4600 Wels / Austria
> Tel: +43 (0)50804-44420
> E-Mail: Li.Weimin at fh-wels.at
> Web: www.fh-ooe.at & www.3dct.at
> 
> <image001.jpg>
> 
> Firmenbuchgericht/Court of registry: Landesgericht Wels
> Firmenbuchnummer/Company registration: FN 236733 m
>  
> _______________________________________________
> 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/20120724/32c04e30/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PedID_PCselection.png
Type: image/png
Size: 82443 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120724/32c04e30/attachment.png>


More information about the vtkusers mailing list