.. _geometry-tutorial:

#################################
Geometry: Create a Geometry Model 
#################################

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

This tutorial shows how to create a :class:`geometry model <cee::geo::GeometryModel>` with different parts and effects.

This tutorial creates two triangle parts and two polyline parts. All parts has color effects.
The second triangle and the second polyline will have the halo effect applied.


.. 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.

**Create model**


Create the model and add it to the view.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModel.cpp
    :language: cpp
    :lines: 49-50


**Set vertices and indices**

Create data arrays of vertices and indices for the triangle parts and polyline parts.
The second triangle will use the same vertices and indices as the first, but apply a transformation.
The two polyline parts will have separate vertices, but share the same array of indices. (They have the same 
connectivities, but different coordinates.)

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModel.cpp
    :language: cpp
    :lines: 57-87

**Create part data and build parts**

Create a :class:`Data <cee::geo::Data>` for each of the triangles and polylines. The part data binds vertices and 
indices and can be used in one or more parts. We only create one part data for triangles, as this will be 
used for both triangle parts below. 

The triangles will be :class:`DataIndexedTriangles <cee::geo::DataIndexedTriangles>` objects, while
the polylines will be :class:`DataIndexedPolylines <cee::geo::DataIndexedPolylines>` objects.

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


Build the parts using the corresponding data parts. Notice that both the triangles uses the same
data part, but the second triangle has a transformation to move it to a separate position.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModel.cpp
    :language: cpp
    :lines: 114-129


**Add effects**

In this tutorial we will draw the triangles with the color red. The lines will be colored blue. The second triangle
and the second polyline will get a halo effect. The halo effect draws a part with silhouetted edges.

Create the effects:

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModel.cpp
    :language: cpp
    :lines: 136-145


Add the effects to the parts:

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModel.cpp
    :language: cpp
    :lines: 152-164

We're done. Add all the parts to the model:

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModel.cpp
    :language: cpp
    :lines: 170-173


**See the complete source code here:**

:ref:`geometry-example`

