[vtkusers] Normal Map

Karthik Krishnan karthik.krishnan at kitware.com
Tue Jul 1 17:41:12 EDT 2008


Tim:

I recently added the class vtkScenePicker which may accomplish what you 
need. It uses vtkVisibleCellSelector under the hood.

The scene picker after a PickRender() call can be queried for the cellId 
at every pixel in your render window. So your code would be something 
like...

renWin->Render();
scenePicker->PickRender();
for_each_display_pixel_in_Your_renderWindow
  scenePicker->GetCellId( displayPosition );
  // Retrieve normal for this cell
end_for

The whole thing is done using 1 pick operation.


For further documentation look at vtkVisibleCellSelector:

"This class operates by putting vtkRenderer into new selection modes and 
telling it to render. When the render happens, each visible cell or data 
set is rendered with the color of each cell chosen to encode a unique 
identifier. After one or more selection render passes, the contents of 
the color buffer are read back, and each pixel is examined to identify 
which cell was frontmost in the scene behind it. Because color buffer 
resolution in VTK is limited to 24 bits, up to five passes may be 
required to obtain a complete result. Up to three passes are used to 
find the visible cells within the rendered datasets. One pass selects 
between actors, and another pass is used in parallel composite rendering 
to determine which processor is responsible for each visible cell."

Hope this helps
--
karthik


Tim Soper wrote:
> I don't appear to find any old posts on how to do this, but is there a way to produce a normal map from the render window.  By this, I mean to say that I want to produce an image where each pixel contains the normal of the polydata point that pixel corresponds to.
>
> I've only managed to do this by iteratively picking each point on the image, but this is taking way too much time. If you could recommend a different approach or point me to a previous post that would be much appreciated. Below is my code:
>
> Thanks,
> -Tim-
>
>     //get the size of the render window
>     int* winsize = renWin->GetSize();
>
>     //create the normal image map to be the same size as the window
>     vtkImageData* normalImage = vtkImageData::New();
>     normalImage->SetDimensions( winsize[0], winsize[1], winsize[2] );
>     normalImage->SetScalarTypeToDouble();
>     normalImage->AllocateScalars();
>
>     //get a pointer to the normal map
>     double* dptr = (double*)normalImage->GetScalarPointer();
>
>     //create a picker to access the normal
>     vtkPointPicker* picker = vtkPointPicker::New();
>     
>     //iterate through image  to create a x-valued normal map to start
>     double normal[3];
>     for( int yidx = 0; yidx < winsize[1]; yidx++)
>     {
>         for( int xidx = 0; xidx < winsize[0]; xidx++)
>         {
>             picker->Pick(xidx,yidx,0.0,ren);
>             int id = picker->GetPointId();
>             polyReader->GetOutput()->GetPointData()->GetNormals()->GetTuple( id, normal );
>             *dptr++ = normal[0]; 
>         }
>     }
>
> //THE ABOVE TAKES A TON OF TIME
>
>
>       
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>   

-- 
--
Karthik Krishnan
R & D Engineer,
Kitware Inc,





More information about the vtkusers mailing list