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

Frese Daniel Dr. frese at heidenhain.de
Thu Dec 6 05:49:43 EST 2012


Hi,

thanks you for your answer.
I guess you talk about the line "lookupTable->SetIndexedLookup(1);".

The general point is, that in my main application (the provided code being a strongly shortened version) I have vertices that I want to display in different colors within a graph, depending on the user interaction. Now initially I just use two colors out of e.g. three colors defined in the lookupTable - let's say I want to display initially colors 0 and 1, whereas the lookupTable contains colors 0, 1, 2. Now unfortunately the colors get scaled to the actually used range and I end up with color 0 displayed as color 0, but color 1 displayed as color 2. From the docs, I got the impression that this scaling is avoided when I use SetIndexedLookup(1). Maybe I am wrong with this ?

So I started playing with it, but that led to even more questions. As I tried to explain below the code, turning IndexedLookup = true gave indefinite colors (I assume, for reasons I don't understand vtk uses NaNcolor ?), while turning it off, it shows altogether different colors than I want it to. Note, that in the output it colors a vertex green, whereas the only colors I define are red, blue and white.


Daniel

-----Ursprüngliche Nachricht-----
Von: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] Im Auftrag von Alessandro
Gesendet: Donnerstag, 6. Dezember 2012 11:32
An: VTK Users
Betreff: Re: [vtkusers] Questions on vtkLookupTable, SetIndexedLookup in connection with graph display

Hi...

looking at you code I really don't see the point... have you tried without that line...?

Il giorno 06/dic/2012, alle ore 10.36, Frese Daniel Dr. ha scritto:

> Hi,
>  
> 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.
>  
> Daniel
>  
> 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

_______________________________________________
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