Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add an option to control the discretization of colormap #1678

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{"bar", "b", "Show scalar bar", "<bool>", "1" },
{"colormap-file", "", "Specify a colormap image", "<filePath/filename/fileStem>", ""},
{"colormap", "", "Specify a custom colormap (ignored if \"colormap-file\" is specified)", "<color_list>", ""},
{"colormap-discretization", "", "Specify the discretization of the colormap", "<int>", "256"},
{"volume", "v", "Show volume if the file is compatible", "<bool>", "1"},
{"inverse", "i", "Inverse opacity function for volume rendering", "<bool>", "1"} } },
{"Camera",
Expand Down
1 change: 1 addition & 0 deletions application/F3DOptionsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ static inline const std::map<std::string_view, std::string_view> LibOptionsNames
{ "range", "model.scivis.range" },
{ "bar", "ui.scalar_bar" },
{ "colormap", "model.scivis.colormap" },
{ "colormap-discretization", "model.scivis.discretization" },
{ "volume", "model.volume.enable" },
{ "inverse", "model.volume.inverse" },
{ "camera-orthographic", "scene.camera.orthographic" },
Expand Down
4 changes: 4 additions & 0 deletions library/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@
"type": "double_vector",
"default_value": "0.0, 0.0, 0.0, 0.0, 0.4, 0.9, 0.0, 0.0, 0.8, 0.9, 0.9, 0.0, 1.0, 1.0, 1.0, 1.0"
},
"discretization" : {
"type": "int",
"default_value": "256"
},
"range": {
"type": "double_vector"
}
Expand Down
1 change: 1 addition & 0 deletions library/src/window_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ void window_impl::UpdateDynamicOptions()

renderer->SetScalarBarRange(opt.model.scivis.range);
renderer->SetColormap(opt.model.scivis.colormap);
renderer->SetColorDiscretization(opt.model.scivis.discretization);
renderer->ShowScalarBar(opt.ui.scalar_bar);

renderer->SetUsePointSprites(opt.model.point_sprites.enable);
Expand Down
23 changes: 23 additions & 0 deletions vtkext/private/module/vtkF3DRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ void vtkF3DRenderer::Initialize()

this->GridInfo = "";

this->Discretization = 256;
this->DiscretizableColorTransferFunctionConfigured = false;

this->AddActor2D(this->ScalarBarActor);
this->ScalarBarActor->VisibilityOff();

Expand Down Expand Up @@ -2125,6 +2128,20 @@ void vtkF3DRenderer::SetColormap(const std::vector<double>& colormap)
}
}

void vtkF3DRenderer::SetColorDiscretization(const int discretization) {
if(discretization >= 0 and discretization <= std::numeric_limits<int>::max()) {
this->Discretization = discretization;

bool enableColoring = this->EnableColoring || (!this->UseRaytracing && this->UseVolume);
F3DColoringInfoHandler& coloringHandler = this->Importer->GetColoringInfoHandler();
auto info = coloringHandler.SetCurrentColoring(enableColoring, this->UseCellColoring, this->ArrayNameForColoring, false);
this->ConfigureRangeAndCTFForColoring(info.value());
} else {
F3DLog::Print(F3DLog::Severity::Error,
"The discretization value need to great than zero");
}
}

//----------------------------------------------------------------------------
void vtkF3DRenderer::SetEnableColoring(bool enable)
{
Expand Down Expand Up @@ -2472,6 +2489,12 @@ void vtkF3DRenderer::ConfigureRangeAndCTFForColoring(
return;
}

// Set Discretization
if(!this->DiscretizableColorTransferFunctionConfigured) {
this->DiscretizableColorTransferFunction->SetNumberOfValues(this->Discretization);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do that directly on the existing colorTransferFunction

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can.

this->DiscretizableColorTransferFunctionConfigured = true;
}

// Set range
bool autoRange = true;
if (this->UserScalarBarRange.has_value())
Expand Down
10 changes: 10 additions & 0 deletions vtkext/private/module/vtkF3DRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "vtkF3DMetaImporter.h"
#include "vtkF3DUIActor.h"

#include <vtkDiscretizableColorTransferFunction.h>
#include <vtkLight.h>
#include <vtkOpenGLRenderer.h>

Expand Down Expand Up @@ -282,6 +283,11 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
*/
void SetColormap(const std::vector<double>& colormap);

/**
* Set the discretization of the colormap
*/
void SetColorDiscretization(const int discretization);

/**
* Set the meta importer to recover coloring information from
*/
Expand Down Expand Up @@ -557,6 +563,10 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
vtkF3DMetaImporter* Importer = nullptr;
vtkMTimeType ImporterTimeStamp = 0;

vtkNew<vtkDiscretizableColorTransferFunction> DiscretizableColorTransferFunction;
bool DiscretizableColorTransferFunctionConfigured = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think you need this

int Discretization = 256;

vtkNew<vtkScalarBarActor> ScalarBarActor;
bool ScalarBarActorConfigured = false;

Expand Down
Loading