\chapter{Isosurfaces}

This assignment was a really interesting one. It introduces a method to implement so called isolines. Such an isoline creates a surface that encapsulates a region
with a value higher than a given threshold. \\

\section{Description}

An isoline is a line that sort to speak follows a given value. If the values of a field ranges from 0 to 1, a good threshold would be 0.6 for instance. The isoline
visualizes the points that equal the value of 0.6. \\

Our program is able to define the number of contour-lines and the minimum and maximum values in between the isolines are rendered. \\

\section{Implementation}

The algorithm that implements the isolines follows a structured pattern. In pseudo-code it looks like this: \\

\begin{tabbing}
  for \= (each cell $ c_i $ of the dataset) \\
  \{ \\
  \> for \= (each vertex $ v_j $ of $ c_i $) \\
  \> \> store inside/outside state of $ v_j $ in bit $ b $ of $ status $; \\
  \> select the optimized code from the case table using $ status $; \\
  \> for \= (all cell edges $ e_j $ of the selected case) \\
  \> \> intersect $ e_j $ with the isovalue; \\
  \> construct the line segment(s); \\
  \} \\
\end{tabbing}

So the algorithm passes through every cell and then checks the four cell vertices \{$ v_0 $, $ v_1 $, $ v_2 $, $ v_3 $\} of that cell. Each vertex has it's own
value. With that value, the algorithm can check if a vertex is inside ($ v_j \geq threshold $) or outside ($ v_j < threshold $) the isosurface. The inside/outside
state is then stored in a bit. \\

\begin {center}
  \includegraphics[width=\textwidth]{isolines.png} \\
  Figure 6: Three fire-like colored isolines on a blue grid \\
\end {center}

If a vertex, say $ v_0 $ is inside the isosurface, $ v_0 $ is set to 1, else it's left to 0. This is done for all four vertices which results in a 4-bit status.
This means there are in total 16 different cases in which the isoline can run through a cell. \\

\begin {center}
  \includegraphics[width=\textwidth]{marching.png} \\
  Figure 7: The 16 marching square cases \\
\end {center}

The above image (figure 7) shows the 16 different cases of the marching squares algorithm. A white vertex indicates that the vertex is outside the isosurface and
black indicates it is inside the isosurface. Every inside or outside case has it's counterpart. So we've reduced the number of cases down to 8. In case 0 and 15 for
instance, no lines have to be rendered, yet they are both very different cases. \\

The cases 5 and 10 are both ambiguous cases as becomes clear from the next image (figure 8). \\

\begin {center}
  \includegraphics[width=100mm]{ambiguous.png} \\
  Figure 8: Two ambiguous cases in the marching squares algorithm \\
\end {center}

\section{Difficulties}

The contouring algorithm is very simple to implement. Just follow the instructions of the method. Still our contour was not very smooth. It had sharp edges
everywhere and there was no smooth curve in the contour. The problem was with the intersection with the isovalue. We did'nt exactly follow the equation that was in
the study material. When we reverted to that equation the isolines where nice and smooth. \\
