\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 more or less follows a given value. If the values of a field ranges from 0 to 1, a good threshold would be 0.6. An isoline could then visualize the points that equal the value of 0.6. \\

The simulation program is able to set a certain the number of isolines with a minimum and maximum values between two 'contour'-isolines. \\

\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}

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. \\

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

If a vertex, $ 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}

Above the 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 its counterpart. Since some cases are equal, they can be reduced to 8. In case 0 and 15 for example, no lines have to be rendered, yet they are both different cases. \\

Cases 5 and 10 are also 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 following the instructions of this previous method. Initially the contour was not very smooth. It was jaggy and had sharp edges everywhere. There was no smooth curve in the contours anywhere. The problem laid within the intersection with the isovalue. After reverting to this method, rather then something self-constructed, the isolines where nice and smooth. \\
