[vtkusers] Questions on vtkLookupTable, SetIndexedLookup in connection with graph display

David Thompson david.thompson at kitware.com
Thu Dec 6 14:39:51 EST 2012


Hi Daniel,

> nobody knows what’s going on ? Or is my question not clear enough ?
> Does anybody have any experience with line lookupTable->SetIndexedLookup() ? For my concrete application, I found work arounds for the most pressing issues, but still I’d really like to understand what’s happening…

Sorry for the slow response. There are 3 changes you must make for the program below to work.

1. You must apply the view theme *after* creating representations. This is because the ApplyViewTheme() immediately visits each representation of the view and sets the lookup table; the representation must already be present for its theme to be changed.

2. You should not call Build() on the lookup table after manually setting table entries. vtkLookupTable::Build() overwrites the table entries with a linear ramp of colors.

3. In IndexedLookup mode, only annotated values are assigned colors from the lookup table; all other values are assigned the NaN color. So, in addition to calling lookupTable->SetTableValue(i, r, g, b), you must also

  for (int i = 0; i < 3; ++i)
    lookupTable->SetAnnotation(vtkVariant(i),"")

Note that the second argument annotation may be any string; if you create a vtkScalarBarActor to draw a legend for vertex colors, these strings will be displayed next to the color swatch in the legend. Attached is a modified version of the code that works for me.

	David

-------------- next part --------------
A non-text attachment was scrubbed...
Name: idxlkup.cxx
Type: application/octet-stream
Size: 3423 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121206/22134af6/attachment.obj>
-------------- next part --------------


>  
> Von: Frese Daniel Dr. 
> Gesendet: Montag, 26. November 2012 14:47
> An: vtkusers at vtk.org
> Betreff: Questions on vtkLookupTable, SetIndexedLookup in connection with graph display
>  
> Hello list,
>  
> I try to display a graph with vertices in three different colors, as defined by a LookupTable. Reading the vtk 6.0 specs I thought that the SetIndexedLookup method would be the right thing to use, but somehow I can’t get it working. Most probably I don’t understand something very fundamental regarding this graph stuff – it would be great if somebody could shine some light on this.
>  
> I put together a small piece of self containing, compilable code, to illustrate my questions. Not, that you might have to replace vtkWin32OpenGLRenderWindow by some class appropriate to your system (I work with Visual Studio 2008 on Windows 7, 64 bit; using a git snapshot a few days old). Here we go with the code :
>  
> #include <iostream>
>  
> #include "vtkWin32OpenGLRenderWindow.h"
> #include "vtkRenderWindow.h"
> #include "vtkWin32RenderWindowInteractor.h"
> #include "vtkGraphLayoutView.h"
> #include "vtkViewTheme.h"
> #include "vtkLookupTable.h"
> #include "vtkMutableDirectedGraph.h"
> #include "vtkTree.h"
> #include "vtkIntArray.h"
> #include "vtkStringArray.h"
> #include "vtkDataRepresentation.h"
> #include "vtkRenderedGraphRepresentation.h"
> #include "vtkDataSetAttributes.h"
>  
> void main() {
>       vtkGraphLayoutView* view = vtkGraphLayoutView::New();
>       vtkWin32OpenGLRenderWindow* RenderWindow = vtkWin32OpenGLRenderWindow::SafeDownCast(view->GetRenderWindow());
>  
>       // Construction of the lookup table, and debug output of GetColor
>       vtkLookupTable* lookupTable = vtkLookupTable::New();
>       lookupTable->SetNumberOfTableValues(3);
>       lookupTable->SetTableValue(0, 1.0, 0.0, 0.0); // red
>       lookupTable->SetTableValue(1, 0.0, 0.0, 1.0); // blue
>       lookupTable->SetTableValue(2, 1.0, 1.0, 1.0); // white
>       lookupTable->SetIndexedLookup(1);
>       lookupTable->SetTableRange(0,2);  // this is ignored, if IndexedLookup = true
>       lookupTable->Build();
>  
>       double rgb[4];
>       for (int i=0; i<3; i++) {
>             lookupTable->GetColor(i,rgb);
>             cout << "Color " << i << " : " << rgb[0] << " " << rgb[1] << " " << rgb[2] << endl;
>       }
>  
>       // construct view, theme and simple graph to display vertex colors
>       vtkViewTheme *theme = vtkViewTheme::New();
>       theme->SetPointLookupTable(lookupTable);
>       view->ApplyViewTheme(theme);
>       vtkMutableDirectedGraph *vtkg = vtkMutableDirectedGraph::New();
>  
>       // array to encode the vertex colors
>       vtkIntArray *vertexColors = vtkIntArray::New();
>       vertexColors->SetNumberOfComponents(1);
>       vertexColors->SetName("Vertex Color");
>       vertexColors->InsertNextValue(0);
>       vertexColors->InsertNextValue(1);
>       vertexColors->InsertNextValue(2);
>  
>       // array to encode vertex names
>       vtkStringArray *names = vtkStringArray::New();
>       names->SetName("Vertex Name");
>       names->InsertNextValue("0");
>       names->InsertNextValue("1");
>       names->InsertNextValue("2");
>  
>       // construct graph and add color/name arrays
>       vtkIdType vtkvertex;
>       cout << "vertex 0 : " << (int) (vtkvertex = vtkg->AddVertex()) << endl;
>       cout << "vertex 1 : " << (int) vtkg->AddChild(vtkvertex) << endl;
>       cout << "vertex 2 : " << (int) vtkg->AddChild(vtkvertex) << endl;
>  
>       vtkg->GetVertexData()->AddArray(vertexColors);
>       view->SetVertexColorArrayName("Vertex Color");
>       vtkg->GetVertexData()->AddArray(names);
>       view->SetVertexLabelArrayName("Vertex Name");
>       view->SetVertexLabelVisibility(true);
>  
>       vtkTree*  vtktree = vtkTree::New();
>       vtktree->CheckedShallowCopy(vtkg);
>       vtkDataRepresentation* rep = view->SetRepresentationFromInput(vtktree);
>       vtkRenderedGraphRepresentation::SafeDownCast(view->GetRepresentation())->ColorVerticesByArrayOn();
>  
>       view->Render();
>       view->ResetCamera();
>       view->GetInteractor()->Initialize();
>       view->GetInteractor()->Start();
> }
>  
> The output in a DOS window is :
> Color 0 : 0.501961 0 0
> Color 1 : 0.501961 0 0
> Color 2 : 0.501961 0 0
> vertex 0 : 0
> vertex 1 : 1
> vertex 2 : 2
>  
> The output in a graphical window shows three connected vertices with the following coloring (see attached png) :
> Vertex 0  (middle vertex) : blue
> Vertex 1 (right vertex) : green
> Vertex 2 (left vertex): red
>  
> This output is different from the one I expect. Here are my questions:
> 1)      Why does the output of lookupTable->GetColor() return these strange values ? I would expect, that it returns e.g. for Color 0 the values 1 0 0 (=red). By the way, it behaves as I expect, when I comment the line lookupTable->SetIndexedLookup(1) …
> 2)      Why does the graphical output shows vertices in the mentioned colors ? I did not define green at all; I would rather expect the following color scheme:
> Vertex 0  (middle vertex) : red
> Vertex 1 (right vertex) : blue
> Vertex 2 (left vertex): white
>                 The “wrong” coloring in the output window occurs regardless whether I call lookupTable->SetIndexedLookup(1) or not.
> It feels somehow, as if the graph wouldn’t care at all about my lookuptable. Am I doing something entirely wrong here ?
> 3)      In the code example above would it have been necessary to call lookupTable->Build() ? It doesn’t seem to make a difference, when I try to omit it.
>  
> I would appreciate any help on this.
> Thanks,
> Daniel
>  
> ------------------------------------------------------------------------------------------------------ 
> Registergericht: Traunstein / Registry Court: HRB 275 - Sitz / Head Office: Traunreut 
> Aufsichtsratsvorsitzender / Chairman of Supervisory Board: Rainer Burkhard 
> Geschäftsführung / Management Board: Thomas Sesselmann (Vorsitzender / Chairman),
> Michael Grimm, Matthias Fauser, Sebastian Tondorf
> 
> E-Mail Haftungsausschluss / E-Mail Disclaimer 
> 
> _______________________________________________
> 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



More information about the vtkusers mailing list