Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /trunk/doc/probe/code/c3d.c
ViewVC logotype

View of /trunk/doc/probe/code/c3d.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 290 - (download) (as text) (annotate)
Sun Aug 15 16:43:40 2010 UTC (9 years, 5 months ago) by jhr
File size: 1787 byte(s)
  Adding Gordon's test harness.
#include <stdio.h>
#include <math.h>

#define IMG_SZ 11

double V[IMG_SZ][IMG_SZ][IMG_SZ];		// image data
double h[4][4] = {		// bspln3
	{ 1.33333,   2.0,  1.0,  0.166667 },   // -2 .. -1
	{ 0.666667,  0.0, -1.0, -0.5 },        // -1 .. 0
	{ 0.666667,  0.0, -1.0,  0.5 },        //  0 .. 1
	{ 1.33333,  -2.0,  1.0, -0.166667 },   //  1 .. 2
};
const int s = 2;       // kernel support

/* double probe (double p[3]) { */
/*   double x[3] = transform(p);	// image-space position */
double probe (double x[3]) { 
  double nxd, nyd, nzd, fx, fy, fz;
  int nx, ny, nz, i, j, k;

  fx = modf (x[0], &nxd); nx = (int)nxd;
  fy = modf (x[1], &nyd); ny = (int)nyd;
  fz = modf (x[2], &nzd); nz = (int)nzd;

  // compute kernel values for each axis
  double hx[4], hy[4], hz[4];
  for (i = 1-s;  i <= s;  i++) {
    double t;
    t = fx - i;
    hx[i+s-1] = h[s-i][0] + t*(h[s-i][1] + t*(h[s-i][2] + t*h[s-i][3]));
    t = fy - i;
    hy[i+s-1] = h[s-i][0] + t*(h[s-i][1] + t*(h[s-i][2] + t*h[s-i][3]));
    t = fz - i;
    hz[i+s-1] = h[s-i][0] + t*(h[s-i][1] + t*(h[s-i][2] + t*h[s-i][3]));
  }

  double vx = 0.0;
  for (i = 1-s;  i <= s;  i++) {
    for (j = 1-s;  j <= s;  j++) {
      for (k = 1-s;  k <= s;  k++) {
      	vx += V[nx+i][ny+j][nz+k] * hz[k+s-1] * hy[j+s-1] * hx[i+s-1];
      }
    }
  }

  return vx;
}

#define AIR_AFFINE(i,x,I,o,O) ( \
((double)(O)-(o))*((double)(x)-(i)) / ((double)(I)-(i)) + (o))

int
main() {
  int I, J, K, N;
  double P[3];

  V[5][5][5] = 1.0;
  N=60;
  for (I=0; I<N; I++) {
    P[0] = AIR_AFFINE(0, I, N, 2.0001, 7.9999);
    for (J=0; J<N; J++) {
      P[1] = AIR_AFFINE(0, J, N, 2.0001, 7.9999);
      for (K=0; K<N; K++) {
        P[2] = AIR_AFFINE(0, K, N, 2.0001, 7.9999);
        printf("%g\n", probe(P));
      }
    }
  }

  return 0;
}

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0