# UnstructGrid: Create an Isosurface

An isosurface is a surface defined of an area with a constant value within a volume of space.

Isosurfaces may be derived based on any scalar variable. In addition, scalar fringes can be mapped onto the isosurface, showing for instance the variation of temperature over a surface of Constant pressure. Any number of isosurfaces can be defined and displayed, and various display attributes can be set separately for each one.

This tutorial 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 geometry with four parts. This tutorial will use the displacement result to define the isosurface.

Load the file and setup the model specification to show the result. For a more thorough explanation on creating a data source from a file interface and setup the model specification, see the Load VFTx tutorial: UnstructGrid: Load Model from File and Set Up Model Specification

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.

Load model

Create the model and a VTFx file interface data source. Open the file and set the created data source in the model.

        cee::PtrRef<cee::ug::UnstructGridModel> ugModel = new cee::ug::UnstructGridModel();
        cee::PtrRef<cee::ug::DataSourceVTFx> source = new cee::ug::DataSourceVTFx(42);

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

        ugModel->setDataSource(source.get());

Set the fourth state as current in the model specification. (The displacement is zero in the first state.)

        std::vector<cee::ug::StateInfo> stateInfos = source->directory()->stateInfos();
        int stateId = stateInfos[3].id();
        ugModel->modelSpec().setStateId(stateId);

Create the isosurface

The isosurface is defined by a scalar result id and a iso scalar value.

Create the isosurface object. Remember that the object is reference counted and should not be created on the stack.

        cee::PtrRef<cee::ug::Isosurface> isoSurface = new cee::ug::Isosurface();
        std::vector<cee::ug::ResultInfo> resultInfos = source->directory()->scalarResultInfos();
        int scalarId = resultInfos[0].id();
        isoSurface->setIsoScalarResultId(scalarId);
        isoSurface->setIsoValue(6.5);

Set the scalar result to be shown as mapped fringes on the isosurface surface.

        isoSurface->setMapScalarResultId(scalarId);

Add the isosurface to the model.

        ugModel->addIsosurface(isoSurface.get());

To get a better view of the cutting plane inside the model, set all normal parts draw style to LINES.

        cee::ug::PartSettingsIterator it(ugModel.get());
        while (it.hasNext())
        {
            cee::ug::PartSettings* partSettings = it.next();
            partSettings->setDrawStyle(cee::ug::PartSettings::OUTLINE);
        }

Set up the created model

The model is ready to use and can be added to the view. Exactly where the view exists depends on the platform and solution. These examples uses Qt and the view is set up in a `cee::qt::ViewerWidget`.

        cee::vis::View* gcView = getTutorialView();
        gcView->addModel(ugModel.get());

See the complete source code here:

UnstructGrid: Create an Isosurface

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your Docs generative AI assistant. Ask me anything about HOOPS Envision for Desktop or choose a sample question below to start a conversation:

What is HOOPS Envision for Desktop?
What are the latest release notes for HOOPS Envision for Desktop?
How do I start evaluating HOOPS Envision for Desktop?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...