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. <br>
<br> // Avoid lookup table and use direct color specification<br> vtkUnsignedCharArray *scalars = vtkUnsignedCharArray::New();<br> scalars->SetNumberOfComponents(3);<br> scalars->SetNumberOfTuples( <NUMBER OF CELLS> );<br>
scalars->InsertTuple3(0, 255, 0, 0);<br> scalars->InsertTuple3(1, 0, 255, 0);<br> ...<br><br><br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
------------------------------<br>
<br>
Message: 2<br>
Date: Sun, 11 Oct 2009 11:53:57 +0000 (GMT)<br>
From: Marcus Thamson <<a href="mailto:markie_thomson@yahoo.de">markie_thomson@yahoo.de</a>><br>
Subject: [vtkusers] VTK surface render with RGB colors<br>
To: <a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a><br>
Message-ID: <<a href="mailto:848349.67120.qm@web23103.mail.ird.yahoo.com">848349.67120.qm@web23103.mail.ird.yahoo.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Dear All,<br>
<br>
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.<br>
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.<br>
<br>
Below is a sketch of the code that works with scalar mapping (presumably with the default color-map):<br>
---<br>
<br>
#include <vtkPolyData.h><br>
...<br>
<br>
dcolarr = vtkDoubleArray::New();<br>
dcolarr->SetArray(dcolors,nfaces,1); //<br>
<br>
vtkPoints *sverts = vtkPoints::New();<br>
vtkCellArray *sfaces = vtkCellArray::New();<br>
...<br>
vtkPolyData *surf = vtkPolyData::New();<br>
surf->SetPoints(sverts);<br>
surf->SetPolys(sfaces);<br>
surf->GetCellData()->SetScalars(dcolarr); //<br>
<br>
vtkDataSetMapper::SetResolveCoincidentTopologyToPolygonOffset();<br>
vtkPolyDataMapper *surfMapper = vtkPolyDataMapper::New();<br>
vtkActor *surfActor = vtkActor::New();<br>
vtkRenderer *aRenderer = vtkRenderer::New();<br>
vtkRenderWindow *renWin = vtkRenderWindow::New();<br>
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br>
<br>
surfMapper->SetInput(surf);<br>
surfMapper->ScalarVisibilityOn(); //<br>
surfMapper->SetScalarRange(0,1); //<br>
<br>
surfActor->SetMapper(surfMapper);<br>
aRenderer->AddActor(surfActor);<br>
iren->SetRenderWindow(renWin);<br>
<br>
renWin->AddRenderer(aRenderer);<br>
renWin->SetSize(500,500);<br>
renWin->Render();<br>
<br>
vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();<br>
iren->SetInteractorStyle(style);<br>
<br>
iren->Start();<br>
...<br>
<br>
---<br>
<br>
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?<br>
<br>
With kind regards,<br>
MT<br>
<br>
<br>
<br>
<br>
<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://www.vtk.org/pipermail/vtkusers/attachments/20091011/68a01367/attachment-0001.htm" target="_blank">http://www.vtk.org/pipermail/vtkusers/attachments/20091011/68a01367/attachment-0001.htm</a>><br>
<br>
------------------------------<br></blockquote></div><br>