Progress*
[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 separate categories; Documents and Number Representations.
6
7 The first half of this chapter will be devoted to documents themselves, including: the representation and displaying of graphics primitives\cite{computergraphics2}, and how collections of these primitives are represented in document formats, focusing on well known standards currently in use\cite{plrm, pdfref17, svg2011-1.1}.
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, these widely used 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, and expand upon the goals outlined in Chapture \ref{Proposal}.
14
15
16 \pagebreak
17
18 \section{Raster and Vector Images}\label{Raster and Vector Images}
19 \input{chapters/Background_Raster-vs-Vector}
20
21 \section{Rasterising Vector Images}\label{Rasterising Vector Images}
22
23 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 papers oriented towards drawing on these devices can be found\cite{brassel1979analgorithm}. Whilst curves can be drawn at high resolution on vector displays, a major disadvantage was shading; by the early 90s the vast majority of computer displays were raster based\cite{computergraphics2}.
24
25 Hearn and Baker's textbook ``Computer Graphics''\cite{computergraphics2} gives a comprehensive overview of graphics from physical display technologies through fundamental drawing algorithms to popular graphics APIs. This section will examine algorithms for drawing two dimensional geometric primitives on raster displays as discussed in ``Computer Graphics'' and the relevant literature. Informal tutorials are abundant on the internet\cite{elias2000graphics}.
26
27 \subsection{Straight Lines}\label{Straight Lines}
28 \input{chapters/Background_Lines}
29
30 \subsection{Spline Curves}\label{Spline Curves}
31
32 Splines are continuous curves formed from piecewise polynomial segments. A polynomial of $n$th degree is defined by $n$ constants $\{a_0, a_1, ... a_n\}$ and:
33 \begin{align}
34         y(x) &= \displaystyle\sum_{k=0}^n a_k x^k
35 \end{align}
36
37
38 A straight line is simply a polynomial of $0$th degree. Splines may be rasterised by sampling of $y(x)$ at a number of points $x_i$ and rendering straight lines between  $(x_i, y_i)$ and $(x_{i+1}, y_{i+1})$ as discussed in Section \ref{Straight Lines}. More direct algorithms for drawing splines based upon Brasenham and Wu's algorithms also exist\cite{citationneeded}.
39
40 There are many different ways to define a spline. One approach is to specify ``knots'' on the spline and solve for the cooefficients to generate a cubic spline ($n = 3$) passing through the points. Beziers are a popular spline which can be created in GUI based graphics editors using several ``control points'' which themselves are not part of the curve.
41
42 \subsubsection{Bezier Curves}
43 \input{chapters/Background_Bezier}
44
45 \subsection{Shading}
46
47 Algorithms for shading on vector displays involved drawing equally spaced lines within a region; this is limited both in the complexity of shading and the performance required to compute the lines\cite{brassel1979analgorithm}.
48
49 On raster displays, shading is typically based upon Lane's algorithm of 1983\cite{lane1983analgorithm} which is implemented in the GPU  \cite{kilgard2012gpu}
50
51 \rephrase{6. Sort of starts here... or at least background does}
52
53 \subsection{Rendering Vector Graphics on the GPU}
54
55 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}
56
57 \rephrase{2. Here are the ways documents are structured ... we got here eventually}
58
59 \section{Document Representations}
60
61 \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.}
62
63 \subsection{Interpreted Model}
64
65 \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?}
66
67 \begin{itemize}
68         \item This model treats a document as the source code program which produces graphics
69         \item Arose from the desire to produce printed documents using computers (which were still limited to text only displays).
70         \item Typed by hand or (later) generated by a GUI program
71         \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?}
72         \item \TeX --- Predates PostScript! {\LaTeX } is being used to create this very document and until now I didn't even have it here!
73         \begin{itemize}
74                 \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
75                 \item There are interpreters (usually WYSIWYG editors) for \LaTeX though
76                 \item Maybe if \LaTeX were more popular there would be desktop viewers that converted \LaTeX directly into graphics
77         \end{itemize}
78         \item Potential for dynamic content, interactivity; dynamic PostScript, enhanced Postscript
79
80         \item Scientific Computing --- Mathematica, Matlab, IPython Notebook --- The document and the code that produces it are stored together
81         \item Problems with security --- Turing complete, can be exploited easily
82 \end{itemize}
83
84 \subsection{Crippled Interpreted Model}
85
86 \rephrase{I'm pretty sure I made that one up}
87
88 \begin{itemize}
89         \item PDF is PostScript but without the Turing Completeness
90         \item Solves security issues, more efficient
91 \end{itemize}
92
93 \subsection{Document Object Model}
94
95 \begin{itemize}
96         \item DOM = Tree of nodes; node may have attributes, children, data
97         \item XML (SGML) is the standard language used to represent documents in the DOM
98         \item XML is plain text
99         \item SVG is a standard for a vector graphics language conforming to XML (ie: a DOM format)
100         \item CSS style sheets represent more complicated styling on objects in the DOM
101 \end{itemize}
102
103 \subsection{Blurring the Line --- Javascript}
104
105 \begin{itemize}
106         \item The document is expressed in DOM format using XML/HTML/SVG
107         \item A Javascript program is run which can modify the DOM
108         \item At a high level this may be simply changing attributes of elements dynamically
109         \item For low level control there is canvas2D and even WebGL which gives direct access to OpenGL functions
110         \item Javascript can be used to make a HTML/SVG interactive
111         \begin{itemize}
112                 \item Overlooking the fact that the SVG standard already allows for interactive elements...
113         \end{itemize}
114         \item Javascript is now becoming used even in desktop environments and programs (Windows 8, GNOME 3, Cinnamon, Game Maker Studio) ({\bf shudder})
115         \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} 
116         \begin{itemize}
117                 \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
118                 \item This is yet more proof that people will converge towards solutions that ``work'' rather than those that are optimal or elegant
119                 \item I guess it's too much effort to make HTML look like PDF (or vice versa) so we could phase one out
120         \end{itemize}
121 \end{itemize}
122
123 \subsection{Why do we still use static PDFs}
124
125 Despite their limitations, we still use static, boring old PDFs. Particularly in scientific communication.
126 \begin{itemize}
127         \item They are portable; you can write an amazing document in Mathematica/Matlab but it 
128         \item Scientific journals would need to adapt to other formats and this is not worth the effort
129         \item No network connection is required to view a PDF (although DRM might change this?)
130         \item All rescources are stored in a single file; a website is stored accross many separate files (call this a ``distributed'' document format?)
131         \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
132         \item Until Javascript becomes part of the PDF standard, including Javascript in PDF documents will not become widespread
133         \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.
134 \end{itemize}
135
136 \rephrase{3. Here are the ways document standards specify precision (or don't)}
137
138 \section{Precision in Modern Document Formats}
139
140 \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.}
141
142
143
144 \begin{itemize}
145         \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}
146  floating point number representations in order to conform to the standards\cite{plrm, pdfref17}.
147         \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}
148         \item Numerical computation packages such as Mathematica and Maple use arbitrary precision floats
149         \begin{itemize}
150                 \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)
151                 \item What about Maple? \cite{HFP} and \cite{fousse2007mpfr} both mention it being buggy. 
152                 \item Octave and Matlab use fixed precision doubles
153         \end{itemize}
154 \end{itemize}
155
156 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.
157
158 \rephrase{4. Here is IEEE-754 which is what these standards use}
159
160 \section{Representation of Numbers}
161
162 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.
163
164 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}.
165
166 \subsection{The IEEE Standard}
167
168 \subsection{Floating Point Number Representations}
169
170 \begin{align*}
171         x &= (-1)^{s} \times m \times B^{e}
172 \end{align*}
173
174 $B = 2$, although IEEE also defines decimal representations for $B = 10$ --- these are useful in financial software\cite{ieee2008-754}.
175
176 \rephrase{Aside: Are decimal representations for a document format eg: CAD also useful because you can then use metric coordinate systems?}
177
178
179 \subsubsection{Precision}
180
181 The floats map an infinite set of real numbers onto a discrete set of representations.
182
183
184
185 \rephrase{Figure: 8 bit ``minifloats'' (all 255 of them) clearly showing the ``precision vs range'' issue}
186
187 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}$.
188
189 \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}
190
191
192 \rephrase{5. Here are limitations of IEEE-754 floating point numbers on compatible hardware}
193
194 \subsection{Limitations Imposed By CPU}
195
196 CPU's are restricted in their representation of floating point numbers by the IEEE standard.
197
198
199
200 \subsection{Limitations Imposed By Graphics APIs and/or GPUs}
201
202 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 
203
204 \rephrase{6. Here are ways GPU might not be IEEE-754 --- This goes *somewhere* in here but not sure yet}
205
206 \begin{itemize}
207         \item Internal representations are GPU dependent and may not match IEEE\cite{hillesland2004paranoia}
208         \item OpenGL standards specify: binary16, binary32, binary64
209         \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}
210         \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. 
211 \end{itemize}
212
213
214
215 \rephrase{7. Sod all that, let's just use an arbitrary precision library (AND THUS WE FINALLY GET TO THE POINT)}
216
217 \subsection{Alternate Number Representations}
218
219 \rephrase{They exist\cite{HFP}}.
220
221 Do it all using MFPR\cite{}, she'll be right.
222
223 \rephrase{8. Here is a brilliant summary of sections 7- above}
224
225 Dear reader, thankyou for your persistance in reading this mangled excuse for a Literature Review.
226 Hopefully we have brought together the radically different areas of interest together in some sort of coherant fashion.
227 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.
228

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