UnstructGrid: Create an Isosurface

An isosurface is a surface defined of an area with a constant value within a volume of space. Several visual settings can be applied to the isosurface, such as mapped fringes, visibility and highlighting.

This example shows how to create an isosurface based on a scalar result id and a scalar value. In addition, the scalar result will be shown as fringes on the isosurface.

The demo file (contact.vtfx) contains a simple model with various results. In this tutorial you will ‘ create an isosurface for the “All displacements” result with iso scalar value == 6.5 for time step 4.

void TutorialRunnerMainWindow::addIsosurface()
    // Load an UnstructGridModel from file
    // Create an isosurface

    // Create the model and data source
    cee::PtrRef<cee::ug::UnstructGridModel> ugModel = new cee::ug::UnstructGridModel();
    cee::PtrRef<cee::ug::DataSourceVTFx> source = new cee::ug::DataSourceVTFx(42);

    // Open the VTFx file
    cee::Str vtfxFile = TutorialUtils::testDataDir() + "contact.vtfx";
    if (!source->open(vtfxFile, 0))
        // VTFx file not found

    // Add the data source to the model

    // Set the fourth state as current. 
    std::vector<cee::ug::StateInfo> stateInfos = source->directory()->stateInfos();
    int stateId = stateInfos[3].id();

    // Create a new isosurface object and set the scalar result id and iso scalar value used to calculate the isosurface topography.
    cee::PtrRef<cee::ug::Isosurface> isoSurface = new cee::ug::Isosurface();

    // User "displacements" scalar result
    std::vector<cee::ug::ResultInfo> resultInfos = source->directory()->scalarResultInfos();
    int scalarId = resultInfos[0].id();

    // Set the same result mapped on the surface also

    // Add the isosurface to the model

    // To be able to see the isosurface inside the part, set draw styles to LINES for all parts
    cee::ug::PartSettingsIterator it(ugModel.get());
    while (it.hasNext())
        cee::ug::PartSettings* partSettings = it.next();

    // Add model to view. Ensure that old models are removed first
    cee::vis::View* gcView = getTutorialView();


    cee::BoundingBox bb = gcView->boundingBox();
    gcView->camera().fitView(bb, cee::Vec3d(0, 0, -1), cee::Vec3d(0, 1, 0));