.. _markup-tutorial:

###################################################
Visualization: Draw Bounding Box Using Markup Model
###################################################

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

This tutorial shows how to create a data source by loading a VTFx file and drawing the
models bounding box as a markup model.

After the unstructured grid model read from file is set up in the view, you can
get the bounding box for this model with :func:`cee::vis::View::boundingBox()`. Use the values
from this bounding box to make a markup model for drawing a bounding box around the 
read model.

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

Set the first state as current.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/MarkupModel.cpp
    :language: cpp
    :lines: 48,51-52,54-60, 62

Set the first state as current in the model specification.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/MarkupModel.cpp
    :language: cpp
    :lines: 65-70

**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/MarkupModel.cpp
    :language: cpp
    :lines: 74-76

**Create the markup model**

Create the markup model object.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/MarkupModel.cpp
    :language: cpp
    :lines: 79

Get the bounding box from the view and get all vertices in the box.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/MarkupModel.cpp
    :language: cpp
    :lines: 83-91

Add all the lines of the bounding box to the model.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/MarkupModel.cpp
    :language: cpp
    :lines: 94-107

Add the markup model to the view

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/MarkupModel.cpp
    :language: cpp
    :lines: 110

Update the view.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/MarkupModel.cpp
    :language: cpp
    :lines: 112-115


**See the complete source code here:**

:ref:`markup-example`
