From 0a89a5fff5c933b9285401923462d093df476c72 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Wed, 15 Dec 2021 12:57:10 -0700 Subject: [PATCH] Store UnknownCellSet instead of DynamicCellSet in DataSet `UnknownCellSet` is an updated replacement for `DynamicCellSet`. The next step in the replacement is to change `DataSet` to use the new class. Also replaced `DynamicCellSet` with `UnknownCellSet` in a few places where `DynamicCellSet.h` was not directly included (and therefore now no longer included at all). This change would have to be made at some point anyway. --- vtkm/cont/CellSet.h | 2 +- vtkm/cont/DataSet.h | 19 ++--- vtkm/cont/testing/Testing.h | 77 +++++++++++++++---- vtkm/io/VTKDataSetReaderBase.h | 2 +- vtkm/io/VTKDataSetWriter.cxx | 2 +- .../raytracing/CylinderExtractor.cxx | 6 +- vtkm/rendering/raytracing/CylinderExtractor.h | 6 +- vtkm/rendering/raytracing/QuadExtractor.cxx | 4 +- vtkm/rendering/raytracing/QuadExtractor.h | 4 +- vtkm/rendering/raytracing/SphereExtractor.cxx | 6 +- vtkm/rendering/raytracing/SphereExtractor.h | 6 +- vtkm/worklet/ExtractGeometry.h | 1 + vtkm/worklet/Tube.h | 1 + 13 files changed, 91 insertions(+), 45 deletions(-) diff --git a/vtkm/cont/CellSet.h b/vtkm/cont/CellSet.h index c63e201cc..412591721 100644 --- a/vtkm/cont/CellSet.h +++ b/vtkm/cont/CellSet.h @@ -65,7 +65,7 @@ template struct CellSetCheck { using U = typename std::remove_pointer::type; - using type = typename std::is_base_of; + using type = typename std::is_base_of::type; }; #define VTKM_IS_CELL_SET(T) VTKM_STATIC_ASSERT(::vtkm::cont::internal::CellSetCheck::type::value) diff --git a/vtkm/cont/DataSet.h b/vtkm/cont/DataSet.h index b41a2cbe1..a4e9295df 100644 --- a/vtkm/cont/DataSet.h +++ b/vtkm/cont/DataSet.h @@ -14,10 +14,10 @@ #include #include -#include #include #include #include +#include namespace vtkm { @@ -221,21 +221,18 @@ public: vtkm::cont::CoordinateSystem& GetCoordinateSystem(const std::string& name); //@} - VTKM_CONT - void SetCellSet(const vtkm::cont::DynamicCellSet& cellSet) { this->CellSet = cellSet; } - template VTKM_CONT void SetCellSet(const CellSetType& cellSet) { - VTKM_IS_CELL_SET(CellSetType); - this->CellSet = vtkm::cont::DynamicCellSet(cellSet); + VTKM_IS_KNOWN_OR_UNKNOWN_CELL_SET(CellSetType); + this->CellSet = vtkm::cont::UnknownCellSet(cellSet); } VTKM_CONT - const vtkm::cont::DynamicCellSet& GetCellSet() const { return this->CellSet; } + const vtkm::cont::UnknownCellSet& GetCellSet() const { return this->CellSet; } VTKM_CONT - vtkm::cont::DynamicCellSet& GetCellSet() { return this->CellSet; } + vtkm::cont::UnknownCellSet& GetCellSet() { return this->CellSet; } VTKM_CONT vtkm::IdComponent GetNumberOfFields() const @@ -290,7 +287,7 @@ private: std::vector CoordSystems; std::map Fields; - vtkm::cont::DynamicCellSet CellSet; + vtkm::cont::UnknownCellSet CellSet; VTKM_CONT vtkm::Id FindFieldIndex(const std::string& name, @@ -370,9 +367,9 @@ public: dataset.AddCoordinateSystem(coords); } - vtkm::cont::DynamicCellSetBase cells; + vtkm::cont::UncertainCellSet cells; vtkmdiy::load(bb, cells); - dataset.SetCellSet(vtkm::cont::DynamicCellSet(cells)); + dataset.SetCellSet(cells); vtkm::IdComponent numberOfFields = 0; vtkmdiy::load(bb, numberOfFields); diff --git a/vtkm/cont/testing/Testing.h b/vtkm/cont/testing/Testing.h index ac291c36a..f8fab3e75 100644 --- a/vtkm/cont/testing/Testing.h +++ b/vtkm/cont/testing/Testing.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -459,10 +460,24 @@ namespace detail struct TestEqualCellSet { + template + void operator()(const CellSetType1& cs1, const CellSetType2& cs2, TestEqualResult& result) const + { + // Avoid ambiguous overloads by specifying whether each cell type is known or unknown. + this->Run(cs1, + typename vtkm::cont::internal::CellSetCheck::type{}, + cs2, + typename vtkm::cont::internal::CellSetCheck::type{}, + result); + } + +private: template - void operator()(const vtkm::cont::CellSetExplicit& cs1, - const vtkm::cont::CellSetExplicit& cs2, - TestEqualResult& result) const + void Run(const vtkm::cont::CellSetExplicit& cs1, + std::true_type, + const vtkm::cont::CellSetExplicit& cs2, + std::true_type, + TestEqualResult& result) const { vtkm::TopologyElementTagCell visitTopo{}; vtkm::TopologyElementTagPoint incidentTopo{}; @@ -505,9 +520,11 @@ struct TestEqualCellSet } template - void operator()(const vtkm::cont::CellSetStructured& cs1, - const vtkm::cont::CellSetStructured& cs2, - TestEqualResult& result) const + void Run(const vtkm::cont::CellSetStructured& cs1, + std::true_type, + const vtkm::cont::CellSetStructured& cs2, + std::true_type, + TestEqualResult& result) const { if (cs1.GetPointDimensions() != cs2.GetPointDimensions()) { @@ -517,26 +534,56 @@ struct TestEqualCellSet } template - void operator()(const vtkm::cont::DynamicCellSetBase& cs1, - const vtkm::cont::DynamicCellSetBase& cs2, - TestEqualResult& result) const + void Run(const vtkm::cont::DynamicCellSetBase& cs1, + std::false_type, + const vtkm::cont::DynamicCellSetBase& cs2, + std::false_type, + TestEqualResult& result) const { cs1.CastAndCall(*this, cs2, result); } - template - void operator()(const CellSet& cs, - const vtkm::cont::DynamicCellSetBase& dcs, - TestEqualResult& result) const + template + void Run(const CellSetType& cs1, + std::true_type, + const vtkm::cont::UnknownCellSet& cs2, + std::false_type, + TestEqualResult& result) const { - if (!dcs.IsSameType(cs)) + if (!cs2.CanConvert()) { result.PushMessage("types don't match"); return; } - this->operator()(cs, dcs.template Cast(), result); + this->Run(cs1, std::true_type{}, cs2.AsCellSet(), std::true_type{}, result); + } + + template + void Run(const vtkm::cont::UnknownCellSet& cs1, + std::false_type, + const CellSetType& cs2, + std::true_type, + TestEqualResult& result) const + { + if (!cs1.CanConvert()) + { + result.PushMessage("types don't match"); + return; + } + this->Run(cs1.AsCellSet(), std::true_type{}, cs2, std::true_type{}, result); + } + + template + void Run(const UnknownCellSetType& cs1, + std::false_type, + const vtkm::cont::UnknownCellSet& cs2, + std::false_type, + TestEqualResult& result) const + { + vtkm::cont::CastAndCall(cs1, *this, cs2, result); } }; + } // detail template diff --git a/vtkm/io/VTKDataSetReaderBase.h b/vtkm/io/VTKDataSetReaderBase.h index ee14fc792..bd75ed7ca 100644 --- a/vtkm/io/VTKDataSetReaderBase.h +++ b/vtkm/io/VTKDataSetReaderBase.h @@ -64,7 +64,7 @@ struct StreamIOType using Type = vtkm::UInt16; }; -inline vtkm::cont::DynamicCellSet CreateCellSetStructured(const vtkm::Id3& dim) +inline vtkm::cont::UnknownCellSet CreateCellSetStructured(const vtkm::Id3& dim) { if (dim[0] > 1 && dim[1] > 1 && dim[2] > 1) { diff --git a/vtkm/io/VTKDataSetWriter.cxx b/vtkm/io/VTKDataSetWriter.cxx index 7527acff8..6a10db2f0 100644 --- a/vtkm/io/VTKDataSetWriter.cxx +++ b/vtkm/io/VTKDataSetWriter.cxx @@ -516,7 +516,7 @@ void Write(std::ostream& out, const vtkm::cont::DataSet& dataSet, vtkm::io::File break; } - vtkm::cont::DynamicCellSet cellSet = dataSet.GetCellSet(); + vtkm::cont::UnknownCellSet cellSet = dataSet.GetCellSet(); if (cellSet.IsType>()) { WriteDataSetAsUnstructured( diff --git a/vtkm/rendering/raytracing/CylinderExtractor.cxx b/vtkm/rendering/raytracing/CylinderExtractor.cxx index 5977b21fc..f5166224d 100644 --- a/vtkm/rendering/raytracing/CylinderExtractor.cxx +++ b/vtkm/rendering/raytracing/CylinderExtractor.cxx @@ -212,7 +212,7 @@ public: } //namespace detail -void CylinderExtractor::ExtractCells(const vtkm::cont::DynamicCellSet& cells, +void CylinderExtractor::ExtractCells(const vtkm::cont::UnknownCellSet& cells, const vtkm::Float32 radius) { vtkm::Id numOfSegments; @@ -222,7 +222,7 @@ void CylinderExtractor::ExtractCells(const vtkm::cont::DynamicCellSet& cells, this->SetUniformRadius(radius); } -void CylinderExtractor::ExtractCells(const vtkm::cont::DynamicCellSet& cells, +void CylinderExtractor::ExtractCells(const vtkm::cont::UnknownCellSet& cells, const vtkm::cont::Field& field, const vtkm::Float32 minRadius, const vtkm::Float32 maxRadius) @@ -243,7 +243,7 @@ void CylinderExtractor::SetUniformRadius(const vtkm::Float32 radius) vtkm::cont::Algorithm::Copy(radiusHandle, Radii); } -void CylinderExtractor::SetCylinderIdsFromCells(const vtkm::cont::DynamicCellSet& cells) +void CylinderExtractor::SetCylinderIdsFromCells(const vtkm::cont::UnknownCellSet& cells) { vtkm::Id numCells = cells.GetNumberOfCells(); if (numCells == 0) diff --git a/vtkm/rendering/raytracing/CylinderExtractor.h b/vtkm/rendering/raytracing/CylinderExtractor.h index 9c475acdf..9cb3bcbd0 100644 --- a/vtkm/rendering/raytracing/CylinderExtractor.h +++ b/vtkm/rendering/raytracing/CylinderExtractor.h @@ -34,12 +34,12 @@ public: // // Extract all vertex shapes with constant radius // - void ExtractCells(const vtkm::cont::DynamicCellSet& cells, vtkm::Float32 radius); + void ExtractCells(const vtkm::cont::UnknownCellSet& cells, vtkm::Float32 radius); // // Extract all vertex elements with radius based on scalar values // - void ExtractCells(const vtkm::cont::DynamicCellSet& cells, + void ExtractCells(const vtkm::cont::UnknownCellSet& cells, const vtkm::cont::Field& field, const vtkm::Float32 minRadius, const vtkm::Float32 maxRadius); @@ -57,7 +57,7 @@ protected: const vtkm::cont::Field& field); // void SetPointIdsFromCoords(const vtkm::cont::CoordinateSystem& coords); - void SetCylinderIdsFromCells(const vtkm::cont::DynamicCellSet& cells); + void SetCylinderIdsFromCells(const vtkm::cont::UnknownCellSet& cells); }; // class ShapeIntersector } diff --git a/vtkm/rendering/raytracing/QuadExtractor.cxx b/vtkm/rendering/raytracing/QuadExtractor.cxx index 5495d5a56..708e0f37b 100644 --- a/vtkm/rendering/raytracing/QuadExtractor.cxx +++ b/vtkm/rendering/raytracing/QuadExtractor.cxx @@ -199,7 +199,7 @@ public: } //namespace detail -void QuadExtractor::ExtractCells(const vtkm::cont::DynamicCellSet& cells) +void QuadExtractor::ExtractCells(const vtkm::cont::UnknownCellSet& cells) { vtkm::Id numOfQuads; vtkm::rendering::Quadralizer quadrizer; @@ -209,7 +209,7 @@ void QuadExtractor::ExtractCells(const vtkm::cont::DynamicCellSet& cells) } -void QuadExtractor::SetQuadIdsFromCells(const vtkm::cont::DynamicCellSet& cells) +void QuadExtractor::SetQuadIdsFromCells(const vtkm::cont::UnknownCellSet& cells) { vtkm::Id numCells = cells.GetNumberOfCells(); if (numCells == 0) diff --git a/vtkm/rendering/raytracing/QuadExtractor.h b/vtkm/rendering/raytracing/QuadExtractor.h index f84276975..cb53400c0 100644 --- a/vtkm/rendering/raytracing/QuadExtractor.h +++ b/vtkm/rendering/raytracing/QuadExtractor.h @@ -26,14 +26,14 @@ protected: vtkm::cont::ArrayHandle Radii; public: - void ExtractCells(const vtkm::cont::DynamicCellSet& cells); + void ExtractCells(const vtkm::cont::UnknownCellSet& cells); vtkm::cont::ArrayHandle> GetQuadIds(); vtkm::Id GetNumberOfQuads() const; protected: - void SetQuadIdsFromCells(const vtkm::cont::DynamicCellSet& cells); + void SetQuadIdsFromCells(const vtkm::cont::UnknownCellSet& cells); }; // class ShapeIntersector } diff --git a/vtkm/rendering/raytracing/SphereExtractor.cxx b/vtkm/rendering/raytracing/SphereExtractor.cxx index ad9cf36f3..7ec989292 100644 --- a/vtkm/rendering/raytracing/SphereExtractor.cxx +++ b/vtkm/rendering/raytracing/SphereExtractor.cxx @@ -181,13 +181,13 @@ void SphereExtractor::ExtractCoordinates(const vtkm::cont::CoordinateSystem& coo this->SetVaryingRadius(minRadius, maxRadius, field); } -void SphereExtractor::ExtractCells(const vtkm::cont::DynamicCellSet& cells, +void SphereExtractor::ExtractCells(const vtkm::cont::UnknownCellSet& cells, const vtkm::Float32 radius) { this->SetPointIdsFromCells(cells); this->SetUniformRadius(radius); } -void SphereExtractor::ExtractCells(const vtkm::cont::DynamicCellSet& cells, +void SphereExtractor::ExtractCells(const vtkm::cont::UnknownCellSet& cells, const vtkm::cont::Field& field, const vtkm::Float32 minRadius, const vtkm::Float32 maxRadius) @@ -212,7 +212,7 @@ void SphereExtractor::SetPointIdsFromCoords(const vtkm::cont::CoordinateSystem& vtkm::worklet::DispatcherMapField(detail::Iterator()).Invoke(this->PointIds); } -void SphereExtractor::SetPointIdsFromCells(const vtkm::cont::DynamicCellSet& cells) +void SphereExtractor::SetPointIdsFromCells(const vtkm::cont::UnknownCellSet& cells) { using SingleType = vtkm::cont::CellSetSingleType<>; vtkm::Id numCells = cells.GetNumberOfCells(); diff --git a/vtkm/rendering/raytracing/SphereExtractor.h b/vtkm/rendering/raytracing/SphereExtractor.h index 16ae644b9..93d7c03fc 100644 --- a/vtkm/rendering/raytracing/SphereExtractor.h +++ b/vtkm/rendering/raytracing/SphereExtractor.h @@ -42,12 +42,12 @@ public: // // Extract all vertex shapes with constant radius // - void ExtractCells(const vtkm::cont::DynamicCellSet& cells, vtkm::Float32 radius); + void ExtractCells(const vtkm::cont::UnknownCellSet& cells, vtkm::Float32 radius); // // Extract all vertex elements with radius based on scalar values // - void ExtractCells(const vtkm::cont::DynamicCellSet& cells, + void ExtractCells(const vtkm::cont::UnknownCellSet& cells, const vtkm::cont::Field& field, const vtkm::Float32 minRadius, const vtkm::Float32 maxRadius); @@ -64,7 +64,7 @@ protected: const vtkm::cont::Field& field); void SetPointIdsFromCoords(const vtkm::cont::CoordinateSystem& coords); - void SetPointIdsFromCells(const vtkm::cont::DynamicCellSet& cells); + void SetPointIdsFromCells(const vtkm::cont::UnknownCellSet& cells); }; // class ShapeIntersector } diff --git a/vtkm/worklet/ExtractGeometry.h b/vtkm/worklet/ExtractGeometry.h index 0af09ef4c..9e0cb5f40 100644 --- a/vtkm/worklet/ExtractGeometry.h +++ b/vtkm/worklet/ExtractGeometry.h @@ -19,6 +19,7 @@ #include #include #include +#include #include diff --git a/vtkm/worklet/Tube.h b/vtkm/worklet/Tube.h index ce70e8a34..0ff9e3e4e 100644 --- a/vtkm/worklet/Tube.h +++ b/vtkm/worklet/Tube.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include