Skip to content

Commit

Permalink
change option type from vector<double> to int
Browse files Browse the repository at this point in the history
  • Loading branch information
gapry committed Nov 30, 2024
1 parent 68a0dbc commit 5df8019
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +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", "", "test colormap discretization", "<color_list>", ""},
{"colormap-discretization", "", "Specify the discretization of the colormap", "<int>", "-1"},
{"volume", "v", "Show volume if the file is compatible", "<bool>", "1"},
{"inverse", "i", "Inverse opacity function for volume rendering", "<bool>", "1"} } },
{"Camera",
Expand Down
4 changes: 2 additions & 2 deletions library/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@
"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": "double_vector",
"default_value": "1.0, 1.0, 1.0, 1.0"
"type": "int",
"default_value": "-1"
},
"range": {
"type": "double_vector"
Expand Down
35 changes: 29 additions & 6 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 = -1;
this->DiscretizableColorTransferFunctionConfigured = false;

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

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

void vtkF3DRenderer::SetColorDiscretization(const std::vector<double>& discretization) {
auto logMsg = std::string("[Gapry PoC][Add CLI Options] " + std::string(__PRETTY_FUNCTION__));
F3DLog::Print(F3DLog::Severity::Warning, logMsg);
for(auto& e : discretization) {
F3DLog::Print(F3DLog::Severity::Warning, std::to_string(e) + std::string(" "));
void vtkF3DRenderer::SetColorDiscretization(const int discretization) {
F3DLog::Print(F3DLog::Severity::Warning,
std::string("[Gapry PoC][Add CLI Options] ") + __PRETTY_FUNCTION__);

F3DLog::Print(F3DLog::Severity::Warning,
std::string("[Gapry PoC][Add CLI Options] ") +
"input discretization = " + std::to_string(discretization));

if(discretization >= 0 && discretization <= 255) {
this->Discretization = discretization;

vtkF3DMetaImporter::ColoringInfo info;
this->ConfigureRangeAndCTFForColoring(info);
} else {
F3DLog::Print(F3DLog::Severity::Error,
"The discretization value is between 0 and 255.");
}
F3DLog::Print(F3DLog::Severity::Warning, std::string("\n"));
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -2481,6 +2494,16 @@ void vtkF3DRenderer::ConfigureRangeAndCTFForColoring(
return;
}

// Set Discretization
if(this->Discretization >= 0 && !this->DiscretizableColorTransferFunctionConfigured) {
F3DLog::Print(F3DLog::Severity::Warning,
std::string("[Gapry PoC][Add CLI Options] " ) + __PRETTY_FUNCTION__ +
" discretization = " + std::to_string(this->Discretization));

this->DiscretizableColorTransferFunction->SetNumberOfValues(this->Discretization);
this->DiscretizableColorTransferFunctionConfigured = true;
}

// Set range
bool autoRange = true;
if (this->UserScalarBarRange.has_value())
Expand Down
10 changes: 9 additions & 1 deletion 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,7 +283,10 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
*/
void SetColormap(const std::vector<double>& colormap);

void SetColorDiscretization(const std::vector<double>& discretization);
/**
* Set the discretization of the colormap
*/
void SetColorDiscretization(const int discretization);

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

vtkNew<vtkDiscretizableColorTransferFunction> DiscretizableColorTransferFunction;
bool DiscretizableColorTransferFunctionConfigured = false;
int Discretization = -1;

vtkNew<vtkScalarBarActor> ScalarBarActor;
bool ScalarBarActorConfigured = false;

Expand Down

0 comments on commit 5df8019

Please sign in to comment.