\chapter{Color mapping}

In chapter 2 it was seen from figure (figure 2) that the fluid had a very bright grey color. How is this color determined at every vertex?

\section{Description}

The technique that maps a value to a specific color is called color mapping. It has already been explained that the simulation is divided into cells with each 4 vertices that can contain different values, a uniform quad grid. A colormap calculates the color, given a certain colormap function, for every value at a vertex. \\

Example:
In figure 2 the smoke was using a grey scaled colormap. If the value of vertices range from 0 to 1, the value can be used to determine each color aspect, red, green and blue. This means, for each vertex:

$$ red = green = blue = value $$

To be able to reason about the colored images, a legend at the top of the screen was added. The leftmost colors indicate low values and the rightmost colors indicate high values. With such a colormap legend, it's easier to understand the produced images and say something about the value of the fluid. \\

Using a slider it is possible to change the number of colors. By default this value is set to 256 colors, but this is easily changed to anything below that. At lower number of colors big bands of colors will start to appear making variations more visible. \\

\section{Implementation}

Next to the 3 supplied colormaps 5 additional colormaps where added. Three of these where only contain one color, red, green or blue. These are not only useful for isolines but also when wanting to see height plots, but not get distracted by the flow of density. The remaining two colormaps are the "Wilrik" colormap, it implements a fire elemental color scheme and the "Oliver" colormap which may seem like a weird odd map, not like a colormap at all. It does serve a purpose however, it allows to easily see rapid changing values. \\

\begin {center}
  \includegraphics[width=100mm]{wilrik.png} \\
  Figure 3: A fire colormap \\
\end {center}

The fire color is determined as follows:

$$ red = value; green = value / 3; blue = 0; $$

If the value is high, a lot of red, one third of green and no blue is taken. Low values only get a bit of red and almost no green. This gives a black to dark red to orange to almost yellow colormap giving the illusion of fire. \\

To create a repeating band of colors, the following formula was used:

$$ value = (((int)(value * 100)) \texttt{ mod } 10)/10 $$

By first multiplying our value by 100 and converting it to an integer the value get's reduced in significance. If this would be divided by 100 again the result would be 100 different bands of color. By taking the module of 10 first however, a repeating sequence of bands is achieved. To compensate for the earlier multiplication of 100 it's required to devide by 10 once more, as color values are set to be between 0 and 1. \\

\section{Difficulties}

The last mechanisms to implement for this assignment were scaling and clamping. With clamping the user is able to set a minimum and maximum for the values. This is done by first enabling clamping and then clicking on in the bottom half of the color legend and drag the minimum and maximum clamping indictors, which are white. Actual data lower then the minimum or higher than the maximum calculated value are then clamped to the this minimum and maximum respectively. \\

The (auto)scaling mechanism was a bit more subtle. When enabled, the scaling is set in the same way as the clamping but for the top half of the legend bar, marked in red. For the auto-scaling bit, the minimum and maximum values are stored and the entire frame and is mapped to the visible colormap. This is was quite trivial, was it not that the values could also be negative. Something that went unnoticed until divergence was implemented. \\
