Geometry: Create a geometry model with texture

This tutorial shows how to create a geometry model using the texture effect to show a scalar result.

Note
This tutorial expect the application to have a correctly configured cee::vis::View in place. See demo applications on how to set up a cee::vis::View in your application.
Create model and part

Create the model and add it to the view.

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.

std::vector<cee::Vec3d> vertices;
vertices.push_back(cee::Vec3d(0,0,0));
vertices.push_back(cee::Vec3d(2,0,0));
vertices.push_back(cee::Vec3d(0,1,0));
vertices.push_back(cee::Vec3d(2,1,0));
vertices.push_back(cee::Vec3d(2,2,0));
std::vector<unsigned int> indices;
indices.push_back(0); indices.push_back(1); indices.push_back(3);
indices.push_back(0); indices.push_back(3); indices.push_back(2);
indices.push_back(2); indices.push_back(3); indices.push_back(4);
part->setData(triangleData.get());

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.

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

Map texture coordinates

Create a Vec2f array of texture coordinates. Use the created scalar mapper for getting the texture coordinate for a specific scalar value.

std::vector<cee::Vec2f> textureCoordinates;
textureCoordinates.push_back(mapper->mapToTextureCoordinate(2.0));
textureCoordinates.push_back(mapper->mapToTextureCoordinate(42.0));
textureCoordinates.push_back(mapper->mapToTextureCoordinate(93.0));
textureCoordinates.push_back(mapper->mapToTextureCoordinate(27.0));
textureCoordinates.push_back(mapper->mapToTextureCoordinate(68.0));
part->setTextureCoordinates(new cee::geo::TextureCoordinates(textureCoordinates));

Create and add textures

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

cee::PtrRef<cee::Image> textureImage = new cee::Image;
mapper->updateTexture(textureImage.get());

Create an EffectTexture configured for showing results with the texture created above and add the effect to the part.

Add the part to the model

model->addPart(part.get());

See the complete source code here:

Geometry: Create a geometry model with texture