Geometry: Create a Geometry Model with Texture

../_images/tut_geometrytexture.png

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.

    cee::PtrRef<cee::geo::GeometryModel> model = new cee::geo::GeometryModel;
    gcView->addModel(model.get());

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);

    cee::PtrRef<cee::geo::Part> part = new cee::geo::Part;
    cee::PtrRef<cee::geo::DataIndexedTriangles> triangleData = new cee::geo::DataIndexedTriangles(vertices, indices);
    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.

    cee::PtrRef<cee::vis::OverlayColorLegendContinuousDomain> legend = new cee::vis::OverlayColorLegendContinuousDomain(cee::vis::Font::createNormalFont().get());
    legend->setTitle("Results Test \nGeometry Model");
    legend->setSize(100,500);
    legend->setTextColor(cee::Color3f(1,1,1));
    gcView->overlay().addItem(legend.get(), cee::vis::OverlayItem::BOTTOM_LEFT, cee::vis::OverlayItem::VERTICAL);

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

    cee::PtrRef<cee::vis::ScalarMapperFilledContoursUniform> mapper = new cee::vis::ScalarMapperFilledContoursUniform;
    mapper->setColors(cee::vis::ColorTableFactory::NORMAL, 16);
    mapper->setRange(0, 100);
    legend->setupFromScalarMapper(mapper.get());

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.

    part->settings().addEffect(cee::geo::EffectTexture::createResultMapping(textureImage.get()).get());

Add the part to the model

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

See the complete source code here:

Geometry: Create a Geometry Model with Texture