.. _scalar-settings-tutorial:

###################################################
UnstructGrid: Set Scalar Settings on a Loaded Model
###################################################

.. image:: ../images/tut_scalarsettings.png
    :height: 300
    :align: center

The scalar result can be configured to make a better visual appearance of your result data, 
for instance settings such as legend scheme, legend range and filtering.

Each scalar result has its own settings.

This tutorial shows how to change scalar settings for visualized result. 

The demo model file (100x100x100.vtf) contains a simple geometry and a scalar result. 

This tutorial will show the scalar as fringes on the model, and set some scalar settings
for demonstration. 

-   Set number of legend levels to 5
-   Set color scheme to "Normal Inverted".
-   Filter away all values under 20.

Load the file and setup the model specification to show the result. For a more thorough 
explanation on creating a data source from a file interface and setup the model specification,
see the Load VFT tutorial:
:ref:`simple-load-vtf-tutorial`

.. note::
    This tutorial expect the application to have a correctly configured :class:`cee::vis::View`
    in place. See demo applications on how to set up a :class:`cee::vis::View` in your application.

**Load model**

Create the model and a VTF file interface data source. Open the file and set the created data
source in the model.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/ScalarSettings.cpp
    :language: cpp
    :lines: 48-50,52-57

**Setup model specification**

The model specification in this tutorial is set up with the first state and the model's only
scalar result set as fringes.

Use the information retrieved from the data source directory to set up the model specification.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/ScalarSettings.cpp
    :language: cpp
    :lines: 63-66,68-70

**Set result visibility**

Toggle on fringes visibility for all parts. For easy access 
to the settings for all available parts in a model, use the :class:`cee::ug::PartSettingsIterator`.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/ScalarSettings.cpp
    :language: cpp
    :lines: 73-78

**Set scalar settings**

Available scalar settings:

-   Range
-   Number of levels
-   Color scheme
-   Legend lines/text colors
-   Filtering
    
In this tutorial we will set number of levels, color scheme and filtering.

Get scalar settings for a specific scalar result by calling 
:func:`cee::ug::UnstructGridModel::scalarSettings()` with the requested scalar result id.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/ScalarSettings.cpp
    :language: cpp
    :lines: 81

Set number of legend levels to 5.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/ScalarSettings.cpp
    :language: cpp
    :lines: 84

Set the color scheme to normal inverted.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/ScalarSettings.cpp
    :language: cpp
    :lines: 87

Use filter to only show values elements where the result value is in the interval from 20 to 99. 
(The scalar result in this data source has a minimum value of 0 and a maximum value of 99.)

Toggle on filtering.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/ScalarSettings.cpp
    :language: cpp
    :lines: 90

**Set up the created model**

The model is ready to use and can be added to the view. Exactly where the view exists
depends on the platform and solution. These examples uses Qt and the view is set up 
in a :class:`cee::qt::ViewerWidget`.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/ScalarSettings.cpp
    :language: cpp
    :lines: 93,95,97


**See the complete source code here:**

:ref:`scalar-settings-example`
