# Difference between revisions of "ParaView/Line Integral Convolution"

## Introduction

 Figure 1b Surface LIC applied to a multiblock CFD simulation of a NASA launch vehicle. Figure 1c Detail view of figure 1b. Figure 1a Surface LIC applied to a contour of a CFD simulation of air flow in an office. Figure 1 Examples of ParaView's surface LIC in action.

The line integral convolution(LIC) vector field visualization technique convolves noise with a vector field producing streaks along vector field tangents. Originally the technique was developed for use with 2D image based data but has since been extended to use on arbitrary surfaces and volumes. ParaView supports LIC on arbitrary surfaces via the Surface LIC plugin. ParaView's surface LIC implementation has been designed to work with composite data in parallel and includes a number of customizations that facilitate interactive data exploration. Some examples are shown in Figure 1.

## Pipeline

 Figure 2 Pipeline internals. Figure 2a (left) Surface LIC pipeline. Figure 2b (right) Internal image LIC pipeline.

The surface LIC algorithm projects vectors defined on an arbitrary surface onto the surface and then from physical space into screen space where an image LIC is computed. After the image space LIC computation scalar colors may be combined with the resulting LIC using a variety of specialized shaders. When running in parallel guard pixels are needed for the image LIC computation and the transition from from world space to screen space necessitates a compositing step to make the screen space vector field consistent where there are overlapping screen space areas across processes. A schematic of the algorithm is presented in figure 2a. Optional processing stages are shaded gray, cached textures are represented by red parallelograms, and green double arrows indicate inter-process communication that occurs only during parallel operation. On the right half of the figure a break-out diagram detailing the processing stages used in our image LIC algorithm are shown. Our image LIC algorithm is implemented in two passes. In the first pass, fragments are masked based on user provided criteria then a basic LIC is computed. In the second pass, the result of the first pass is run through contrast and edge enhancement stages before being used as "noise" texture in the second LIC pass. The second pass substantially improves the visual quality of the streaks. Finally optional anti-aliasing and contrast enhancement stages are applied.

## Noise generator

 Figure 4. LIC of ion velocity colored by velocity magnitude. Fragments with ${\displaystyle |V_{i}|<=1e^{-5}}$ were masked. The difference between the left an right panels is achieved by varying the parameters of the input noise.

Given a noise dataset and vector field, the resulting streaking patterns produce by the LIC can vary widely based on the choice of screen resolutions and camera view parameters. The statistical properties of the noise dataset also play an important role in determining the characteristics of streaking patterns produced. Varying properties of the noise can be an effective method for controlling streaking characteristics in the resulting LIC. For these reasons a run time tune-able noise texture generator is a key component in ParaView's implementation. ParaView's noise texture generator defines the following 9 run time modifiable degrees of freedom, which together provide an effective means for controlling streaking pattern, dynamic range, and contrast, in in the resulting LIC. For example, by varying the impulse probability along with the choice of background intensity control over number of light or dark pixels in the LIC image is attained. Varying the noise grain size along with impulse probability and impulse background back color give greater control over the width of the streaks generated by the image LIC stage. With the ability to selecting a noise distribution, its minimum, maximum, and number of noise levels, control over the contrast is gained. Figure 4 shows an example of how noise data set parameters may be used to control the streaking patterns produced by the LIC.

 Noise generator parameters Noise type This parameter controls the underlying statistical distribution of values in the generated noise texture, or type of noise generated. The user may choose from Gaussian noise, uniformly distributed noise, or Perlin noise. By default Gaussian noise is used. Texture size This parameter controls the size of the square noise texture in each direction. Support for non-power of 2 textures is assumed. However in the case of Perlin noise the texture size is adjusted to the nearest power of 2. Grain size Select the number of pixels in each direction that each generated noise element fills in the resulting texture. For Perlin noise this sets the size of the largest scale, and must be a power of 2. Min value This parameter sets the lowest gray scale value realizable in the generated noise texture. This parameter can range between 0 and 1 and the default value is 0. Max value This parameter sets the highest gray scale value realizable in the generated noise texture. This parameter can range between 0 and 1 and the default value is 0.8. Number of levels Set the number of realizable gray scale values. This parameter can range from 2 to 1024 and the default value is 1024. Impulse probability This parameter controls how likely a given element is to be assigned a value. When set to 1 all elements are filled. When set to some number lower than one a fraction of the texture's elements are filled with generated noise. Elements that are not filled take on a background color value. The default impulse probability is 1. Background color The gray scale value to use for untouched pixels when the impulse probability parameter is set less than 1. The default background value is 0. RNG seed Modify the seed value of the random number generators. Figure 5 Varying properties of the noise input to the image LIC can be an effective method for controlling streaking characteristics in the resulting LIC. Gaussian, uniform, Perlin, and impulse noise are shown.

Figure 3 Scalar color shaders. Blending (left column) lit colored geometry with the LIC compared to mapping (right column) them onto the LIC, with (bottom row) and without (top row) scalar colors mapped onto the lit surface rendering.

Prior to computing the LIC in image space lighting calculations and mapped scalar colors are applied to surface geometry and stored in texture. Once the LIC has been computed and stored in a texture, these two textures are combined to produce the final lit colored rendering. ParaView implements two algorithms for blending rendering of lit colored geometry with the LIC, a multiplicative or mapping approach and an additive or blending approach. In addition an algorithm for coloring masked fragments is provided.

### Mapping colors onto the LIC

The mapping approach is described by the following equation:

${\displaystyle \left.c_{ij}=(L_{ij}+f)*S_{ij}\right.}$

where the indices ${\displaystyle i,j}$ identify a specific fragment, ${\displaystyle c}$ is the final RGB color, ${\displaystyle L}$ is LIC gray scale intensity, ${\displaystyle S}$ is the scalar RGB color, and ${\displaystyle f}$ is a biasing parameter, typically 0, that may be used for fine tuning. When ${\displaystyle f=0}$, the typical case, colors are transferred directly to the final image where the LIC is 1, and a linearly scaled transfer of scalar colors where LIC gray scale color is less than one down to 0, where the final color is black. The bias parameter ${\displaystyle f}$ may be set to small positive or negative values between -1 and 1 to increase or decrease LIC values uniformly resulting in brighter or darker images. When ${\displaystyle f!=0}$ final fragment colors, ${\displaystyle c}$, are clamped such that ${\displaystyle 0<=c<=1}$.

With the mapping approach the distribution of intensity values in the LIC directly affect the accuracy and intensity with which scalar colors and lighting effects are transfered to the final result and the average brightness and contrast of the result. Note in the final result that individual RGB channel values will be less then or equal to the maximum grayscale value in the image LIC. Also, the greater the number of pixels close to 1 in the image LIC, the more acurately and intensly scalar coloring and lighting are transferred into the final image. However, this must be balanced with a sufficient number of highly contrasting pixels where the value is closer to 0 in order to accurately represent the LIC pattern. Put sucinctly it's critical that the image LIC has high contrast and dynamic range with a good mix of light and dark values if it is to be effectively mapped onto scalar colors. However, the convolution process inherently reduces both contrast and dynamic range in the image LIC. To correct this we've introduced contrast enhancment stages in three places in the pipeline. An example demonstrating the effectiveness of the contrast enhancement stages is shown in figure \ref{fig:cce-khb}.

### Blending colors with the LIC

The blending approach for combining scalar colors, lighting effects, and the image LIC is described by the following equation:

${\displaystyle \left.c_{ij}=L_{ij}*I+S_{ij}*(1-I)\right.}$

where the indices ${\displaystyle i,j}$ identify a specific fragment, ${\displaystyle c}$ is final RGB color, ${\displaystyle L}$ is LIC gray scale value, ${\displaystyle S}$ is the scalar RGB color, and ${\displaystyle I}$ is a constant ranging from 0 to 1, with a default of 0.8. Decreasing ${\displaystyle I}$ to obtain brighter colors diminishes the intensity of the LIC, and vise versa. When colors are bright the LIC is difficult to see. Currently, the best results are obtained by sacrificing slightly on both fronts. The blending approach benefits from an image LIC with high contrast and dynamic range as this tends to make patterns in the image LIC more easily visible after blending. Note that despite the fact that it inherently decreases visibility of features in scalar coloring and image LIC, the blending approach is especially useful with curved surfaces and pronounced lighting effects and also when scalar color map is very intense.

Masking is a technique that provides a specialized shader for handling the blending of fragments that have a vector magnitude below a user provided threshold. The masking test may be applied either to the original vectors or the surface projected vectors. For fragments with magnitude below the user supplied threshold, ParaView's implementations can render:

1. unmodified noise data
2. lit scalar colored geometry directly
3. blend the rendering of lit scalar colored geometry with a mask color

Fragments are masked according to the following equation:

${\displaystyle \left.c_{ij}=M*I+S_{ij}*(1-I)\right.}$

where the indices ${\displaystyle i,j}$ identify a specific fragment, ${\displaystyle c}$ is final RGB color, ${\displaystyle M}$ is the RGB mask color, ${\displaystyle S}$ is the scalar RGB color, and ${\displaystyle I}$ is the mask color intensity. This allows one control over the masking process so that masked fragments may be: highlighted (by setting a unique mask color and mask intensity > 0), made invisible with and without passing the un-convolved noise texture (by setting mask intensity 0), or made to show the scalar color at a similar level of intensity as the LIC (mask intensity > 0).

## Contrast enhancement

The convolution process tends to decrease both contrast and dynamic range narrowing and concentrating the distribution of intensity values around a mid tone which tends to darken and dull the final result making the combination with scalar colors and light fragments difficult. Using Gaussian noise during LIC computation often produces relatively higher quality streaking in the LIC but tends to make this narrowing effect worse since the input intensities are already concentrated about a mid tone. In order to counteract this, optional contrast enhancement (CE) stages have been added. The new stages increase the dynamic range and contrast, improve the streaking patterns that emerge during the convolution process and facilitate combination of scalar colors. Three CE stages have been added, one after each LIC stage and one after the combination of scalar colors and LIC.

 Figure 3a Input and output of first image LIC CE stage with histogram. Figure 3b Input and output of the second image LIC CE stage. Figure 3c Input and output of the surface LIC painter color CE stage. Figure 3 Intermediate results showing the input and output of contrast enhancement stages. In these figures the vertical lines show the min and max values in the inputs. The contrast enhancement algorithm works by stretching the distributions so that the min is 0 and the max is 1 effectively increasing the contrast and dynamic range in the final rendered image.

### Image LIC CE stages

The LIC CE stages are implemented by histogram stretching of the gray scale colors in the LIC'ed image as follows:

${\displaystyle \left.c_{ij}={\frac {c_{ij}-m}{M-m}}\right.}$

where, the indices ${\displaystyle i,j}$ identify a specific fragment, ${\displaystyle c}$ is the fragment's gray scale color, ${\displaystyle m}$ is the gray scale color value to map to 0, ${\displaystyle M}$ is the gray scale color value to map to 1. When the contrast enhancement stage is applied on the input of the high-pass filter stage, ${\displaystyle m}$ and ${\displaystyle M}$ are always set to the minimum and maximum gray scale color of all fragments. In the final contrast enhancement stage ${\displaystyle m}$ and ${\displaystyle M}$ take on minimum and maximum gray scale colors by default but may be individually adjusted by the following set of equations:

${\displaystyle \left.m=min(C)+F_{m}*(max(C)-min(C))\right.}$

${\displaystyle \left.M=max(C)-F_{M}*(max(C)-min(C))\right.}$

where, ${\displaystyle C=\{c_{00},c_{01},...,c_{nm}\}}$, are all of the gray scale fragments in the LIC image and ${\displaystyle F_{m}}$ and ${\displaystyle F_{M}}$ are adjustment factors that take on values between 0 and 1. When ${\displaystyle F_{m}}$ and ${\displaystyle F_{M}}$ are 0 minimum and maximum are gray scale values are used. This is the default. Adjusting ${\displaystyle F_{m}}$ and ${\displaystyle F_{M}}$ above zero controls the saturation of normalization. This is useful, for example, if the brightness of pixels near the border dominate because these are convolved less because we can't integrate outside of the dataset.

The two LIC CE stages are controlled together, and only the final CE stage make use of the saturation tuning. In other words when two pass LIC is enabled the first LIC CE stage map the input distribution onto the range 0 to 1. Occasionally, often depending on the contrast and dynamic range and graininess of the noise texture, somewhat jagged or pixelated patterns may emerge in the LIC. These can be reduced by enabling the optional anti-aliasing (AA) stage. The AA stage, when enabled, is applied to the input of the final LIC CE stage.

 Figure 4. Improving the transfer of scalar coloring via CE stages. Visualization of surface LIC of magnetic field colored by magnetic field magnitude. Figure 4a (left) Without CE stages. Figure 4b (right) With CE and CCE stages enabled. Figure 3c Input and output of the surface LIC painter color CE stage. Figure 3 Intermediate results showing the input and output of contrast enhancement stages. In these figures the vertical lines show the min and max values in the inputs. The contrast enhancement algorithm works by stretching the distributions so that the min is 0 and the max is 1 effectively increasing the contrast and dynamic range in the final rendered image.

### Painter CE stage

After the combination of lighting computations and mapped scalar colors with the LIC an option color contrast enhancement (CCE) stage may be applied. The CCE stage is implemented using histogram stretching on the fragments lightness in the HSL color space.

${\displaystyle \left.L_{ij}={\frac {L_{ij}-m}{M-m}}\right.}$

where, the indices ${\displaystyle i,j}$ identify a specific fragment, ${\displaystyle L}$ is the fragment's lightness in HSL space, ${\displaystyle m}$ is the lightness to map to 0, ${\displaystyle M}$ is the lightness to map to 1. ${\displaystyle m}$ and ${\displaystyle M}$ take on minimum and maximum lightness over all fragments by default but may be individually adjusted by the following set of equations:

${\displaystyle \left.m=min(L)+F_{m}*(max(L)-min(L))\right.}$

${\displaystyle \left.M=max(L)-F_{M}*(max(L)-min(L))\right.}$

where, ${\displaystyle L}$ are fragment lightness values and ${\displaystyle F_{m}}$ and ${\displaystyle F_{M}}$ are the adjustment factors that take on values between 0 and 1. When ${\displaystyle F_{m}}$ and ${\displaystyle F_{M}}$ are 0 minimum and maximum are lightness values are used. This is the default. Adjusting ${\displaystyle F_{m}}$ and ${\displaystyle F_{M}}$ above zero provides fine-tuning control over the saturation.

 Figure 4. Improving the transfer of scalar coloring via CE stages. Visualization of surface LIC of magnetic field colored by magnetic field magnitude. Figure 4a (left) Without CE stages. Figure 4b (right) With CE and CCE stages enabled.

### Integrator Normalization

vec-norm.png

 Caption caption

Normalizing vectors during integration is a trick that can be used to simplify integrator configuration and give the resulting LIC a uniformly smooth look. By using normalized vector field values the convolution occurs over the same integrated arclength for all pixels in the image. This gives the result a smooth and uniform look and makes it possible to provide reasonable default values for step size and number of steps to the integrator independent of the input vector field. The resulting visualization accurately shows the tangent field however variations in the relative strength of the vector field is lost and can alter the relationships of flow features making weak features prominent and strong features less so. In the context of developing a general purpose tool for interactive data exploration it's important to provide both options and let the user select the option that best fits her needs. For example figure \ref{fig:vec-norm} shows the result of the algorithm applied to a simulation of magnetic reconnection in a hot plasma with and without integrator normalization. In this case normalization can give a false sense of the importance of a number of flow features.

# PV DOC

${\displaystyle \operatorname {erfc} (x)={\frac {2}{\sqrt {\pi }}}\int _{x}^{\infty }e^{-t^{2}}\,dt={\frac {e^{-x^{2}}}{x{\sqrt {\pi }}}}\sum _{n=0}^{\infty }(-1)^{n}{\frac {(2n)!}{n!(2x)^{2n}}}}$


${\displaystyle c_{ij}=L_{ij}*I+S_{ij}*(1-I)}$

# Surface LIC Plugin Parameters

## Integrator

Select Input Vectors
This is used to select the vector field.
Number Of Steps
Number of integration steps.
Step Size
Step size given in the original vector field's units.
Normalize Vectors
When on the vector field will be normalized during integration. Normalization doesn't change the tangent field and makes it so the same step size and number of steps parameters work well on a variety of data. Disabling normalization can help reveal relationships between individual flow features.
Enhanced LIC
Enabling enhanced LIC activates an algorithm sub-pipeline that applies some image processing techniques to improve the visibility of streaking patterns in the result. The enhanced LIC algorithm requires two LIC passes. In the first pass a traditional LIC is computed, in the second pass image processing is applied to the output of pass 1 which is then used in place of noise in the second LIC pass over 1/2 of the number of integration steps.

Color Mode
This selects the shader that is used to combine mapped scalar colors with the gray scale LIC.
Blend
LIC and mapped scalar colors are combined in inverse proportion to produce the final color, $$c_{ij} = L_{ij} * I + S_{ij} * (1 - I)$$
Multiply
LIC and mapped scalar colors are multiplied together to produce the final color, $$c_{ij} = ( L_{ij} + f ) * S_{ij}$$
LIC Intensity
This sets the intensity for LIC pattern when using Blend shader.
Map Mode Bias
An additive term that could be used to brighten or darken the final colors when using the Multiply shader.

### Contrast Enhancement

The contrast enhancement(CE) feature applies an image processing technique called histogram stretching at various points in the algorithm to increase contrast and dynamic range in the LIC streaks and final colored image. We've used CE in three places internally. A gray scale implementation occurs after each LIC pass and a color based implementation after scalar colors and LIC have been combined. The latter is referred to as color contrast enhancement(CCE) and is applied in HSL space on the L channel but in other respects is similar to the gray scale implementation.

We've implemented this as follows: $$c_{ij} = \frac{c_{ij} - m}{M - m}$$ where, the indices $i,j$ identify a specific fragment, $c$ is the fragment's gray scale intensity (or HSL lightness for CCE), $m$ is the gray scale color value to map to 0, $M$ is the gray scale color value to map to 1. When the contrast enhancement stage is applied on the input of the high-pass filter stage, $m$ and $M$ are always set to the minimum and maximum gray scale color of all fragments. In the final contrast enhancement stage $m$ and $M$ take on minimum and maximum gray scale colors by default but may be individually adjusted by the following set of equations: $$m = min(C) + F_{m} * ( max(C) - min(C) )$$ $$M = max(C) - F_{M} * ( max(C) - min(C) )$$ where, $C = \{c_{00},c_{01},...,c_{nm}\}$, are all of the gray scale(L channel) fragments in the image and $F_m$ and $F_M$ are adjustment factors that take on values between 0 and 1. When $F_m$ and $F_M$ are 0 minimum and maximum are input values are used. This is the default. Adjusting $F_m$ and $F_M$ above zero controls the saturation of normalization. This is useful, for example, if the brightness of pixels near the border dominate because these are convolved less because we can't integrate outside of the dataset.

Enhance Contrast
Low LIC Contrast Enhancement Factor
This can be used to adjust the minimum value in the output of the contrast enhancement. This applies only to the final CE stage in the LIC.
High LIC Contrast Enhancement Factor
This can be used to adjust the minimum value in the output of the contrast enhancement. This applies only to the final CE stage in the LIC.
Low Color Contrast Enhancement Factor
High Color Contrast Enhancement Factor

AntiAlias

## Noise texture generator

Generate Noise Texture
Noise Type
Noise Texture Size
Noise Grain Size
Min Noise Value
Max Noise Value
Number Of Noise Levels
Impulse Noise Probability
Impulse Noise Background Value
Noise Generator Seed

## Parallelization

Composite Strategy

Use LIC For LOD