Skip to content

Commit

Permalink
Coloring: Split --scalars in two options, --scalar-coloring and `…
Browse files Browse the repository at this point in the history
…--coloring-array`

 - Remove `--scalars, -s`
 - Introduce `--scalar-coloring, -s` option and corresponding libf3d option
 - Introduce `coloring-array` option and corresponding libf3d option
 - Update tests and configs
 - Add an `enable` boolean to the SetColoring API
 - Update API usage in window and interactor
 - Remove fully F3D_RESERVED* constants
  • Loading branch information
mwestphal committed Sep 1, 2024
1 parent a7912e6 commit 63c1865
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 60 deletions.
7 changes: 4 additions & 3 deletions application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ static inline const std::vector<CLIGroup> CLIOptions = {
{"blur-coc", "", "Blur circle of confusion radius", "<value>", ""},
{"light-intensity", "", "Light intensity", "<value>", ""} } },
{"Scientific visualization",
{ {"scalars", "s", "Color by scalars", "<array_name>", "f3d_reserved_true" }, // TODO
{"comp", "y", "Component from the scalar array to color with. -1 means magnitude, -2 or the short option, -y, means direct scalars", "<comp_index>", "-2"},
{"cells", "c", "Use a scalar array from the cells", "<bool>", "1"},
{ {"scalar-coloring", "s", "Color by a scalar array", "<bool>", "1" },
{"coloring-array", "", "Name of the array to color with", "<array_name>", "" },
{"comp", "y", "Component from the array to color with. -1 means magnitude, -2 or the short option, -y, means direct scalars", "<comp_index>", "-2"},
{"cells", "c", "Use an array from the cells", "<bool>", "1"},
{"range", "", "Custom range for the coloring by array", "<min,max>", ""},
{"bar", "b", "Show scalar bar", "<bool>", "1" },
{"colormap-file", "", "Specify a colormap image", "<filePath/filename/fileStem>", ""},
Expand Down
3 changes: 2 additions & 1 deletion application/F3DOptionsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ static inline const std::map<std::string_view, std::string_view> LibOptionsNames
{ "metadata", "ui.metadata" },
{ "blur-background", "render.background.blur" },
{ "blur-coc", "render.background.blur_coc" },
{ "scalars", "model.scivis.array_name" },
{ "scalar-coloring", "model.scivis.enable" },
{ "coloring-array", "model.scivis.array_name" },
{ "light-intensity", "render.light.intensity" },
{ "comp", "model.scivis.component" },
{ "cells", "model.scivis.cells" },
Expand Down
70 changes: 35 additions & 35 deletions application/testing/CMakeLists.txt

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion library/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,17 @@
}
},
"scivis": {
"enable": {
"type": "bool",
"default_value": "false"
},
"cells": {
"type": "bool",
"default_value": "false"
},
"array_name": {
"type": "string",
"default_value": "f3d_reserved"
"default_value": ""
},
"component": {
"type": "int",
Expand Down
1 change: 1 addition & 0 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class interactor_impl::internals
if (checkColoring)
{
// Resynchronise renderer coloring status with options
self->Options.model.scivis.enable = renWithColor->GetColoringEnabled();
self->Options.model.scivis.cells = renWithColor->GetColoringUseCell();
self->Options.model.scivis.array_name = renWithColor->GetColoringArrayName();
self->Options.model.scivis.component = renWithColor->GetColoringComponent();
Expand Down
4 changes: 2 additions & 2 deletions library/src/window_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ void window_impl::UpdateDynamicOptions()
renderer->SetNormalScale(opt.model.normal.scale);
renderer->SetTextureMatCap(opt.model.matcap.texture);

renderer->SetColoring(
opt.model.scivis.cells, opt.model.scivis.array_name, opt.model.scivis.component);
renderer->SetColoring(opt.model.scivis.enable, opt.model.scivis.cells,
opt.model.scivis.array_name, opt.model.scivis.component);
renderer->SetScalarBarRange(opt.model.scivis.range);
renderer->SetColormap(opt.model.scivis.colormap);
renderer->ShowScalarBar(opt.ui.scalar_bar);
Expand Down
2 changes: 1 addition & 1 deletion resources/configs/config.d/05_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"progress": true,
"anti-aliasing": true,
"filename": true,
"scalars": "",
"scalar-coloring": true,
"camera-direction": "-1,-0.5,-1",
"hdri-ambient": true,
"translucency-support": true,
Expand Down
2 changes: 1 addition & 1 deletion resources/configs/thumbnail.d/05_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"max-size":100,
"no-background": true,
"verbose": "quiet",
"scalars": "",
"scalar-coloring": true,
"tone-mapping": true,
"translucency-support": true
}
Expand Down
2 changes: 1 addition & 1 deletion testing/configs/complex.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
".*":
{
"scalars": "",
"scalar-coloring": true,
"interactor.axis": true,
"grid": true
},
Expand Down
6 changes: 3 additions & 3 deletions vtkext/private/module/Testing/TestF3DRendererWithColoring.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int TestF3DRendererWithColoring(int argc, char* argv[])
renderer->ShowGrid(true);

// Check error paths
if (renderer->GetColoringArrayName() != F3D_RESERVED_STRING)
if (!renderer->GetColoringArrayName().empty())
{
std::cerr << "Unexpected coloring information without an importer" << std::endl;
return EXIT_FAILURE;
Expand All @@ -37,7 +37,7 @@ int TestF3DRendererWithColoring(int argc, char* argv[])
importer->Update();

// Check invalid array code path
renderer->SetColoring(false, "Invalid", 0);
renderer->SetColoring(true, false, "Invalid", 0);
renderer->SetUseVolume(false);
renderer->UpdateActors();
renderer->CycleScalars(vtkF3DRendererWithColoring::CycleType::COMPONENT);
Expand All @@ -51,7 +51,7 @@ int TestF3DRendererWithColoring(int argc, char* argv[])
}

// Check invalid component code path
renderer->SetColoring(false, "Momentum", 5);
renderer->SetColoring(true, false, "Momentum", 5);
renderer->UpdateActors();
renderer->SetUseVolume(true);
renderer->UpdateActors();
Expand Down
1 change: 0 additions & 1 deletion vtkext/private/module/vtkF3DConfigure.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <string>

static const std::string F3D_RESERVED_STRING = "f3d_reserved";
static const std::string F3D_EXIT_HOTKEY_SYM = "Escape";

// TODO: Use CMake definitions and get rid of these
Expand Down
25 changes: 16 additions & 9 deletions vtkext/private/module/vtkF3DRendererWithColoring.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ vtkF3DRendererWithColoring::CycleType vtkF3DRendererWithColoring::CheckColoring(
assert(this->Importer);

// Never force change of anything if we are currently not coloring
if (this->ArrayIndexForColoring == -1)
if (this->ArrayIndexForColoring < 0)
{
return CycleType::NONE;
}
Expand Down Expand Up @@ -501,7 +501,7 @@ vtkF3DRendererWithColoring::CycleType vtkF3DRendererWithColoring::CheckColoring(
}

//----------------------------------------------------------------------------
void vtkF3DRendererWithColoring::SetColoring(
void vtkF3DRendererWithColoring::SetColoring(bool enable,
bool useCellData, const std::string& arrayName, int component)
{
if (!this->Importer)
Expand All @@ -511,13 +511,16 @@ void vtkF3DRendererWithColoring::SetColoring(

// XXX This should be reworked to avoid handling multiple information in one parameters
// while still being future-proof and flexible enough.
if (this->GetColoringUseCell() != useCellData || this->GetColoringArrayName() != arrayName ||
this->GetColoringComponent() != component)
if (enable != (this->ArrayIndexForColoring >= 0)
|| useCellData != this->UseCellColoring
|| component != this->ComponentForColoring
|| arrayName != this->GetColoringArrayName())
{
this->UseCellColoring = useCellData;
this->ComponentForColoring = component;

int nIndexes = this->Importer->GetNumberOfIndexesForColoring(this->UseCellColoring);
if (arrayName == F3D_RESERVED_STRING)
if (!enable)
{
// Not coloring
this->ArrayIndexForColoring = -1;
Expand All @@ -544,8 +547,6 @@ void vtkF3DRendererWithColoring::SetColoring(
}
}

this->ComponentForColoring = component;

this->ColorTransferFunctionConfigured = false;
this->GeometryMappersConfigured = false;
this->PointSpritesMappersConfigured = false;
Expand All @@ -555,6 +556,12 @@ void vtkF3DRendererWithColoring::SetColoring(
}
}

//----------------------------------------------------------------------------
bool vtkF3DRendererWithColoring::GetColoringEnabled()
{
return this->ArrayIndexForColoring >= 0;
}

//----------------------------------------------------------------------------
bool vtkF3DRendererWithColoring::GetColoringUseCell()
{
Expand All @@ -566,7 +573,7 @@ std::string vtkF3DRendererWithColoring::GetColoringArrayName()
{
if (!this->Importer)
{
return F3D_RESERVED_STRING;
return "";
}

vtkF3DGenericImporter::ColoringInfo info;
Expand All @@ -576,7 +583,7 @@ std::string vtkF3DRendererWithColoring::GetColoringArrayName()
}
else
{
return F3D_RESERVED_STRING;
return "";
}
}

Expand Down
5 changes: 3 additions & 2 deletions vtkext/private/module/vtkF3DRendererWithColoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,18 @@ class vtkF3DRendererWithColoring : public vtkF3DRenderer
void SetImporter(vtkF3DGenericImporter* importer);

/**
* Set the coloring, call after SetColoringAttributes.
* Set coloring information.
* This method will try to find the corresponding array in the coloring attributes and will
* position ArrayIndexForColoring and DataForColoring accordingly.
*/
void SetColoring(bool useCellData, const std::string& arrayName, int component);
void SetColoring(bool enable, bool useCellData, const std::string& arrayName, int component);

///@{
/**
* Get current coloring information,
* Useful after using Cycle methods
*/
bool GetColoringEnabled();
bool GetColoringUseCell();
std::string GetColoringArrayName();
int GetColoringComponent();
Expand Down

0 comments on commit 63c1865

Please sign in to comment.