Home My Page Projects Code Snippets Project Openings diderot

SCM Repository

[diderot] Diff of /trunk/doc/probe/paper.tex
 [diderot] / trunk / doc / probe / paper.tex

Diff of /trunk/doc/probe/paper.tex

revision 278, Wed Aug 11 21:35:05 2010 UTC revision 279, Thu Aug 12 17:02:59 2010 UTC
# Line 113  Line 113
113    \label{fig:1d-probe}    \label{fig:1d-probe}
114  \end{figure}%  \end{figure}%
115
116  \begin{figure}[p]  \begin{figure}[t]
117  \begin{quote}  \begin{quote}
118  \lstset{language=C}  \lstset{language=C}
119  \begin{lstlisting}  \begin{lstlisting}
# Line 152  Line 152
152  \texttt{c}, and \texttt{d}, and put the \texttt{t} values into a vector too.  \texttt{c}, and \texttt{d}, and put the \texttt{t} values into a vector too.
153  We then use a dot product to compute the sum of the products of the  We then use a dot product to compute the sum of the products of the
154  convolution-filter values and the image values.  convolution-filter values and the image values.
155  \begin{figure}[p]  \begin{figure}[t]
156  \begin{quote}  \begin{quote}
157  \lstset{language=OpenCL}  \lstset{language=OpenCL}
158  \begin{lstlisting}  \begin{lstlisting}
# Line 234  Line 234
234      hz[i+s-1] = h[s-i][0] + t*(h[s-i][1] + t*(h[s-i][2] + t*h[s-i][3]));      hz[i+s-1] = h[s-i][0] + t*(h[s-i][1] + t*(h[s-i][2] + t*h[s-i][3]));
235    }    }
236
237    double vx = 0.0    double vx = 0.0;
238    for (int i = 1-s;  i <= s;  i++) {    for (int i = 1-s;  i <= s;  i++) {
239      double vy = 0.0      double vy = 0.0;
240      for (int j = 1-s;  j <= s;  j++) {      for (int j = 1-s;  j <= s;  j++) {
241        double vz = 0.0;        double vz = 0.0;
242        for (int k = 1-s;  k <= s;  k++) {        for (int k = 1-s;  k <= s;  k++) {
# Line 303  Line 303
303  \section{Probing a 3D derivative field}  \section{Probing a 3D derivative field}
304  We next consider the case of probing the derivative of a scalar field $F = V\circledast{}h$, where $s$ is the support  We next consider the case of probing the derivative of a scalar field $F = V\circledast{}h$, where $s$ is the support
305  of $h$.  of $h$.
306  The probe $(\mkw{D}\;F)\mkw{@}\vecp$ produces a vector result as follows:  The probe $(\nabla F)\mkw{@}\vecp$ produces a vector result as follows:
307  \begin{eqnarray*}  \begin{eqnarray*}
308    \vecx & = & \matM^{-1} \vecp \qquad \text{\textit{transform to image space}} \\    \vecx & = & \matM^{-1} \vecp \qquad \text{\textit{transform to image space}} \\
309    \vecn & = & \FLOOR{\vecx} \qquad \text{\textit{integer part of position}} \\    \vecn & = & \FLOOR{\vecx} \qquad \text{\textit{integer part of position}} \\
310    \vecf & = & \vecx - \vecn \qquad \text{\textit{fractional part of position}} \\    \vecf & = & \vecx - \vecn \qquad \text{\textit{fractional part of position}} \\
311    (\mkw{D}\;F)\mkw{@}\vecp & = & \left[\begin{array}{c}    (\nabla F)\mkw{@}\vecp & = & \left[\begin{array}{c}
312      \sum_{i=1-s}^s {\sum_{j=1-s}^s {\sum_{k=1-s}^s {V(\vecn+\VEC{i,j,k}) h'(\vecf_x - i) h(\vecf_y - j) h(\vecf_z - k)}}} \\      \sum_{i=1-s}^s {\sum_{j=1-s}^s {\sum_{k=1-s}^s {V(\vecn+\VEC{i,j,k}) h'(\vecf_x - i) h(\vecf_y - j) h(\vecf_z - k)}}} \\
313      \sum_{i=1-s}^s {\sum_{j=1-s}^s {\sum_{k=1-s}^s {V(\vecn+\VEC{i,j,k}) h(\vecf_x - i) h'(\vecf_y - j) h(\vecf_z - k)}}} \\      \sum_{i=1-s}^s {\sum_{j=1-s}^s {\sum_{k=1-s}^s {V(\vecn+\VEC{i,j,k}) h(\vecf_x - i) h'(\vecf_y - j) h(\vecf_z - k)}}} \\
314      \sum_{i=1-s}^s {\sum_{j=1-s}^s {\sum_{k=1-s}^s {V(\vecn+\VEC{i,j,k}) h(\vecf_x - i) h(\vecf_y - j) h'(\vecf_z - k)}}} \\      \sum_{i=1-s}^s {\sum_{j=1-s}^s {\sum_{k=1-s}^s {V(\vecn+\VEC{i,j,k}) h(\vecf_x - i) h(\vecf_y - j) h'(\vecf_z - k)}}} \\
315    \end{array}\right]    \end{array}\right]
316  \end{eqnarray*}%  \end{eqnarray*}%
317
318    \begin{figure}[p]
319    \begin{quote}
320    \lstset{language=C}
321    \begin{lstlisting}
322    double probe (vec3 p)
323    {
324      double x[3] = transform(p);   // image-space position
325      double nx, ny, nz, fx, fy, fz;
326
327      fx = modf (x[0], &nx);
328      fy = modf (x[1], &ny);
329      fz = modf (x[2], &nz);
330
331      // compute kernel values for each axis
332      double hx[4], dhx[4], hy[4], dhy[4], hz[4], dhz[4];
333      for (int i = 1-s;  i < s;  i++) {
334        double t;
335        t = fx - i;
336        hx[i+s-1] = h[s-i][0] + t*(h[s-i][1] + t*(h[s-i][2] + t*h[s-i][3]));
337        dhx[i+s-1] = h[s-i][1] + t*(2*h[s-i][2] + t*3*h[s-i][3]);
338        t = fy - i;
339        hy[i+s-1] = h[s-i][0] + t*(h[s-i][1] + t*(h[s-i][2] + t*h[s-i][3]));
340        dhy[i+s-1] = h[s-i][1] + t*(2*h[s-i][2] + t*3*h[s-i][3]);
341        t = fz - i;
342        hz[i+s-1] = h[s-i][0] + t*(h[s-i][1] + t*(h[s-i][2] + t*h[s-i][3]));
343        dhz[i+s-1] = h[s-i][1] + t*(2*h[s-i][2] + t*3*h[s-i][3]);
344      }
345
346      vec3 vx = {0, 0, 0};
347      for (int i = 1-s;  i <= s;  i++) {
348        vec3 vy = {0, 0, 0};
349        for (int j = 1-s;  j <= s;  j++) {
350          vec3 vz = {0, 0, 0};
351          for (int k = 1-s;  k <= s;  k++) {
352            double v = V[nx+i][ny+j][nz+k];
353            vz[0] = v * hz[k+s-1];
354            vz[1] = vz[0];
355            vz[2] = v * dhz[k+s-1];
356          }
357          vy[0] += vz[0] * hy[j+s-1];
358          vy[1] += vz[1] * dhy[j+s-1];
359          vy[2] += vz[2] * hy[j+s-1];
360        }
361        vx[0] += vx[0] * dhx[i+s-1];
362        vx[1] += vx[1] * hx[i+s-1];
363        vx[2] += vx[2] * hx[i+s-1];
364      }
365
366      return vx;
367    }
368    \end{lstlisting}%
369    \end{quote}%
370    \caption{Computing $(\nabla F)\mkw{@}\vecx$ for a 3D scalar field in C}
371    \label{fig:3d-deriv-probe-code-c}
372    \end{figure}
373
374  \end{document}  \end{document}

Legend:
 Removed from v.278 changed lines Added in v.279