Created Rate My Lit Review
[ipdf/sam.git] / chapters / Background.tex
1 \chapter{Literature Review}\label{Background}
2
3 \rephrase{0. Here is a brilliant summary of the sections below}
4
5 This chapter provides an overview of relevant literature. The areas of interest can be broadly grouped into two largely seperate categories; Documents and Number Representations.
6
7 The first half of this chapter will be devoted to documents themselves, including: the representation and rendering of low level graphics primitives, how collections of these primitives are represented in document formats, and the various standards for documents in use today. 
8
9 We will find that although there has been a great deal of research into the rendering, storing, editing, manipulation, and extension of document formats, all popular document standards are content to specify at best a single precision IEEE-754 floating point number representations. 
10
11 The research on arbitrary precision arithmetic applied to documents is very sparse; however arbitrary precision arithmetic itself is a very active field of research. Therefore, the second half of this chapter will be devoted to considering the IEEE-754 standard, its advantages and limitations, and possible alternative number representations to allow for arbitrary precision arithmetic.
12
13 In Chapter \ref{Progress}, we will discuss our findings so far with regards to arbitrary precision arithmetic applied to document formats.
14
15
16 \pagebreak
17
18 \section{Raster and Vector Graphics}\label{vector-vs-raster-graphics}
19
20 \rephrase{1. Here are the fundamentals of graphics (raster and vector, rendering)}
21
22 At a fundamental level everything that is seen on a display device is represented as either a vector or raster image. These images can be stored as stand alone documents or embedded in a much more complex document format capable of containing many other types of information.
23
24 A raster image's structure closely matches it's representation as shown on modern display hardware; the image is represented as a grid of filled square ``pixels''. Each pixel is the same size and contains information describing its colour. This representation is simple and also well suited to storing images as produced by cameras and scanners\cite{citationneeded}.
25
26 The drawback of raster images is that by their very nature there can only be one level of detail. Figures \ref{vector-vs-raster} and \ref{vector-vs-raster-scaled} attempt to illustrate this by comparing raster images to vector images in a similar way to Worth and Packard\cite{worth2003xr}.
27
28 Consider the right side of Figure \ref{vector-vs-raster}. This is a raster image which should be recognisable as an animal defined by fairly sharp edges. Figure \ref{vector-vs-raster-scaled} shows that zooming on the animal's face causes these edges to appear jagged. There is no information in the original image as to what should be displayed at a larger size, so each square shaped pixel is simply increased in size. A blurring effect will probably be visible in most PDF viewers; the software has attempted to make the ``edge'' appear more realistic using a technique called ``antialiasing'' which averages neighbouring pixels in the original image in order to generate extra pixels in the scaled image\cite{citationneeded}.\footnote{The exact appearance of the images at different zoom levels will depend greatly on the PDF viewer or printer used to display this report. On the author's display using the Atril (1.6.0) viewer, the top images appear to be pixel perfect mirror images at a 100\% scale. In the bottom raster image, antialiasing is not applied at zoom levels above $125\%$ and the effect of scaling is quite noticable.}
29
30 %\footnote{\noindent This behaviour may be configured in some PDF viewers (Adobe Reader) whilst others (Evince, Atril, Okular) will choose whether or not to bother with antialiasing based on the zoom level. For best results experiment with changing the zoom level in your PDF viewer.\footnotemark}\footnotetext{On the author's hardware, the animals in the vector and raster images should appear mirrored pixel for pixel; but they may vary slightly on other PDF viewers or display devices.}
31
32 In contrast, the left sides of Figures \ref{vector-vs-raster} and \ref{vector-vs-raster-scaled} are a vector image. A vector image contains information about a number of geometric shapes. To display this image on modern display hardware, the coordinates are transformed according to the view and \emph{then} the image is converted into a raster like representation. Whilst the raster image merely appears to contain edges, the vector image actually contains information about these edges, meaning they can be displayed ``infinitely sharply'' at any level of detail\cite{citationneeded} --- or they could be if the coordinates are stored with enough precision (see Section \ref{}). Thus, vector images are well suited to high quality digital art\footnote{Figure \ref{vector-vs-raster} is not to be taken as an example of this.} and text\cite{citationneeded}.
33
34
35 \rephrase{Woah, an entire page with only one citation ham fisted in after I had written the rest... and the ``actually writing it'' phase of the Lit Review is off to a great start.}
36
37 \newlength\imageheight
38 \newlength\imagewidth
39 \settoheight\imageheight{\includegraphics{figures/fox-raster.png}}
40 \settowidth\imagewidth{\includegraphics{figures/fox-raster.png}}
41
42 %Height: \the\imageheight
43 %Width: \the\imagewidth
44
45
46 \begin{figure}[H]
47         \centering
48         \includegraphics[scale=0.7528125]{figures/fox-vector.pdf}
49         \includegraphics[scale=0.7528125]{figures/fox-raster.png}
50         \caption{Original Vector and Raster Images}\label{vector-vs-raster}
51 \end{figure} % As much as I hate to break up the party, these fit best over the page (at the moment)
52 \begin{figure}[H]
53         \centering
54         \includegraphics[scale=0.7528125, viewport=210 85 280 150,clip, width=0.45\textwidth]{figures/fox-vector.pdf}
55         \includegraphics[scale=0.7528125, viewport=0 85 70 150,clip, width=0.45\textwidth]{figures/fox-raster.png}
56         \caption{Scaled Vector and Raster Images}\label{vector-vs-raster-scaled}
57 \end{figure}
58
59 \section{Rendering Vector Images}
60
61 Throughout Section \ref{vector-vs-raster-graphics} we were careful to refer to ``modern'' display devices, which are raster based. It is of some historical significance that vector display devices were popular during the 70s and 80s, and so algorithms for drawing a vector image directly without rasterisation exist. An example is the shading of polygons which is somewhat more complicated on a vector display than a raster display\cite{brassel1979analgorithm, lane1983analgorithm}.
62
63 All modern displays of practical interest are raster based. In this section we explore the structure of vector graphics in more detail, and how different primitives are rendered.
64
65 \rephrase{After the wall of citationless text in Section \ref{vector-vs-raster-graphics} we should probably redeem ourselves a bit here}
66
67 \subsection{Bezier Curves}
68
69 The bezier curve is of vital importance in vector graphics.
70
71 \rephrase{Things this section lacks}
72 \begin{itemize}
73         \item Who came up with them (presumably it was a guy named Bezier)
74         \item Flesh out how they evolved or came into use?
75         \item Naive algorithm
76         \item De Casteljau Algorithm
77 \end{itemize}
78
79 Recently, Goldman presented an argument that Bezier's could be considered as fractal in nature, a fractal being the fixed point of an iterated function system\cite{goldman_thefractal}. Goldman's proof depends upon a modification to the De Casteljau Subdivision algorithm. Whilst we will not go the details of the proof, or attempt comment on its theoretical value, it is interesting to note that Goldman's algorithm is not only worse than the De Casteljau algorithm upon which it was based, but it also performs worse than a naive Bezier rendering algorithm. Figure \ref{bezier-goldman} shows our results using implementations of the various algorithms in python.
80
81 \begin{figure}[H]
82         \centering
83         \includegraphics[width=0.7\textwidth]{figures/bezier-goldman.png}
84         \caption{Performance of Bezier Subdivision Algorithms}\label{bezier-goldman}
85 \end{figure} 
86
87 \rephrase{Does the Goldman bit need to be here? Probably NOT. Do I need to check very very carefully that I haven't made a mistake before saying this? YES. Will I have made a mistake? Probably.}
88
89
90 \subsection{Shapes}
91 Shapes are just bezier curves joined together.
92
93 \subsubsection{Approximating a Circle Using Cubic Beziers}
94
95 An example of a shape is a circle. We used some algorithm on wikipedia that I'm sure is in Literature somewhere
96 \cite{citationneeded} and made a circle. It's in my magical ipython notebook with the De Casteljau stuff.
97
98 \subsection{Text}
99 Text is just Bezier Curves, I think we proved out point with the circle, but maybe find some papers to cite\cite{citationneeded}
100
101
102 \subsection{Shading}
103
104 Shading is actually extremely complicated! \cite{brassel1979analgorithm, lane1983analgorithm}
105 \rephrase{Sure, but do we care enough to talk about it? We will run out of space at this rate}
106
107 \subsection{Other Things}
108 We don't really care about other things in this report.
109
110 \rephrase{6. Sort of starts here... or at least background does}
111
112 \subsection{Rendering Vector Graphics on the GPU}
113
114 Traditionally, vector graphics have been rasterized by the CPU before being sent to the GPU for drawing\cite{kilgard2012gpu}. Lots of people would like to change this \cite{worth2003xr, loop2007rendering, rice2008openvg, kilgard2012gpu, green2007improved} ... \rephrase{All of these are things David found except kilgard which I thought I found and then realised David already had it :S}
115
116 \rephrase{2. Here are the ways documents are structured ... we got here eventually}
117
118 \section{Document Representations}
119
120 \rephrase{The file format can be either human readable\footnote{For some definition of human and some definition of readable} or binary\footnote{So, our viewer is basically a DOM style but stored in a binary format}. Can also be compressed or not. Here we are interested in how the document is interpreted or traversed in order to produce graphics output.}
121
122 \subsection{Interpreted Model}
123
124 \rephrase{Did I just invent that terminology or did I read it in a paper? Is there actually existing terminology for this that sounds similar enough to ``Document Object Model'' for me to compare them side by side?}
125
126 \begin{itemize}
127         \item This model treats a document as the source code program which produces graphics
128         \item Arose from the desire to produce printed documents using computers (which were still limited to text only displays).
129         \item Typed by hand or (later) generated by a GUI program
130         \item PostScript --- largely supersceded by PDF on the desktop but still used by printers\footnote{Desktop pdf viewers can still cope with PS, but I wonder if a smartphone pdf viewer would implement it?}
131         \item \TeX --- Predates PostScript! {\LaTeX } is being used to create this very document and until now I didn't even have it here!
132         \begin{itemize}
133                 \item I don't really want to go down the path of investigating the billion steps involved in getting \LaTeX into an actually viewable format
134                 \item There are interpreters (usually WYSIWYG editors) for \LaTeX though
135                 \item Maybe if \LaTeX were more popular there would be desktop viewers that converted \LaTeX directly into graphics
136         \end{itemize}
137         \item Potential for dynamic content, interactivity; dynamic PostScript, enhanced Postscript
138
139         \item Scientific Computing --- Mathematica, Matlab, IPython Notebook --- The document and the code that produces it are stored together
140         \item Problems with security --- Turing complete, can be exploited easily
141 \end{itemize}
142
143 \subsection{Crippled Interpreted Model}
144
145 \rephrase{I'm pretty sure I made that one up}
146
147 \begin{itemize}
148         \item PDF is PostScript but without the Turing Completeness
149         \item Solves security issues, more efficient
150 \end{itemize}
151
152 \subsection{Document Object Model}
153
154 \begin{itemize}
155         \item DOM = Tree of nodes; node may have attributes, children, data
156         \item XML (SGML) is the standard language used to represent documents in the DOM
157         \item XML is plain text
158         \item SVG is a standard for a vector graphics language conforming to XML (ie: a DOM format)
159         \item CSS style sheets represent more complicated styling on objects in the DOM
160 \end{itemize}
161
162 \subsection{Blurring the Line --- Javascript}
163
164 \begin{itemize}
165         \item The document is expressed in DOM format using XML/HTML/SVG
166         \item A Javascript program is run which can modify the DOM
167         \item At a high level this may be simply changing attributes of elements dynamically
168         \item For low level control there is canvas2D and even WebGL which gives direct access to OpenGL functions
169         \item Javascript can be used to make a HTML/SVG interactive
170         \begin{itemize}
171                 \item Overlooking the fact that the SVG standard already allows for interactive elements...
172         \end{itemize}
173         \item Javascript is now becoming used even in desktop environments and programs (Windows 8, GNOME 3, Cinnamon, Game Maker Studio) ({\bf shudder})
174         \item There are also a range of papers about including Javascript in PDF ``Pixels or Perish'' being the only one we have actually read\cite{hayes2012pixels} 
175         \begin{itemize}
176                 \item I have no idea how this works; PDF is based on PostScript... it seems very circular to be using a programming language to modify a document that is modelled on being a (non turing complete) program
177                 \item This is yet more proof that people will converge towards solutions that ``work'' rather than those that are optimal or elegant
178                 \item I guess it's too much effort to make HTML look like PDF (or vice versa) so we could phase one out
179         \end{itemize}
180 \end{itemize}
181
182 \subsection{Why do we still use static PDFs}
183
184 Despite their limitations, we still use static, boring old PDFs. Particularly in scientific communication.
185 \begin{itemize}
186         \item They are portable; you can write an amazing document in Mathematica/Matlab but it 
187         \item Scientific journals would need to adapt to other formats and this is not worth the effort
188         \item No network connection is required to view a PDF (although DRM might change this?)
189         \item All rescources are stored in a single file; a website is stored accross many seperate files (call this a ``distributed'' document format?)
190         \item You can create PDFs easily using desktop processing WYSIWYG editors; WYSIWYG editors for web based documents are worthless due to the more complex content
191         \item Until Javascript becomes part of the PDF standard, including Javascript in PDF documents will not become widespread
192         \item Once you complicate a PDF by adding Javascript, it becomes more complicated to create; it is simply easier to use a series of static figures than to embed a shader in your document. Even for people that know WebGL.
193 \end{itemize}
194
195 \rephrase{3. Here are the ways document standards specify precision (or don't)}
196
197 \section{Precision in Modern Document Formats}
198
199 \rephrase{All the above is very interesting and provides important context, but it is not actually directly related to the problem of infinite precision which we are going to try and solve. Sorry to make you read it all.}
200
201
202
203 \begin{itemize}
204         \item Implementations of PostScript and PDF must by definition restrict themselves to IEEE binary32 ``single precision''\footnote{The original IEEE-754 defined single, double and extended precisions; in the revision these were renamed to binary32, binary64 and binary128 to explicitly state the base and number of bits}
205  floating point number representations in order to conform to the standards\cite{plrm, pdfref17}.
206         \item Implementations of SVG are by definition required to use IEEE binary32 as a {\bf minimum}. ``High Quality'' SVG viewers are required to use at least IEEE binary64.\cite{svg2011-1.1}
207         \item Numerical computation packages such as Mathematica and Maple use arbitrary precision floats
208         \begin{itemize}
209                 \item Mathematica is not open source which is an issue when publishing scientific research (because people who do not fork out money for Mathematica cannot verify results)
210                 \item What about Maple? \cite{HFP} and \cite{fousse2007mpfr} both mention it being buggy. 
211                 \item Octave and Matlab use fixed precision doubles
212         \end{itemize}
213 \end{itemize}
214
215 The use of IEEE binary32 floats in the PostScript and PDF standards is not surprising if we consider that these documents are oriented towards representing static pages. They don't actually need higher precision to do this; 32 bits is more than sufficient for A4 paper.
216
217 \rephrase{4. Here is IEEE-754 which is what these standards use}
218
219 \section{Representation of Numbers}
220
221 Although this project has been motivated by a desire for more flexible document formats, the fundamental source of limited precision in vector document formats is the restriction to IEEE floating point numbers for representation of coordinates.
222
223 Whilst David Gow will be focusing on structures \rephrase{and the use of multiple coordinate systems} to represent a document so as to avoid or reduce these limitations\cite{proposalGow}, the focus of our own research will be \rephrase{increased precision in the representation of real numbers so as to get away with using a single global coordinate system}.
224
225 \subsection{The IEEE Standard}
226
227 \subsection{Floating Point Number Representations}
228
229 \begin{align*}
230         x &= (-1)^{s} \times m \times B^{e}
231 \end{align*}
232
233 $B = 2$, although IEEE also defines decimal representations for $B = 10$ --- these are useful in financial software\cite{ieee2008-754}.
234
235 \rephrase{Aside: Are decimal representations for a document format eg: CAD also useful because you can then use metric coordinate systems?}
236
237
238 \subsubsection{Precision}
239
240 The floats map an infinite set of real numbers onto a discrete set of representations.
241
242 \rephrase{Figure: 8 bit ``minifloats'' (all 255 of them) clearly showing the ``precision vs range'' issue}
243
244 The most a result can be rounded in conversion to a floating point number is the units in last place; $m_{N} \times B^{e}$.
245
246 \rephrase{Even though that paper that claims double is the best you will ever need because the error can be as much as the size of a bacterium relative to the distance to the moon}\cite{} \rephrase{there are many cases where increased number of bits will not save you}.\cite{HFP}
247
248
249 \rephrase{5. Here are limitations of IEEE-754 floating point numbers on compatible hardware}
250
251 \subsection{Limitations Imposed By CPU}
252
253 CPU's are restricted in their representation of floating point numbers by the IEEE standard.
254
255
256
257 \subsection{Limitations Imposed By Graphics APIs and/or GPUs}
258
259 Traditionally algorithms for drawing vector graphics are performed on the CPU; the image is rasterised and then sent to the GPU for rendering\cite{}. Recently there has been a great deal of literature relating to implementation of algorithms such as bezier curve rendering\cite{} or shading\cite{} on the GPU. As it seems the trend is to move towards GPU 
260
261 \rephrase{6. Here are ways GPU might not be IEEE-754 --- This goes *somewhere* in here but not sure yet}
262
263 \begin{itemize}
264         \item Internal representations are GPU dependent and may not match IEEE\cite{hillesland2004paranoia}
265         \item OpenGL standards specify: binary16, binary32, binary64
266         \item OpenVG aims to become a standard API for SVG viewers but the API only uses binary32 and hardware implementations may use less than this internally\cite{rice2008openvg}
267         \item It seems that IEEE has not been entirely successful; although all modern CPUs and GPUs are able to read and write IEEE floating point types, many do not conform to the IEEE standard in how they represent floating point numbers internally. 
268 \end{itemize}
269
270
271
272 \rephrase{7. Sod all that, let's just use an arbitrary precision library (AND THUS WE FINALLY GET TO THE POINT)}
273
274 \subsection{Alternate Number Representations}
275
276 \rephrase{They exist\cite{HFP}}.
277
278 Do it all using MFPR\cite{}, she'll be right.
279
280 \rephrase{8. Here is a brilliant summary of sections 7- above}
281
282 Dear reader, thankyou for your persistance in reading this mangled excuse for a Literature Review.
283 Hopefully we have brought together the radically different areas of interest together in some sort of coherant fashion.
284 In the next chapter we will talk about how we have succeeded in rendering a rectangle. It will be fun. I am looking forward to it.
285

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