31f4968604832333407a8fda766266826948824f
[ipdf/documents.git] / LitReviewDavid.tex
1 \documentclass[a4paper,10pt]{article}
2 \usepackage[utf8]{inputenc}
3 \usepackage{hyperref}
4 \usepackage{graphicx}
5 \usepackage{amsmath}
6 \usepackage{amssymb}
7
8 %opening
9 \title{Literature Review}
10 \author{David Gow}
11
12 \begin{document}
13
14 \maketitle
15
16 \section{Introduction}
17
18 Since mankind first climbed down from the trees, it is our ability to communicate that has made us unique.
19 Once ideas could be passed from person to person, it made sense to have a permanent record of them; one which
20 could be passed on from person to person without them ever meeting.
21
22 And thus the document was born.
23
24 Traditionally, documents have been static: just marks on paper, but with the advent of computers many more possibilities open up.
25
26 \section{Document Formats}
27
28 Most existing document formats --- such as the venerable PostScript and PDF --- are, however, designed to imitate
29 existing paper documents, largely to allow for easy printing. In order to truly take advantage of the possibilities operating in the digital
30 domain opens up to us, we must look to new formats.
31
32 Formats such as \texttt{HTML} allow for a greater scope of interactivity and for a more data-driven model, allowing
33 the content of the document to be explored in ways that perhaps the author had not anticipated.\cite{hayes2012pixels}
34 However, these data-driven formats typically do not support fixed layouts, and the display differs from renderer to
35 renderer.
36
37 \subsection{A Taxonomy of Document formats}
38
39 The process of creating and displaying a document is a rather universal one (\ref{documenttimeline}), though
40 different document formats approach it slightly differently. A document often begins as raw content: text and images
41 (be they raster or vector) and it must end up as a set of photons flying towards the reader's eyes.
42
43 \begin{figure}
44         \label{documenttimeline}
45         \centering \includegraphics[width=0.8\linewidth]{figures/documenttimeline}
46         \caption{The lifecycle of a document}
47 \end{figure}
48
49 There are two fundamental stages by which all documents --- digital or otherwise --- are produced and displayed:
50 \emph{layout} and \emph{rendering}. The \emph{layout} stage is where the positions and sizes of text and other graphics are
51 determined. The text will be \emph{flowed} around graphics, the positions of individual glyphs will be placed, ensuring
52 that there is no undesired overlap and that everything will fit on the page or screen.
53
54 The \emph{display} stage actually produces the final output, whether as ink on paper or pixels on a computer monitor.
55 Each graphical element is rasterized and composited into a single image of the target resolution.
56
57
58 Different document formats cover documents in different stages of this project. Bitmapped images,
59 for example, would represent the output of the final stage of the process, whereas markup languages typically specify
60 a document which has not yet been processed, ready for the layout stage. 
61
62 Furthermore, some document formats treat the document as a program, written in
63 a (usually turing complete) document language with instructions which emit shapes to be displayed. These shapes are either displayed
64 immediately, as in PostScript, or stored in another file, such as with \TeX or \LaTeX, which emit a \texttt{DVI} file. Most other
65 forms of document use a \emph{Document Object Model}, being a list or tree of objects to be rendered. \texttt{DVI}, \texttt{PDF},
66 \texttt{HTML}\footnote{Some of these formats --- most notably \texttt{HTML} --- implement a scripting lanugage such as JavaScript,
67 which permit the DOM to be modified while the document is being viewed.} and SVG\cite{svg2011-1.1}. Of these, only \texttt{HTML} and \TeX typically
68 store documents in pre-layout stages, whereas even turing complete document formats such as PostScript typically encode documents
69 which already have their elements placed.
70
71 \begin{description}
72         \item[\TeX \, and \LaTeX]
73         Donald Knuth's typesetting language \TeX \, is one of the older computer typesetting systems, originally conceived in 1977\cite{texdraft}.
74         It implements a turing-complete language and is human-readable and writable, and is still popular
75         due to its excellent support for typesetting mathematics.
76         \TeX only implements the ``layout'' stage of document display, and produces a typeset file,
77         traditionally in \texttt{DVI} format, though modern implementations will often target \texttt{PDF} instead.
78         
79         This document was prepared in \LaTeXe.
80         
81         \item[\texttt{DVI}]
82         \TeX \, traditionally outputs to the \texttt{DVI} format: a binary format which consists of a
83         simple stack machine with instructions for drawing glyphs and curves\cite{fuchs1982theformat}.
84         
85         A \texttt{DVI} file is a representation of a document which has been typeset, and \texttt{DVI}
86         viewers will rasterize this for display or printing, or convert it to another similar format like PostScript
87         to be rasterized.
88         
89         \item[\texttt{HTML}]
90         
91         
92 \end{description}
93
94
95
96 Existing document formats, due to being designed to model paper,
97 have limited precision (8 decimal digits for PostScript\cite{plrm}, 5 decimal digits for PDF\cite{pdfref17}).
98 This matches the limited resolution of printers and ink, but is limited when compared to what aught to be possible
99 with ``zoom'' functionality, which is prevent from working beyond a limited scale factor, lest artefacts appear due
100 to issues with numeric precision.
101
102 \section{Rendering}
103
104 Computer graphics comes in two forms: bit-mapped (or raster) graphics, which is defined by an array of pixel colours; 
105 and \emph{vector} graphics, defined by mathematical descriptions of objects. Bit-mapped graphics are well suited to photographs
106 and are match how cameras, printers and monitors work. However, bitmap devices do not handle zooming beyond their
107 ``native'' resolution --- the resolution where one document pixel maps to one display pixel ---, exhibiting an artefact
108 called pixelation where the pixel structure becomes evident. Attempts to use interpolation to hide this effect are
109 never entirely successful, and sharp edges, such as those found in text and diagrams, are particularly affected.
110
111 \begin{figure}[h]
112         \centering \includegraphics[width=0.8\linewidth]{figures/vectorraster_example}
113         \caption{A circle as a vector image and a $32 \times 32$ pixel raster image}
114 \end{figure}
115
116
117 Vector graphics lack many of these problems: the representation is independent of the output resolution, and rather
118 an abstract description of what it is being rendered, typically as a combination of simple geometric shapes like lines,
119 arcs and ``B\'ezier curves''\cite{catmull1974asubdivision}. 
120 As existing displays (and printers) are bit-mapped devices, vector documents must be \emph{rasterized} into a bitmap at
121 a given resolution. This bitmap is then displayed or printed. The resulting bitmap is then an approximation of the vector image
122 at that resolution.
123
124 This project will be based around vector graphics, as these properties make it more suited to experimenting with zoom
125 quality.
126
127
128 The rasterization process typically operates on an individual ``object'' or ``shape'' at a time: there are special algorithms
129 for rendering lines\cite{bresenham1965algorithm}, triangles\cite{giesen2013triangle}, polygons\cite{pineda1988parallel} and B\'ezier
130 Curves\cite{goldman_thefractal}. Typically, these are rasterized independently and composited in the bitmap domain using Porter-Duff
131 compositing\cite{porter1984compositing} into a single image. This allows complex images to be formed from many simple pieces, as well
132 as allowing for layered translucent objects, which would otherwise require the solution of some very complex constructive geometry problems.
133
134 While traditionally, rasterization was done entirely in software, modern computers and mobile devices have hardware support for rasterizing
135 some basic primitives --- typically lines and triangles ---, designed for use rendering 3D scenes. This hardware is usually programmed with an
136 API like \texttt{OpenGL}\cite{openglspec}.
137
138 More complex shapes like B\'ezier curves can be rendered by combining the use of bitmapped textures (possibly using signed-distance
139 fields\cite{leymarie1992fast}\cite{frisken2000adaptively}\cite{green2007improved}) with polygons approximating the curve's shape\cite{loop2005resolution}\cite{loop2007rendering}.
140
141 Indeed, there are several implementations of entire vector graphics systems using OpenGL: OpenVG\cite{robart2009openvg} on top of OpenGL ES\cite{oh2007implementation};
142 the Cairo\cite{worth2003xr} library, based around the PostScript/PDF rendering model, has the ``Glitz'' OpenGL backend\cite{nilsson2004glitz} and the SVG/PostScript GPU
143 renderer by nVidia\cite{kilgard2012gpu} as an OpenGL extension\cite{kilgard300programming}.
144
145
146 \section{Numeric formats}
147
148 On modern computer architectures, there are two basic number formats supported:
149 fixed-width integers and \emph{floating-point} numbers. Typically, computers
150 natively support integers of up to 64 bits, capable of representing all integers
151 between $0$ and $2^{64} - 1$, inclusive\footnote{Most machines also support \emph{signed} integers,
152 which have the same cardinality as their \emph{unsigned} counterparts, but which
153 represent integers in the range $[-(2^{63}), 2^{63} - 1]$}.
154
155 By introducing a fractional component (analogous to a decimal point), we can convert
156 integers to \emph{fixed-point} numbers, which have a more limited range, but a fixed, greater
157 precision. For example, a number in 4.4 fixed-point format would have four bits representing the integer
158 component, and four bits representing the fractional component:
159 \begin{equation}
160         \underbrace{0101}_\text{integer component}.\underbrace{1100}_\text{fractional component} = 5.75
161 \end{equation}
162
163
164 Floating-point numbers\cite{goldberg1992thedesign} are the binary equivalent of scientific notation:
165 each number consisting of an exponent ($e$) and a mantissa ($m$) such that a number is given by
166 \begin{equation}
167         n = 2^{e} \times m
168 \end{equation}
169
170 The IEEE 754 standard\cite{ieee754std1985} defines several floating-point data types
171 which are used\footnote{Many systems' implement the IEEE 754 standard's storage formats,
172 but do not implement arithmetic operations in accordance with this standard.} by most
173 computer systems. The standard defines 32-bit (8-bit exponent, 23-bit mantissa, 1 sign bit) and 
174 64-bit (11-bit exponent, 53-bit mantissa, 1 sign bit) formats\footnote{The 2008
175 revision to this standard\cite{ieee754std2008} adds some additional formats, but is
176 less widely supported in hardware.}, which can store approximately 7 and 15 decimal digits
177 of precision respectively.
178
179 Floating-point numbers behave quite differently to integers or fixed-point numbers, as
180 the representable numbers are not evenly distributed. Large numbers are stored to a lesser
181 precision than numbers close to zero. This can present problems in documents when zooming in
182 on objects far from the origin.
183
184 IEEE floating-point has some interesting features as well, including values for negative zero,
185 positive and negative infinity, the ``Not a Number'' (NaN) value and \emph{denormal} values, which
186 trade precision for range when dealing with very small numbers. Indeed, with these values,
187 IEEE 754 floating-point equality does not form an equivalence relation, which can cause issues
188 when not considered carefully.\cite{goldberg1991whatevery}
189
190 There also exist formats for storing numbers with arbitrary precising and/or range.
191 Some programming languages support ``big integer''\cite{java_bigint} types which can
192 represent any integer that can fit in the system's memory. Similarly, there are
193 arbitrary-precision floating-point data types\cite{java_bigdecimal}\cite{boost_multiprecision}
194 which can represent any number of the form
195 \begin{equation}
196         \frac{n}{2^d} \; \; \; \; n,d \in \mathbb{Z} % This spacing is horrible, and I should be ashamed.
197 \end{equation}
198 These types are typically built from several native data types such as integers and floats,
199 paired with custom routines implementing arithmetic primitives.\cite{priest1991algorithms}
200 These, therefore, are likely slower than the native types they are built on.
201
202 While traditionally, GPUs have supported some approximation of IEEE 754's 32-bit floats,
203 modern graphics processors also support 16-bit\cite{nv_half_float} and 64-bit\cite{arb_gpu_shader_fp64}
204 IEEE floats.  Note, however, that some parts of the GPU are only able to use some formats,
205 so precision will likely be truncated at some point before display.
206 Higher precision numeric types can be implemented or used on the GPU, but are
207 slow.\cite{emmart2010high}
208
209 Pairs of integers $(a \in \mathbb{Z},b \in \mathbb{Z}\setminus 0)$ can be used to represent rationals. This allows
210 values such as $\frac{1}{3}$ to be represented exactly, whereas in fixed or floating-point formats,
211 this would have a recurring representation:
212 \begin{equation}
213         \underbrace{0}_\text{integer part} . \underbrace{01}_\text{recurring part} 01 \; \; 01 \; \; 01 \dots
214 \end{equation}
215 Whereas with a rational type, this is simply $\frac{1}{3}$.
216 Rationals do not have a unique representation for each value, typically the reduced fraction is used
217 as a characteristic element.
218
219
220 \section{Quadtrees}
221 When viewing or processing a small part of a large document, it may be helpful to
222 only processs --- or \emph{cull} --- parts of the document which are not on-screen.
223
224 \begin{figure}[h]
225         \centering \includegraphics[width=0.4\linewidth]{figures/quadtree_example}
226         \caption{A simple quadtree.}
227 \end{figure}
228 The quadtree\cite{finkel1974quad}is a data structure --- one of a family of \emph{spatial}
229 data structures --- which recursively breaks down space into smaller subregions
230 which can be processed independently. Points (or other objects) are added to a single
231 node, which if certain criteria are met --- typically the number of points in a node
232 exceeding a maximum, though in our case likely the level of precision required exceeding
233 that supported by the data type in use --- is split into four equal-sized subregions, and
234 points attached to the region which contains them.
235
236 In this project, we will be experimenting with a form of quadtree in which each
237 node has its own independent coordinate system, allowing us to store some spatial
238 information\footnote{One bit per-coordinate, per-level of the quadtree} within the
239 quadtree structure, eliminating redundancy in the coordinates of nearby objects.
240
241 Other spatial data structures exist, such as the KD-tree\cite{bentley1975multidimensional},
242 which partitions the space on any axis-aligned line; or the BSP tree\cite{fuchs1980onvisible},
243 which splits along an arbitrary line which need not be axis aligned. We believe, however,
244 that the simpler conversion from binary coordinates to the quadtree's binary split make
245 it a better avenue for initial research to explore.
246
247 \bibliographystyle{unsrt}
248 \bibliography{papers}
249
250 \end{document}

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