.. _cutting-plane-tutorial:

######################################################################
UnstructGrid: Create a Cutting Plane with a Scalar Result as Fringes
######################################################################

.. image:: ../images/tut_cuttingplane.png
    :height: 300
    :align: center
    
Cutting planes are slices through the structure onto which scalar and vector fields can be 
visualized. By dynamically changing the position and orientation of the cutting plane, you can 
quickly analyze the results inside the system.

Each cutting plane can have its own settings and be moved individually.

This tutorial shows how to create a cutting plane and show a scalar result mapped as fringes to the surface.

The demo file (30x30x30.vtf) contains a single part geometry with a synthetic scalar result. 

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 the 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/CuttingPlane.cpp
    :language: cpp
    :lines: 48,49,52-57,60

Set the first state as current in the model specification.

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

Find the id of the first scalar result from the data source's directory.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/CuttingPlane.cpp
    :language: cpp
    :lines: 68-69

**Create cutting plane**

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

The cutting plane is defined by a point in the plane and the normal to the plane.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/CuttingPlane.cpp
    :language: cpp
    :lines: 72-74

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

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

Add the cutting plane to the model.

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


To get a better view of the cutting plane inside the model, set all parts to transparent.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/CuttingPlane.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/CuttingPlane.cpp
    :language: cpp
    :lines: 91,93,95

**See the complete source code here:**

:ref:`cutting-plane-example`
