From fae4cc4c797404ea7e3c23a8dd33c6508732a2eb Mon Sep 17 00:00:00 2001 From: Roxana Bujack Date: Tue, 7 Nov 2023 13:52:05 -0700 Subject: [PATCH] first round of fixes --- vtkm/cont/DataSet.h | 9 +- vtkm/cont/Field.h | 9 -- vtkm/filter/multi_block/AmrArrays.cxx | 41 +++++-- vtkm/rendering/Actor.cxx | 156 +++++++++++--------------- vtkm/rendering/Actor.h | 12 +- 5 files changed, 106 insertions(+), 121 deletions(-) diff --git a/vtkm/cont/DataSet.h b/vtkm/cont/DataSet.h index 32f0b2fff..2aa06da04 100644 --- a/vtkm/cont/DataSet.h +++ b/vtkm/cont/DataSet.h @@ -167,7 +167,7 @@ public: /// whether a particular field exists. ///@{ VTKM_CONT - const vtkm::cont::Field GetGhostCellField() const; + vtkm::cont::Field GetGhostCellField() const; ///@} /// \brief Returns the first point field that matches the provided name. @@ -243,13 +243,6 @@ public: this->AddField(make_FieldCell(fieldName, field)); } - template - VTKM_CONT void AddCellField(const std::string& fieldName, - const vtkm::cont::ArrayHandleConstant& field) - { - this->AddField(make_FieldCell(fieldName, field)); - } - template VTKM_CONT void AddCellField(const std::string& fieldName, const std::vector& field) { diff --git a/vtkm/cont/Field.h b/vtkm/cont/Field.h index 1107c065f..189b3a76c 100644 --- a/vtkm/cont/Field.h +++ b/vtkm/cont/Field.h @@ -251,15 +251,6 @@ inline vtkm::cont::Field make_FieldCell(std::string name, { return vtkm::cont::Field(name, vtkm::cont::Field::Association::Cells, data); } - -/// Convenience function to build cell fields from vtkm::cont::ArrayHandleConstant -template -inline vtkm::cont::Field make_FieldCell(std::string name, - const vtkm::cont::ArrayHandleConstant& data) -{ - return vtkm::cont::Field(name, vtkm::cont::Field::Association::Cells, data); -} - } // namespace cont } // namespace vtkm diff --git a/vtkm/filter/multi_block/AmrArrays.cxx b/vtkm/filter/multi_block/AmrArrays.cxx index e7d4cb8eb..aa86207e5 100644 --- a/vtkm/filter/multi_block/AmrArrays.cxx +++ b/vtkm/filter/multi_block/AmrArrays.cxx @@ -224,10 +224,20 @@ void AmrArrays::ComputeGenerateGhostType() vtkm::cont::CellSetStructured cellset; partition.GetCellSet().AsCellSet(cellset); vtkm::cont::ArrayHandle ghostArrayHandle; - vtkm::cont::Invoker invoke; - invoke(vtkm::worklet::ResetGhostTypeWorklet{}, - partition.GetGhostCellField().GetData().ExtractComponent(0), - ghostArrayHandle); + if (!partition.HasGhostCellField()) + { + ghostArrayHandle.AllocateAndFill(partition.GetNumberOfCells(), 0); + // vtkm::cont::ArrayHandleConstant ghostArrayHandle = vtkm::cont::ArrayHandleConstant (0, partition.GetNumberOfCells()); + } + else + { + vtkm::cont::Invoker invoke; + invoke(vtkm::worklet::ResetGhostTypeWorklet{}, + partition.GetGhostCellField() + .GetData() + .AsArrayHandle>(), + ghostArrayHandle); + } partition.AddCellField(vtkm::cont::GetGlobalGhostCellFieldName(), ghostArrayHandle); auto pointField = partition.GetCoordinateSystem().GetDataAsMultiplexer(); @@ -244,10 +254,11 @@ void AmrArrays::ComputeGenerateGhostType() .GetBounds(); // std::cout<<" is (partly) contained in level "<ChildrenIdsVector.at(this->PartitionIds.at(l).at(bParent)).at(bChild)<<" with bounds "<{ boundsChild }, cellset, pointField, - partition.GetGhostCellField().GetData().ExtractComponent(0)); + ghostArrayHandle); } this->AmrDataSet.ReplacePartition(this->PartitionIds.at(l).at(bParent), partition); } @@ -264,15 +275,21 @@ void AmrArrays::GenerateIndexArrays() { vtkm::cont::DataSet partition = this->AmrDataSet.GetPartition(this->PartitionIds.at(l).at(b)); - partition.AddCellField( - "vtkAmrLevel", vtkm::cont::ArrayHandleConstant(l, partition.GetNumberOfCells())); + vtkm::cont::ArrayHandle fieldAmrLevel; + vtkm::cont::ArrayCopy( + vtkm::cont::ArrayHandleConstant(l, partition.GetNumberOfCells()), fieldAmrLevel); + partition.AddCellField("vtkAmrLevel", fieldAmrLevel); - partition.AddCellField( - "vtkAmrIndex", vtkm::cont::ArrayHandleConstant(b, partition.GetNumberOfCells())); + vtkm::cont::ArrayHandle fieldBlockId; + vtkm::cont::ArrayCopy( + vtkm::cont::ArrayHandleConstant(b, partition.GetNumberOfCells()), fieldBlockId); + partition.AddCellField("vtkAmrIndex", fieldBlockId); - partition.AddCellField("vtkCompositeIndex", - vtkm::cont::ArrayHandleConstant( - this->PartitionIds.at(l).at(b), partition.GetNumberOfCells())); + vtkm::cont::ArrayHandle fieldPartitionIndex; + vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleConstant( + this->PartitionIds.at(l).at(b), partition.GetNumberOfCells()), + fieldPartitionIndex); + partition.AddCellField("vtkCompositeIndex", fieldPartitionIndex); this->AmrDataSet.ReplacePartition(this->PartitionIds.at(l).at(b), partition); } diff --git a/vtkm/rendering/Actor.cxx b/vtkm/rendering/Actor.cxx index baf6b8b23..57b31b7f7 100644 --- a/vtkm/rendering/Actor.cxx +++ b/vtkm/rendering/Actor.cxx @@ -25,114 +25,94 @@ namespace rendering struct Actor::InternalsType { - vtkm::cont::UnknownCellSet Cells; - vtkm::cont::CoordinateSystem Coordinates; - vtkm::cont::Field ScalarField; + vtkm::cont::PartitionedDataSet Data; + std::string CoordinateName; + std::string FieldName; + vtkm::cont::Field::Association FieldAssociation; + vtkm::cont::ColorTable ColorTable; vtkm::Range ScalarRange; vtkm::Bounds SpatialBounds; - vtkm::cont::PartitionedDataSet DataSet; - std::string FieldName; - VTKM_CONT InternalsType(const vtkm::cont::PartitionedDataSet partitionedDataSet, + const std::string coordinateName, const std::string fieldName, const vtkm::rendering::Color& color) - : Cells(partitionedDataSet.GetPartition(0).GetCellSet()) - , Coordinates(partitionedDataSet.GetPartition(0).GetCoordinateSystem()) - , ScalarField(partitionedDataSet.GetPartition(0).GetField(fieldName)) - , ColorTable(vtkm::Range{ 0, 1 }, color.Components, color.Components) - , DataSet(partitionedDataSet) + : Data(partitionedDataSet) + , CoordinateName(coordinateName) , FieldName(fieldName) - { - } - - VTKM_CONT - InternalsType(const vtkm::cont::PartitionedDataSet partitionedDataSet, - const std::string fieldName, - const vtkm::cont::ColorTable& colorTable = vtkm::cont::ColorTable::Preset::Default) - : Cells(partitionedDataSet.GetPartition(0).GetCellSet()) - , Coordinates(partitionedDataSet.GetPartition(0).GetCoordinateSystem()) - , ScalarField(partitionedDataSet.GetPartition(0).GetField(fieldName)) - , ColorTable(colorTable) - , DataSet(partitionedDataSet) - , FieldName(fieldName) - { - } - - VTKM_CONT - InternalsType(const vtkm::cont::UnknownCellSet& cells, - const vtkm::cont::CoordinateSystem& coordinates, - const vtkm::cont::Field& scalarField, - const vtkm::rendering::Color& color) - : Cells(std::move(cells)) - , Coordinates(std::move(coordinates)) - , ScalarField(std::move(scalarField)) , ColorTable(vtkm::Range{ 0, 1 }, color.Components, color.Components) { } VTKM_CONT - InternalsType(vtkm::cont::UnknownCellSet cells, - vtkm::cont::CoordinateSystem coordinates, - vtkm::cont::Field scalarField, + InternalsType(const vtkm::cont::PartitionedDataSet partitionedDataSet, + const std::string coordinateName, + const std::string fieldName, const vtkm::cont::ColorTable& colorTable = vtkm::cont::ColorTable::Preset::Default) - : Cells(std::move(cells)) - , Coordinates(std::move(coordinates)) - , ScalarField(std::move(scalarField)) + : Data(partitionedDataSet) + , CoordinateName(coordinateName) + , FieldName(fieldName) , ColorTable(colorTable) { } }; -Actor::Actor(const vtkm::cont::DataSet dataSet, const std::string fieldName) +Actor::Actor(const vtkm::cont::DataSet dataSet, + const std::string coordinateName, + const std::string fieldName) { - vtkm::cont::PartitionedDataSet partitionedDataSet; - partitionedDataSet.AppendPartition(dataSet); - this->Internals = std::make_unique(partitionedDataSet, fieldName); + vtkm::cont::PartitionedDataSet partitionedDataSet(dataSet); + this->Internals = std::make_unique(partitionedDataSet, coordinateName, fieldName); this->Init(); } Actor::Actor(const vtkm::cont::DataSet dataSet, + const std::string coordinateName, const std::string fieldName, const vtkm::rendering::Color& color) { - vtkm::cont::PartitionedDataSet partitionedDataSet; - partitionedDataSet.AppendPartition(dataSet); - this->Internals = std::make_unique(partitionedDataSet, fieldName, color); + vtkm::cont::PartitionedDataSet partitionedDataSet(dataSet); + this->Internals = + std::make_unique(partitionedDataSet, coordinateName, fieldName, color); this->Init(); } Actor::Actor(const vtkm::cont::DataSet dataSet, + const std::string coordinateName, const std::string fieldName, const vtkm::cont::ColorTable& colorTable) { - vtkm::cont::PartitionedDataSet partitionedDataSet; - partitionedDataSet.AppendPartition(dataSet); - this->Internals = std::make_unique(partitionedDataSet, fieldName, colorTable); + vtkm::cont::PartitionedDataSet partitionedDataSet(dataSet); + this->Internals = + std::make_unique(partitionedDataSet, coordinateName, fieldName, colorTable); this->Init(); } -Actor::Actor(const vtkm::cont::PartitionedDataSet dataSet, const std::string fieldName) - : Internals(new InternalsType(dataSet, fieldName)) +Actor::Actor(const vtkm::cont::PartitionedDataSet dataSet, + const std::string coordinateName, + const std::string fieldName) + : Internals(new InternalsType(dataSet, coordinateName, fieldName)) { this->Init(); } Actor::Actor(const vtkm::cont::PartitionedDataSet dataSet, + const std::string coordinateName, const std::string fieldName, const vtkm::rendering::Color& color) - : Internals(new InternalsType(dataSet, fieldName, color)) + : Internals(new InternalsType(dataSet, coordinateName, fieldName, color)) { this->Init(); } Actor::Actor(const vtkm::cont::PartitionedDataSet dataSet, + const std::string coordinateName, const std::string fieldName, const vtkm::cont::ColorTable& colorTable) - : Internals(new InternalsType(dataSet, fieldName, colorTable)) + : Internals(new InternalsType(dataSet, coordinateName, fieldName, colorTable)) { this->Init(); } @@ -140,27 +120,42 @@ Actor::Actor(const vtkm::cont::PartitionedDataSet dataSet, Actor::Actor(const vtkm::cont::UnknownCellSet& cells, const vtkm::cont::CoordinateSystem& coordinates, const vtkm::cont::Field& scalarField) - : Internals(std::make_unique(cells, coordinates, scalarField)) { - this->Init(coordinates, scalarField); + vtkm::cont::DataSet dataSet; + dataSet.SetCellSet(cells); + dataSet.AddCoordinateSystem(coordinates); + dataSet.AddField(scalarField); + this->Internals = + std::make_unique(dataSet, coordinates.GetName(), scalarField.GetName()); + this->Init(); } Actor::Actor(const vtkm::cont::UnknownCellSet& cells, const vtkm::cont::CoordinateSystem& coordinates, const vtkm::cont::Field& scalarField, const vtkm::rendering::Color& color) - : Internals(std::make_unique(cells, coordinates, scalarField, color)) { - this->Init(coordinates, scalarField); + vtkm::cont::DataSet dataSet; + dataSet.SetCellSet(cells); + dataSet.AddCoordinateSystem(coordinates); + dataSet.AddField(scalarField); + this->Internals = + std::make_unique(dataSet, coordinates.GetName(), scalarField.GetName(), color); + this->Init(); } Actor::Actor(const vtkm::cont::UnknownCellSet& cells, const vtkm::cont::CoordinateSystem& coordinates, const vtkm::cont::Field& scalarField, const vtkm::cont::ColorTable& colorTable) - : Internals(std::make_unique(cells, coordinates, scalarField, colorTable)) { - this->Init(coordinates, scalarField); + vtkm::cont::DataSet dataSet; + dataSet.SetCellSet(cells); + dataSet.AddCoordinateSystem(coordinates); + dataSet.AddField(scalarField); + this->Internals = std::make_unique( + dataSet, coordinates.GetName(), scalarField.GetName(), colorTable); + this->Init(); } Actor::Actor(const Actor& rhs) @@ -194,18 +189,11 @@ Actor::Actor(vtkm::rendering::Actor&&) noexcept = default; Actor& Actor::operator=(Actor&&) noexcept = default; Actor::~Actor() = default; -void Actor::Init(const vtkm::cont::CoordinateSystem& coordinates, - const vtkm::cont::Field& scalarField) -{ - scalarField.GetRange(&this->Internals->ScalarRange); - this->Internals->SpatialBounds = coordinates.GetBounds(); -} - void Actor::Init() { - this->Internals->SpatialBounds = vtkm::cont::BoundsCompute(this->Internals->DataSet); + this->Internals->SpatialBounds = vtkm::cont::BoundsCompute(this->Internals->Data); this->Internals->ScalarRange = - vtkm::cont::FieldRangeCompute(this->Internals->DataSet, this->Internals->FieldName) + vtkm::cont::FieldRangeCompute(this->Internals->Data, this->Internals->FieldName) .ReadPortal() .Get(0); } @@ -216,39 +204,27 @@ void Actor::Render(vtkm::rendering::Mapper& mapper, { mapper.SetCanvas(&canvas); mapper.SetActiveColorTable(this->Internals->ColorTable); - if (this->Internals->DataSet.GetNumberOfPartitions() > 0) - { - mapper.RenderCellsPartitioned(this->Internals->DataSet, - this->Internals->FieldName, - this->Internals->ColorTable, - camera, - this->Internals->ScalarRange); - } - else - { - mapper.RenderCells(this->Internals->Cells, - this->Internals->Coordinates, - this->Internals->ScalarField, - this->Internals->ColorTable, - camera, - this->Internals->ScalarRange); - } + mapper.RenderCellsPartitioned(this->Internals->Data, + this->Internals->FieldName, + this->Internals->ColorTable, + camera, + this->Internals->ScalarRange); } const vtkm::cont::UnknownCellSet& Actor::GetCells() const { - return this->Internals->Cells; + return this->Internals->Data.GetPartition(0).GetCellSet(); } const vtkm::cont::CoordinateSystem& Actor::GetCoordinates() const { - return this->Internals->Coordinates; + return this->Internals->Data.GetPartition(0).GetCoordinateSystem(this->Internals->CoordinateName); } const vtkm::cont::Field& Actor::GetScalarField() const { - return this->Internals->ScalarField; + return this->Internals->Data.GetPartition(0).GetField(this->Internals->FieldName); } const vtkm::cont::ColorTable& Actor::GetColorTable() const diff --git a/vtkm/rendering/Actor.h b/vtkm/rendering/Actor.h index 54c5ecf0f..9a4718479 100644 --- a/vtkm/rendering/Actor.h +++ b/vtkm/rendering/Actor.h @@ -26,23 +26,31 @@ namespace rendering class VTKM_RENDERING_EXPORT Actor { public: - Actor(const vtkm::cont::DataSet dataSet, const std::string fieldName); + Actor(const vtkm::cont::DataSet dataSet, + const std::string coordinateName, + const std::string fieldName); Actor(const vtkm::cont::DataSet dataSet, + const std::string coordinateName, const std::string fieldName, const vtkm::cont::ColorTable& colorTable); Actor(const vtkm::cont::DataSet dataSet, + const std::string coordinateName, const std::string fieldName, const vtkm::rendering::Color& color); - Actor(const vtkm::cont::PartitionedDataSet dataSet, const std::string fieldName); + Actor(const vtkm::cont::PartitionedDataSet dataSet, + const std::string coordinateName, + const std::string fieldName); Actor(const vtkm::cont::PartitionedDataSet dataSet, + const std::string coordinateName, const std::string fieldName, const vtkm::cont::ColorTable& colorTable); Actor(const vtkm::cont::PartitionedDataSet dataSet, + const std::string coordinateName, const std::string fieldName, const vtkm::rendering::Color& color);