UnstructGrid: Set vector settings on a loaded model

The vector result can be configured to make a better visual appearance of your result data, for instance settings such as scaling and coloring.

This example will show the vector result on the model, and set some vector settings for demonstration.

  • Set the relative scaling to 0.2.
  • Set single vector color to yellow.

The demo model file (10x10x10.vtf) contains a simple geometry and a vector result.

//--------------------------------------------------------------------------
// Load a UnstructGridModel from file and set a vector result
// Apply some vector settings
//--------------------------------------------------------------------------
// Create the model and data source
// Open the vtf file
cee::Str vtfFile = TutorialUtils::testDataDir() + "10x10x10.vtf";
if (!source->open(vtfFile))
{
// VTF file not found
return;
}
// Add the data source to the model
ugModel->setDataSource(source.get());
// Set the first state as current
std::vector<cee::ug::StateInfo> stateInfos = source->directory()->stateInfos();
int stateId = stateInfos[0].id();
ugModel->modelSpec().setStateId(stateId);
// Show the vector result on the model
std::vector<cee::ug::ResultInfo> vectorResultInfos = source->directory()->vectorResultInfos();
int vectorId = vectorResultInfos[0].id();
ugModel->modelSpec().setVectorResultId(vectorId);
// Set vector visible for all parts
while (it.hasNext())
{
cee::ug::PartSettings* partSettings = it.next();
partSettings->setVectorsVisible(true);
}
// Get vector settings for the current vector result
cee::ug::VectorSettings* settings = ugModel->vectorSettings(vectorId);
// Set relative scaling to 0.2
// Set single vector coloring to yellow for all vectors
settings->setSingleVectorColor(cee::Color3f(1.0, 1.0, 0.0));
// Add model to view. Ensure that old models are removed first
cee::vis::View* gcView = getTutorialView();
gcView->removeAllModels();
gcView->addModel(ugModel.get());
ugModel->updateVisualization();
cee::BoundingBox bb = gcView->boundingBox();
gcView->camera().fitView(bb, cee::Vec3d(0, 0, -1), cee::Vec3d(0, 1, 0));
gcView->requestRedraw();