From 249321fa52825e062cce49d246f34288b5293699 Mon Sep 17 00:00:00 2001 From: gapry Date: Wed, 23 Oct 2024 07:07:00 +0800 Subject: [PATCH 1/7] Add CLI option to discretize colormap --- application/F3DOptionsTools.h | 1 + 1 file changed, 1 insertion(+) diff --git a/application/F3DOptionsTools.h b/application/F3DOptionsTools.h index b404c83e5f..4d59d75643 100644 --- a/application/F3DOptionsTools.h +++ b/application/F3DOptionsTools.h @@ -113,6 +113,7 @@ static inline const std::map 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" }, From 4899fc143f8c9958e66745c9ecc365fa7006d33a Mon Sep 17 00:00:00 2001 From: gapry Date: Fri, 25 Oct 2024 17:39:26 +0800 Subject: [PATCH 2/7] [PoC][Part02]: Add CLI option to discretize colormap --- application/F3DOptionsTools.cxx | 1 + library/options.json | 4 ++++ library/src/window_impl.cxx | 1 + vtkext/private/module/vtkF3DRenderer.cxx | 5 +++++ vtkext/private/module/vtkF3DRenderer.h | 2 ++ 5 files changed, 13 insertions(+) diff --git a/application/F3DOptionsTools.cxx b/application/F3DOptionsTools.cxx index 5cf22597ec..bca3cd7c46 100644 --- a/application/F3DOptionsTools.cxx +++ b/application/F3DOptionsTools.cxx @@ -136,6 +136,7 @@ static inline const std::array CLIOptions = {{ {"bar", "b", "Show scalar bar", "", "1" }, {"colormap-file", "", "Specify a colormap image", "", ""}, {"colormap", "", "Specify a custom colormap (ignored if \"colormap-file\" is specified)", "", ""}, + {"colormap-discretization", "", "test", "", "1"}, {"volume", "v", "Show volume if the file is compatible", "", "1"}, {"inverse", "i", "Inverse opacity function for volume rendering", "", "1"} } }, {"Camera", diff --git a/library/options.json b/library/options.json index 050c896c35..0ad042e75c 100644 --- a/library/options.json +++ b/library/options.json @@ -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": "bool", + "default_value": "false" + }, "range": { "type": "double_vector" } diff --git a/library/src/window_impl.cxx b/library/src/window_impl.cxx index 3523402c0d..473550834b 100644 --- a/library/src/window_impl.cxx +++ b/library/src/window_impl.cxx @@ -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); diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index 573c24d131..3449732d93 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -2125,6 +2125,11 @@ void vtkF3DRenderer::SetColormap(const std::vector& colormap) } } +void vtkF3DRenderer::SetColorDiscretization(const bool discretization) { + auto logMsg = std::string("[Gapry PoC][Add CLI Options] " + std::string(__PRETTY_FUNCTION__)); + F3DLog::Print(F3DLog::Severity::Warning, logMsg); +} + //---------------------------------------------------------------------------- void vtkF3DRenderer::SetEnableColoring(bool enable) { diff --git a/vtkext/private/module/vtkF3DRenderer.h b/vtkext/private/module/vtkF3DRenderer.h index f7afa057fa..302c833529 100644 --- a/vtkext/private/module/vtkF3DRenderer.h +++ b/vtkext/private/module/vtkF3DRenderer.h @@ -282,6 +282,8 @@ class vtkF3DRenderer : public vtkOpenGLRenderer */ void SetColormap(const std::vector& colormap); + void SetColorDiscretization(const bool discretization); + /** * Set the meta importer to recover coloring information from */ From 68a0dbcba2ab939b861039657f901c1dfc43c347 Mon Sep 17 00:00:00 2001 From: gapry Date: Fri, 29 Nov 2024 22:29:17 +0800 Subject: [PATCH 3/7] change option type from bool to vector --- application/F3DOptionsTools.cxx | 2 +- library/options.json | 4 ++-- vtkext/private/module/vtkF3DRenderer.cxx | 6 +++++- vtkext/private/module/vtkF3DRenderer.h | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/application/F3DOptionsTools.cxx b/application/F3DOptionsTools.cxx index bca3cd7c46..61408389d3 100644 --- a/application/F3DOptionsTools.cxx +++ b/application/F3DOptionsTools.cxx @@ -136,7 +136,7 @@ static inline const std::array CLIOptions = {{ {"bar", "b", "Show scalar bar", "", "1" }, {"colormap-file", "", "Specify a colormap image", "", ""}, {"colormap", "", "Specify a custom colormap (ignored if \"colormap-file\" is specified)", "", ""}, - {"colormap-discretization", "", "test", "", "1"}, + {"colormap-discretization", "", "test colormap discretization", "", ""}, {"volume", "v", "Show volume if the file is compatible", "", "1"}, {"inverse", "i", "Inverse opacity function for volume rendering", "", "1"} } }, {"Camera", diff --git a/library/options.json b/library/options.json index 0ad042e75c..2ef270b0f6 100644 --- a/library/options.json +++ b/library/options.json @@ -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": "bool", - "default_value": "false" + "type": "double_vector", + "default_value": "1.0, 1.0, 1.0, 1.0" }, "range": { "type": "double_vector" diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index 3449732d93..a42f4af02c 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -2125,9 +2125,13 @@ void vtkF3DRenderer::SetColormap(const std::vector& colormap) } } -void vtkF3DRenderer::SetColorDiscretization(const bool discretization) { +void vtkF3DRenderer::SetColorDiscretization(const std::vector& 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(" ")); + } + F3DLog::Print(F3DLog::Severity::Warning, std::string("\n")); } //---------------------------------------------------------------------------- diff --git a/vtkext/private/module/vtkF3DRenderer.h b/vtkext/private/module/vtkF3DRenderer.h index 302c833529..aecdbcdb34 100644 --- a/vtkext/private/module/vtkF3DRenderer.h +++ b/vtkext/private/module/vtkF3DRenderer.h @@ -282,7 +282,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer */ void SetColormap(const std::vector& colormap); - void SetColorDiscretization(const bool discretization); + void SetColorDiscretization(const std::vector& discretization); /** * Set the meta importer to recover coloring information from From 5df80195587ed3575156e22eb94ed442e9e9676b Mon Sep 17 00:00:00 2001 From: gapry Date: Sat, 30 Nov 2024 14:11:04 +0800 Subject: [PATCH 4/7] change option type from vector to int --- application/F3DOptionsTools.cxx | 2 +- library/options.json | 4 +-- vtkext/private/module/vtkF3DRenderer.cxx | 35 ++++++++++++++++++++---- vtkext/private/module/vtkF3DRenderer.h | 10 ++++++- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/application/F3DOptionsTools.cxx b/application/F3DOptionsTools.cxx index 61408389d3..3eac67b5af 100644 --- a/application/F3DOptionsTools.cxx +++ b/application/F3DOptionsTools.cxx @@ -136,7 +136,7 @@ static inline const std::array CLIOptions = {{ {"bar", "b", "Show scalar bar", "", "1" }, {"colormap-file", "", "Specify a colormap image", "", ""}, {"colormap", "", "Specify a custom colormap (ignored if \"colormap-file\" is specified)", "", ""}, - {"colormap-discretization", "", "test colormap discretization", "", ""}, + {"colormap-discretization", "", "Specify the discretization of the colormap", "", "-1"}, {"volume", "v", "Show volume if the file is compatible", "", "1"}, {"inverse", "i", "Inverse opacity function for volume rendering", "", "1"} } }, {"Camera", diff --git a/library/options.json b/library/options.json index 2ef270b0f6..0f1225da85 100644 --- a/library/options.json +++ b/library/options.json @@ -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" diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index a42f4af02c..2600407293 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -283,6 +283,9 @@ void vtkF3DRenderer::Initialize() this->GridInfo = ""; + this->Discretization = -1; + this->DiscretizableColorTransferFunctionConfigured = false; + this->AddActor2D(this->ScalarBarActor); this->ScalarBarActor->VisibilityOff(); @@ -2125,13 +2128,23 @@ void vtkF3DRenderer::SetColormap(const std::vector& colormap) } } -void vtkF3DRenderer::SetColorDiscretization(const std::vector& 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")); } //---------------------------------------------------------------------------- @@ -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()) diff --git a/vtkext/private/module/vtkF3DRenderer.h b/vtkext/private/module/vtkF3DRenderer.h index aecdbcdb34..ed86cfb00d 100644 --- a/vtkext/private/module/vtkF3DRenderer.h +++ b/vtkext/private/module/vtkF3DRenderer.h @@ -14,6 +14,7 @@ #include "vtkF3DMetaImporter.h" #include "vtkF3DUIActor.h" +#include #include #include @@ -282,7 +283,10 @@ class vtkF3DRenderer : public vtkOpenGLRenderer */ void SetColormap(const std::vector& colormap); - void SetColorDiscretization(const std::vector& discretization); + /** + * Set the discretization of the colormap + */ + void SetColorDiscretization(const int discretization); /** * Set the meta importer to recover coloring information from @@ -559,6 +563,10 @@ class vtkF3DRenderer : public vtkOpenGLRenderer vtkF3DMetaImporter* Importer = nullptr; vtkMTimeType ImporterTimeStamp = 0; + vtkNew DiscretizableColorTransferFunction; + bool DiscretizableColorTransferFunctionConfigured = false; + int Discretization = -1; + vtkNew ScalarBarActor; bool ScalarBarActorConfigured = false; From dd9c2b872110b00e96a49398bf5c2c5691aec62a Mon Sep 17 00:00:00 2001 From: gapry Date: Sat, 30 Nov 2024 14:44:30 +0800 Subject: [PATCH 5/7] fix: the default value of discretization is 256 --- application/F3DOptionsTools.cxx | 2 +- library/options.json | 2 +- vtkext/private/module/vtkF3DRenderer.cxx | 8 ++++---- vtkext/private/module/vtkF3DRenderer.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/application/F3DOptionsTools.cxx b/application/F3DOptionsTools.cxx index 3eac67b5af..a77eea153d 100644 --- a/application/F3DOptionsTools.cxx +++ b/application/F3DOptionsTools.cxx @@ -136,7 +136,7 @@ static inline const std::array CLIOptions = {{ {"bar", "b", "Show scalar bar", "", "1" }, {"colormap-file", "", "Specify a colormap image", "", ""}, {"colormap", "", "Specify a custom colormap (ignored if \"colormap-file\" is specified)", "", ""}, - {"colormap-discretization", "", "Specify the discretization of the colormap", "", "-1"}, + {"colormap-discretization", "", "Specify the discretization of the colormap", "", "256"}, {"volume", "v", "Show volume if the file is compatible", "", "1"}, {"inverse", "i", "Inverse opacity function for volume rendering", "", "1"} } }, {"Camera", diff --git a/library/options.json b/library/options.json index 0f1225da85..42741766da 100644 --- a/library/options.json +++ b/library/options.json @@ -248,7 +248,7 @@ }, "discretization" : { "type": "int", - "default_value": "-1" + "default_value": "256" }, "range": { "type": "double_vector" diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index 2600407293..4054de59e6 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -283,7 +283,7 @@ void vtkF3DRenderer::Initialize() this->GridInfo = ""; - this->Discretization = -1; + this->Discretization = 256; this->DiscretizableColorTransferFunctionConfigured = false; this->AddActor2D(this->ScalarBarActor); @@ -2136,14 +2136,14 @@ void vtkF3DRenderer::SetColorDiscretization(const int discretization) { std::string("[Gapry PoC][Add CLI Options] ") + "input discretization = " + std::to_string(discretization)); - if(discretization >= 0 && discretization <= 255) { + if(discretization >= 0 and discretization <= std::numeric_limits::max()) { this->Discretization = discretization; vtkF3DMetaImporter::ColoringInfo info; this->ConfigureRangeAndCTFForColoring(info); } else { F3DLog::Print(F3DLog::Severity::Error, - "The discretization value is between 0 and 255."); + "The discretization value need to great than zero"); } } @@ -2495,7 +2495,7 @@ void vtkF3DRenderer::ConfigureRangeAndCTFForColoring( } // Set Discretization - if(this->Discretization >= 0 && !this->DiscretizableColorTransferFunctionConfigured) { + if(!this->DiscretizableColorTransferFunctionConfigured) { F3DLog::Print(F3DLog::Severity::Warning, std::string("[Gapry PoC][Add CLI Options] " ) + __PRETTY_FUNCTION__ + " discretization = " + std::to_string(this->Discretization)); diff --git a/vtkext/private/module/vtkF3DRenderer.h b/vtkext/private/module/vtkF3DRenderer.h index ed86cfb00d..68a911a759 100644 --- a/vtkext/private/module/vtkF3DRenderer.h +++ b/vtkext/private/module/vtkF3DRenderer.h @@ -565,7 +565,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer vtkNew DiscretizableColorTransferFunction; bool DiscretizableColorTransferFunctionConfigured = false; - int Discretization = -1; + int Discretization = 256; vtkNew ScalarBarActor; bool ScalarBarActorConfigured = false; From 7ebcd861a14d8a526a78a5238c5cf25bc4465fde Mon Sep 17 00:00:00 2001 From: gapry Date: Thu, 5 Dec 2024 08:10:04 +0800 Subject: [PATCH 6/7] use F3DColoringInfoHandler to replace the vtkF3DMetaImporter::ColoringInfo --- vtkext/private/module/vtkF3DRenderer.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index 4054de59e6..fd519bf592 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -2139,8 +2139,10 @@ void vtkF3DRenderer::SetColorDiscretization(const int discretization) { if(discretization >= 0 and discretization <= std::numeric_limits::max()) { this->Discretization = discretization; - vtkF3DMetaImporter::ColoringInfo info; - this->ConfigureRangeAndCTFForColoring(info); + 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"); From c3ec7aebcc852f998d17faea3f6097827f9ead44 Mon Sep 17 00:00:00 2001 From: gapry Date: Thu, 5 Dec 2024 08:14:47 +0800 Subject: [PATCH 7/7] remove the log of PoC --- vtkext/private/module/vtkF3DRenderer.cxx | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index fd519bf592..07bc4b3607 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -2128,14 +2128,7 @@ void vtkF3DRenderer::SetColormap(const std::vector& colormap) } } -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)); - +void vtkF3DRenderer::SetColorDiscretization(const int discretization) { if(discretization >= 0 and discretization <= std::numeric_limits::max()) { this->Discretization = discretization; @@ -2498,10 +2491,6 @@ void vtkF3DRenderer::ConfigureRangeAndCTFForColoring( // Set Discretization if(!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; }