Hi Wang, <div><br><div>ZBuffer is buffer that contains depth map of currently rendered scene you are searching for (google z-buffer ). </div><div>When you render scene multiple transformations are applied to the objects coordinates including computation of 'z' (depth) value. It is not z coordinate but really depth. I will use z-notation, but i think by this depth.</div>
<div><br></div><div>Single z-value is float from range [0,1], so to get unsigned char you should do ( z*255 ) and convert it to unsigned char.</div><div>By default (at least in Opengl) 1 represent the farest point , 0 the nearest. </div>
<div><br></div><div>From vtk view, you could apply after <span style>vtkWindowToImageFilter the</span> vtkImageShiftScale with 255 proposed by Dorian and than vtkImageCastFilter proposed by David. </div><div><br></div><div>
Warning: Using this approach z-values will not cover full range [0,1] (the nearest point will not be absolutely black and the farest absolutely white ) because default vtk model-view matrices move rendered scene little bit far and whole volume around scene is bigger.So you can see that nearest point is not likely at depth 0. But for 'see' depths the result could be sufficient. If not there are other approaches. Real z-values are not mapped linearly into [0,1] . Read <a href="http://www.opengl.org/archives/resources/faq/technical/depthbuffer.htm">http://www.opengl.org/archives/resources/faq/technical/depthbuffer.htm</a> section <strong style="font-family:Arial,Lucida,sans-serif;background-color:rgb(255,255,255);font-size:medium">12.050 .</strong></div>
<div>If you would need 'nice' linear mapping into range [0,1] I would propose other technique using shaders.</div><div><br></div><div><div>I read your requirements on output again, you would like have the nearest point white and the farest black. Therefore you need one more operation : invert computed value of z. </div>
<div>I will summarise formula : </div><div>z .... output value from z-buffer from range [0,1]</div><div>z_color = ( unsigned char ) 255-(z*255) </div></div><div>I do not know how to realise this 255- something with vtk fitlers.</div>
<div><span class="kw6" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;border-left-width:0px;border-style:initial;border-color:initial;font:inherit;vertical-align:baseline;font-family:Monaco,'Lucida Console',monospace;line-height:18px;text-align:left;white-space:nowrap"><br>
</span></div><div><span class="kw6" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;border-left-width:0px;border-style:initial;border-color:initial;font:inherit;vertical-align:baseline;font-family:Monaco,'Lucida Console',monospace;line-height:18px;text-align:left;white-space:nowrap">Good Luck, Jana</span></div>
<div><br><br><div class="gmail_quote">On 7 May 2012 15:59, Wenlong Wang <span dir="ltr"><<a href="mailto:scc.wwl@gmail.com" target="_blank">scc.wwl@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi, Jana<br><br>Thank you for your suggestion. I tried vtkWindowToImageFilter and SetInputBufferTypeToZBuffer(), but the application returns an error says<br><br>"ERROR: In ..\..\VTK\IO\vtkBMPWriter.cxx, line 109<br>
vtkBMPWriter (00C53A10): BMPWriter only accepts unsigned char scalars!"<br>
<br>I then changed the image writer to vtkJPEGWriter, but it pops similar error says the writer only accepts unsigned char input.<br><br>I have no idea how z buffer works in vtk. Can you help me?<br><br>Thank you very much. I greatly appreciate your help.<br>
<br>Best wishes<span class="HOEnZb"><font color="#888888"><br>Wenlong</font></span><div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">2012/5/7 Jana Sefcikova <span dir="ltr"><<a href="mailto:neollie@gmail.com" target="_blank">neollie@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="text-align:left">Hello, </div><div style="text-align:left">I would try use vtkWindowToImageFilter to make screenshot of depth map. Here is an example <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/Screenshot" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/Screenshot</a> </div>
<div style="text-align:left"><br></div><div style="text-align:left">Instead of </div><div style="text-align:left"># <span style="line-height:1.2em;font-size:11px">windowToImageFilter</span><span style="font-size:11px;line-height:1.2em;color:rgb(0,0,64)">-</span><span style="font-size:11px;line-height:1.2em;color:rgb(0,0,128)">></span><span style="line-height:1.2em;font-size:11px">SetInputBufferTypeToRGBA</span><span style="font-size:11px;line-height:1.2em;color:rgb(0,128,0)">(</span><span style="font-size:11px;line-height:1.2em;color:rgb(0,128,0)">)</span><span style="font-size:11px;line-height:1.2em"><font color="#008080">;</font></span></div>
<div style="text-align:left">try </div><div style="text-align:left"># <span style="line-height:1.2em;font-size:11px">windowToImageFilte<font color="#000040">r->SetInputBufferTypeToZBuffer();</font></span></div>
<div style="text-align:left"><span style="line-height:1.2em;font-size:11px"><font color="#000040"><br></font></span></div><div style="text-align:left">I am new in vtk, this is only idea.</div>
<div style="text-align:left"><br></div><div style="text-align:left">J.</div><div><div><br></div><div><br><div class="gmail_quote"><div>
On 7 May 2012 14:45, Wenlong <span dir="ltr"><<a href="mailto:scc.wwl@gmail.com" target="_blank">scc.wwl@gmail.com</a>></span> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
Hi, Jana,<br>
<br>
Thank you for your reply.<br>
<br>
No, I don't want to color my input model. I only need the depth information<br>
visualized. The intensity of a pixel varies as the depth changes at<br>
corresponding point on my model surface. Thus the pixel will become darker<br>
or brighter.<br>
<br>
To have an idea of how it looks like, you can google it.<br>
<br>
Best wishes<br>
Wenlong<br>
<br></div><span><font color="#888888">
--<br>
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/Build-depth-map-of-a-3D-model-tp5689116p5690963.html" target="_blank">http://vtk.1045678.n5.nabble.com/Build-depth-map-of-a-3D-model-tp5689116p5690963.html</a></font></span><div>
<br>
<div><div>Sent from the VTK - Users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a 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 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 href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</div></div></div></blockquote></div><br></div></div>
</blockquote></div><br>
</div></div></blockquote></div><br></div></div>