[vtkusers] vtkLookupTable shows wrong colour

madz madaramh at gmail.com
Fri Apr 4 08:06:24 EDT 2014


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.


More information about the vtkusers mailing list