[vtkusers] Assigning colors to scalars

John Platt jcplatt at lineone.net
Mon Nov 7 19:11:32 EST 2005


Hi Jens,

	reader->GetOutput()->GetCellData()->SetActiveScalars("Velocity
X");

will only work when the output from the reader is up to date at the
point this line is executed, for example, following a call to
reader->Update(). If the reader executes again, it resets the output and
removes all traces of any previous cell data. 

As Bruno has suggested, you can use vtkAssignAttribute to change the
scalars in the reader output or SetScalarModeToUseCellFieldData() &
SelectColorArray("Velocity X") in your mapper.

HTH
John.

-----Original Message-----
From: vtkusers-bounces+jcplatt=lineone.net at vtk.org
[mailto:vtkusers-bounces+jcplatt=lineone.net at vtk.org] On Behalf Of Jens
Sent: 07 November 2005 17:47
To: Bruno da Silva de Oliveira; vtkusers at vtk.org
Subject: Re: [vtkusers] Assigning colors to scalars

Hi Bruno
Thanks for your help.
I have written a reader-class inherited from
vtkUnstructuredGridAlgorithmn 
where I add all cell-attributes to the unstructured grid. The reader
returnes 
that ugrid including all cell-attributes through "GetOutputPort()".
I add velocity for x,y,z in the reader class like this:
	vtkDoubleArray* velocityX = vtkDoubleArray::New();
	velocityX->SetName("Velocity X");
	velocityX->SetNumberOfComponents(1);
	velocityX->SetArray(ptrToAnDoubleArray, numOfCells, 0);
	ugrid->GetCellData()->AddArray(velocityX);
If I use that reader class I already have all cell-attributes assigned
to my 
ugrid and I only want to change the activation status.

	Shouldn´t that be possible using 
reader->GetOutput()->GetCellData()->SetActiveScalars("Velocity X");

(It works as long as I call SetActiveScalars() before the first
"Render()")

Do you know an example, where the user can switch between different
attributes 
which are loaded before?

	Greetings 
		Jens

Am Montag, 7. November 2005 15:36 schrieben Sie:
> You can't assign the scalars by hand; in the next update of the
> pipeline, you will lose this modification. Try to use a
> vtkAssignAttribute filter.
>
> HTH,
>
> Jens wrote:
> >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
> >_______________________________________________
> >This is the private VTK discussion list.
> >Please keep messages on-topic. Check the FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ Follow this link to
> > subscribe/unsubscribe:
> >http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the 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