[vtkusers] VTK surface render with RGB colors
Andy Bauer
andy.bauer at kitware.com
Sun Oct 11 12:27:24 EDT 2009
One thing to know is that scalar can be anywhere from 1 to 4 components
(based in image scalar values which are I, IA, RGB, RGBA). A very quick way
to do it is to use a vtkUnsignedCharArray if you want to avoid using a
lookup table. An example is below for setting RGB.
// Avoid lookup table and use direct color specification
vtkUnsignedCharArray *scalars = vtkUnsignedCharArray::New();
scalars->SetNumberOfComponents(3);
scalars->SetNumberOfTuples( <NUMBER OF CELLS> );
scalars->InsertTuple3(0, 255, 0, 0);
scalars->InsertTuple3(1, 0, 255, 0);
...
------------------------------
>
> Message: 2
> Date: Sun, 11 Oct 2009 11:53:57 +0000 (GMT)
> From: Marcus Thamson <markie_thomson at yahoo.de>
> Subject: [vtkusers] VTK surface render with RGB colors
> To: vtkusers at vtk.org
> Message-ID: <848349.67120.qm at web23103.mail.ird.yahoo.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Dear All,
>
> I am writing some C++ DLLs which use VTK to render a surface.? I want to
> set the color of each facet using an array of RGB values passed to the
> function, although I only have code examples using scalar values.
> After some reading, I see that there is huge potential to do this (e.g.
> vtkColorTransferFunction), but I am getting out of my depth (jumping around
> the VTK class tree like a headless chicken!), and hope there is a simple way
> to do this.
>
> Below is a sketch of the code that works with scalar mapping (presumably
> with the default color-map):
> ---
>
> #include <vtkPolyData.h>
> ...
>
> dcolarr = vtkDoubleArray::New();
> dcolarr->SetArray(dcolors,nfaces,1); //
>
> vtkPoints *sverts = vtkPoints::New();
> vtkCellArray *sfaces = vtkCellArray::New();
> ...
> vtkPolyData *surf = vtkPolyData::New();
> surf->SetPoints(sverts);
> surf->SetPolys(sfaces);
> surf->GetCellData()->SetScalars(dcolarr); //
>
> vtkDataSetMapper::SetResolveCoincidentTopologyToPolygonOffset();
> vtkPolyDataMapper *surfMapper = vtkPolyDataMapper::New();
> vtkActor *surfActor = vtkActor::New();
> vtkRenderer *aRenderer = vtkRenderer::New();
> vtkRenderWindow *renWin = vtkRenderWindow::New();
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>
> surfMapper->SetInput(surf);
> surfMapper->ScalarVisibilityOn(); //
> surfMapper->SetScalarRange(0,1); //
>
> surfActor->SetMapper(surfMapper);
> aRenderer->AddActor(surfActor);
> iren->SetRenderWindow(renWin);
>
> renWin->AddRenderer(aRenderer);
> renWin->SetSize(500,500);
> renWin->Render();
>
> vtkInteractorStyleTrackballCamera *style =
> vtkInteractorStyleTrackballCamera::New();
> iren->SetInteractorStyle(style);
>
> iren->Start();
> ...
>
> ---
>
> Could someone please advise how to modify this (I guess, in particular the
> lines ending with '//') to take an array of RGB values (0-1, 0-255,
> whatever...) for the facet colors?
>
> With kind regards,
> MT
>
>
>
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://www.vtk.org/pipermail/vtkusers/attachments/20091011/68a01367/attachment-0001.htm
> >
>
> ------------------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091011/391babbe/attachment.htm>
More information about the vtkusers
mailing list