[vtkusers] vtkLookupTable shows wrong colour
Frese Daniel Dr.
frese at heidenhain.de
Fri Apr 4 08:48:15 EDT 2014
Hi madz,
I remember encountering a similar problem, some time ago. See this archived mailing list thread : http://vtk.1045678.n5.nabble.com/Questions-on-vtkLookupTable-SetIndexedLookup-in-connection-with-graph-display-tt5717456.html#none
I don't remember all the details any more (I somehow managed to work around this issue by changing my app's user interface), but I think the problem was that the input values of your vertices are scaled to the LookUpTable's range. So if the input range of your data is initially different than your LUT range (in fact it's 0 if you have only one color initially), it might do unexpected stuff. At the time I thought that the lookuptable->SetIndexLookup() function is made to resolve this issue (see the vtk documentation and also the above mentioned mail thread). Somehow I did not make it working and saw other strange things as well, and I never really figured if I was doing something stupid or if this was a bug within vtk.
Maybe these pointers can help a bit; if you find a solution for this I would be very interested in that too.
Daniel
-----Ursprüngliche Nachricht-----
Von: vtkusers [mailto:vtkusers-bounces at vtk.org] Im Auftrag von madz
Gesendet: Freitag, 4. April 2014 14:06
An: vtkusers at vtk.org
Betreff: [vtkusers] vtkLookupTable shows wrong colour
I have a lookup table with 3 values in it. When I initially draw the graph I only use one colour, but when I add more edges dynamically I assign different colours to them. The problem is initially, when I only use one colour, that particular colour doesn't show. And when I add them dynamically,the graph doesn't show the correct colour until all colour values are used.
How can I avoid this?
Here is a simplified example.
#include <vtkSmartPointer.h>
#include <vtkDataSetAttributes.h>
#include <vtkGraphLayoutView.h>
#include <vtkIntArray.h>
#include <vtkLookupTable.h>
#include <vtkMutableUndirectedGraph.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkViewTheme.h>
int main(int, char *[])
{
vtkSmartPointer<vtkGraphLayoutView> graphLayoutView = vtkSmartPointer<vtkGraphLayoutView>::New();
// Create a graph
vtkSmartPointer<vtkMutableUndirectedGraph> graph = vtkSmartPointer<vtkMutableUndirectedGraph>::New();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
for(int x=0;x<3;x++){
vtkIdType v1 = graph->AddVertex();
vtkIdType v2 = graph->AddVertex();
graph->AddEdge(v1,v2);
points->InsertNextPoint(x*2,0,0);
points->InsertNextPoint(x*2,4,0);
}
graph->SetPoints(points);
// Visualize
graphLayoutView->AddRepresentationFromInput(graph);
graphLayoutView->SetLayoutStrategyToPassThrough();
//Set colour to edges
vtkSmartPointer<vtkIntArray> edgeColors = vtkSmartPointer<vtkIntArray>::New();
edgeColors->SetNumberOfComponents(3);
edgeColors->SetName("Color");
vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
lookupTable->SetNumberOfTableValues(3);
lookupTable->SetTableValue(0, 1.0, 1.0, 1.0); // white
lookupTable->SetTableValue(1, 0.5, 1.0, 0.5); // light green
lookupTable->SetTableValue(2, 1.0, 0.0, 0.0); // red
lookupTable->Build();
edgeColors->InsertNextValue(2); //------------------------only use red - but white shows
edgeColors->InsertNextValue(2);
edgeColors->InsertNextValue(2);
graph->GetEdgeData()->AddArray(edgeColors);
graphLayoutView->SetEdgeColorArrayName("Color");
graphLayoutView->ColorEdgesOn();
vtkSmartPointer<vtkViewTheme> theme = vtkSmartPointer<vtkViewTheme>::New();
theme->SetCellLookupTable(lookupTable);
graphLayoutView->ApplyViewTheme(theme);
graphLayoutView->ResetCamera();
graphLayoutView->GetRenderWindow()->Render();
graphLayoutView->GetInteractor()->Initialize();
graphLayoutView->GetInteractor()->Start();
}
Thank you.
--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkLookupTable-shows-wrong-colour-tp5726645.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
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
------------------------------------------------------------------------------------------------------
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: http://www.heidenhain.de/disclaimer
More information about the vtkusers
mailing list