.. _isovolume-tutorial:

#################################
UnstructGrid: Create an Isovolume
#################################

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

An isovolume is defined as the combined volume of the element model where the scalar field is 
between a given minimum and maximum value. The surface of the isovolume will be the hull of this volume.
Any element on the border of the model (a surface with no neighbor) is also included in the volume if 
if the value of that surface is in the given range.

Isovolumes may be computed from any scalar result. In addition, another scalar result can be 
mapped as fringes onto the isovolume, showing for instance the variation of temperature over a 
volume of of a given min and max pressure. 

This tutorial shows how to create an isovolume based on a scalar result id and a maximum and minimum 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/Isovolume.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/Isovolume.cpp
    :language: cpp
    :lines: 63-65

**Create the isovolume**

The isovolume is defined by a scalar result id and a minimum and a maximum scalar value.

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

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/Isovolume.cpp
    :language: cpp
    :lines: 68-69,71-75

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

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/Isovolume.cpp
    :language: cpp
    :lines: 78

Add the isovolume to the model.

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

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

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/Isovolume.cpp
    :language: cpp
    :lines: 84-89

**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/Isovolume.cpp
    :language: cpp
    :lines: 92,94

**See the complete source code here:**

:ref:`isovolume-example`

