[vtkusers] trilinear interpolation

tony hakki tony2007vtk at yahoo.com
Thu Mar 15 07:03:35 EDT 2007


Hello All;
Supposing that Pi(xi,yi,zi) is a position on the surface of a dataset and Ni(xi,yi,zi) is the normal calculated from the point Pi using the that
dataset; I will take 50 samples though the normal vector; either positive direction or negatine direction; So I need a trilinear interpolation to get the density values(grey scale values). My problem is that how can  I implement trileinear interpolation using VTK. I have found some code through the internet, I haven't understood it if it can able to implement what I would like to do. is there anybody who has done such kind of application?
 this is the code: the link is: http://216.239.59.104/search?q=cache:lH_qNB2Ge1UJ:dit.lbl.gov/VTK/GlCache/vtk.cache/contrib/vtkGridTransform.cxx+vtkTrilinearinterpolation&hl=de&ct=clnk&cd=5&gl=at

static void vtkTrilinearInterpolation(float point[3], 
				      float displacement[3],
				      float derivatives[3][3],
				      void *gridPtr, int gridType, 
				      int gridExt[6], int gridInc[3])
{
  // change point into integer plus fraction
  float f[3];
  int floorX = vtkGridFloor(point[0],f[0]);
  int floorY = vtkGridFloor(point[1],f[1]);
  int floorZ = vtkGridFloor(point[2],f[2]);

  int gridId0[3];
  gridId0[0] = floorX - gridExt[0];
  gridId0[1] = floorY - gridExt[2];
  gridId0[2] = floorZ - gridExt[4];

  int gridId1[3];
  gridId1[0] = gridId0[0] + 1;
  gridId1[1] = gridId0[1] + 1;
  gridId1[2] = gridId0[2] + 1;

  int ext[3];
  ext[0] = gridExt[1] - gridExt[0];
  ext[1] = gridExt[3] - gridExt[2];
  ext[2] = gridExt[5] - gridExt[4];

  // do bounds check, most points will be inside so optimize for that
  if ((gridId0[0] | (ext[0] - gridId1[0]) |
       gridId0[1] | (ext[1] - gridId1[1]) |
       gridId0[2] | (ext[2] - gridId1[2])) < 0)
    {
    for (int i = 0; i < 3; i++)
      {
      if (gridId0[i] < 0)
        {
        gridId0[i] = 0;
        gridId1[i] = 0;
        f[i] = 0;
        }
      else if (gridId1[i] > ext[i])
        {
        gridId0[i] = ext[i];
        gridId1[i] = ext[i];
        f[i] = 0;
        }
      }
    }

  // do trilinear interpolation
  int factX0 = gridId0[0]*gridInc[0];
  int factY0 = gridId0[1]*gridInc[1];
  int factZ0 = gridId0[2]*gridInc[2];

  int factX1 = gridId1[0]*gridInc[0];
  int factY1 = gridId1[1]*gridInc[1];
  int factZ1 = gridId1[2]*gridInc[2];
    
  int i000 = factX0+factY0+factZ0;
  int i001 = factX0+factY0+factZ1;
  int i010 = factX0+factY1+factZ0;
  int i011 = factX0+factY1+factZ1;
  int i100 = factX1+factY0+factZ0;
  int i101 = factX1+factY0+factZ1;
  int i110 = factX1+factY1+factZ0;
  int i111 = factX1+factY1+factZ1;
switch (gridType)
    {
    case VTK_CHAR:
      vtkLinearHelper(displacement, derivatives, f[0], f[1], f[2], 
		      (char *)gridPtr,
		      i000, i001, i010, i011, i100, i101, i110, i111);
      break;
    case VTK_UNSIGNED_CHAR:
      vtkLinearHelper(displacement, derivatives, f[0], f[1], f[2], 
		      (unsigned char *)gridPtr,
		      i000, i001, i010, i011, i100, i101, i110, i111);
      break;
    case VTK_SHORT:
      vtkLinearHelper(displacement, derivatives, f[0], f[1], f[2], 
		      (short *)gridPtr, 
		      i000, i001, i010, i011, i100, i101, i110, i111);
      break;
    case VTK_UNSIGNED_SHORT:
      vtkLinearHelper(displacement, derivatives, f[0], f[1], f[2], 
		      (unsigned short *)gridPtr,
		      i000, i001, i010, i011, i100, i101, i110, i111);
      break;
    case VTK_FLOAT:
      vtkLinearHelper(displacement, derivatives, f[0], f[1], f[2], 
		      (float *)gridPtr,
		      i000, i001, i010, i011, i100, i101, i110, i111);
      break;
    }
}

thank you 
Tony


 
____________________________________________________________________________________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070315/9e652f68/attachment.htm>


More information about the vtkusers mailing list