[vtkusers] How to color a line
R K Shyam Prakash
ramakrishna.prakash at quest-global.com
Fri Jul 30 00:53:33 EDT 2004
Patrick,
To add scalar values you can use the following code. The
code is in java.
int numCells = polydata.GetNumberOfCells(); //number of cells in
your polydata
vtkIntArray newScalars = new vtkIntArray(); //You can use any
subclass of vtkDataArray here
newScalars.SetNumberOfTuples(numCells); //I am setting cell
scalars here. You can change it to point scalars as well
newScalars.SetNumberOfComponents(1); //# of components can vary
based on your requirements
//iterate over number of cells in the polydata
for (int i = 0; i < numCells; i++) {
//set the scalar value
newScalars.InsertComponent(i, 0, 0);
}
//create a lookup table and set it to the scalars
vtkLookupTable scalarLUT = new vtkLookupTable();
scalarLUT.SetTableValue(255, 1, 0, 0, 1.0); //I am setting red
color for a scalar value 255
scalarLUT.SetTableValue(0, 0, 0, 1.0, 1.0); //I am setting blue
color for a scalar value 0
newScalars.SetLookupTable(scalarLUT);
//set the scalar to the polydata (cell scalars)
data.GetCellData().SetScalars(newScalars);
--Shyam
> -----Original Message-----
> From: vtkusers-bounces at vtk.org
> [mailto:vtkusers-bounces at vtk.org] On Behalf Of Patrick (Peng) Cheng
> Sent: Thursday, July 29, 2004 11:11 PM
> To: R K Shyam Prakash; 'vtkusers'
> Subject: Re: RE: [vtkusers] How to color a line
>
>
> hi,
> Sorry I didn't say it clearly.
> I mean I want to color the line with different colors.
> These colors will be determined by the scalar values at each
> point. I don't know how to add the scalar values into the
> polydata as in my code. I know the polydatamapper have method
> like : ScalarVisibilityOn() and SetLookupTable() once I have
> put the scalar value into the polydata, I think it will work. right?
> ---------------------------
> Patrick (Peng) Cheng
> Biomedical Engineering
> University of Iowa
> Tel:(319) 400-7442
> Email: peng-cheng at uiowa.edu
>
> ===========2004-07-29 11:08:25 You wrote in your letter:==============
>
> >Patrick,
> > Look at the example /Examples/Medical/Cxx/Medical3.cxx.
> >You can use SetTableValue to specify the color.
> >
> >--Shyam
> >
> >> -----Original Message-----
> >> From: vtkusers-bounces at vtk.org
> >> [mailto:vtkusers-bounces at vtk.org] On Behalf Of Patrick (Peng) Cheng
> >> Sent: Thursday, July 29, 2004 10:50 PM
> >> To: vtkusers
> >> Subject: [vtkusers] How to color a line
> >>
> >>
> >> Hi,
> >> I have the following code to draw a tube in the scene.
> >> The tube is of the same color. Now I have some scalar values
> >> at each point How do I use something like lookup table to
> >> color the line according to the scalar values. Thanks a lot
> >>
> >> vtkPolyData *data = vtkPolyData::New();
> >> data->SetPoints(points); // points is vtkPoints
> >> data->SetLines(line); // line is vtkCellArray
> >>
> >> vtkCleanPolyData *clean = vtkCleanPolyData::New();
> >> clean->SetInput(data);
> >>
> >> vtkTubeFilter *tube = vtkTubeFilter::New();
> >> tube->SetInput(clean->GetOutput());
> >> tube->SetRadius(0.6);
> >> tube->SetNumberOfSides(6);
> >> tube->SetVaryRadiusToVaryRadiusOff();
> >>
> >> vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
> >> mapper->SetInput(tube->GetOutput());
> >>
> >> vtkProperty *pro = vtkProperty::New();
> >> pro->SetColor(1,0,0);
> >>
> >> vtkActor *actor = vtkActor::New();
> >> actor->SetMapper(mapper);
> >> actor->SetProperty(pro);
> >> ---------------------------
> >> Patrick (Peng) Cheng
> >> Biomedical Engineering
> >> University of Iowa
> >> Tel:(319) 400-7442
> >> Email: peng-cheng at uiowa.edu
> >>
> >>
> >>
> >>
> >> _______________________________________________
> >> This is the private VTK discussion list.
> >> Please keep messages on-topic. Check the FAQ at:
> >> <http://public.kitware.com/cgi-bin/vtkfaq>
> >> 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://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link
> to subscribe/unsubscribe: http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list