<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hi Andrew, <br>
<br>
Good. It is helpful for the people who has the same question as
me. <br>
Thank you very much!!<br>
<br>
best,<br>
Jian Cheng<br>
<br>
On 06/25/2014 07:06 PM, Andrew Maclean wrote:<br>
</div>
<blockquote
cite="mid:CAHDsG9MPiHidx55gwevsdczvmw8Enh3UyT1e=2iE6A-mr3Qv2g@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>Hi Jian,</div>
<div>Glad to be of help.</div>
I have also done a more comprehensive example that also uses
color transfer functions in addition to a lookup table of
predefined colors, it also writes and reads vtp files, see: <span
style="font-family:arial,sans-serif;font-size:13px"> </span><a
moz-do-not-send="true"
href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/AssignColorsFromLUT"
target="_blank"
style="font-family:arial,sans-serif;font-size:13px">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/AssignColorsFromLUT</a>
<div>
<br>
</div>
<div>Regards</div>
<div> Andrew<br>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Thu, Jun 26, 2014 at 2:31 AM,
Jian Cheng <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:jian.cheng.1983@gmail.com"
target="_blank">jian.cheng.1983@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div>Hi Andrew,<br>
<br>
Thank you very much for your help!<br>
That is what I am looking for. <br>
I will use this way for my codes. <br>
Thank you!<br>
<br>
best,<br>
Jian Cheng
<div>
<div><br>
<br>
On 06/23/2014 02:02 AM, Andrew Maclean wrote:<br>
</div>
</div>
</div>
<div>
<div>
<blockquote type="cite">
<div dir="ltr">
<div>Hi Jan,</div>
I may not be reading the question correctly
but you can map the colours from the
vtkLookupTable as follows in the attached
code.
<div>Essentially you use an unsigned char
array and calculate the colour for each cell
by interpolating using the vtkLookupTable,
then you set the array as a scalar in your
polydata. VTK will then treat it as the cell
colour.</div>
<div>This will allow you to save the colours
of your cells.</div>
<div><br>
</div>
<div>Attached is a zip file with the code
based on your code and a CMakeLists.txt
file.</div>
<div><br>
</div>
<div>Regards</div>
<div> Andrew<br>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">
<blockquote class="gmail_quote"
style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
---------- Forwarded message
----------<br>
From: Bill Lorensen <<a
moz-do-not-send="true"
href="mailto:bill.lorensen@gmail.com"
target="_blank">bill.lorensen@gmail.com</a>><br>
To: Jian Cheng <<a
moz-do-not-send="true"
href="mailto:jian.cheng.1983@gmail.com"
target="_blank">jian.cheng.1983@gmail.com</a>><br>
Cc: VTK Users <<a
moz-do-not-send="true"
href="mailto:vtkusers@vtk.org"
target="_blank">vtkusers@vtk.org</a>><br>
Date: Fri, 20 Jun 2014 14:45:29 -0400<br>
Subject: Re: [vtkusers] write
vtkPolyData with colors from
vtkPolyDataMapper<br>
The lut is only used for rendering.
The cell data contains scalar<br>
values that are mapped through the lut
to provide r,g,b for display.<br>
If youo want to save r,g,b colors in
the file, you must create r,g,b<br>
cell data.<br>
<br>
See for example:<br>
<a moz-do-not-send="true"
href="http://vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ColorCellsWithRGB"
target="_blank">http://vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ColorCellsWithRGB</a><br>
<br>
<br>
On Tue, Jun 17, 2014 at 6:28 PM, Jian
Cheng <<a moz-do-not-send="true"
href="mailto:jian.cheng.1983@gmail.com"
target="_blank">jian.cheng.1983@gmail.com</a>>
wrote:<br>
> Hi,<br>
><br>
> I would like to write a
vtkPolydata into .vtk file with the
colors from<br>
> vtkPolyDataMapper.<br>
> However the written .vtk file has
incorrect color which is different<br>
> from the rendered color.<br>
> Please see the following small
code.<br>
> Your help will be appreciated.<br>
><br>
> best,<br>
> Jian Cheng<br>
><br>
> #include
<vtkSmartPointer.h><br>
> #include
<vtkPolyDataMapper.h><br>
> #include <vtkActor.h><br>
> #include
<vtkRenderWindow.h><br>
> #include <vtkRenderer.h><br>
> #include
<vtkRenderWindowInteractor.h><br>
><br>
> #include <vtkLookupTable.h><br>
> #include <vtkFloatArray.h><br>
> #include <vtkCellData.h><br>
> #include <vtkPolyData.h><br>
> #include <vtkPlaneSource.h><br>
><br>
> #include
<vtkPolyDataWriter.h><br>
> #include
<vtkSmartPointer.h><br>
><br>
> int main(int , char *[])<br>
> {<br>
> // Provide some geometry<br>
> int resolution = 3;<br>
>
vtkSmartPointer<vtkPlaneSource>
aPlane =<br>
>
vtkSmartPointer<vtkPlaneSource>::New();<br>
>
aPlane->SetXResolution(resolution);<br>
>
aPlane->SetYResolution(resolution);<br>
><br>
> // Create cell data<br>
>
vtkSmartPointer<vtkFloatArray>
cellData =<br>
>
vtkSmartPointer<vtkFloatArray>::New();<br>
> for (int i = 0; i <
resolution * resolution; i++)<br>
> {<br>
>
cellData->InsertNextValue(i + 1);<br>
> }<br>
><br>
> // Create a lookup table to map
cell data to colors<br>
>
vtkSmartPointer<vtkLookupTable>
lut =<br>
>
vtkSmartPointer<vtkLookupTable>::New();<br>
> int tableSize =
std::max(resolution*resolution + 1,
10);<br>
>
lut->SetNumberOfTableValues(tableSize);<br>
> lut->Build();<br>
><br>
> // Fill in a few known colors,
the rest will be generated if needed<br>
> lut->SetTableValue(0 , 0
, 0 , 0, 1); //Black<br>
> lut->SetTableValue(1,
0.8900, 0.8100, 0.3400, 1); // Banana<br>
> lut->SetTableValue(2,
1.0000, 0.3882, 0.2784, 1); // Tomato<br>
> lut->SetTableValue(3,
0.9608, 0.8706, 0.7020, 1); // Wheat<br>
> lut->SetTableValue(4,
0.9020, 0.9020, 0.9804, 1); //
Lavender<br>
> lut->SetTableValue(5,
1.0000, 0.4900, 0.2500, 1); // Flesh<br>
> lut->SetTableValue(6,
0.5300, 0.1500, 0.3400, 1); //
Raspberry<br>
> lut->SetTableValue(7,
0.9804, 0.5020, 0.4471, 1); // Salmon<br>
> lut->SetTableValue(8,
0.7400, 0.9900, 0.7900, 1); // Mint<br>
> lut->SetTableValue(9,
0.2000, 0.6300, 0.7900, 1); // Peacock<br>
><br>
> aPlane->Update(); // Force
an update so we can set cell data<br>
>
aPlane->GetOutput()->GetCellData()->SetScalars(cellData);<br>
><br>
> // Setup actor and mapper<br>
>
vtkSmartPointer<vtkPolyDataMapper>
mapper =<br>
>
vtkSmartPointer<vtkPolyDataMapper>::New();<br>
>
mapper->SetInputConnection(aPlane->GetOutputPort());<br>
> mapper->SetScalarRange(0,
tableSize - 1);<br>
> mapper->SetLookupTable(lut);<br>
><br>
> mapper->Update();<br>
><br>
>
vtkSmartPointer<vtkPolyDataWriter>
writer =<br>
>
vtkSmartPointer<vtkPolyDataWriter>::New();<br>
> writer->SetFileName(
"aa.vtk" );<br>
> writer->SetInputData(
mapper->GetInput() );<br>
> writer->Write();<br>
><br>
><br>
> vtkSmartPointer<vtkActor>
actor =<br>
>
vtkSmartPointer<vtkActor>::New();<br>
> actor->SetMapper(mapper);<br>
><br>
> // Setup render window,
renderer, and interactor<br>
>
vtkSmartPointer<vtkRenderer>
renderer =<br>
>
vtkSmartPointer<vtkRenderer>::New();<br>
>
vtkSmartPointer<vtkRenderWindow>
renderWindow =<br>
>
vtkSmartPointer<vtkRenderWindow>::New();<br>
>
renderWindow->AddRenderer(renderer);<br>
>
vtkSmartPointer<vtkRenderWindowInteractor>
renderWindowInteractor =<br>
>
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
>
renderWindowInteractor->SetRenderWindow(renderWindow);<br>
> renderer->AddActor(actor);<br>
>
renderer->SetBackground(.1,.2,.3);<br>
> renderWindow->Render();<br>
>
renderWindowInteractor->Start();<br>
><br>
> return EXIT_SUCCESS;<br>
> }<br>
><br>
>
_______________________________________________<br>
> Powered by <a
moz-do-not-send="true"
href="http://www.kitware.com"
target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source
projects at <a moz-do-not-send="true"
href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and
check the VTK FAQ at: <a
moz-do-not-send="true"
href="http://www.vtk.org/Wiki/VTK_FAQ"
target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to
subscribe/unsubscribe:<br>
> <a moz-do-not-send="true"
href="http://public.kitware.com/mailman/listinfo/vtkusers"
target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br>
<br>
<br>
--<br>
Unpaid intern in BillsBasement at
noware dot com<br>
<br>
<br>
_______________________________________________<br>
vtkusers mailing list<br>
<a moz-do-not-send="true"
href="mailto:vtkusers@vtk.org"
target="_blank">vtkusers@vtk.org</a><br>
<a moz-do-not-send="true"
href="http://public.kitware.com/mailman/listinfo/vtkusers"
target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
___________________________________________<br>
Andrew J. P. Maclean<br>
<br>
___________________________________________
</div>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
Powered by <a moz-do-not-send="true" href="http://www.kitware.com" target="_blank">www.kitware.com</a>
Visit other Kitware open-source projects at <a moz-do-not-send="true" href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the VTK FAQ at: <a moz-do-not-send="true" href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a>
Follow this link to subscribe/unsubscribe:
<a moz-do-not-send="true" href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a>
</pre>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
___________________________________________<br>
Andrew J. P. Maclean<br>
<br>
___________________________________________
</div>
</div>
</div>
</blockquote>
<br>
</body>
</html>