From 8f22a8fbeef89267f1658893d51cef2e3a2899ac Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Tue, 22 Oct 2024 09:00:23 +0200 Subject: [PATCH 1/7] Move coloring info logic into a dedicated helper --- vtkext/private/module/CMakeLists.txt | 1 + .../private/module/F3DColoringInfoHelper.cxx | 155 +++++++++++++++ vtkext/private/module/F3DColoringInfoHelper.h | 63 ++++++ vtkext/private/module/vtkF3DMetaImporter.cxx | 187 ++---------------- vtkext/private/module/vtkF3DMetaImporter.h | 32 +-- vtkext/private/module/vtkF3DRenderer.cxx | 43 ++-- vtkext/private/module/vtkF3DRenderer.h | 2 +- 7 files changed, 263 insertions(+), 220 deletions(-) create mode 100644 vtkext/private/module/F3DColoringInfoHelper.cxx create mode 100644 vtkext/private/module/F3DColoringInfoHelper.h diff --git a/vtkext/private/module/CMakeLists.txt b/vtkext/private/module/CMakeLists.txt index 3e8de7fd99..9dd0b912a6 100644 --- a/vtkext/private/module/CMakeLists.txt +++ b/vtkext/private/module/CMakeLists.txt @@ -31,6 +31,7 @@ endforeach() set(classes F3DLog + F3DColoringInfoHelper vtkF3DCachedLUTTexture vtkF3DCachedSpecularTexture vtkF3DConsoleOutputWindow diff --git a/vtkext/private/module/F3DColoringInfoHelper.cxx b/vtkext/private/module/F3DColoringInfoHelper.cxx new file mode 100644 index 0000000000..23bbe2577e --- /dev/null +++ b/vtkext/private/module/F3DColoringInfoHelper.cxx @@ -0,0 +1,155 @@ +#include "F3DColoringInfoHelper.h" + +#include +#include +#include +#include + +#include +#include + +//---------------------------------------------------------------------------- +void F3DColoringInfoHelper::ClearColoringInfo() +{ + this->PointDataColoringInfo.clear(); + this->CellDataColoringInfo.clear(); +} + +//---------------------------------------------------------------------------- +void F3DColoringInfoHelper::UpdateColoringInfo(vtkDataSet* dataset, bool useCellData) +{ + // XXX: This assumes importer do not import actors with an empty input + assert(dataset); + + // Recover all possible names + std::set arrayNames; + + vtkDataSetAttributes* attr = useCellData + ? static_cast(dataset->GetCellData()) + : static_cast(dataset->GetPointData()); + + for (int i = 0; i < attr->GetNumberOfArrays(); i++) + { + vtkDataArray* array = attr->GetArray(i); + if (array && array->GetName()) + { + arrayNames.insert(array->GetName()); + } + } + + auto& data = useCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; + + for (const std::string& arrayName : arrayNames) + { + // Recover/Create a coloring info + F3DColoringInfoHelper::ColoringInfo& info = data[arrayName]; + info.Name = arrayName; + + vtkDataArray* array = useCellData ? dataset->GetCellData()->GetArray(arrayName.c_str()) + : dataset->GetPointData()->GetArray(arrayName.c_str()); + if (array) + { + info.MaximumNumberOfComponents = + std::max(info.MaximumNumberOfComponents, array->GetNumberOfComponents()); + + // Set ranges + // XXX this does not take animation into account + std::array range; + array->GetRange(range.data(), -1); + info.MagnitudeRange[0] = std::min(info.MagnitudeRange[0], range[0]); + info.MagnitudeRange[1] = std::max(info.MagnitudeRange[1], range[1]); + + for (size_t i = 0; i < static_cast(array->GetNumberOfComponents()); i++) + { + array->GetRange(range.data(), static_cast(i)); + if (i < info.ComponentRanges.size()) + { + info.ComponentRanges[i][0] = std::min(info.ComponentRanges[i][0], range[0]); + info.ComponentRanges[i][1] = std::max(info.ComponentRanges[i][1], range[1]); + } + else + { + info.ComponentRanges.emplace_back(range); + } + } + + // Set component names + if (array->HasAComponentName()) + { + for (size_t i = 0; i < static_cast(array->GetNumberOfComponents()); i++) + { + const char* compName = array->GetComponentName(i); + if (i < info.ComponentNames.size()) + { + if (compName && info.ComponentNames[i] != std::string(compName)) + { + // set non-coherent component names to empty string + info.ComponentNames[i] = ""; + } + } + else + { + // Add components names to the back of the component names vector + info.ComponentNames.emplace_back(compName ? compName : ""); + } + } + } + } + } +} + +//---------------------------------------------------------------------------- +void F3DColoringInfoHelper::FinalizeColoringInfo(bool useCellData) +{ + auto& names = useCellData ? this->CellDataArrayNames : this->PointDataArrayNames; + names.clear(); + + auto& data = useCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; + int index = 0; + for (auto& [name, info] : data) + { + info.Index = index; + names.emplace_back(name); + index++; + } +} + +//---------------------------------------------------------------------------- +bool F3DColoringInfoHelper::GetInfoForColoring( + bool useCellData, int index, F3DColoringInfoHelper::ColoringInfo& info) +{ + auto& data = + useCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; + auto& names = + useCellData ? this->CellDataArrayNames : this->PointDataArrayNames; + + if (index < 0 || index >= static_cast(data.size())) + { + return false; + } + + info = data[names[index]]; + return true; +} + +//---------------------------------------------------------------------------- +int F3DColoringInfoHelper::GetNumberOfIndexesForColoring(bool useCellData) +{ + auto& data = + useCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; + return static_cast(data.size()); +} + +//---------------------------------------------------------------------------- +int F3DColoringInfoHelper::FindIndexForColoring(bool useCellData, const std::string& arrayName) +{ + auto& data = + useCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; + + auto it = data.find(arrayName); + if (it != data.end()) + { + return it->second.Index; + } + return -1; +} diff --git a/vtkext/private/module/F3DColoringInfoHelper.h b/vtkext/private/module/F3DColoringInfoHelper.h new file mode 100644 index 0000000000..939cff16a0 --- /dev/null +++ b/vtkext/private/module/F3DColoringInfoHelper.h @@ -0,0 +1,63 @@ +/** + * @class F3DColoringInfoHelper + * @brief A statefull helper to handle coloring info + */ +#ifndef F3DColoringInfoHelper_h +#define F3DColoringInfoHelper_h + +#include +#include +#include +#include +#include + +class vtkDataSet; +class F3DColoringInfoHelper +{ +public: + /** + * A struct containing information about possible coloring + */ + struct ColoringInfo + { + std::string Name; + int MaximumNumberOfComponents = 0; + std::vector ComponentNames; + std::vector> ComponentRanges; + std::array MagnitudeRange = { std::numeric_limits::max(), + std::numeric_limits::min() }; + int Index = -1; // TODO remove + }; + + + void UpdateColoringInfo(vtkDataSet* dataset, bool useCellData); + void FinalizeColoringInfo(bool useCellData); + void ClearColoringInfo(); + + /** + * Recover information about coloring by index + * Should be called after actors have been imported + */ + bool GetInfoForColoring(bool useCellData, int index, ColoringInfo& info); + + /** + * Get the maximum index possible for coloring + * Should be called after actors have been imported + */ + int GetNumberOfIndexesForColoring(bool useCellData); + + /** + * Find an index for coloring corresponding to provided arrayName if available + * Should be called after actors have been imported + */ + int FindIndexForColoring(bool useCellData, const std::string& arrayName); + +private: + // Map of arrayName -> coloring info + std::map PointDataColoringInfo; + std::map CellDataColoringInfo; + std::vector PointDataArrayNames; + std::vector CellDataArrayNames; +}; + +#endif diff --git a/vtkext/private/module/vtkF3DMetaImporter.cxx b/vtkext/private/module/vtkF3DMetaImporter.cxx index 457db524e1..96afced90c 100644 --- a/vtkext/private/module/vtkF3DMetaImporter.cxx +++ b/vtkext/private/module/vtkF3DMetaImporter.cxx @@ -24,120 +24,11 @@ struct vtkF3DMetaImporter::Internals { - void ClearColoringInfo() - { - this->PointDataColoringInfo.clear(); - this->CellDataColoringInfo.clear(); - } - - void UpdateColoringInfo(vtkDataSet* dataset, bool useCellData) - { - // XXX: This assumes importer do not import actors with an empty input - assert(dataset); - - // Recover all possible names - std::set arrayNames; - - vtkDataSetAttributes* attr = useCellData - ? static_cast(dataset->GetCellData()) - : static_cast(dataset->GetPointData()); - - for (int i = 0; i < attr->GetNumberOfArrays(); i++) - { - vtkDataArray* array = attr->GetArray(i); - if (array && array->GetName()) - { - arrayNames.insert(array->GetName()); - } - } - - auto& data = useCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; - - for (const std::string& arrayName : arrayNames) - { - // Recover/Create a coloring info - vtkF3DMetaImporter::ColoringInfo& info = data[arrayName]; - info.Name = arrayName; - - vtkDataArray* array = useCellData ? dataset->GetCellData()->GetArray(arrayName.c_str()) - : dataset->GetPointData()->GetArray(arrayName.c_str()); - if (array) - { - info.MaximumNumberOfComponents = - std::max(info.MaximumNumberOfComponents, array->GetNumberOfComponents()); - - // Set ranges - // XXX this does not take animation into account - std::array range; - array->GetRange(range.data(), -1); - info.MagnitudeRange[0] = std::min(info.MagnitudeRange[0], range[0]); - info.MagnitudeRange[1] = std::max(info.MagnitudeRange[1], range[1]); - - for (size_t i = 0; i < static_cast(array->GetNumberOfComponents()); i++) - { - array->GetRange(range.data(), static_cast(i)); - if (i < info.ComponentRanges.size()) - { - info.ComponentRanges[i][0] = std::min(info.ComponentRanges[i][0], range[0]); - info.ComponentRanges[i][1] = std::max(info.ComponentRanges[i][1], range[1]); - } - else - { - info.ComponentRanges.emplace_back(range); - } - } - - // Set component names - if (array->HasAComponentName()) - { - for (size_t i = 0; i < static_cast(array->GetNumberOfComponents()); i++) - { - const char* compName = array->GetComponentName(i); - if (i < info.ComponentNames.size()) - { - if (compName && info.ComponentNames[i] != std::string(compName)) - { - // set non-coherent component names to empty string - info.ComponentNames[i] = ""; - } - } - else - { - // Add components names to the back of the component names vector - info.ComponentNames.emplace_back(compName ? compName : ""); - } - } - } - } - } - } - - void FinalizeColoringInfo(bool useCellData) - { - auto& names = useCellData ? this->CellDataArrayNames : this->PointDataArrayNames; - names.clear(); - - auto& data = useCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; - int index = 0; - for (auto& [name, info] : data) - { - info.Index = index; - names.emplace_back(name); - index++; - } - } - // Actors related vectors std::vector ColoringActorsAndMappers; std::vector PointSpritesActorsAndMappers; std::vector VolumePropsAndMappers; - // Map of arrayName -> coloring info - std::map PointDataColoringInfo; - std::map CellDataColoringInfo; - std::vector PointDataArrayNames; - std::vector CellDataArrayNames; - struct ImporterPair { vtkSmartPointer Importer; @@ -148,6 +39,8 @@ struct vtkF3DMetaImporter::Internals vtkBoundingBox GeometryBoundingBox; bool ColoringInfoUpdated = false; + F3DColoringInfoHelper ColoringInfoHelper; + #if VTK_VERSION_NUMBER < VTK_VERSION_CHECK(9, 3, 20240707) std::map> ActorsForImporterMap; #endif @@ -178,7 +71,7 @@ void vtkF3DMetaImporter::Clear() this->Pimpl->ColoringActorsAndMappers.clear(); this->Pimpl->PointSpritesActorsAndMappers.clear(); this->Pimpl->VolumePropsAndMappers.clear(); - this->Pimpl->ClearColoringInfo(); + this->Pimpl->ColoringInfoHelper.ClearColoringInfo(); this->Modified(); } @@ -217,61 +110,6 @@ const vtkBoundingBox& vtkF3DMetaImporter::GetGeometryBoundingBox() return this->Pimpl->GeometryBoundingBox; } -//---------------------------------------------------------------------------- -bool vtkF3DMetaImporter::GetInfoForColoring( - bool useCellData, int index, vtkF3DMetaImporter::ColoringInfo& info) -{ - if (!this->Pimpl->ColoringInfoUpdated) - { - this->UpdateInfoForColoring(); - } - - auto& data = - useCellData ? this->Pimpl->CellDataColoringInfo : this->Pimpl->PointDataColoringInfo; - auto& names = - useCellData ? this->Pimpl->CellDataArrayNames : this->Pimpl->PointDataArrayNames; - - if (index < 0 || index >= static_cast(data.size())) - { - return false; - } - - info = data[names[index]]; - return true; -} - -//---------------------------------------------------------------------------- -int vtkF3DMetaImporter::GetNumberOfIndexesForColoring(bool useCellData) -{ - if (!this->Pimpl->ColoringInfoUpdated) - { - this->UpdateInfoForColoring(); - } - - auto& data = - useCellData ? this->Pimpl->CellDataColoringInfo : this->Pimpl->PointDataColoringInfo; - return static_cast(data.size()); -} - -//---------------------------------------------------------------------------- -int vtkF3DMetaImporter::FindIndexForColoring(bool useCellData, const std::string& arrayName) -{ - if (!this->Pimpl->ColoringInfoUpdated) - { - this->UpdateInfoForColoring(); - } - - auto& data = - useCellData ? this->Pimpl->CellDataColoringInfo : this->Pimpl->PointDataColoringInfo; - - auto it = data.find(arrayName); - if (it != data.end()) - { - return it->second.Index; - } - return -1; -} - //---------------------------------------------------------------------------- const std::vector& vtkF3DMetaImporter::GetColoringActorsAndMappers() @@ -672,13 +510,13 @@ void vtkF3DMetaImporter::UpdateInfoForColoring() datasetForColoring = genericImporter->GetImportedPoints(); } } - this->Pimpl->UpdateColoringInfo(datasetForColoring, false); - this->Pimpl->UpdateColoringInfo(datasetForColoring, true); + this->Pimpl->ColoringInfoHelper.UpdateColoringInfo(datasetForColoring, false); + this->Pimpl->ColoringInfoHelper.UpdateColoringInfo(datasetForColoring, true); } } - this->Pimpl->FinalizeColoringInfo(false); - this->Pimpl->FinalizeColoringInfo(true); + this->Pimpl->ColoringInfoHelper.FinalizeColoringInfo(false); + this->Pimpl->ColoringInfoHelper.FinalizeColoringInfo(true); this->Pimpl->ColoringInfoUpdated = true; } @@ -715,3 +553,14 @@ std::string vtkF3DMetaImporter::GetMetaDataDescription() const description += std::to_string(nCells); return description; } + +//---------------------------------------------------------------------------- +F3DColoringInfoHelper& vtkF3DMetaImporter::GetColoringInfoHelper() +{ + if (!this->Pimpl->ColoringInfoUpdated) + { + this->UpdateInfoForColoring(); + } + + return this->Pimpl->ColoringInfoHelper; +} diff --git a/vtkext/private/module/vtkF3DMetaImporter.h b/vtkext/private/module/vtkF3DMetaImporter.h index 37b2ee4999..6a13d5db38 100644 --- a/vtkext/private/module/vtkF3DMetaImporter.h +++ b/vtkext/private/module/vtkF3DMetaImporter.h @@ -7,6 +7,7 @@ #define vtkF3DMetaImporter_h #include "vtkF3DImporter.h" +#include "F3DColoringInfoHelper.h" #include #include @@ -77,20 +78,6 @@ class vtkF3DMetaImporter : public vtkF3DImporter }; ///@} - /** - * A struct containing information about possible coloring - */ - struct ColoringInfo - { - std::string Name; - int MaximumNumberOfComponents = 0; - std::vector ComponentNames; - std::vector> ComponentRanges; - std::array MagnitudeRange = { std::numeric_limits::max(), - std::numeric_limits::min() }; - int Index = -1; - }; - /** * Clear all importers and internal structures */ @@ -112,23 +99,8 @@ class vtkF3DMetaImporter : public vtkF3DImporter */ std::string GetMetaDataDescription() const; - /** - * Recover information about coloring by index - * Should be called after actors have been imported - */ - bool GetInfoForColoring(bool useCellData, int index, ColoringInfo& info); - /** - * Get the maximum index possible for coloring - * Should be called after actors have been imported - */ - int GetNumberOfIndexesForColoring(bool useCellData); - - /** - * Find an index for coloring corresponding to provided arrayName if available - * Should be called after actors have been imported - */ - int FindIndexForColoring(bool useCellData, const std::string& arrayName); + F3DColoringInfoHelper& GetColoringInfoHelper(); ///@{ /** diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index 6dcf884f91..8030ebfdbf 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -2,6 +2,7 @@ #include "F3DDefaultHDRI.h" #include "F3DLog.h" +#include "F3DColoringInfoHelper.h" #include "vtkF3DCachedLUTTexture.h" #include "vtkF3DCachedSpecularTexture.h" #include "vtkF3DConfigure.h" @@ -1429,9 +1430,9 @@ void vtkF3DRenderer::FillCheatSheetHotkeys(std::stringstream& cheatSheetText) { assert(this->Importer); - vtkF3DMetaImporter::ColoringInfo info; + F3DColoringInfoHelper::ColoringInfo info; bool hasColoring = - this->Importer->GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); + this->Importer->GetColoringInfoHelper().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); cheatSheetText << " C: Cell scalars coloring [" << (this->UseCellColoring ? "ON" : "OFF") << "]\n"; @@ -2275,14 +2276,14 @@ vtkF3DRenderer::CycleType vtkF3DRenderer::CheckColoring() } // Never force change of CellData/PointData coloring on the user - if (this->Importer->GetNumberOfIndexesForColoring(this->UseCellColoring) == 0) + if (this->Importer->GetColoringInfoHelper().GetNumberOfIndexesForColoring(this->UseCellColoring) == 0) { return CycleType::NONE; } // Suggest to change the array index only if current index is not valid - vtkF3DMetaImporter::ColoringInfo info; - if (!this->Importer->GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) + F3DColoringInfoHelper::ColoringInfo info; + if (!this->Importer->GetColoringInfoHelper().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) { return CycleType::ARRAY_INDEX; } @@ -2312,7 +2313,7 @@ void vtkF3DRenderer::SetColoring(bool enable, this->UseCellColoring = useCellData; this->ComponentForColoring = component; - int nIndexes = this->Importer->GetNumberOfIndexesForColoring(this->UseCellColoring); + int nIndexes = this->Importer->GetColoringInfoHelper().GetNumberOfIndexesForColoring(this->UseCellColoring); if (!enable) { // Not coloring @@ -2332,7 +2333,7 @@ void vtkF3DRenderer::SetColoring(bool enable, else { // Coloring with named array - this->ArrayIndexForColoring = this->Importer->FindIndexForColoring(useCellData, arrayName.value()); + this->ArrayIndexForColoring = this->Importer->GetColoringInfoHelper().FindIndexForColoring(useCellData, arrayName.value()); if (this->ArrayIndexForColoring == -1) { // Could not find named array @@ -2367,8 +2368,8 @@ std::optional vtkF3DRenderer::GetColoringArrayName() assert(this->Importer); std::optional arrayName; - vtkF3DMetaImporter::ColoringInfo info; - if (this->Importer && this->Importer->GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) + F3DColoringInfoHelper::ColoringInfo info; + if (this->Importer && this->Importer->GetColoringInfoHelper().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) { arrayName = info.Name; } @@ -2387,9 +2388,11 @@ void vtkF3DRenderer::ConfigureColoring() assert(this->Importer); // Recover coloring information - vtkF3DMetaImporter::ColoringInfo info; + F3DColoringInfoHelper& coloringHelper = this->Importer->GetColoringInfoHelper(); + F3DColoringInfoHelper::ColoringInfo info; + bool hasColoring = - this->Importer->GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); + coloringHelper.GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); bool volumeVisible = !this->UseRaytracing && this->UseVolume; if (!hasColoring && volumeVisible) @@ -2397,7 +2400,7 @@ void vtkF3DRenderer::ConfigureColoring() // When showing volume, always try to find an array to color with this->CycleScalars(vtkF3DRenderer::CycleType::ARRAY_INDEX); hasColoring = - this->Importer->GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); + coloringHelper.GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); } if (hasColoring && !this->ColorTransferFunctionConfigured) @@ -2523,8 +2526,8 @@ std::string vtkF3DRenderer::GetColoringDescription() assert(this->Importer); std::stringstream stream; - vtkF3DMetaImporter::ColoringInfo info; - if (this->Importer->GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) + F3DColoringInfoHelper::ColoringInfo info; + if (this->Importer->GetColoringInfoHelper().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) { stream << "Coloring using " << (this->UseCellColoring ? "cell" : "point") << " array named " << info.Name << ", " @@ -2657,7 +2660,7 @@ void vtkF3DRenderer::ConfigureScalarBarActorForColoring( //---------------------------------------------------------------------------- void vtkF3DRenderer::ConfigureRangeAndCTFForColoring( - const vtkF3DMetaImporter::ColoringInfo& info) + const F3DColoringInfoHelper::ColoringInfo& info) { if (this->ComponentForColoring == -2) { @@ -2748,7 +2751,7 @@ void vtkF3DRenderer::CycleArrayIndexForColoring() { assert(this->Importer); - int nIndex = this->Importer->GetNumberOfIndexesForColoring(this->UseCellColoring); + int nIndex = this->Importer->GetColoringInfoHelper().GetNumberOfIndexesForColoring(this->UseCellColoring); if (nIndex <= 0) { return; @@ -2771,8 +2774,8 @@ void vtkF3DRenderer::CycleComponentForColoring() { assert(this->Importer); - vtkF3DMetaImporter::ColoringInfo info; - if (!this->Importer->GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) + F3DColoringInfoHelper::ColoringInfo info; + if (!this->Importer->GetColoringInfoHelper().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) { return; } @@ -2797,8 +2800,8 @@ std::string vtkF3DRenderer::ComponentToString(int component) } else { - vtkF3DMetaImporter::ColoringInfo info; - if (!this->Importer->GetInfoForColoring( + F3DColoringInfoHelper::ColoringInfo info; + if (!this->Importer->GetColoringInfoHelper().GetInfoForColoring( this->UseCellColoring, this->ArrayIndexForColoring, info)) { return ""; diff --git a/vtkext/private/module/vtkF3DRenderer.h b/vtkext/private/module/vtkF3DRenderer.h index 973862a47d..0c1fecbd54 100644 --- a/vtkext/private/module/vtkF3DRenderer.h +++ b/vtkext/private/module/vtkF3DRenderer.h @@ -434,7 +434,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer * Configure internal range and color transfer function according to provided * coloring info */ - void ConfigureRangeAndCTFForColoring(const vtkF3DMetaImporter::ColoringInfo& info); + void ConfigureRangeAndCTFForColoring(const F3DColoringInfoHelper::ColoringInfo& info); /** * Switch between point data and cell data coloring From f01a0b37058b98a4cf32fb49f49bd771aec31159 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Thu, 24 Oct 2024 09:04:53 +0200 Subject: [PATCH 2/7] non working version --- library/src/interactor_impl.cxx | 14 +- library/src/window_impl.cxx | 7 +- vtkext/private/module/CMakeLists.txt | 2 +- ...oHelper.cxx => F3DColoringInfoHandler.cxx} | 102 +++++++- ...gInfoHelper.h => F3DColoringInfoHandler.h} | 23 +- vtkext/private/module/vtkF3DMetaImporter.cxx | 16 +- vtkext/private/module/vtkF3DMetaImporter.h | 4 +- vtkext/private/module/vtkF3DRenderer.cxx | 223 ++++++++---------- vtkext/private/module/vtkF3DRenderer.h | 72 +++--- 9 files changed, 270 insertions(+), 193 deletions(-) rename vtkext/private/module/{F3DColoringInfoHelper.cxx => F3DColoringInfoHandler.cxx} (58%) rename vtkext/private/module/{F3DColoringInfoHelper.h => F3DColoringInfoHandler.h} (65%) diff --git a/library/src/interactor_impl.cxx b/library/src/interactor_impl.cxx index eb46de7f88..0dab0cbd66 100644 --- a/library/src/interactor_impl.cxx +++ b/library/src/interactor_impl.cxx @@ -190,7 +190,7 @@ class interactor_impl::internals case 'C': if (ren) { - ren->CycleScalars(vtkF3DRenderer::CycleType::FIELD); + ren->CycleFieldForColoring(); self->Window.PrintColoringDescription(log::VerboseLevel::DEBUG); checkColoring = true; render = true; @@ -199,7 +199,7 @@ class interactor_impl::internals case 'S': if (ren) { - ren->CycleScalars(vtkF3DRenderer::CycleType::ARRAY_INDEX); + ren->CycleArrayForColoring(); self->Window.PrintColoringDescription(log::VerboseLevel::DEBUG); checkColoring = true; render = true; @@ -208,7 +208,7 @@ class interactor_impl::internals case 'Y': if (ren) { - ren->CycleScalars(vtkF3DRenderer::CycleType::COMPONENT); + ren->CycleComponentForColoring();; self->Window.PrintColoringDescription(log::VerboseLevel::DEBUG); checkColoring = true; render = true; @@ -379,10 +379,10 @@ class interactor_impl::internals if (checkColoring) { // Resynchronise renderer coloring status with options - self->Options.model.scivis.enable = ren->GetColoringEnabled(); - self->Options.model.scivis.cells = ren->GetColoringUseCell(); - self->Options.model.scivis.array_name = ren->GetColoringArrayName(); - self->Options.model.scivis.component = ren->GetColoringComponent(); + self->Options.model.scivis.enable = ren->GetEnableColoring(); + self->Options.model.scivis.cells = ren->GetUseCellColoring(); + self->Options.model.scivis.array_name = ren->GetArrayNameForColoring(); + self->Options.model.scivis.component = ren->GetComponentForColoring(); } if (render) { diff --git a/library/src/window_impl.cxx b/library/src/window_impl.cxx index 47483cd037..33ff621822 100644 --- a/library/src/window_impl.cxx +++ b/library/src/window_impl.cxx @@ -533,8 +533,11 @@ void window_impl::UpdateDynamicOptions() renderer->SetNormalScale(opt.model.normal.scale); renderer->SetTextureMatCap(opt.model.matcap.texture); - renderer->SetColoring(opt.model.scivis.enable, opt.model.scivis.cells, - opt.model.scivis.array_name, opt.model.scivis.component); + renderer->SetEnableColoring(opt.model.scivis.enable); + renderer->SetUseCellColoring(opt.model.scivis.cells); + renderer->SetArrayNameForColoring(opt.model.scivis.array_name); + renderer->SetComponentForColoring(opt.model.scivis.component); + renderer->SetScalarBarRange(opt.model.scivis.range); renderer->SetColormap(opt.model.scivis.colormap); renderer->ShowScalarBar(opt.ui.scalar_bar); diff --git a/vtkext/private/module/CMakeLists.txt b/vtkext/private/module/CMakeLists.txt index 9dd0b912a6..26086ede7b 100644 --- a/vtkext/private/module/CMakeLists.txt +++ b/vtkext/private/module/CMakeLists.txt @@ -31,7 +31,7 @@ endforeach() set(classes F3DLog - F3DColoringInfoHelper + F3DColoringInfoHandler vtkF3DCachedLUTTexture vtkF3DCachedSpecularTexture vtkF3DConsoleOutputWindow diff --git a/vtkext/private/module/F3DColoringInfoHelper.cxx b/vtkext/private/module/F3DColoringInfoHandler.cxx similarity index 58% rename from vtkext/private/module/F3DColoringInfoHelper.cxx rename to vtkext/private/module/F3DColoringInfoHandler.cxx index 23bbe2577e..7a57c13b74 100644 --- a/vtkext/private/module/F3DColoringInfoHelper.cxx +++ b/vtkext/private/module/F3DColoringInfoHandler.cxx @@ -1,4 +1,6 @@ -#include "F3DColoringInfoHelper.h" +#include "F3DColoringInfoHandler.h" + +#include "F3DLog.h" #include #include @@ -9,14 +11,14 @@ #include //---------------------------------------------------------------------------- -void F3DColoringInfoHelper::ClearColoringInfo() +void F3DColoringInfoHandler::ClearColoringInfo() { this->PointDataColoringInfo.clear(); this->CellDataColoringInfo.clear(); } //---------------------------------------------------------------------------- -void F3DColoringInfoHelper::UpdateColoringInfo(vtkDataSet* dataset, bool useCellData) +void F3DColoringInfoHandler::UpdateColoringInfo(vtkDataSet* dataset, bool useCellData) { // XXX: This assumes importer do not import actors with an empty input assert(dataset); @@ -42,7 +44,7 @@ void F3DColoringInfoHelper::UpdateColoringInfo(vtkDataSet* dataset, bool useCell for (const std::string& arrayName : arrayNames) { // Recover/Create a coloring info - F3DColoringInfoHelper::ColoringInfo& info = data[arrayName]; + F3DColoringInfoHandler::ColoringInfo& info = data[arrayName]; info.Name = arrayName; vtkDataArray* array = useCellData ? dataset->GetCellData()->GetArray(arrayName.c_str()) @@ -99,7 +101,7 @@ void F3DColoringInfoHelper::UpdateColoringInfo(vtkDataSet* dataset, bool useCell } //---------------------------------------------------------------------------- -void F3DColoringInfoHelper::FinalizeColoringInfo(bool useCellData) +void F3DColoringInfoHandler::FinalizeColoringInfo(bool useCellData) { auto& names = useCellData ? this->CellDataArrayNames : this->PointDataArrayNames; names.clear(); @@ -115,8 +117,8 @@ void F3DColoringInfoHelper::FinalizeColoringInfo(bool useCellData) } //---------------------------------------------------------------------------- -bool F3DColoringInfoHelper::GetInfoForColoring( - bool useCellData, int index, F3DColoringInfoHelper::ColoringInfo& info) +/*bool F3DColoringInfoHandler::GetInfoForColoring( + bool useCellData, int index, F3DColoringInfoHandler::ColoringInfo& info) { auto& data = useCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; @@ -133,7 +135,7 @@ bool F3DColoringInfoHelper::GetInfoForColoring( } //---------------------------------------------------------------------------- -int F3DColoringInfoHelper::GetNumberOfIndexesForColoring(bool useCellData) +int F3DColoringInfoHandler::GetNumberOfIndicesForColoring(bool useCellData) { auto& data = useCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; @@ -141,7 +143,7 @@ int F3DColoringInfoHelper::GetNumberOfIndexesForColoring(bool useCellData) } //---------------------------------------------------------------------------- -int F3DColoringInfoHelper::FindIndexForColoring(bool useCellData, const std::string& arrayName) +int F3DColoringInfoHandler::FindIndexForColoring(bool useCellData, const std::string& arrayName) { auto& data = useCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; @@ -152,4 +154,86 @@ int F3DColoringInfoHelper::FindIndexForColoring(bool useCellData, const std::str return it->second.Index; } return -1; +}*/ + +//---------------------------------------------------------------------------- +bool F3DColoringInfoHandler::SetCurrentColoring(bool enable, bool useCellData, std::optional arrayName, ColoringInfo& info) +{ + this->CurrentUsingCellData = useCellData; + auto& data = + this->CurrentUsingCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; + int nIndices = static_cast(data.size()); + + if (!enable) + { + // Not coloring + this->CurrentArrayIndex = -1; + } + else if (nIndices == 0) + { + // Trying to color but no array available + F3DLog::Print(F3DLog::Severity::Debug, "No array to color with"); + this->CurrentArrayIndex = -1; + } + else if (!arrayName.has_value()) + { + // Coloring with first array + this->CurrentArrayIndex = 0; + } + else + { + // Coloring with named array + auto it = data.find(arrayName.value()); + if (it != data.end()) + { + this->CurrentArrayIndex = it->second.Index; + } + else + { + // Could not find named array + this->CurrentArrayIndex = -1; + F3DLog::Print(F3DLog::Severity::Warning, "Unknown scalar array: \"" + arrayName.value() + "\"\n"); + } + } + return this->GetCurrentColoring(info); +} + +//---------------------------------------------------------------------------- +bool F3DColoringInfoHandler::GetCurrentColoring(ColoringInfo& info) +{ + if (this->CurrentArrayIndex != -1) + { + auto& data = + this->CurrentUsingCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; + auto& names = this->CurrentUsingCellData ? this->CellDataArrayNames : this->PointDataArrayNames; + info = data[names[this->CurrentArrayIndex]]; + return true; + } + else + { + return false; + } +} + +//---------------------------------------------------------------------------- +void F3DColoringInfoHandler::CycleColoringArray(bool cycleToNonColoring) +{ + auto& data = + this->CurrentUsingCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo; + int nIndices = static_cast(data.size()); + if (nIndices <= 0) + { + return; + } + + if (cycleToNonColoring) + { + // Cycle through arrays looping back to -1 + // -1 0 1 2 -1 0 1 2 ... + this->CurrentArrayIndex = (this->CurrentArrayIndex + 2) % (nIndices + 1) - 1; + } + else + { + this->CurrentArrayIndex = (this->CurrentArrayIndex + 1) % nIndices; + } } diff --git a/vtkext/private/module/F3DColoringInfoHelper.h b/vtkext/private/module/F3DColoringInfoHandler.h similarity index 65% rename from vtkext/private/module/F3DColoringInfoHelper.h rename to vtkext/private/module/F3DColoringInfoHandler.h index 939cff16a0..dee6c197c5 100644 --- a/vtkext/private/module/F3DColoringInfoHelper.h +++ b/vtkext/private/module/F3DColoringInfoHandler.h @@ -1,18 +1,19 @@ /** - * @class F3DColoringInfoHelper - * @brief A statefull helper to handle coloring info + * @class F3DColoringInfoHandler + * @brief A statefull Handler to handle coloring info */ -#ifndef F3DColoringInfoHelper_h -#define F3DColoringInfoHelper_h +#ifndef F3DColoringInfoHandler_h +#define F3DColoringInfoHandler_h #include #include #include #include #include +#include class vtkDataSet; -class F3DColoringInfoHelper +class F3DColoringInfoHandler { public: /** @@ -34,23 +35,27 @@ class F3DColoringInfoHelper void FinalizeColoringInfo(bool useCellData); void ClearColoringInfo(); + bool SetCurrentColoring(bool enable, bool useCellData, std::optional arrayName, ColoringInfo& info); + bool GetCurrentColoring(ColoringInfo& info); + void CycleColoringArray(bool cycleToNonColoring); + /** * Recover information about coloring by index * Should be called after actors have been imported */ - bool GetInfoForColoring(bool useCellData, int index, ColoringInfo& info); +// bool GetInfoForColoring(bool useCellData, int index, ColoringInfo& info); /** * Get the maximum index possible for coloring * Should be called after actors have been imported */ - int GetNumberOfIndexesForColoring(bool useCellData); +// int GetNumberOfIndexesForColoring(bool useCellData); /** * Find an index for coloring corresponding to provided arrayName if available * Should be called after actors have been imported */ - int FindIndexForColoring(bool useCellData, const std::string& arrayName); +// int FindIndexForColoring(bool useCellData, const std::string& arrayName); private: // Map of arrayName -> coloring info @@ -58,6 +63,8 @@ class F3DColoringInfoHelper std::map CellDataColoringInfo; std::vector PointDataArrayNames; std::vector CellDataArrayNames; + int CurrentArrayIndex = -1; + bool CurrentUsingCellData = false; }; #endif diff --git a/vtkext/private/module/vtkF3DMetaImporter.cxx b/vtkext/private/module/vtkF3DMetaImporter.cxx index 96afced90c..14bced4a3c 100644 --- a/vtkext/private/module/vtkF3DMetaImporter.cxx +++ b/vtkext/private/module/vtkF3DMetaImporter.cxx @@ -39,7 +39,7 @@ struct vtkF3DMetaImporter::Internals vtkBoundingBox GeometryBoundingBox; bool ColoringInfoUpdated = false; - F3DColoringInfoHelper ColoringInfoHelper; + F3DColoringInfoHandler ColoringInfoHandler; #if VTK_VERSION_NUMBER < VTK_VERSION_CHECK(9, 3, 20240707) std::map> ActorsForImporterMap; @@ -71,7 +71,7 @@ void vtkF3DMetaImporter::Clear() this->Pimpl->ColoringActorsAndMappers.clear(); this->Pimpl->PointSpritesActorsAndMappers.clear(); this->Pimpl->VolumePropsAndMappers.clear(); - this->Pimpl->ColoringInfoHelper.ClearColoringInfo(); + this->Pimpl->ColoringInfoHandler.ClearColoringInfo(); this->Modified(); } @@ -510,13 +510,13 @@ void vtkF3DMetaImporter::UpdateInfoForColoring() datasetForColoring = genericImporter->GetImportedPoints(); } } - this->Pimpl->ColoringInfoHelper.UpdateColoringInfo(datasetForColoring, false); - this->Pimpl->ColoringInfoHelper.UpdateColoringInfo(datasetForColoring, true); + this->Pimpl->ColoringInfoHandler.UpdateColoringInfo(datasetForColoring, false); + this->Pimpl->ColoringInfoHandler.UpdateColoringInfo(datasetForColoring, true); } } - this->Pimpl->ColoringInfoHelper.FinalizeColoringInfo(false); - this->Pimpl->ColoringInfoHelper.FinalizeColoringInfo(true); + this->Pimpl->ColoringInfoHandler.FinalizeColoringInfo(false); + this->Pimpl->ColoringInfoHandler.FinalizeColoringInfo(true); this->Pimpl->ColoringInfoUpdated = true; } @@ -555,12 +555,12 @@ std::string vtkF3DMetaImporter::GetMetaDataDescription() const } //---------------------------------------------------------------------------- -F3DColoringInfoHelper& vtkF3DMetaImporter::GetColoringInfoHelper() +F3DColoringInfoHandler& vtkF3DMetaImporter::GetColoringInfoHandler() { if (!this->Pimpl->ColoringInfoUpdated) { this->UpdateInfoForColoring(); } - return this->Pimpl->ColoringInfoHelper; + return this->Pimpl->ColoringInfoHandler; } diff --git a/vtkext/private/module/vtkF3DMetaImporter.h b/vtkext/private/module/vtkF3DMetaImporter.h index 6a13d5db38..cb6a53a72f 100644 --- a/vtkext/private/module/vtkF3DMetaImporter.h +++ b/vtkext/private/module/vtkF3DMetaImporter.h @@ -7,7 +7,7 @@ #define vtkF3DMetaImporter_h #include "vtkF3DImporter.h" -#include "F3DColoringInfoHelper.h" +#include "F3DColoringInfoHandler.h" #include #include @@ -100,7 +100,7 @@ class vtkF3DMetaImporter : public vtkF3DImporter std::string GetMetaDataDescription() const; - F3DColoringInfoHelper& GetColoringInfoHelper(); + F3DColoringInfoHandler& GetColoringInfoHandler(); ///@{ /** diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index 8030ebfdbf..2ecf062989 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -2,7 +2,7 @@ #include "F3DDefaultHDRI.h" #include "F3DLog.h" -#include "F3DColoringInfoHelper.h" +#include "F3DColoringInfoHandler.h" #include "vtkF3DCachedLUTTexture.h" #include "vtkF3DCachedSpecularTexture.h" #include "vtkF3DConfigure.h" @@ -282,9 +282,6 @@ void vtkF3DRenderer::Initialize() this->AnimationNameInfo = ""; this->GridInfo = ""; - this->ArrayIndexForColoring = -1; - this->ComponentForColoring = -1; - this->AddActor2D(this->ScalarBarActor); this->ScalarBarActor->VisibilityOff(); @@ -1430,9 +1427,9 @@ void vtkF3DRenderer::FillCheatSheetHotkeys(std::stringstream& cheatSheetText) { assert(this->Importer); - F3DColoringInfoHelper::ColoringInfo info; - bool hasColoring = - this->Importer->GetColoringInfoHelper().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); + F3DColoringInfoHandler::ColoringInfo info; + bool hasColoring = false; +// this->Importer->GetColoringInfoHandler().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); cheatSheetText << " C: Cell scalars coloring [" << (this->UseCellColoring ? "ON" : "OFF") << "]\n"; @@ -2232,88 +2229,25 @@ void vtkF3DRenderer::SetColormap(const std::vector& colormap) } //---------------------------------------------------------------------------- -void vtkF3DRenderer::CycleScalars(CycleType type) -{ - switch (type) - { - case (CycleType::NONE): - return; - break; - case (CycleType::FIELD): - this->CycleFieldForColoring(); - break; - case (CycleType::ARRAY_INDEX): - this->CycleArrayIndexForColoring(); - break; - case (CycleType::COMPONENT): - this->CycleComponentForColoring(); - break; - default: - break; - } - - // Check attributes are valid and cycle recursively if needed - this->CycleScalars(this->CheckColoring()); - - this->ColorTransferFunctionConfigured = false; - this->ColoringMappersConfigured = false; - this->PointSpritesMappersConfigured = false; - this->VolumePropsAndMappersConfigured = false; - this->ScalarBarActorConfigured = false; - this->CheatSheetConfigured = false; - this->ColoringConfigured = false; -} - -//---------------------------------------------------------------------------- -vtkF3DRenderer::CycleType vtkF3DRenderer::CheckColoring() -{ - assert(this->Importer); - - // Never force change of anything if we are currently not coloring - if (this->ArrayIndexForColoring < 0) - { - return CycleType::NONE; - } - - // Never force change of CellData/PointData coloring on the user - if (this->Importer->GetColoringInfoHelper().GetNumberOfIndexesForColoring(this->UseCellColoring) == 0) - { - return CycleType::NONE; - } - - // Suggest to change the array index only if current index is not valid - F3DColoringInfoHelper::ColoringInfo info; - if (!this->Importer->GetColoringInfoHelper().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) - { - return CycleType::ARRAY_INDEX; - } - - // Suggest to change the component if current component is invalid - if (this->ComponentForColoring >= info.MaximumNumberOfComponents) - { - return CycleType::COMPONENT; - } - - return CycleType::NONE; -} - -//---------------------------------------------------------------------------- -void vtkF3DRenderer::SetColoring(bool enable, +/*void vtkF3DRenderer::SetColoring(bool enable, bool useCellData, const std::optional& arrayName, int component) { assert(this->Importer); // XXX This should be reworked to avoid handling multiple information in one parameters // while still being future-proof and flexible enough. + // TODO SPLIT if (enable != (this->ArrayIndexForColoring >= 0) || useCellData != this->UseCellColoring || component != this->ComponentForColoring || arrayName != this->GetColoringArrayName()) { + this->EnableColoring = enable; this->UseCellColoring = useCellData; this->ComponentForColoring = component; + this->ArrayNameForColoring = arrayName; - int nIndexes = this->Importer->GetColoringInfoHelper().GetNumberOfIndexesForColoring(this->UseCellColoring); + int nIndexes = this->Importer->GetColoringInfoHandler().GetNumberOfIndexesForColoring(this->UseCellColoring); if (!enable) { // Not coloring @@ -2333,7 +2267,7 @@ void vtkF3DRenderer::SetColoring(bool enable, else { // Coloring with named array - this->ArrayIndexForColoring = this->Importer->GetColoringInfoHelper().FindIndexForColoring(useCellData, arrayName.value()); + this->ArrayIndexForColoring = this->Importer->GetColoringInfoHandler().FindIndexForColoring(useCellData, arrayName.value()); if (this->ArrayIndexForColoring == -1) { // Could not find named array @@ -2348,38 +2282,75 @@ void vtkF3DRenderer::SetColoring(bool enable, this->ScalarBarActorConfigured = false; this->ColoringConfigured = false; } -} +}*/ //---------------------------------------------------------------------------- -bool vtkF3DRenderer::GetColoringEnabled() +bool vtkF3DRenderer::SetColoringOnHandler(F3DColoringInfoHandler::ColoringInfo& info) { - return this->ArrayIndexForColoring >= 0; + bool enableColoring = this->EnableColoring || (!this->UseRaytracing && this->UseVolume); + F3DColoringInfoHandler& coloringHandler = this->Importer->GetColoringInfoHandler(); + return coloringHandler.SetCurrentColoring(enableColoring, this->UseCellColoring, this->ArrayNameForColoring, info); } //---------------------------------------------------------------------------- -bool vtkF3DRenderer::GetColoringUseCell() +void vtkF3DRenderer::SetEnableColoring(bool enable) { - return this->UseCellColoring; + if (enable != this->EnableColoring) + { + this->EnableColoring = enable; + this->ColoringConfigured = false; + } } //---------------------------------------------------------------------------- -std::optional vtkF3DRenderer::GetColoringArrayName() +void vtkF3DRenderer::SetUseCellColoring(bool useCell) { - assert(this->Importer); + if (useCell != this->UseCellColoring) + { + this->UseCellColoring = useCell; + this->ColorTransferFunctionConfigured = false; + this->ColoringMappersConfigured = false; + this->PointSpritesMappersConfigured = false; + this->VolumePropsAndMappersConfigured = false; + this->ScalarBarActorConfigured = false; + this->ColoringConfigured = false; + } +} - std::optional arrayName; - F3DColoringInfoHelper::ColoringInfo info; - if (this->Importer && this->Importer->GetColoringInfoHelper().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) +//---------------------------------------------------------------------------- +void vtkF3DRenderer::SetArrayNameForColoring(const std::optional& arrayName) +{ + if (arrayName != this->ArrayNameForColoring) { - arrayName = info.Name; + this->ArrayNameForColoring = arrayName; + this->ColorTransferFunctionConfigured = false; + this->ColoringMappersConfigured = false; + this->PointSpritesMappersConfigured = false; + this->VolumePropsAndMappersConfigured = false; + this->ScalarBarActorConfigured = false; + this->ColoringConfigured = false; } - return arrayName; } //---------------------------------------------------------------------------- -int vtkF3DRenderer::GetColoringComponent() +std::optional vtkF3DRenderer::GetArrayNameForColoring() { - return this->ComponentForColoring; + return this->ArrayNameForColoring; +} + +//---------------------------------------------------------------------------- +void vtkF3DRenderer::SetComponentForColoring(int component) +{ + if (component != this->ComponentForColoring) + { + this->ComponentForColoring = component; + this->ColorTransferFunctionConfigured = false; + this->ColoringMappersConfigured = false; + this->PointSpritesMappersConfigured = false; + this->VolumePropsAndMappersConfigured = false; + this->ScalarBarActorConfigured = false; + this->ColoringConfigured = false; + } } //---------------------------------------------------------------------------- @@ -2387,21 +2358,9 @@ void vtkF3DRenderer::ConfigureColoring() { assert(this->Importer); - // Recover coloring information - F3DColoringInfoHelper& coloringHelper = this->Importer->GetColoringInfoHelper(); - F3DColoringInfoHelper::ColoringInfo info; - - bool hasColoring = - coloringHelper.GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); - - bool volumeVisible = !this->UseRaytracing && this->UseVolume; - if (!hasColoring && volumeVisible) - { - // When showing volume, always try to find an array to color with - this->CycleScalars(vtkF3DRenderer::CycleType::ARRAY_INDEX); - hasColoring = - coloringHelper.GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); - } + // Recover coloring information and update hel + F3DColoringInfoHandler::ColoringInfo info; + bool hasColoring = this->SetColoringOnHandler(info); if (hasColoring && !this->ColorTransferFunctionConfigured) { @@ -2466,6 +2425,7 @@ void vtkF3DRenderer::ConfigureColoring() } // Handle Volume prop + bool volumeVisible = !this->UseRaytracing && this->UseVolume; const auto& volPropsAndMappers = this->Importer->GetVolumePropsAndMappers(); for (const auto& [prop, mapper] : volPropsAndMappers) { @@ -2526,8 +2486,8 @@ std::string vtkF3DRenderer::GetColoringDescription() assert(this->Importer); std::stringstream stream; - F3DColoringInfoHelper::ColoringInfo info; - if (this->Importer->GetColoringInfoHelper().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) +/* F3DColoringInfoHandler::ColoringInfo info; + if (this->Importer->GetColoringInfoHandler().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) { stream << "Coloring using " << (this->UseCellColoring ? "cell" : "point") << " array named " << info.Name << ", " @@ -2536,7 +2496,7 @@ std::string vtkF3DRenderer::GetColoringDescription() else { stream << "Not coloring\n"; - } + }*/ return stream.str(); } @@ -2660,7 +2620,7 @@ void vtkF3DRenderer::ConfigureScalarBarActorForColoring( //---------------------------------------------------------------------------- void vtkF3DRenderer::ConfigureRangeAndCTFForColoring( - const F3DColoringInfoHelper::ColoringInfo& info) + const F3DColoringInfoHandler::ColoringInfo& info) { if (this->ComponentForColoring == -2) { @@ -2742,30 +2702,33 @@ void vtkF3DRenderer::ConfigureRangeAndCTFForColoring( //---------------------------------------------------------------------------- void vtkF3DRenderer::CycleFieldForColoring() { - // A generic approach will be better when adding categorical field data coloring + // XXX: A generic approach will be better when adding categorical field data coloring this->UseCellColoring = !this->UseCellColoring; + F3DColoringInfoHandler::ColoringInfo info; + if (!this->SetColoringOnHandler(info)) + { + // Cycle array if the current one is not valid + this->CycleArrayForColoring(); + } } //---------------------------------------------------------------------------- -void vtkF3DRenderer::CycleArrayIndexForColoring() +void vtkF3DRenderer::CycleArrayForColoring() { assert(this->Importer); + this->Importer->GetColoringInfoHandler().CycleColoringArray(!this->UseVolume); + F3DColoringInfoHandler::ColoringInfo info; - int nIndex = this->Importer->GetColoringInfoHelper().GetNumberOfIndexesForColoring(this->UseCellColoring); - if (nIndex <= 0) - { - return; - } - - if (this->UseVolume) + // Update coloring properties accordingly + this->EnableColoring = this->SetColoringOnHandler(info); + if (this->EnableColoring) { - this->ArrayIndexForColoring = (this->ArrayIndexForColoring + 1) % nIndex; - } - else - { - // Cycle through arrays looping back to -1 - // -1 0 1 2 -1 0 1 2 ... - this->ArrayIndexForColoring = (this->ArrayIndexForColoring + 2) % (nIndex + 1) - 1; + this->ArrayNameForColoring = info.Name; + if (this->ComponentForColoring >= info.MaximumNumberOfComponents) + { + // Cycle component if the current one is not valid + this->CycleComponentForColoring(); + } } } @@ -2774,8 +2737,8 @@ void vtkF3DRenderer::CycleComponentForColoring() { assert(this->Importer); - F3DColoringInfoHelper::ColoringInfo info; - if (!this->Importer->GetColoringInfoHelper().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) + F3DColoringInfoHandler::ColoringInfo info; + if (!this->Importer->GetColoringInfoHandler().GetCurrentColoring(info)) { return; } @@ -2800,8 +2763,8 @@ std::string vtkF3DRenderer::ComponentToString(int component) } else { - F3DColoringInfoHelper::ColoringInfo info; - if (!this->Importer->GetColoringInfoHelper().GetInfoForColoring( +/* F3DColoringInfoHandler::ColoringInfo info; + if (!this->Importer->GetColoringInfoHandler().GetInfoForColoring( this->UseCellColoring, this->ArrayIndexForColoring, info)) { return ""; @@ -2822,5 +2785,7 @@ std::string vtkF3DRenderer::ComponentToString(int component) componentName += std::to_string(component); } return componentName; + */ + return ""; } } diff --git a/vtkext/private/module/vtkF3DRenderer.h b/vtkext/private/module/vtkF3DRenderer.h index 0c1fecbd54..097a626708 100644 --- a/vtkext/private/module/vtkF3DRenderer.h +++ b/vtkext/private/module/vtkF3DRenderer.h @@ -282,18 +282,18 @@ class vtkF3DRenderer : public vtkOpenGLRenderer */ void SetColormap(const std::vector& colormap); - enum class CycleType +/* enum class CycleType { NONE, FIELD, ARRAY_INDEX, COMPONENT - }; + };*/ /** * Cycle the shown scalars according to the cycle type */ - void CycleScalars(CycleType type); +// void CycleScalars(CycleType type); /** * Set the meta importer to recover coloring information from @@ -305,24 +305,56 @@ class vtkF3DRenderer : public vtkOpenGLRenderer * This method will try to find the corresponding array in the coloring attributes and will * position ArrayIndexForColoring and DataForColoring accordingly. */ - void SetColoring(bool enable, bool useCellData, const std::optional& arrayName, int component); +// void SetColoring(bool enable, bool useCellData, const std::optional& arrayName, int component); ///@{ /** * Get current coloring information, * Useful after using Cycle methods */ - bool GetColoringEnabled(); +/* bool GetColoringEnabled(); bool GetColoringUseCell(); std::optional GetColoringArrayName(); - int GetColoringComponent(); + int GetColoringComponent();*/ ///@} + void SetEnableColoring(bool enable); + vtkGetMacro(EnableColoring, bool); + + void SetUseCellColoring(bool useCell); + vtkGetMacro(UseCellColoring, bool); + + void SetArrayNameForColoring(const std::optional& arrayName); + std::optional GetArrayNameForColoring(); + + void SetComponentForColoring(int component); + vtkGetMacro(ComponentForColoring, int); + /** * Get information about the current coloring */ virtual std::string GetColoringDescription(); + /** + * Switch between point data and cell data coloring + */ + void CycleFieldForColoring(); + + /** + * Increment the array index or loop it back + * When not using volume, it will loop back + * to not coloring + * TODO + */ + void CycleArrayForColoring(); + + /** + * Cycle the component in used for rendering + * looping back to direct scalars + */ + void CycleComponentForColoring(); + + private: vtkF3DRenderer(); ~vtkF3DRenderer() override; @@ -434,30 +466,14 @@ class vtkF3DRenderer : public vtkOpenGLRenderer * Configure internal range and color transfer function according to provided * coloring info */ - void ConfigureRangeAndCTFForColoring(const F3DColoringInfoHelper::ColoringInfo& info); - - /** - * Switch between point data and cell data coloring - */ - void CycleFieldForColoring(); - - /** - * Increment the array index or loop it back - * When not using volume, it will loop back - * to not coloring - */ - void CycleArrayIndexForColoring(); - - /** - * Cycle the component in used for rendering - * looping back to direct scalars - */ - void CycleComponentForColoring(); + void ConfigureRangeAndCTFForColoring(const F3DColoringInfoHandler::ColoringInfo& info); /** * Check coloring is currently valid and return a cycle type to perform if not */ - CycleType CheckColoring(); +// CycleType CheckColoring(); + + bool SetColoringOnHandler(F3DColoringInfoHandler::ColoringInfo& info); /** * Convert a component index into a string @@ -580,9 +596,11 @@ class vtkF3DRenderer : public vtkOpenGLRenderer double ColorRange[2] = { 0.0, 1.0 }; bool ColorTransferFunctionConfigured = false; + bool EnableColoring = false; bool UseCellColoring = false; - int ArrayIndexForColoring = -1; +// int ArrayIndexForColoring = -1; int ComponentForColoring = -1; + std::optional ArrayNameForColoring; bool ScalarBarVisible = false; bool UsePointSprites = false; From f6c1ead5fd15c2384ccce61b541527c4659693bd Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Fri, 25 Oct 2024 09:21:59 +0200 Subject: [PATCH 3/7] make it work --- .../private/module/F3DColoringInfoHandler.cxx | 7 +- .../private/module/F3DColoringInfoHandler.h | 2 +- vtkext/private/module/vtkF3DRenderer.cxx | 205 ++++++------------ vtkext/private/module/vtkF3DRenderer.h | 49 +---- 4 files changed, 76 insertions(+), 187 deletions(-) diff --git a/vtkext/private/module/F3DColoringInfoHandler.cxx b/vtkext/private/module/F3DColoringInfoHandler.cxx index 7a57c13b74..70a3f90243 100644 --- a/vtkext/private/module/F3DColoringInfoHandler.cxx +++ b/vtkext/private/module/F3DColoringInfoHandler.cxx @@ -157,7 +157,7 @@ int F3DColoringInfoHandler::FindIndexForColoring(bool useCellData, const std::st }*/ //---------------------------------------------------------------------------- -bool F3DColoringInfoHandler::SetCurrentColoring(bool enable, bool useCellData, std::optional arrayName, ColoringInfo& info) +bool F3DColoringInfoHandler::SetCurrentColoring(bool enable, bool useCellData, std::optional arrayName, ColoringInfo& info, bool quiet) { this->CurrentUsingCellData = useCellData; auto& data = @@ -192,7 +192,10 @@ bool F3DColoringInfoHandler::SetCurrentColoring(bool enable, bool useCellData, s { // Could not find named array this->CurrentArrayIndex = -1; - F3DLog::Print(F3DLog::Severity::Warning, "Unknown scalar array: \"" + arrayName.value() + "\"\n"); + if (!quiet) + { + F3DLog::Print(F3DLog::Severity::Warning, "Unknown scalar array: \"" + arrayName.value() + "\"\n"); + } } } return this->GetCurrentColoring(info); diff --git a/vtkext/private/module/F3DColoringInfoHandler.h b/vtkext/private/module/F3DColoringInfoHandler.h index dee6c197c5..310dbc3924 100644 --- a/vtkext/private/module/F3DColoringInfoHandler.h +++ b/vtkext/private/module/F3DColoringInfoHandler.h @@ -35,7 +35,7 @@ class F3DColoringInfoHandler void FinalizeColoringInfo(bool useCellData); void ClearColoringInfo(); - bool SetCurrentColoring(bool enable, bool useCellData, std::optional arrayName, ColoringInfo& info); + bool SetCurrentColoring(bool enable, bool useCellData, std::optional arrayName, ColoringInfo& info, bool quiet); bool GetCurrentColoring(ColoringInfo& info); void CycleColoringArray(bool cycleToNonColoring); diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index 2ecf062989..a3004dc142 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -1367,11 +1367,54 @@ void vtkF3DRenderer::ShowCheatSheet(bool show) //---------------------------------------------------------------------------- void vtkF3DRenderer::ConfigureCheatSheet() { + assert(this->Importer); if (this->CheatSheetVisible) { + F3DColoringInfoHandler::ColoringInfo info; + bool hasColoring = + this->Importer->GetColoringInfoHandler().GetCurrentColoring(info); + std::stringstream cheatSheetText; cheatSheetText << "\n"; - this->FillCheatSheetHotkeys(cheatSheetText); + cheatSheetText << " C: Cell scalars coloring [" << (this->UseCellColoring ? "ON" : "OFF") + << "]\n"; + cheatSheetText << " S: Scalars coloring [" + << (hasColoring ? vtkF3DRenderer::ShortName(info.Name, 19) : "OFF") << "]\n"; + cheatSheetText << " Y: Coloring component [" + << vtkF3DRenderer::ComponentToString(this->ComponentForColoring) + << "]\n"; + cheatSheetText << " B: Scalar bar " << (this->ScalarBarVisible ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " V: Volume representation " << (this->UseVolume ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " I: Inverse volume opacity " + << (this->UseInverseOpacityFunction ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " O: Point sprites " << (this->UsePointSprites ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " W: Cycle animation [" + << vtkF3DRenderer::ShortName(this->AnimationNameInfo, 22) << "]\n"; + cheatSheetText << " P: Translucency support " << (this->UseDepthPeelingPass ? "[ON]" : "[OFF]") + << "\n"; + cheatSheetText << " Q: Ambient occlusion " << (this->UseSSAOPass ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " A: Anti-aliasing " << (this->UseFXAAPass ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " T: Tone mapping " << (this->UseToneMappingPass ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " E: Edge visibility " << (this->EdgeVisible ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " X: Axis " << (this->AxisVisible ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " G: Grid " << (this->GridVisible ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " N: File name " << (this->FilenameVisible ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " M: Metadata " << (this->MetaDataVisible ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " Z: FPS Timer " << (this->TimerVisible ? "[ON]" : "[OFF]") << "\n"; +#if F3D_MODULE_RAYTRACING + cheatSheetText << " R: Raytracing " << (this->UseRaytracing ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " D: Denoiser " << (this->UseRaytracingDenoiser ? "[ON]" : "[OFF]") << "\n"; +#endif + cheatSheetText << " U: Blur background " << (this->UseBlurBackground ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " K: Trackball interaction " << (this->UseTrackball ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " F: HDRI ambient lighting " + << (this->GetUseImageBasedLighting() ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText << " J: HDRI skybox " << (this->HDRISkyboxVisible ? "[ON]" : "[OFF]") << "\n"; + cheatSheetText.precision(2); + cheatSheetText << std::fixed; + cheatSheetText << " L: Light (increase, shift+L: decrease) [" << this->LightIntensity << "]" + << " \n"; + cheatSheetText << "\n H : Cheat sheet \n"; cheatSheetText << " ? : Print scene descr to terminal\n"; cheatSheetText << " ESC : Quit \n"; @@ -1384,7 +1427,7 @@ void vtkF3DRenderer::ConfigureCheatSheet() cheatSheetText << " 3: Right View camera\n"; cheatSheetText << " 4: Roll the camera left by 90 degrees\n"; cheatSheetText << " 5: Toggle Orthographic Projection " - << (this->UseOrthographicProjection ? "[ON]" : "[OFF]") << "\n"; + << (this->UseOrthographicProjection ? "[ON]" : "[OFF]") << "\n"; cheatSheetText << " 6: Roll the camera right by 90 degrees\n"; cheatSheetText << " 7: Top View camera\n"; cheatSheetText << " 9: Isometric View camera\n"; @@ -1422,56 +1465,6 @@ void vtkF3DRenderer::ShowHDRISkybox(bool show) } } -//---------------------------------------------------------------------------- -void vtkF3DRenderer::FillCheatSheetHotkeys(std::stringstream& cheatSheetText) -{ - assert(this->Importer); - - F3DColoringInfoHandler::ColoringInfo info; - bool hasColoring = false; -// this->Importer->GetColoringInfoHandler().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info); - - cheatSheetText << " C: Cell scalars coloring [" << (this->UseCellColoring ? "ON" : "OFF") - << "]\n"; - cheatSheetText << " S: Scalars coloring [" - << (hasColoring ? vtkF3DRenderer::ShortName(info.Name, 19) : "OFF") << "]\n"; - cheatSheetText << " Y: Coloring component [" - << vtkF3DRenderer::ComponentToString(this->ComponentForColoring) - << "]\n"; - cheatSheetText << " B: Scalar bar " << (this->ScalarBarVisible ? "[ON]" : "[OFF]") << "\n"; - - cheatSheetText << " V: Volume representation " << (this->UseVolume ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " I: Inverse volume opacity " - << (this->UseInverseOpacityFunction ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " O: Point sprites " << (this->UsePointSprites ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " W: Cycle animation [" - << vtkF3DRenderer::ShortName(this->AnimationNameInfo, 22) << "]\n"; - cheatSheetText << " P: Translucency support " << (this->UseDepthPeelingPass ? "[ON]" : "[OFF]") - << "\n"; - cheatSheetText << " Q: Ambient occlusion " << (this->UseSSAOPass ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " A: Anti-aliasing " << (this->UseFXAAPass ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " T: Tone mapping " << (this->UseToneMappingPass ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " E: Edge visibility " << (this->EdgeVisible ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " X: Axis " << (this->AxisVisible ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " G: Grid " << (this->GridVisible ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " N: File name " << (this->FilenameVisible ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " M: Metadata " << (this->MetaDataVisible ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " Z: FPS Timer " << (this->TimerVisible ? "[ON]" : "[OFF]") << "\n"; -#if F3D_MODULE_RAYTRACING - cheatSheetText << " R: Raytracing " << (this->UseRaytracing ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " D: Denoiser " << (this->UseRaytracingDenoiser ? "[ON]" : "[OFF]") << "\n"; -#endif - cheatSheetText << " U: Blur background " << (this->UseBlurBackground ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " K: Trackball interaction " << (this->UseTrackball ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " F: HDRI ambient lighting " - << (this->GetUseImageBasedLighting() ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText << " J: HDRI skybox " << (this->HDRISkyboxVisible ? "[ON]" : "[OFF]") << "\n"; - cheatSheetText.precision(2); - cheatSheetText << std::fixed; - cheatSheetText << " L: Light (increase, shift+L: decrease) [" << this->LightIntensity << "]" - << " \n"; -} - //---------------------------------------------------------------------------- void vtkF3DRenderer::ShowEdge(const std::optional& show) { @@ -1914,7 +1907,7 @@ void vtkF3DRenderer::ConfigureActorsProperties() emissiveFactor = this->EmissiveFactor.value().data(); } } - + bool setBackfaceCulling = false; bool backfaceCulling = true; if (this->BackfaceType.has_value()) @@ -2228,76 +2221,13 @@ void vtkF3DRenderer::SetColormap(const std::vector& colormap) } } -//---------------------------------------------------------------------------- -/*void vtkF3DRenderer::SetColoring(bool enable, - bool useCellData, const std::optional& arrayName, int component) -{ - assert(this->Importer); - - // XXX This should be reworked to avoid handling multiple information in one parameters - // while still being future-proof and flexible enough. - // TODO SPLIT - if (enable != (this->ArrayIndexForColoring >= 0) - || useCellData != this->UseCellColoring - || component != this->ComponentForColoring - || arrayName != this->GetColoringArrayName()) - { - this->EnableColoring = enable; - this->UseCellColoring = useCellData; - this->ComponentForColoring = component; - this->ArrayNameForColoring = arrayName; - - int nIndexes = this->Importer->GetColoringInfoHandler().GetNumberOfIndexesForColoring(this->UseCellColoring); - if (!enable) - { - // Not coloring - this->ArrayIndexForColoring = -1; - } - else if (nIndexes == 0) - { - // Trying to color but no array available - F3DLog::Print(F3DLog::Severity::Debug, "No array to color with"); - this->ArrayIndexForColoring = -1; - } - else if (!arrayName.has_value()) - { - // Coloring with first array - this->ArrayIndexForColoring = 0; - } - else - { - // Coloring with named array - this->ArrayIndexForColoring = this->Importer->GetColoringInfoHandler().FindIndexForColoring(useCellData, arrayName.value()); - if (this->ArrayIndexForColoring == -1) - { - // Could not find named array - F3DLog::Print(F3DLog::Severity::Warning, "Unknown scalar array: \"" + arrayName.value() + "\"\n"); - } - } - - this->ColorTransferFunctionConfigured = false; - this->ColoringMappersConfigured = false; - this->PointSpritesMappersConfigured = false; - this->VolumePropsAndMappersConfigured = false; - this->ScalarBarActorConfigured = false; - this->ColoringConfigured = false; - } -}*/ - -//---------------------------------------------------------------------------- -bool vtkF3DRenderer::SetColoringOnHandler(F3DColoringInfoHandler::ColoringInfo& info) -{ - bool enableColoring = this->EnableColoring || (!this->UseRaytracing && this->UseVolume); - F3DColoringInfoHandler& coloringHandler = this->Importer->GetColoringInfoHandler(); - return coloringHandler.SetCurrentColoring(enableColoring, this->UseCellColoring, this->ArrayNameForColoring, info); -} - //---------------------------------------------------------------------------- void vtkF3DRenderer::SetEnableColoring(bool enable) { if (enable != this->EnableColoring) { this->EnableColoring = enable; + this->CheatSheetConfigured = false; this->ColoringConfigured = false; } } @@ -2313,6 +2243,7 @@ void vtkF3DRenderer::SetUseCellColoring(bool useCell) this->PointSpritesMappersConfigured = false; this->VolumePropsAndMappersConfigured = false; this->ScalarBarActorConfigured = false; + this->CheatSheetConfigured = false; this->ColoringConfigured = false; } } @@ -2328,6 +2259,7 @@ void vtkF3DRenderer::SetArrayNameForColoring(const std::optional& a this->PointSpritesMappersConfigured = false; this->VolumePropsAndMappersConfigured = false; this->ScalarBarActorConfigured = false; + this->CheatSheetConfigured = false; this->ColoringConfigured = false; } } @@ -2349,6 +2281,7 @@ void vtkF3DRenderer::SetComponentForColoring(int component) this->PointSpritesMappersConfigured = false; this->VolumePropsAndMappersConfigured = false; this->ScalarBarActorConfigured = false; + this->CheatSheetConfigured = false; this->ColoringConfigured = false; } } @@ -2358,10 +2291,11 @@ void vtkF3DRenderer::ConfigureColoring() { assert(this->Importer); - // Recover coloring information and update hel + // Recover coloring information and update handler + bool enableColoring = this->EnableColoring || (!this->UseRaytracing && this->UseVolume); + F3DColoringInfoHandler& coloringHandler = this->Importer->GetColoringInfoHandler(); F3DColoringInfoHandler::ColoringInfo info; - bool hasColoring = this->SetColoringOnHandler(info); - + bool hasColoring = coloringHandler.SetCurrentColoring(enableColoring, this->UseCellColoring, this->ArrayNameForColoring, info, false); if (hasColoring && !this->ColorTransferFunctionConfigured) { this->ConfigureRangeAndCTFForColoring(info); @@ -2486,8 +2420,8 @@ std::string vtkF3DRenderer::GetColoringDescription() assert(this->Importer); std::stringstream stream; -/* F3DColoringInfoHandler::ColoringInfo info; - if (this->Importer->GetColoringInfoHandler().GetInfoForColoring(this->UseCellColoring, this->ArrayIndexForColoring, info)) + F3DColoringInfoHandler::ColoringInfo info; + if (this->Importer->GetColoringInfoHandler().GetCurrentColoring(info)) { stream << "Coloring using " << (this->UseCellColoring ? "cell" : "point") << " array named " << info.Name << ", " @@ -2496,7 +2430,7 @@ std::string vtkF3DRenderer::GetColoringDescription() else { stream << "Not coloring\n"; - }*/ + } return stream.str(); } @@ -2703,9 +2637,11 @@ void vtkF3DRenderer::ConfigureRangeAndCTFForColoring( void vtkF3DRenderer::CycleFieldForColoring() { // XXX: A generic approach will be better when adding categorical field data coloring - this->UseCellColoring = !this->UseCellColoring; + this->SetUseCellColoring(!this->UseCellColoring); + bool enableColoring = this->EnableColoring || (!this->UseRaytracing && this->UseVolume); + F3DColoringInfoHandler& coloringHandler = this->Importer->GetColoringInfoHandler(); F3DColoringInfoHandler::ColoringInfo info; - if (!this->SetColoringOnHandler(info)) + if (!coloringHandler.SetCurrentColoring(enableColoring, this->UseCellColoring, this->ArrayNameForColoring, info, true)) { // Cycle array if the current one is not valid this->CycleArrayForColoring(); @@ -2716,14 +2652,14 @@ void vtkF3DRenderer::CycleFieldForColoring() void vtkF3DRenderer::CycleArrayForColoring() { assert(this->Importer); - this->Importer->GetColoringInfoHandler().CycleColoringArray(!this->UseVolume); + this->Importer->GetColoringInfoHandler().CycleColoringArray(!this->UseVolume); //TODO check this cond F3DColoringInfoHandler::ColoringInfo info; + bool enable = this->Importer->GetColoringInfoHandler().GetCurrentColoring(info); - // Update coloring properties accordingly - this->EnableColoring = this->SetColoringOnHandler(info); + this->SetEnableColoring(enable); if (this->EnableColoring) { - this->ArrayNameForColoring = info.Name; + this->SetArrayNameForColoring(info.Name); if (this->ComponentForColoring >= info.MaximumNumberOfComponents) { // Cycle component if the current one is not valid @@ -2744,8 +2680,8 @@ void vtkF3DRenderer::CycleComponentForColoring() } // -2 -1 0 1 2 3 4 - this->ComponentForColoring = - (this->ComponentForColoring + 3) % (info.MaximumNumberOfComponents + 2) - 2; + this->SetComponentForColoring( + (this->ComponentForColoring + 3) % (info.MaximumNumberOfComponents + 2) - 2); } //---------------------------------------------------------------------------- @@ -2763,9 +2699,8 @@ std::string vtkF3DRenderer::ComponentToString(int component) } else { -/* F3DColoringInfoHandler::ColoringInfo info; - if (!this->Importer->GetColoringInfoHandler().GetInfoForColoring( - this->UseCellColoring, this->ArrayIndexForColoring, info)) + F3DColoringInfoHandler::ColoringInfo info; + if (!this->Importer->GetColoringInfoHandler().GetCurrentColoring(info)) { return ""; } @@ -2785,7 +2720,5 @@ std::string vtkF3DRenderer::ComponentToString(int component) componentName += std::to_string(component); } return componentName; - */ - return ""; } } diff --git a/vtkext/private/module/vtkF3DRenderer.h b/vtkext/private/module/vtkF3DRenderer.h index 097a626708..085e28b528 100644 --- a/vtkext/private/module/vtkF3DRenderer.h +++ b/vtkext/private/module/vtkF3DRenderer.h @@ -282,42 +282,11 @@ class vtkF3DRenderer : public vtkOpenGLRenderer */ void SetColormap(const std::vector& colormap); -/* enum class CycleType - { - NONE, - FIELD, - ARRAY_INDEX, - COMPONENT - };*/ - - /** - * Cycle the shown scalars according to the cycle type - */ -// void CycleScalars(CycleType type); - /** * Set the meta importer to recover coloring information from */ void SetImporter(vtkF3DMetaImporter* importer); - /** - * 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 enable, bool useCellData, const std::optional& arrayName, int component); - - ///@{ - /** - * Get current coloring information, - * Useful after using Cycle methods - */ -/* bool GetColoringEnabled(); - bool GetColoringUseCell(); - std::optional GetColoringArrayName(); - int GetColoringComponent();*/ - ///@} - void SetEnableColoring(bool enable); vtkGetMacro(EnableColoring, bool); @@ -341,9 +310,6 @@ class vtkF3DRenderer : public vtkOpenGLRenderer void CycleFieldForColoring(); /** - * Increment the array index or loop it back - * When not using volume, it will loop back - * to not coloring * TODO */ void CycleArrayForColoring(); @@ -401,7 +367,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer void ConfigureActorsProperties(); /** - * Configure the cheatsheet text and mark it for rendering + * Configure the cheatsheet text and hotkeys and mark it for rendering */ void ConfigureCheatSheet(); @@ -415,11 +381,6 @@ class vtkF3DRenderer : public vtkOpenGLRenderer */ void ConfigureRenderPasses(); - /** - * Add all hotkeys options to the cheatsheet. - */ - void FillCheatSheetHotkeys(std::stringstream& sheet); - /** * Generate a padded metadata description * using the internal importer @@ -468,13 +429,6 @@ class vtkF3DRenderer : public vtkOpenGLRenderer */ void ConfigureRangeAndCTFForColoring(const F3DColoringInfoHandler::ColoringInfo& info); - /** - * Check coloring is currently valid and return a cycle type to perform if not - */ -// CycleType CheckColoring(); - - bool SetColoringOnHandler(F3DColoringInfoHandler::ColoringInfo& info); - /** * Convert a component index into a string * If there is a component name defined in the current coloring information, display it. @@ -598,7 +552,6 @@ class vtkF3DRenderer : public vtkOpenGLRenderer bool EnableColoring = false; bool UseCellColoring = false; -// int ArrayIndexForColoring = -1; int ComponentForColoring = -1; std::optional ArrayNameForColoring; From 98da4c9bac338c9c4b40ea088f8c8cff67d212eb Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Fri, 25 Oct 2024 09:26:06 +0200 Subject: [PATCH 4/7] fixup tests --- .../Testing/TestF3DMetaImporterMultiColoring.cxx | 8 ++++---- .../Testing/TestF3DRendererWithColoring.cxx | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/vtkext/private/module/Testing/TestF3DMetaImporterMultiColoring.cxx b/vtkext/private/module/Testing/TestF3DMetaImporterMultiColoring.cxx index 97f220253f..ee8a5dd87b 100644 --- a/vtkext/private/module/Testing/TestF3DMetaImporterMultiColoring.cxx +++ b/vtkext/private/module/Testing/TestF3DMetaImporterMultiColoring.cxx @@ -41,11 +41,11 @@ int TestF3DMetaImporterMultiColoring(int argc, char* argv[]) return EXIT_FAILURE; } - if (importer->FindIndexForColoring(false, "") != -1) +/* if (importer->FindIndexForColoring(false, "") != -1) { std::cerr << "Unexpected FindIndexForColoring success" << std::endl; return EXIT_FAILURE; - } + }*/ // Read a vts and a vtu with same array names @@ -71,7 +71,7 @@ int TestF3DMetaImporterMultiColoring(int argc, char* argv[]) importer->SetRenderWindow(window); importer->Update(); - if (importer->GetNumberOfIndexesForColoring(false) != 3) + /*if (importer->GetNumberOfIndexesForColoring(false) != 3) { std::cerr << "Importer provide unexpected number of indexes for coloring" << std::endl; return EXIT_FAILURE; @@ -122,7 +122,7 @@ int TestF3DMetaImporterMultiColoring(int argc, char* argv[]) { std::cerr << "Unexpected coloring magnitude range" << std::endl; return EXIT_FAILURE; - } + }*/ return EXIT_SUCCESS; } diff --git a/vtkext/private/module/Testing/TestF3DRendererWithColoring.cxx b/vtkext/private/module/Testing/TestF3DRendererWithColoring.cxx index 6b1c58e67a..70593f7d6e 100644 --- a/vtkext/private/module/Testing/TestF3DRendererWithColoring.cxx +++ b/vtkext/private/module/Testing/TestF3DRendererWithColoring.cxx @@ -31,33 +31,35 @@ int TestF3DRendererWithColoring(int argc, char* argv[]) importer->Update(); // Check invalid array code path - renderer->SetColoring(true, false, "Invalid", 0); + renderer->SetEnableColoring(true); + renderer->SetArrayNameForColoring("Invalid"); renderer->SetUseVolume(false); renderer->UpdateActors(); - renderer->CycleScalars(vtkF3DRenderer::CycleType::COMPONENT); + renderer->CycleComponentForColoring(); renderer->SetUseVolume(true); renderer->UpdateActors(); - if (renderer->GetColoringArrayName() != "Density" || renderer->GetColoringComponent() != 0) + if (renderer->GetArrayNameForColoring() != "Density" || renderer->GetComponentForColoring() != 0) { std::cerr << "Unexpected coloring information with invalid array" << std::endl; return EXIT_FAILURE; } // Check invalid component code path - renderer->SetColoring(true, false, "Momentum", 5); + renderer->SetArrayNameForColoring("Momentum"); + renderer->SetComponentForColoring(5); renderer->UpdateActors(); renderer->SetUseVolume(true); renderer->UpdateActors(); - if (renderer->GetColoringArrayName() != "Momentum" || renderer->GetColoringComponent() != 5) + if (renderer->GetArrayNameForColoring() != "Momentum" || renderer->GetComponentForColoring() != 5) { std::cerr << "Unexpected coloring information with invalid component" << std::endl; return EXIT_FAILURE; } - renderer->CycleScalars(vtkF3DRenderer::CycleType::COMPONENT); - if (renderer->GetColoringArrayName() != "Momentum" || renderer->GetColoringComponent() != 1) + renderer->CycleComponentForColoring(); + if (renderer->GetArrayNameForColoring() != "Momentum" || renderer->GetComponentForColoring() != 1) { std::cerr << "Unexpected coloring information after cycling component" << std::endl; return EXIT_FAILURE; From 2f84540655ca170ac9d711084269fd3b2a7d197f Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Fri, 25 Oct 2024 22:06:11 +0200 Subject: [PATCH 5/7] Add many missing eol --- vtkext/private/module/vtkF3DRenderer.cxx | 30 ++++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index a3004dc142..09d837e460 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -336,7 +336,7 @@ void vtkF3DRenderer::InitializeUpVector(const std::string& upString) } else { - F3DLog::Print(F3DLog::Severity::Warning, upString + " is not a valid up direction"); + F3DLog::Print(F3DLog::Severity::Warning, upString + " is not a valid up direction\n"); } } @@ -403,7 +403,7 @@ void vtkF3DRenderer::ConfigureRenderPasses() else { F3DLog::Print(F3DLog::Severity::Warning, - "Final shader must define a function named \"pixel\""); + "Final shader must define a function named \"pixel\"\n"); } } @@ -425,7 +425,7 @@ void vtkF3DRenderer::ConfigureRenderPasses() if (this->UseRaytracing || this->UseRaytracingDenoiser) { F3DLog::Print(F3DLog::Severity::Warning, - "Raytracing options can't be used if F3D has not been built with raytracing"); + "Raytracing options can't be used if F3D has not been built with raytracing\n"); } #endif this->RenderPassesConfigured = true; @@ -500,7 +500,7 @@ void vtkF3DRenderer::ShowAxis(bool show) } else { - F3DLog::Print(F3DLog::Severity::Error, "Axis widget cannot be shown without an interactor"); + F3DLog::Print(F3DLog::Severity::Error, "Axis widget cannot be shown without an interactor\n"); } } @@ -787,7 +787,7 @@ void vtkF3DRenderer::ConfigureHDRIReader() if (!vtksys::SystemTools::FileExists(this->HDRIFile.value(), true)) { F3DLog::Print( - F3DLog::Severity::Warning, std::string("HDRI file does not exist ") + this->HDRIFile.value()); + F3DLog::Severity::Warning, std::string("HDRI file does not exist ") + this->HDRIFile.value() + "\n"); } else { @@ -801,7 +801,7 @@ void vtkF3DRenderer::ConfigureHDRIReader() { F3DLog::Print(F3DLog::Severity::Warning, std::string("Cannot open HDRI file ") + this->HDRIFile.value() + - std::string(". Using default HDRI")); + std::string(". Using default HDRI\n")); } } } @@ -1119,7 +1119,7 @@ void vtkF3DRenderer::ConfigureTextActors() else { F3DLog::Print( - F3DLog::Severity::Warning, std::string("Cannot find \"") + tmpFontFile + "\" font file."); + F3DLog::Severity::Warning, std::string("Cannot find \"") + tmpFontFile + "\" font file.\n"); } } @@ -1924,7 +1924,7 @@ void vtkF3DRenderer::ConfigureActorsProperties() else { setBackfaceCulling = false; - F3DLog::Print(F3DLog::Severity::Warning, this->BackfaceType.value() + " is not a valid backface type, assuming it is not set"); + F3DLog::Print(F3DLog::Severity::Warning, this->BackfaceType.value() + " is not a valid backface type, assuming it is not set\n"); } } @@ -2062,7 +2062,7 @@ void vtkF3DRenderer::SetPointSpritesProperties(SplatType type, double pointSprit { F3DLog::Print(F3DLog::Severity::Warning, "Compute shaders are not supported, gaussians are not sorted, resulting in blending " - "artifacts"); + "artifacts\n"); } #endif } @@ -2097,7 +2097,7 @@ void vtkF3DRenderer::SetPointSpritesProperties(SplatType type, double pointSprit mapper->SetLowpassMatrix(lowPass); #else F3DLog::Print(F3DLog::Severity::Warning, - "Gaussian splatting selected but VTK <= 9.3 only supports isotropic gaussians"); + "Gaussian splatting selected but VTK <= 9.3 only supports isotropic gaussians\n"); #endif actor->ForceTranslucentOn(); @@ -2383,7 +2383,7 @@ void vtkF3DRenderer::ConfigureColoring() if (!visible) { F3DLog::Print( - F3DLog::Severity::Warning, "Cannot find the array \"" + info.Name + "\" to display volume with"); + F3DLog::Severity::Warning, "Cannot find the array \"" + info.Name + "\" to display volume with\n"); } } } @@ -2395,7 +2395,7 @@ void vtkF3DRenderer::ConfigureColoring() if (!this->VolumePropsAndMappersConfigured && volPropsAndMappers.size() == 0) { F3DLog::Print( - F3DLog::Severity::Error, "Cannot use volume with this data"); + F3DLog::Severity::Error, "Cannot use volume with this data\n"); } this->VolumePropsAndMappersConfigured = true; } @@ -2460,7 +2460,7 @@ bool vtkF3DRenderer::ConfigureMapperForColoring(vtkPolyDataMapper* mapper, const { // comp > 4 is actually not supported and would fail with a vtk error F3DLog::Print(F3DLog::Severity::Warning, - "Direct scalars rendering not supported by array with more than 4 components"); + "Direct scalars rendering not supported by array with more than 4 components\n"); return false; } else @@ -2512,7 +2512,7 @@ bool vtkF3DRenderer::ConfigureVolumeForColoring(vtkSmartVolumeMapper* mapper, { // comp > 4 is actually not supported and would fail with a vtk error F3DLog::Print(F3DLog::Severity::Warning, - "Direct scalars rendering not supported by array with more than 4 components"); + "Direct scalars rendering not supported by array with more than 4 components\n"); return false; } else @@ -2618,7 +2618,7 @@ void vtkF3DRenderer::ConfigureRangeAndCTFForColoring( else { F3DLog::Print(F3DLog::Severity::Warning, - "Specified color map list count is not a multiple of 4, ignoring it."); + "Specified color map list count is not a multiple of 4, ignoring it.\n"); } } From 12bfbb43c8e7866683b2277d5a9045168dcf9777 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Fri, 25 Oct 2024 22:06:27 +0200 Subject: [PATCH 6/7] fix test --- vtkext/private/module/Testing/TestF3DRendererWithColoring.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vtkext/private/module/Testing/TestF3DRendererWithColoring.cxx b/vtkext/private/module/Testing/TestF3DRendererWithColoring.cxx index 70593f7d6e..1f5ac4c12b 100644 --- a/vtkext/private/module/Testing/TestF3DRendererWithColoring.cxx +++ b/vtkext/private/module/Testing/TestF3DRendererWithColoring.cxx @@ -39,7 +39,7 @@ int TestF3DRendererWithColoring(int argc, char* argv[]) renderer->SetUseVolume(true); renderer->UpdateActors(); - if (renderer->GetArrayNameForColoring() != "Density" || renderer->GetComponentForColoring() != 0) + if (renderer->GetArrayNameForColoring() != "Invalid" || renderer->GetComponentForColoring() != -1) { std::cerr << "Unexpected coloring information with invalid array" << std::endl; return EXIT_FAILURE; From 46efaa6c6e1a6b06a6aa9986065e2cb15f47f790 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Fri, 25 Oct 2024 22:07:24 +0200 Subject: [PATCH 7/7] fixup interactor --- library/src/interactor_impl.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/interactor_impl.cxx b/library/src/interactor_impl.cxx index 0dab0cbd66..c81bfb63b2 100644 --- a/library/src/interactor_impl.cxx +++ b/library/src/interactor_impl.cxx @@ -208,7 +208,7 @@ class interactor_impl::internals case 'Y': if (ren) { - ren->CycleComponentForColoring();; + ren->CycleComponentForColoring(); self->Window.PrintColoringDescription(log::VerboseLevel::DEBUG); checkColoring = true; render = true;