[vtkusers] Normal Map

Karthik Krishnan karthik.krishnan at kitware.com
Wed Jul 9 12:42:09 EDT 2008


Sorry for the late response. Please see the test TestScenePicker.

The test let's you move your mouse around on the scene and assuming 
camera parameters are stagnant, prints the actor you are mousing over....

Tim Soper wrote:
> Karthik,
>
> Thanks so much for your reply, the method you proposed works great. I wanted to clarify how I might use this in a more general sense, say by subclassing vtkWindowToImageFilter which outputs a normal map rather than an image. I have 2 questions:
>
> 1. What is the easiest way to find the polyData that the cellID corresponds to? So if I have a render window with multiple actors and polydata, I need to know which polydata owns the cell Id that was found by the vtkVisisbleCellSelector (the guts of that class are a bit hard to understand ).
>   
Basically, the method

vtkScenePicker::GetViewProp( in displayPos[2] ) should give you the prop 
at the given position. Now if *one* actor contains multiple polydata's 
distinguishing that isn't possible.

> 2. Am I limited to the cell id, (as opposed to the point id). I'm assuming that for polydata that has ComputePointNormals on, I need to recompute with the ComputeCellNormals on using the vtkPolyDataNormals class.
>   
vtkScenePicker::GetVertexId(..) is the method you want isn't it. The 
class supports both cell and pt ids via

vtkScenePicker::GetCellId( displayPos )

> Thanks so much
>
>
>  Tim Soper
>
>
> Research Assistant
> University of Washington
> Department of Bioengineering 
> Box 352142
>
>
>
> ----- Original Message ----
> From: Karthik Krishnan <karthik.krishnan at kitware.com>
> To: Tim Soper <tsoper at u.washington.edu>
> Cc: vtkusers at vtk.org
> Sent: Tuesday, July 1, 2008 2:41:12 PM
> Subject: Re: [vtkusers] Normal Map
>
> 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,
Ph: +1 518 3713971 x119
Fax: +1 518 3714573




More information about the vtkusers mailing list