.. _geometry-texture-tutorial:

##############################################
Geometry: Create a Geometry Model with Texture
##############################################


.. image:: ../images/tut_geometrytexture.png
    :height: 300
    :align: center
    
This tutorial shows how to create a :class:`geometry model <cee::geo::GeometryModel>` using the texture
effect to show a scalar result.

   
.. 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 and part**

Create the model and add it to the view.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModelWithTexture.cpp
    :language: cpp
    :lines: 51-52

Create data arrays of vertices and indices for the triangles. The part is a simple structure containing 
three adjacent triangles.

Build a indexed triangles part with the created vertices and indices.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModelWithTexture.cpp
    :language: cpp
    :lines: 55-69

**Create color legend and scalar mapper**

Create a color legend. Set title, size, text color and position it in the bottom left corner
of the view.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModelWithTexture.cpp
    :language: cpp
    :lines: 77-81

Create a color mapper with 16 uniform levels within the range from 0 to 100. Update the
legend with this color mapper.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModelWithTexture.cpp
    :language: cpp
    :lines: 84-87

**Map texture coordinates**

Create a :class:`Vec2f <cee::Vec2f>` array of texture coordinates. Use the created scalar mapper for
getting the texture coordinate for a specific scalar value.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModelWithTexture.cpp
    :language: cpp
    :lines: 95-101

**Create and add textures**

Create a texture image and update it from the scalar mapper.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModelWithTexture.cpp
    :language: cpp
    :lines: 109-110

Create an :class:`EffectTexture <cee::geo::EffectTexture>` configured for showing results with the texture created above 
and add the effect to the part.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModelWithTexture.cpp
    :language: cpp
    :lines: 113

Add the part to the model

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/GeometryModelWithTexture.cpp
    :language: cpp
    :lines: 119


**See the complete source code here:**

:ref:`geometry-texture-example`
