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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 156, Mon Jul 12 02:25:43 2010 UTC revision 157, Mon Jul 12 14:54:15 2010 UTC
# Line 19  Line 19 
19  \setlength{\parskip}{5pt}  \setlength{\parskip}{5pt}
20    
21  \newcommand{\matM}{\mathbf{M}}  \newcommand{\matM}{\mathbf{M}}
22  \newcommand{\vecp}{\mathbf{p}}  \newcommand{\vecx}{\mathbf{x}}
23  \newcommand{\vecn}{\mathbf{n}}  \newcommand{\vecn}{\mathbf{n}}
24  \newcommand{\vecf}{\mathbf{f}}  \newcommand{\vecf}{\mathbf{f}}
25  \newcommand{\VEC}[1]{\left\langle{#1}\right\rangle}  \newcommand{\VEC}[1]{\left\langle{#1}\right\rangle}
# Line 46  Line 46 
46  This note describes the code needed to implement a probe of a field operation.  This note describes the code needed to implement a probe of a field operation.
47    
48  In the discussion below, we use $\matM^{-1}$ for the homogeneous matrix that maps from world  In the discussion below, we use $\matM^{-1}$ for the homogeneous matrix that maps from world
49  coordinates to image coordinates and use $\vecp$ for the position vector.  coordinates to image coordinates and use $\vecx$ for the position vector.
50    
51  \section{Probing a 1D scalar field}  \section{Probing a 1D scalar field}
52  The simplest case is probing a 1D scalar field $F = V\circledast{}h$, where $s$ is the support  The simplest case is probing a 1D scalar field $F = V\circledast{}h$, where $s$ is the support
# Line 63  Line 63 
63  \begin{displaymath}  \begin{displaymath}
64    h(x) = \left\{\begin{array}{ll}    h(x) = \left\{\begin{array}{ll}
65      0 & \text{$x < s$} \\      0 & \text{$x < s$} \\
66      h_i(x) & \text{$-s \leq -i \leq x < 1-i \leq 0$} \\      h_i(-x) & \text{$-s \leq -i \leq x < 1-i \leq 0$} \\
67      h_i(x) & \text{$0 < i-1 \leq x < i \leq s$} \\      h_i(x) & \text{$0 < i-1 \leq x < i \leq s$} \\
68      0 & \text{$x > s$} \\      0 & \text{$x > s$} \\
69    \end{array}\right.    \end{array}\right.
70  \end{displaymath}%  \end{displaymath}%
71  Thus, we can rewrite the probe computation as  Thus, we can rewrite the probe computation as
72  \begin{displaymath}  \begin{displaymath}
73    F\mkw{@}x = \sum_{i=1-s}^{0} {V(n+i) h_{1-i}(f - i)} + \sum_{i=1}^s {V(n+i) h_i(f - i)}    F\mkw{@}x = \sum_{i=1-s}^{0} {V(n+i) h_{1-i}(i - f)} + \sum_{i=1}^s {V(n+i) h_i(f - i)}
74  \end{displaymath}%  \end{displaymath}%
75  \figref{fig:1d-probe} illustrates the situation for a kernel $h$ with support $s = 2$,  \figref{fig:1d-probe} illustrates the situation for a kernel $h$ with support $s = 2$,
76  and \figref{fig:1d-probe-code} gives the C code for the probe operation, assuming that  and \figref{fig:1d-probe-code} gives the C code for the probe operation, assuming that
# Line 98  Line 98 
98    
99    double value = 0.0, x;    double value = 0.0, x;
100    
101    w = f + 1.0;    w = -1.0 - f;
102    value += img[n-1] * (h2[0] + w*(h2[1] + w*(h2[2] + w*h2[3])));    value += img[n-1] * (h2[0] + w*(h2[1] + w*(h2[2] + w*h2[3])));
103    w = f;    w = -f;
104    value += img[n] * (h1[0] + w*(h1[1] + w*(h1[2] + w*h1[3])));    value += img[n] * (h1[0] + w*(h1[1] + w*(h1[2] + w*h1[3])));
105    w = f - 1.0;    w = f - 1.0;
106    value += img[n+1] * (h1[0] + w*(h1[1] + w*(h1[2] + w*h1[3])));    value += img[n+1] * (h1[0] + w*(h1[1] + w*(h1[2] + w*h1[3])));
# Line 111  Line 111 
111  }  }
112  \end{lstlisting}%  \end{lstlisting}%
113  \end{quote}%  \end{quote}%
114  \caption{Computing $F\mkw{@}x$ for 1D scalar field in C}  \caption{Computing $F\mkw{@}x$ for a 1D scalar field in C}
115  \label{fig:1d-probe-code}  \label{fig:1d-probe-code}
116  \end{figure}  \end{figure}
117    
# Line 122  Line 122 
122  double4 c = (double4)(h2[1], h1[1], h1[1], h2[1]); // x^1 coeffs  double4 c = (double4)(h2[1], h1[1], h1[1], h2[1]); // x^1 coeffs
123  double4 b = (double4)(h2[2], h1[2], h1[2], h2[2]); // x^2 coeffs  double4 b = (double4)(h2[2], h1[2], h1[2], h2[2]); // x^2 coeffs
124  double4 a = (double4)(h2[3], h1[3], h1[3], h2[3]); // x^3 coeffs  double4 a = (double4)(h2[3], h1[3], h1[3], h2[3]); // x^3 coeffs
 double4 offsets = (double4)(1.0, 0.0, -1.0, -2.0);  
125    
126  double probe (double x)  double probe (double x)
127  {  {
# Line 132  Line 131 
131    f = modf (imgPos, &n);    f = modf (imgPos, &n);
132    
133    double4 v = (double4)(img[n-1], img[n], img[n+1], img[n+2]);    double4 v = (double4)(img[n-1], img[n], img[n+1], img[n+2]);
134    double4 w = (double4)(f) + offsets;    double4 w = (double4)(-1.0 - f, -f, f - 1.0, f - 2.0);
135    return dot(v, d + w*(c + w*(b + w*a)));    return dot(v, d + w*(c + w*(b + w*a)));
136  }  }
137  \end{lstlisting}%  \end{lstlisting}%
138  \end{quote}%  \end{quote}%
139  \caption{Computing $F\mkw{@}x$ for 1D scalar field in OpenCL}  \caption{Computing $F\mkw{@}x$ for a 1D scalar field in OpenCL}
140  \label{fig:1d-probe-code-opencl}  \label{fig:1d-probe-code-opencl}
141  \end{figure}  \end{figure}
142    
# Line 146  Line 145 
145  The more common case is when the field is a convolution of a scalar 3-dimensional  The more common case is when the field is a convolution of a scalar 3-dimensional
146  field ($F = V\circledast{}h$).  field ($F = V\circledast{}h$).
147  Let  $s$ be the support of $h$.  Let  $s$ be the support of $h$.
148  Then the probe $F\mkw{@}\vecp$ is computed as follows:  Then the probe $F\mkw{@}\vecx$ is computed as follows:
149  \begin{eqnarray*}  \begin{eqnarray*}
150    \vecp' & = & \matM^{-1} \vecp \qquad \text{\textit{transform to image space}} \\    \vecx' & = & \matM^{-1} \vecx \qquad \text{\textit{transform to image space}} \\
151    \vecn  & = & \FLOOR{\vecp'} \qquad \text{\textit{integer part of position}} \\    \vecn  & = & \FLOOR{\vecx'} \qquad \text{\textit{integer part of position}} \\
152    \vecf  & = & \vecp' - \vecn \qquad \text{\textit{fractional part of position}} \\    \vecf  & = & \vecx' - \vecn \qquad \text{\textit{fractional part of position}} \\
153    F\mkw{@}\vecp & = & \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)}}}    F\mkw{@}\vecx & = & \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)}}}
154  \end{eqnarray*}%  \end{eqnarray*}%
155    
156  \begin{figure}[t]  \begin{figure}[t]
# Line 171  Line 170 
170    
171  double probe (vec3 ***img, kernel *h, vec3 pos)  double probe (vec3 ***img, kernel *h, vec3 pos)
172  {  {
     vec3        imgPos, u, v;  
   
     MultMv4 (Minv, pos, imgPos);  
   
     for (int i = 0;  i < 3;  i++) v[i] = modf(imgPos[i], &(u[i]));  
   
     double value = 0.0;  
     int lo = 1 - h->support;  
     int hi = h->support;  
     for (int i = lo;  i < hi;  i++) {  
         for (int j = lo;  j < hi;  j++) {  
             for (int k = lo;  k < hi;  k++) {  
                 value += img[(int)u[0]+i][(int)u[1]+j][(int)u[2]+k]  
                         * eval(h->segments[abs(i)], v[0]-i)  
                         * eval(h->segments[abs(j)], v[1]-j)  
                         * eval(h->segments[abs(k)], v[2]-k);  
             }  
         }  
     }  
   
173  }  }
174  \end{lstlisting}%  \end{lstlisting}%
175  \end{quote}%  \end{quote}%
176    \caption{Computing $F\mkw{@}\vecx$ for a 3D scalar field in C}
177  \end{figure}  \end{figure}
178    
179  \end{document}  \end{document}

Legend:
Removed from v.156  
changed lines
  Added in v.157

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