[vtkusers] Normal Map
Tim Soper
tim_d_soper at yahoo.com
Thu Jun 26 17:02:44 EDT 2008
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
More information about the vtkusers
mailing list