[vtkusers] Assigning colors to scalars

Jens jens-devel at gmx.de
Mon Nov 7 07:50:21 EST 2005


Hi Lise
You seem to have the same problem that I have. 
I can make a cell-attribute visible as long as I call 
SetActiveScalars(attName) before I use Render() the first time.
After I have called Render() once I can change the active scalars but get no 
visible change after a Render()-call.

Try to use pointers for vtk-instance.

Am Montag, 7. November 2005 11:42 schrieb Lise Angell:
> ..........
> With:
> 	# allocate VTK structures
> 	vtk_field = vtk.vtkUnstructuredGrid()
> 	pts = vtk.vtkPoints()					# coordinates
> 	pts.SetNumberOfPoints(nno)
> 	data = vtk.vtkDoubleArray()				# data
> 	data.SetNumberOfValues(nno)
> 	data.SetName('Values')
>
>        [...]  # read node and coordinate info

You add a attribute array using 
	myAttArray->SetArray(...);
	vtk_field->AddArray(myAttArray);

> 	vtk_field.SetPoints(pts)
> 	vtk_field.GetPointData().SetActiveScalars('Values')
>
>        [...]  # mount graphics stuff
>
> 	lut = vtk.vtkLookupTable()
> 	lut.SetNumberOfColors(10)
> 	#lut.SetTableRange(scalar_range[0], scalar_range[1])
> 	lut.SetHueRange(0.0, 0.3)
> 	#lut.SetSaturationRange(0, 0)
> 	#lut.SetValueRange(0.2, 1.0)
> 	lut.Build()
>
> 	mapper = visualize(renderer, vtk_field, nsd)
That should work... perhaps your scalar-field is wrong ?
> 	#mapper.SetScalarRange(vtk_field.GetScalarRange())    # gives [0,1], wrong
> 	mapper.SetScalarRange(scalar_range) # contains min,max of the scalar
> fields mapper.SetLookupTable(lut)
>
>        for each scalar field:
>               [read field from file into vtk_field]
>               vtk_field.Update()
> 		mapper.Update()
> 		renWin.Render()

	Greetings
		Jens



More information about the vtkusers mailing list