[vtkusers] VTK surface render with RGB colors

Marcus Thamson markie_thomson at yahoo.de
Sun Oct 11 07:53:57 EDT 2009


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.htm>


More information about the vtkusers mailing list