[vtkusers] Build depth map of a 3D model

Jana Sefcikova neollie at gmail.com
Mon May 7 12:01:10 EDT 2012


Hi Wang,

ZBuffer is buffer that contains depth map of currently rendered scene you
are searching for (google z-buffer ).
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.

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.
By default (at least in Opengl) 1 represent the farest point , 0 the
nearest.

>From vtk view, you could apply after vtkWindowToImageFilter the
vtkImageShiftScale
with 255 proposed by Dorian and than vtkImageCastFilter proposed by David.

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
http://www.opengl.org/archives/resources/faq/technical/depthbuffer.htmsection
*12.050 .*
If you would need 'nice' linear mapping into range [0,1] I would propose
other technique using shaders.

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.
I will summarise formula :
z  .... output value from z-buffer from range [0,1]
z_color = ( unsigned char ) 255-(z*255)
I do not know how to realise this 255- something with vtk fitlers.

Good Luck, Jana


On 7 May 2012 15:59, Wenlong Wang <scc.wwl at gmail.com> wrote:

> Hi, Jana
>
> Thank you for your suggestion. I tried vtkWindowToImageFilter and
> SetInputBufferTypeToZBuffer(), but the application returns an error says
>
> "ERROR: In ..\..\VTK\IO\vtkBMPWriter.cxx, line 109
> vtkBMPWriter (00C53A10): BMPWriter only accepts unsigned char scalars!"
>
> I then changed the image writer to vtkJPEGWriter, but it pops similar
> error says the writer only accepts unsigned char input.
>
> I have no idea how z buffer works in vtk. Can you help me?
>
> Thank you very much. I greatly appreciate your help.
>
> Best wishes
> Wenlong
>
>
> 2012/5/7 Jana Sefcikova <neollie at gmail.com>
>
>> Hello,
>> I would try use vtkWindowToImageFilter to make screenshot of depth map.
>> Here is an example
>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/Screenshot
>>
>> Instead of
>> # windowToImageFilter->SetInputBufferTypeToRGBA();
>> try
>> # windowToImageFilter->SetInputBufferTypeToZBuffer();
>>
>> I am new in vtk, this is only idea.
>>
>> J.
>>
>>
>> On 7 May 2012 14:45, Wenlong <scc.wwl at gmail.com> wrote:
>>
>>>  Hi, Jana,
>>>
>>> Thank you for your reply.
>>>
>>> No, I don't want to color my input model. I only need the depth
>>> information
>>> visualized. The intensity of a pixel varies as the depth changes at
>>> corresponding point on my model surface. Thus the pixel will become
>>> darker
>>> or brighter.
>>>
>>> To have an idea of how it looks like, you can google it.
>>>
>>> Best wishes
>>> Wenlong
>>>
>>> --
>>> View this message in context:
>>> http://vtk.1045678.n5.nabble.com/Build-depth-map-of-a-3D-model-tp5689116p5690963.html
>>>
>>> Sent from the VTK - Users mailing list archive at Nabble.com.
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK FAQ at:
>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120507/25bbdfe0/attachment.htm>


More information about the vtkusers mailing list