[vtkusers] Assigning colors to scalars
Lise Angell
lise.angell at gmail.com
Mon Nov 7 05:42:53 EST 2005
Hi Jens,
Thanks for your reply.
I've tried what you suggested, but I still don't get the wanted result...
My unstructuredGrid is made from a vtkPoints and a vtkDoubleArray
object, and the grid (and the scene) is updated as several scalar
fields are read from file.
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
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)
#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()
What is the difference between SetScalars and SetActiveScalars?
Lise
P.S: Concerning your question, I would think it would be enough to
update the pipeline with the grid's Update() function and then
Render(), but if you say it doesn't work I really don't know (it might
turn out I've got the same problem as you)...
On 11/6/05, Jens <jens-devel at gmx.de> wrote:
> Hi Lise
> you need to call
> u_field->GetPointData()->SetActiveScalars("attribute-name");
> mapper->SetScalarRange(u_field->GetScalarRange());
> ,too.
> This works for me as long as I call all functions before Render().
> (and remove SetTableRange(...) )
>
> Greetings
> Jens
> P.S:
> Please read my mail "How to change the active cell attribute after "Render()"
> I wrote just before your mail and give me an answer for that ...
>
> Am Sonntag, 6. November 2005 21:00 schrieb Lise Angell:
> > Dear vtk-users,
> >
> > I'm working with a 3D dataset containing a heart model. This model is
> > read into vtk as an UnstructuredGrid with a scalar value in each
> > point.
> > I would like to color the model according to these scalars. I've tried
> > vtkLookupTable, setting the table range to the min and max value of
> > the scalar values, but the model still turns out all red...
> >
> > This is (parts of) my code, I would be grateful for any advise:
> >
> >
> > # scalar_range contains min and max value in the unstructured grid u_field
> > lut = vtk.vtkLookupTable()
> > lut.SetNumberOfColors(10)
> > lut.SetTableRange(scalar_range[0], scalar_range[1])
> > lut.SetHueRange(0.0, 0.3)
> > lut.Build()
> >
> > mapper = vtk.vtkDataSetMapper()
> > mapper.SetInput(u_field)
> > mapper.SetLookupTable(lut)
> >
> >
> >
> > Best regards,
> > Lise
> >
> > --
> > "Je forme une entreprise qui n'eut jamais d'exemple,
> > et dont l'exécution n'aura point d'imitateur." J-J Rousseau
> > _______________________________________________
> > 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
>
--
"Je forme une entreprise qui n'eut jamais d'exemple,
et dont l'exécution n'aura point d'imitateur." J-J Rousseau
More information about the vtkusers
mailing list