[vtkusers] Polydata to Image

Bernhard Mayrhofer berninho1 at hotmail.com
Wed Sep 22 14:19:06 EDT 2004


Hi!

I wrote some Code to get an image of a surface where i stored the color in scalars. I search for the closest point from the centre of the image (i use ann because it´s faster than vtkpointfinder). i transform the coordinates to  x y which i store in an 2dim array. This code works but i ´m not satisfied. The output of the renderer on the screen is much better than the image i created. So, maybe you have some ideas to optimize following code.

Thanks a lot
Bernhard


void Image(vtkPolyDataNormals *Data,ANNkd_tree *Tree,int **Image,int ID,int N,int W,double bin)
{
 int i;
 float *initialPoint,*point,*normal,*color;
 double x,y,norm;
 double n[3],xv[3],yv[3];
 ANNidxArray AnnIDs= new ANNidx[N]; 
 ANNdistArray AnnDist= new ANNdist[N];
 
 initialPoint=Data->GetOutput()->GetPoint(ID);
 normal=Data->GetOutput()->GetPointData()->GetNormals()->GetTuple(ID);
 norm=vtkMath::Norm (normal);
 
 n[0]=normal[0]/norm;
 n[1]=normal[1]/norm;
 n[2]=normal[2]/norm;  
 
 kdLocator(N,initialPoint,Tree,AnnIDs,AnnDist);
 delete[] AnnDist;

 for(i=0;i<N;i++)
 { 
  point=Data->GetOutput()->GetPoint(AnnIDs[i]); 

  vtkMath::Perpendiculars  (n,xv,yv,0);
  x=(point[0]-initialPoint[0])*xv[0]+
     (point[1]-initialPoint[1])*xv[1]+
     (point[2]-initialPoint[2])*xv[2];
  y=(point[0]-initialPoint[0])*yv[0]+
     (point[1]-initialPoint[1])*yv[1]+
     (point[2]-initialPoint[2])*yv[2];
  x=x/bin+W/2;
  y=y/bin+W/2;

  color=Data->GetOutput()->GetPointData()->GetScalars()->GetTuple(AnnIDs[i]); 
  if(x>=0 && y>=0 &&x<W && y<W)
       Image[int(x)][int(y)]=int(0.3*color[0] + 0.59*color[1] + 0.11*color[2]); 

 } 
 delete[] AnnIDs;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040922/ccc5d988/attachment.htm>


More information about the vtkusers mailing list