Drafted into submission
[ipdf/sam.git] / chapters / Results.tex
1 \chapter{Results and Discussion}\label{Results and Discussion}
2
3 \section{Qualitative Rendering Accuracy}
4         
5 Our ultimate goal is to be able to insert detail at an arbitrary point in the document. Therefore, we are interested in how the same test SVG would appear when scaled to the view coordinates, as the view coordinates are varied. 
6
7
8 \subsection{Applying the view transformation directly}\label{direct_transform}
9
10 Figure \ref{qualitative-rendering-fox} shows the rendering of a vector image\footnote{Unfortunately, since a rendered vector image is a raster image and this figure must be scaled to fit the PDF, the figure as seen here is not a pixel perfect representation of the actual rendering. Most notably, antialiasing effects will be apparent}. Transformation \eqref{view-transformation} is applied to object coordinates with default IEEE-754 rounding behaviour (to nearest). The loss of precision in the second figure is obvious. This is because division by $10^{-6}$ increases the rounding error in $x - v_x$, by $10^{6}$, so the total error is of the order $10^6$ ulp which is of the order $0.25$
11
12
13 \begin{figure}[H]
14         \centering
15         \includegraphics[width=800px]{figures/fox-vector_screenshot2.png}
16         \includegraphics[width=800px]{figures/fox-vector_highzoom1.png}
17         \caption{The vector image from Figure \ref{vector-vs-raster} under two different scales}\label{qualitative-rendering-fox}
18 \end{figure}
19
20 \subsection{Applying cumulative transformations to all B\'{e}ziers}\label{cumulative_transform}
21
22 Rather than applying \eqref{view-transformation} to object coordinates specified relative to the document, we can store the bounds of objects relative to the view and modify these bounds according to transformations \eqref{} and \eqref{} as the view is changed. This is convenient for an interactive document, as detail is typically added by inserting objects into the document within the view rectangle. As a result this approach makes the rendering of detail added to the document independent of the view coordinates --- until the view is moved.
23
24 Repeated transformations on the view will cause an accumulated error on the coordinates of object bounds. This is most noticable when zooming \emph{out} and then back into the document; the object coordinates will gradually underflow and eventually round to zero. An example of this effect is shown in Figure \ref{qualitative-rendering-fox-cumulative} b)
25 %label start
26 %setbounds 0.5 0.5 1e-6 1e-6
27 %loadsvg svg-tests/fox-vector.svg
28 %loop 1950 pxzoom 0 0 -1
29 %loop 200 wait
30 %debug hi
31 %loop 1950 pxzoom 0 0 1
32 %wait
33 \begin{figure}[H]
34         \centering
35         \includegraphics[width=800px]{figures/fox-vector_cumulative_before_transforms.png}
36         \includegraphics[width=800px]{figures/fox-vector_cumulative_after_transforms.png}
37         \caption{The effect of applying cumulative transformations to all B\'{e}ziers}\label{qualitative-rendering-fox-cumulative}
38 \end{figure}
39
40 \subsection{Applying cumulative transformations to Paths}\label{path_transform}
41
42 In Figure \ref{qualitative-rendering-fox}, transformations are applied to the bounds of each B\'{e}zier. Figure \ref{qualitative-rendering-fox-cumulative-relative} a) shows the effect of introducing an intermediate coordinate system expressing B\'{e}zier coordinates relative to the path which contains them. In this case, the rendering of a single path is accurate, but the overall positions of the paths drift as the view is moved. 
43
44 We can correct this drift whilst maintaining performance by using an arbitrary or high precision number representation to express the coordinates of the paths - but maintaining the floating point coordinates for B\'{e}zier curves relative to their path. This is shown in Figure \ref{qualitative-rendering-fox-cumulative-relative} b).
45
46 \begin{figure}[H]
47         \centering
48         \includegraphics[width=800px]{figures/fox-vector_cumulative_relative_to_path.png}
49         \includegraphics[width=800px]{figures/fox-vector_cumulative_relative_to_path_GMPrat.png}
50         \caption{Effect of cumulative transformations applied to Paths\\a) Path bounds represented using floats b) Path bounds represented using Rationals}\label{qualitative-rendering-fox-cumulative-relative}
51 \end{figure}
52
53 Videos showing the effects discussed in Section \ref{direct_transform}, \ref{cumulative_transform} and \ref{path_transform} can be found at:
54
55  \url{http://szmoore.net/ipdf/sam/presentation}.
56         
57 \section{Quantitative Measurements of Rendering Accuracy}
58         
59 A useful test SVG is a simple grid of horizontal and vertical lines seperated by 1 pixel. When this SVG is correctly scaled to a view, all that should be visible is a coloured rectangle filling the screen. Increasing the magnification will reveal the grid of lines indicating how the original size of a pixel is scaled.
60
61 Figure \ref{grid-precision} illustrates the effect of applying the view transformation \eqref{view-transformation} directly to the grid. When the grid is correctly rendered, as in Figure \ref{grid-precision} a) it appears as a black rectangle. Further from the origin, not all pixels in the grid can be represented and individual lines become visible. As the distance from the origin increases, fewer pixel locations can be represented exactly after performing the view transformation.
62
63 An error of 1 ulp is increased by a factor of $10^6$ to end up comparable to the size of the display ($0 \to 1$).
64
65
66 \begin{figure}[H]
67         \centering
68         \includegraphics[width=800px]{figures/grid_0_1e-6.png}
69         \includegraphics[width=800px]{figures/{grid_0.5_1e-6}.png}
70         \includegraphics[width=800px]{figures/grid_1_1e-6.png}
71         \includegraphics[width=800px]{figures/grid_2_1e-6.png}
72         \caption{Effect of applying \eqref{view-transformation} to a grid of lines seperated by 1 pixel \\
73         a) Near origin (denormals) b), c), d) Increasing the exponent of $(v_x,v_y)$ by 1}\label{grid-precision}
74 \end{figure}
75
76
77 \subsection{Precision for Fixed View}
78
79
80 By counting the number of distinctly representable lines within a particular view, we can show the degradation of precision quantitatively. The test grid is added to each view rectangle.
81
82
83 Figure \ref{loss_of_precision_grid_0.5.pdf} shows how precision degrades with $(V_x, V_y) = (0.5,0.5)$ for different precision settings using MPFR floating point values to represent the view coordinates. A constant line at $1401$ grid locations indicates no loss of precision. From this figure it is clear that 
84
85
86 \begin{figure}[H]
87         \centering
88                 \includegraphics[width=0.8\textwidth]{{figures/loss_of_precision_grid_0.5}.pdf}
89         \caption{Loss of precision of the grid}
90         \label{loss_of_precision_grid_0.5.pdf}
91 \end{figure}
92
93 \subsection{Accumulated error after changing the View}
94
95 Figure \ref{cumulative_error_grid.pdf} shows the total error in the coordinates of each line in the grid after the view is scaled (zooming \emph{out}) by repeated transformations. A constant line at $0$ indicates no accumulated error.
96
97 \begin{figure}[H]
98         \centering
99                 \includegraphics[width=0.8\textwidth]{figures/cumulative_error_grid.pdf}
100         \caption{Error in the coordinates of the grid}
101         \label{cumulative_error_grid.pdf}
102 \end{figure}
103
104 By considering Figure \ref{loss_of_precision_grid_0.5.pdf} and \ref{cumulative_error_grid.pdf}, \verb/path-rat/ is the winner.
105         
106 \section{Performance Measurements}
107         
108 As discussed above, we succeeded in preserving rendering accuracy as defined above for an arbitrary view.
109 However this comes at a performance cost, as the size of the Rational number representation must grow accordingly. Figures \ref{memory.pdf} and \ref{time.pdf} were obtained by repeatedly clearing the document, scaling, and adding a fixed number of B\'{e}zier curves. The \texttt{mpfr-1024} number representation performs much better in terms of memory usage and performance; however as discussed in Section \ref{}, due to the fixed precision it cannot represent detail seperated by a truly arbitrary distance.
110
111 \begin{figure}[H]
112         \centering
113         \includegraphics[width=0.7\textwidth]{figures/memory.pdf}
114         \label{memory.pdf}
115         \caption{Memory used per Path coordinate whilst zooming in}
116 \end{figure}
117
118 \begin{figure}[H]
119         \centering
120         \includegraphics[width=0.7\textwidth]{figures/time.pdf}
121         \label{time.pdf}
122         \caption{Time taken to scale about the fixed point}
123 \end{figure}
124

UCC git Repository :: git.ucc.asn.au