.. _isosurface-tutorial:

##################################
UnstructGrid: Create an Isosurface 
##################################

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

An isosurface is a surface defined of an area with a constant value within a volume of space.

Isosurfaces may be derived based on any scalar variable. In addition, scalar fringes can be 
mapped onto the isosurface, showing for instance the variation of temperature over a surface 
of Constant pressure. Any number of isosurfaces can be defined and displayed, and various display 
attributes can be set separately for each one.

This tutorial shows how to create an isosurface based on a scalar result id and a scalar value.
In addition, the scalar result will be shown as fringes on the isosurface.

The demo file (contact.vtfx) contains a geometry with four parts. This tutorial will use the 
displacement result to define the isosurface.

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 VFTx 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 VTFx file interface data source. Open the file and set the created data
source in the model.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/Isosurface.cpp
    :language: cpp
    :lines: 48-50,52-58,60

Set the fourth state as current in the model specification. (The displacement is zero in the first 
state.)

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/Isosurface.cpp
    :language: cpp
    :lines: 63-65

**Create the isosurface**

The isosurface is defined by a scalar result id and a iso scalar value.

Create the isosurface object. Remember that the object is reference counted and should not
be created on the stack.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/Isosurface.cpp
    :language: cpp
    :lines: 68,71-74

Set the scalar result to be shown as mapped fringes on the isosurface surface.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/Isosurface.cpp
    :language: cpp
    :lines: 77

Add the isosurface to the model.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/Isosurface.cpp
    :language: cpp
    :lines: 80

To get a better view of the cutting plane inside the model, set all normal parts draw style to
LINES.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/Isosurface.cpp
    :language: cpp
    :lines: 83-88

**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/Isosurface.cpp
    :language: cpp
    :lines: 91,93

**See the complete source code here:**

:ref:`isosurface-example`

