A 1.5th order approximation to a 1st draft
[ipdf/sam.git] / chapters / Background.tex
index 4bedb57..6a7b3a5 100644 (file)
 \chapter{Literature Review}\label{Background}
 
-This chapter will \rephrase{review the literature. It will also include some figures created by us from our test programs to aid with conceptual understanding of the literature.} A paper by paper summary of the literature is also available at: \\ \url{http://szmoore.net/ipdf/documents/LiteratureNotes.pdf}.
+%\section{Overview}
+\input{chapters/Background/Overview}
+\section{Raster and Vector Graphics}
+\input{chapters/Background/RasterAndVectorGraphics}
+\section{Rendering Vector Primitives}
+\input{chapters/Background/Rendering}
+\section{Coordinate Systems and Transformations}
+\input{chapters/Background/CoordinateSystems}
+\section{Precision Specified by Document Standards}
+\input{chapters/Background/Standards}
 
-\rephrase{TODO: If I want to link to the Paper by Paper summary it will need a bit of rewriting}.
 
-\rephrase{TODO: Actually (re)write this entire chapter}.
 
-\rephrase{TODO: Un dot point ify}
 
-\rephrase{TODO: Citations}
+\section{Fixed Point and Integer Number Representations}
+\input{chapters/Background/FixedPoint}
+\section{Floating Point Number Representations}
+\input{chapters/Background/Floats}
+\section{Rational Number Representations}
+\input{chapters/Background/Rationals}
 
-\rephrase{TODO: Make less terrible}
+\section{Floating Point Operations on the CPU and GPU}
+\input{chapters/Background/FloatingPointOnTheGPU}
 
 
-\rephrase{TODO: Reconsider sections (do I really want to make this go down to} \verb/\subsubsection/?)
-
-\rephrase{TODO: :-(}
-
-
-
-\section{Vector Graphics vs Raster Graphics}
-
-\newlength\imageheight
-\newlength\imagewidth
-\settoheight\imageheight{\includegraphics{figures/fox-raster.png}}
-\settowidth\imagewidth{\includegraphics{figures/fox-raster.png}}
-
-%Height: \the\imageheight
-%Width: \the\imagewidth
-
-\rephrase{TODO: Distinguish between Raster Formats and the Rasterisation of an image (which may or may not be in a raster format)}
-
-
-\subsubsection{Raster Graphics}
-\begin{itemize}
-       \item Bitmap --- array of colour information for pixels
-       \item Exact pixels in a similar format to how they would appear on a (modern) display device.
-       \begin{itemize}
-               \item Also similar to how they would be stored by a camera or scanner
-               \item \rephrase{Is it misleading to say 2D array? Pixels are actually stored in a 1D array, but conceptually it's nicer to say 2D}
-               \item \rephrase{For that matter, should it described as 3D (3rd dimension = colour)?}
-       \end{itemize}
-       \item Lowest level representation of a document
-       \item Issues with scaling; values of extra pixels must be calculated
-       \item Not convenient to edit; ill suited to text
-\end{itemize}
-
-
-\subsubsection{Vector Graphics}
-\begin{itemize}
-       \item Stores relative position of primitives - scales better
-       \item In particular, \emph{edges} of lines can be zoomed without becomming jagged; sometimes (somewhat misleadingly) described as ``infinitely sharp''
-       \item Vector Graphics must be rasterised before being drawn on most display devices.
-       \item Still can't scale forever due to use of fixed size floats
-\end{itemize}
-
-\subsubsection{Resolution and Raster Graphics}
-\begin{itemize}
-       \item DPI = dots (pixels) per inch differs per display device - a rastered image looks different on different display devices
-       \item PostScript/PDF use 72 points per inch; this means a rasterised image will look the same in all pdf viewers regardless of the display.
-       \item Tex uses 72.27 points per inch (?)
-       \item The vector image was rastered at 96 points per inch
-       \item Hence, have to scale by 72.27/96 = 0.7528125 to get the vector and rastered version to look exactly the same in the pdf
-\end{itemize}
-
-
-
-\begin{figure}[H]
-       \centering
-
-       \includegraphics[scale=0.7528125]{figures/fox-vector.pdf}
-       \includegraphics[scale=0.7528125]{figures/fox-raster.png}
-       \includegraphics[scale=0.7528125, viewport=210 85 280 150,clip, width=0.45\textwidth]{figures/fox-vector.pdf}
-       \includegraphics[scale=0.7528125, viewport=0 85 70 150,clip, width=0.45\textwidth]{figures/fox-raster.png}
-       \caption{Scaling of vector and Raster Graphics}\label{vector-vs-raster}
-\end{figure}
-
-
-
-Figure \ref{vector-vs-raster} shows a vector image (left) which has been rasterised (right). At the original scale the two foxes should appear to be mirror images\footnote{If I've worked out the scaling to account for dpi differences between inkscape and latex/pdf correctly}. When the scale is increased, the edges of the vector image remain sharp, whilst the raster image begins to appear jagged. PDF viewers will typically use antialiasing to smooth the edges of a scaled bitmap, causing the image to appear blurred.\footnote{In the Atril Document Viewer 1.6.0 this image will only be antialiased at zoom levels $\leq 125\%$}.
-
-Various ways to end this section:
-\begin{enumerate}
-       \item \rephrase{It should be obvious that documents containing text must use the vector graphics format, and so the remainder of this chapter will concentrate on the latter}.
-       \item \rephrase{As can be seen in Figure \ref{fox}, if we were to decide to pursue ``infinite precision'' in raster graphics we would be shooting ourselves in both feet and then the face before we even started. The rest of this chapter will concentrate on vector graphics.}
-       \item \rephrase{You can't have infinite precision in raster graphics by definition, therefore we no longer care about them in this report.}
-       \item \rephrase{This report being in a vector format is a clue that we only care about vector formats}.
-\end{enumerate}
-
-\section{Primitives in Vector Graphics Formats (and how they are Rendered)}
-
-\subsection{Bezier Curves}
-\rephrase{I did an ipython notebook on this in February, but I forgot all of it}
-
-\subsection{Text}
-Text is just Bezier Curves
-
-\subsection{Shapes}
-Shapes are just bezier curves joined together.
-
-\subsection{Other Things}
-We don't really care about other things (ie: Colour gradients etc) in this report.
-
-\section{Document Representations}
-
-\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.}
-
-
-
-\subsection{Interpreted Model}
-
-\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?}
-
-\begin{itemize}
-       \item This model treats a document as the source code program which produces graphics
-       \item Arose from the desire to produce printed documents using computers (which were still limited to text only displays).
-       \item Typed by hand or (later) generated by a GUI program
-       \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?}
-       \item \TeX --- Predates PostScript! {\LaTeX } is being used to create this very document and until now I didn't even have it here!
-       \begin{itemize}
-               \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
-               \item There are interpreters (usually WYSIWYG editors) for \LaTeX though
-               \item Maybe if \LaTeX were more popular there would be desktop viewers that converted \LaTeX directly into graphics
-       \end{itemize}
-       \item Potential for dynamic content, interactivity; dynamic PostScript, enhanced Postscript
-
-       \item Scientific Computing --- Mathematica, Matlab, IPython Notebook --- The document and the code that produces it are stored together
-       \item Problems with security --- Turing complete, can be exploited easily
-\end{itemize}
-
-\subsection{Crippled Interpreted Model}
-
-\rephrase{I'm pretty sure I made that one up}
-
-\begin{itemize}
-       \item PDF is PostScript but without the Turing Completeness
-       \item Solves security issues, more efficient
-\end{itemize}
-
-\subsection{Document Object Model}
-
-\begin{itemize}
-       \item DOM = Tree of nodes; node may have attributes, children, data
-       \item XML (SGML) is the standard language used to represent documents in the DOM
-       \item XML is plain text
-       \item SVG is a standard for a vector graphics language conforming to XML (ie: a DOM format)
-       \item CSS style sheets represent more complicated styling on objects in the DOM
-\end{itemize}
-
-\subsection{Blurring the Line --- Javascript}
-
-\begin{itemize}
-       \item The document is expressed in DOM format using XML/HTML/SVG
-       \item A Javascript program is run which can modify the DOM
-       \item At a high level this may be simply changing attributes of elements dynamically
-       \item For low level control there is canvas2D and even WebGL which gives direct access to OpenGL functions
-       \item Javascript can be used to make a HTML/SVG interactive
-       \begin{itemize}
-               \item Overlooking the fact that the SVG standard already allows for interactive elements...
-       \end{itemize}
-       \item Javascript is now becoming used even in desktop environments and programs (Windows 8, GNOME 3, Cinnamon, Game Maker Studio) ({\bf shudder})
-       \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} 
-       \begin{itemize}
-               \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
-               \item This is yet more proof that people will converge towards solutions that ``work'' rather than those that are optimal or elegant
-               \item I guess it's too much effort to make HTML look like PDF (or vice versa) so we could phase one out
-       \end{itemize}
-\end{itemize}
-
-\subsection{Why do we still use static PDFs}
-
-Despite their limitations, we still use static, boring old PDFs. Particularly in scientific communication.
-\begin{itemize}
-       \item They are portable; you can write an amazing document in Mathematica/Matlab but it 
-       \item Scientific journals would need to adapt to other formats and this is not worth the effort
-       \item No network connection is required to view a PDF (although DRM might change this?)
-       \item All rescources are stored in a single file; a website is stored accross many seperate files (call this a ``distributed'' document format?)
-       \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
-       \item Until Javascript becomes part of the PDF standard, including Javascript in PDF documents will not become widespread
-       \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.
-\end{itemize}
-
-
-\section{Precision in Modern Document Formats}
-
-\rephrase{All this 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}.
-
-
-
-\begin{itemize}
-       \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}
- floating point number representations in order to conform to the standards\cite{plrm, pdfref17}.
-       \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}
-       \item Numerical computation packages such as Mathematica and Maple use arbitrary precision floats
-       \begin{itemize}
-               \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)
-               \item What about Maple? \cite{HFP} and \cite{fousse2007mpfr} both mention it being buggy. 
-               \item Octave and Matlab use fixed precision doubles
-       \end{itemize}
-\end{itemize}
-
-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.
-
-\section{Representation of Numbers}
-
-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.
-
-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}.
-
-\subsection{The IEEE Standard}
-
-\subsection{Floating Point Number Representations}
-
-\begin{align*}
-       x &= (-1)^{s} \times m \times B^{e}
-\end{align*}
-
-$B = 2$, although IEEE also defines decimal representations for $B = 10$ --- these are useful in financial software\cite{ieee2008-754}.
-
-\rephrase{Aside: Are decimal representations for a document format eg: CAD also useful because you can then use metric coordinate systems?}
-
-\subsubsection{Precision}
-
-The floats map an infinite set of real numbers onto a discrete set of representations.
-
-\rephrase{Figure: 8 bit ``minifloats'' (all 255 of them) clearly showing the ``precision vs range'' issue}
-
-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}$.
-
-\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}
-
-\subsection{Limitations Imposed By CPU}
-
-CPU's are restricted in their representation of floating point numbers by the IEEE standard.
-
-
-
-\subsection{Limitations Imposed By Graphics APIs and/or GPUs}
-
-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 
-
-\begin{itemize}
-       \item Internal representations are GPU dependent and may not match IEEE\cite{hillesland2004paranoia}
-       \item OpenGL standards specify: binary16, binary32, binary64
-       \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}
-       \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. 
-\end{itemize}
-
-
-
-\rephrase{AND THUS WE FINALLY GET TO THE POINT}
-
-
-\subsection{Examples of Precision Related Errors in Floating Point Arithmetic}
-
-\subsection{Relate This to the Sorts of Maths Done By Document Formats}
-
-\subsection{Techniques for Arbitrary Precision Arithmetic}
-
-\begin{itemize}
-       \item Fast2SUM for summation (and multiplication).
-       \item Guard digits.
-       \item Other techniques
-       \item Hardware techniques that improve speed (which may be beneficial because you can get away with higher precision in hardware)
-       \item Anything you can do in hardware you can do in software but it will be slower and have more segmentation faults
-\end{itemize}
-
-\subsection{Alternate Number Representations}
-
-\rephrase{They exist\cite{HFP}}.
-
 

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