From e8278094f9822c0c8d4cdefc18be1a13fbde68af Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Mon, 10 Jan 2022 11:11:12 -0700 Subject: [PATCH] migrate Mask tidy up language and library usage update benchmark --- benchmarking/BenchmarkFilters.cxx | 2 +- vtkm/filter/CMakeLists.txt | 1 - vtkm/filter/Mask.h | 55 +++----- vtkm/filter/entity_extraction/CMakeLists.txt | 2 + .../entity_extraction/ExternalFaces.cxx | 3 +- vtkm/filter/entity_extraction/ExternalFaces.h | 2 +- .../entity_extraction/ExtractGeometry.cxx | 2 +- .../entity_extraction/ExtractGeometry.h | 6 +- .../entity_extraction/ExtractPoints.cxx | 13 +- vtkm/filter/entity_extraction/ExtractPoints.h | 2 +- .../entity_extraction/ExtractStructured.cxx | 3 +- .../entity_extraction/ExtractStructured.h | 2 +- .../entity_extraction/GhostCellRemove.cxx | 6 +- .../entity_extraction/GhostCellRemove.h | 2 +- .../{Mask.hxx => entity_extraction/Mask.cxx} | 79 ++++++------ vtkm/filter/entity_extraction/Mask.h | 53 ++++++++ vtkm/filter/entity_extraction/MaskPoints.cxx | 2 +- vtkm/filter/entity_extraction/Threshold.cxx | 2 +- .../entity_extraction/ThresholdPoints.cxx | 6 +- .../entity_extraction/ThresholdPoints.h | 6 +- .../entity_extraction/testing/CMakeLists.txt | 1 + .../testing/UnitTestGhostCellRemove.cxx | 49 ++++---- .../testing/UnitTestMaskFilter.cxx | 8 +- .../entity_extraction/worklet/CMakeLists.txt | 1 + .../worklet/ExtractGeometry.h | 7 +- .../entity_extraction/worklet/ExtractPoints.h | 13 +- .../worklet/ExtractStructured.h | 15 +-- .../entity_extraction}/worklet/Mask.h | 2 - .../entity_extraction/worklet/MaskPoints.h | 1 - .../entity_extraction/worklet/Threshold.h | 2 - .../worklet/ThresholdPoints.h | 11 +- vtkm/filter/testing/CMakeLists.txt | 1 - vtkm/worklet/CMakeLists.txt | 1 - vtkm/worklet/testing/CMakeLists.txt | 1 - vtkm/worklet/testing/UnitTestMask.cxx | 119 ------------------ 35 files changed, 188 insertions(+), 293 deletions(-) rename vtkm/filter/{Mask.hxx => entity_extraction/Mask.cxx} (59%) create mode 100644 vtkm/filter/entity_extraction/Mask.h rename vtkm/filter/{ => entity_extraction}/testing/UnitTestMaskFilter.cxx (94%) rename vtkm/{ => filter/entity_extraction}/worklet/Mask.h (96%) delete mode 100644 vtkm/worklet/testing/UnitTestMask.cxx diff --git a/benchmarking/BenchmarkFilters.cxx b/benchmarking/BenchmarkFilters.cxx index 076bb2c9a..3dd748713 100644 --- a/benchmarking/BenchmarkFilters.cxx +++ b/benchmarking/BenchmarkFilters.cxx @@ -193,7 +193,7 @@ void BenchThreshold(::benchmark::State& state) vtkm::Float64 quarter = range.Length() / 4.; vtkm::Float64 mid = range.Center(); - vtkm::filter::Threshold filter; + vtkm::filter::entity_extraction::Threshold filter; filter.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::POINTS); filter.SetLowerThreshold(mid - quarter); filter.SetUpperThreshold(mid + quarter); diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index e16f9ab77..c774ef855 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -139,7 +139,6 @@ set(extra_header_template_sources ImageMedian.hxx Lagrangian.hxx LagrangianStructures.hxx - Mask.hxx MeshQuality.hxx MIRFilter.hxx NDEntropy.hxx diff --git a/vtkm/filter/Mask.h b/vtkm/filter/Mask.h index 2eb870495..4eabdb99f 100644 --- a/vtkm/filter/Mask.h +++ b/vtkm/filter/Mask.h @@ -7,57 +7,32 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_Mask_h #define vtk_m_filter_Mask_h -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Subselect cells using a stride -/// -/// Extract only every Nth cell where N is equal to a stride value -class Mask : public vtkm::filter::FilterDataSet + +VTKM_DEPRECATED(1.8, "Use vtkm/filter/entity_extraction/Mask.h instead of vtkm/filter/Mask.h.") +inline void Mask_deprecated() {} + +inline void Mask_deprecated_warning() { -public: - VTKM_CONT - Mask(); + Mask_deprecated(); +} - // When CompactPoints is set, instead of copying the points and point fields - // from the input, the filter will create new compact fields without the unused elements - VTKM_CONT - bool GetCompactPoints() const { return this->CompactPoints; } - VTKM_CONT - void SetCompactPoints(bool value) { this->CompactPoints = value; } - - // Set the stride of the subsample - VTKM_CONT - vtkm::Id GetStride() const { return this->Stride; } - VTKM_CONT - void SetStride(vtkm::Id& stride) { this->Stride = stride; } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy); - - //Map a new field onto the resulting dataset after running the filter - template - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase policy); - -private: - vtkm::Id Stride; - bool CompactPoints; - vtkm::worklet::Mask Worklet; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::Mask.") Mask + : public vtkm::filter::entity_extraction::Mask +{ + using entity_extraction::Mask::Mask; }; + } } // namespace vtkm::filter -#include - -#endif // vtk_m_filter_Mask_h +#endif //vtk_m_filter_Mask_h diff --git a/vtkm/filter/entity_extraction/CMakeLists.txt b/vtkm/filter/entity_extraction/CMakeLists.txt index c538c04ef..cd350b19f 100644 --- a/vtkm/filter/entity_extraction/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/CMakeLists.txt @@ -13,6 +13,7 @@ set(entity_extraction_headers ExtractPoints.h ExtractStructured.h GhostCellRemove.h + Mask.h MaskPoints.h Threshold.h ThresholdPoints.h @@ -23,6 +24,7 @@ set(entity_extraction_sources_device ExtractPoints.cxx ExtractStructured.cxx GhostCellRemove.cxx + Mask.cxx MaskPoints.cxx Threshold.cxx ThresholdPoints.cxx diff --git a/vtkm/filter/entity_extraction/ExternalFaces.cxx b/vtkm/filter/entity_extraction/ExternalFaces.cxx index 40beff9fc..1fb314fdc 100644 --- a/vtkm/filter/entity_extraction/ExternalFaces.cxx +++ b/vtkm/filter/entity_extraction/ExternalFaces.cxx @@ -46,7 +46,8 @@ vtkm::cont::DataSet ExternalFaces::GenerateOutput(const vtkm::cont::DataSet& inp bool hasCellFields = false; for (vtkm::Id fieldIdx = 0; fieldIdx < numFields && !hasCellFields; ++fieldIdx) { - hasCellFields = input.GetField(fieldIdx).IsFieldCell(); + const auto& f = input.GetField(fieldIdx); + hasCellFields = f.IsFieldCell(); } if (!hasCellFields) diff --git a/vtkm/filter/entity_extraction/ExternalFaces.h b/vtkm/filter/entity_extraction/ExternalFaces.h index 677429c48..f15dd276c 100644 --- a/vtkm/filter/entity_extraction/ExternalFaces.h +++ b/vtkm/filter/entity_extraction/ExternalFaces.h @@ -36,7 +36,7 @@ class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT ExternalFaces : public vtkm::filter:: { public: ExternalFaces(); - ~ExternalFaces(); + ~ExternalFaces() override; // New Design: I am too lazy to make this filter thread-safe. Let's use it as an example of // thread un-safe filter. diff --git a/vtkm/filter/entity_extraction/ExtractGeometry.cxx b/vtkm/filter/entity_extraction/ExtractGeometry.cxx index 9737ffdd2..faed88cc8 100644 --- a/vtkm/filter/entity_extraction/ExtractGeometry.cxx +++ b/vtkm/filter/entity_extraction/ExtractGeometry.cxx @@ -117,7 +117,7 @@ vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input) output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.SetCellSet(outCells); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; MapFieldsOntoOutput(input, output, mapper); return output; diff --git a/vtkm/filter/entity_extraction/ExtractGeometry.h b/vtkm/filter/entity_extraction/ExtractGeometry.h index 46850b8f8..b4f0c37c6 100644 --- a/vtkm/filter/entity_extraction/ExtractGeometry.h +++ b/vtkm/filter/entity_extraction/ExtractGeometry.h @@ -51,7 +51,7 @@ public: const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; } VTKM_CONT - bool GetExtractInside() { return this->ExtractInside; } + bool GetExtractInside() const { return this->ExtractInside; } VTKM_CONT void SetExtractInside(bool value) { this->ExtractInside = value; } VTKM_CONT @@ -60,7 +60,7 @@ public: void ExtractInsideOff() { this->ExtractInside = false; } VTKM_CONT - bool GetExtractBoundaryCells() { return this->ExtractBoundaryCells; } + bool GetExtractBoundaryCells() const { return this->ExtractBoundaryCells; } VTKM_CONT void SetExtractBoundaryCells(bool value) { this->ExtractBoundaryCells = value; } VTKM_CONT @@ -69,7 +69,7 @@ public: void ExtractBoundaryCellsOff() { this->ExtractBoundaryCells = false; } VTKM_CONT - bool GetExtractOnlyBoundaryCells() { return this->ExtractOnlyBoundaryCells; } + bool GetExtractOnlyBoundaryCells() const { return this->ExtractOnlyBoundaryCells; } VTKM_CONT void SetExtractOnlyBoundaryCells(bool value) { this->ExtractOnlyBoundaryCells = value; } VTKM_CONT diff --git a/vtkm/filter/entity_extraction/ExtractPoints.cxx b/vtkm/filter/entity_extraction/ExtractPoints.cxx index 344f4946b..fd53ede8e 100644 --- a/vtkm/filter/entity_extraction/ExtractPoints.cxx +++ b/vtkm/filter/entity_extraction/ExtractPoints.cxx @@ -13,10 +13,6 @@ #include #include -namespace vtkm -{ -namespace filter -{ namespace { bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field) @@ -38,7 +34,12 @@ bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field) return false; } } -} +} // anonymous namespace + +namespace vtkm +{ +namespace filter +{ namespace entity_extraction { //----------------------------------------------------------------------------- @@ -62,7 +63,7 @@ vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& input) output.SetCellSet(outCellSet); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); }; this->MapFieldsOntoOutput(input, output, mapper); // compact the unused points in the output dataset diff --git a/vtkm/filter/entity_extraction/ExtractPoints.h b/vtkm/filter/entity_extraction/ExtractPoints.h index fe850c7cd..98942c1d0 100644 --- a/vtkm/filter/entity_extraction/ExtractPoints.h +++ b/vtkm/filter/entity_extraction/ExtractPoints.h @@ -51,7 +51,7 @@ public: const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; } VTKM_CONT - bool GetExtractInside() { return this->ExtractInside; } + bool GetExtractInside() const { return this->ExtractInside; } VTKM_CONT void SetExtractInside(bool value) { this->ExtractInside = value; } VTKM_CONT diff --git a/vtkm/filter/entity_extraction/ExtractStructured.cxx b/vtkm/filter/entity_extraction/ExtractStructured.cxx index c69c8dab5..79b1408da 100644 --- a/vtkm/filter/entity_extraction/ExtractStructured.cxx +++ b/vtkm/filter/entity_extraction/ExtractStructured.cxx @@ -11,7 +11,6 @@ #include #include - #include namespace vtkm @@ -75,7 +74,7 @@ vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& inpu auto PointFieldMap = Worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints())); - auto mapper = [&, this](auto& result, const auto& f) { + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, CellFieldMap, PointFieldMap); }; MapFieldsOntoOutput(input, output, mapper); diff --git a/vtkm/filter/entity_extraction/ExtractStructured.h b/vtkm/filter/entity_extraction/ExtractStructured.h index 081db8747..5218a0a00 100644 --- a/vtkm/filter/entity_extraction/ExtractStructured.h +++ b/vtkm/filter/entity_extraction/ExtractStructured.h @@ -73,7 +73,7 @@ public: /// Get if we should include the outer boundary on a subsample VTKM_CONT - bool GetIncludeBoundary() { return this->IncludeBoundary; } + bool GetIncludeBoundary() const { return this->IncludeBoundary; } /// Set if we should include the outer boundary on a subsample VTKM_CONT void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; } diff --git a/vtkm/filter/entity_extraction/GhostCellRemove.cxx b/vtkm/filter/entity_extraction/GhostCellRemove.cxx index 8c2b454a4..654fce6dd 100644 --- a/vtkm/filter/entity_extraction/GhostCellRemove.cxx +++ b/vtkm/filter/entity_extraction/GhostCellRemove.cxx @@ -24,7 +24,7 @@ class RemoveAllGhosts { public: VTKM_CONT - RemoveAllGhosts() {} + RemoveAllGhosts() = default; VTKM_EXEC bool operator()(const vtkm::UInt8& value) const { return (value == 0); } }; @@ -39,7 +39,7 @@ public: } VTKM_CONT - RemoveGhostByType(const vtkm::UInt8& val) + explicit RemoveGhostByType(const vtkm::UInt8& val) : RemoveType(static_cast(~val)) { } @@ -378,7 +378,7 @@ VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(const vtkm::cont::DataS output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.SetCellSet(cellOut); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; MapFieldsOntoOutput(input, output, mapper); return output; diff --git a/vtkm/filter/entity_extraction/GhostCellRemove.h b/vtkm/filter/entity_extraction/GhostCellRemove.h index ddb744433..41c17328f 100644 --- a/vtkm/filter/entity_extraction/GhostCellRemove.h +++ b/vtkm/filter/entity_extraction/GhostCellRemove.h @@ -40,7 +40,7 @@ public: this->RemoveVals = vals; } VTKM_CONT - bool GetRemoveGhostField() { return this->RemoveField; } + bool GetRemoveGhostField() const { return this->RemoveField; } VTKM_CONT bool GetRemoveAllGhost() const { return this->RemoveAll; } diff --git a/vtkm/filter/Mask.hxx b/vtkm/filter/entity_extraction/Mask.cxx similarity index 59% rename from vtkm/filter/Mask.hxx rename to vtkm/filter/entity_extraction/Mask.cxx index 569f8fc3c..ceb6c2810 100644 --- a/vtkm/filter/Mask.hxx +++ b/vtkm/filter/entity_extraction/Mask.cxx @@ -7,11 +7,14 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_filter_Mask_hxx -#define vtk_m_filter_Mask_hxx - #include +#include +#include +namespace vtkm +{ +namespace filter +{ namespace { @@ -35,43 +38,9 @@ struct CallWorklet } }; -} // end anon namespace - -namespace vtkm -{ -namespace filter -{ - -//----------------------------------------------------------------------------- -inline VTKM_CONT Mask::Mask() - : vtkm::filter::FilterDataSet() - , Stride(1) - , CompactPoints(false) -{ -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy) -{ - const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); - vtkm::cont::UnknownCellSet cellOut; - CallWorklet workletCaller(this->Stride, cellOut, this->Worklet); - vtkm::filter::ApplyPolicyCellSet(cells, policy, *this).CastAndCall(workletCaller); - - // create the output dataset - vtkm::cont::DataSet output; - output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - output.SetCellSet(cellOut); - return output; -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT bool Mask::MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase) +VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::worklet::Mask& Worklet) { if (field.IsFieldPoint() || field.IsFieldGlobal()) { @@ -80,13 +49,37 @@ inline VTKM_CONT bool Mask::MapFieldOntoOutput(vtkm::cont::DataSet& result, } else if (field.IsFieldCell()) { - return vtkm::filter::MapFieldPermutation(field, this->Worklet.GetValidCellIds(), result); + return vtkm::filter::MapFieldPermutation(field, Worklet.GetValidCellIds(), result); } else { return false; } } +} // end anon namespace + +namespace entity_extraction +{ +//----------------------------------------------------------------------------- +VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(const vtkm::cont::DataSet& input) +{ + const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); + vtkm::cont::UnknownCellSet cellOut; + vtkm::worklet::Mask Worklet; + + CallWorklet workletCaller(this->Stride, cellOut, Worklet); + cells.CastAndCallForTypes(workletCaller); + + // create the output dataset + vtkm::cont::DataSet output; + output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); + output.SetCellSet(cellOut); + + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; + MapFieldsOntoOutput(input, output, mapper); + + return output; } -} -#endif +} // namespace entity_extraction +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/entity_extraction/Mask.h b/vtkm/filter/entity_extraction/Mask.h new file mode 100644 index 000000000..4611b0341 --- /dev/null +++ b/vtkm/filter/entity_extraction/Mask.h @@ -0,0 +1,53 @@ +//============================================================================ +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//============================================================================ + +#ifndef vtk_m_filter_Mask_h +#define vtk_m_filter_Mask_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace entity_extraction +{ +/// \brief Subselect cells using a stride +/// +/// Extract only every Nth cell where N is equal to a stride value +class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT Mask : public vtkm::filter::NewFilterField +{ +public: + // When CompactPoints is set, instead of copying the points and point fields + // from the input, the filter will create new compact fields without the unused elements + VTKM_CONT + bool GetCompactPoints() const { return this->CompactPoints; } + VTKM_CONT + void SetCompactPoints(bool value) { this->CompactPoints = value; } + + // Set the stride of the subsample + VTKM_CONT + vtkm::Id GetStride() const { return this->Stride; } + VTKM_CONT + void SetStride(vtkm::Id& stride) { this->Stride = stride; } + +private: + VTKM_CONT + vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + vtkm::Id Stride = 1; + bool CompactPoints = false; +}; +} // namespace entity_extraction +} // namespace filter +} // namespace vtk + +#endif // vtk_m_filter_Mask_h diff --git a/vtkm/filter/entity_extraction/MaskPoints.cxx b/vtkm/filter/entity_extraction/MaskPoints.cxx index 7693d0f60..20064efa3 100644 --- a/vtkm/filter/entity_extraction/MaskPoints.cxx +++ b/vtkm/filter/entity_extraction/MaskPoints.cxx @@ -59,7 +59,7 @@ VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute(const vtkm::cont::DataSet& i output.SetCellSet(outCellSet); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); }; this->MapFieldsOntoOutput(input, output, mapper); // compact the unused points in the output dataset diff --git a/vtkm/filter/entity_extraction/Threshold.cxx b/vtkm/filter/entity_extraction/Threshold.cxx index 4dac3158b..8cd46df3c 100644 --- a/vtkm/filter/entity_extraction/Threshold.cxx +++ b/vtkm/filter/entity_extraction/Threshold.cxx @@ -101,7 +101,7 @@ vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input) output.SetCellSet(cellOut); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; MapFieldsOntoOutput(input, output, mapper); return output; diff --git a/vtkm/filter/entity_extraction/ThresholdPoints.cxx b/vtkm/filter/entity_extraction/ThresholdPoints.cxx index d5435816b..a1c69d239 100644 --- a/vtkm/filter/entity_extraction/ThresholdPoints.cxx +++ b/vtkm/filter/entity_extraction/ThresholdPoints.cxx @@ -19,7 +19,7 @@ class ValuesBelow { public: VTKM_CONT - ValuesBelow(const vtkm::Float64& value) + explicit ValuesBelow(const vtkm::Float64& value) : Value(value) { } @@ -39,7 +39,7 @@ class ValuesAbove { public: VTKM_CONT - ValuesAbove(const vtkm::Float64& value) + explicit ValuesAbove(const vtkm::Float64& value) : Value(value) { } @@ -178,7 +178,7 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS output.SetCellSet(outCellSet); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); }; this->MapFieldsOntoOutput(input, output, mapper); // compact the unused points in the output dataset diff --git a/vtkm/filter/entity_extraction/ThresholdPoints.h b/vtkm/filter/entity_extraction/ThresholdPoints.h index a2cda39ee..58ce00b47 100644 --- a/vtkm/filter/entity_extraction/ThresholdPoints.h +++ b/vtkm/filter/entity_extraction/ThresholdPoints.h @@ -41,11 +41,11 @@ public: void SetUpperThreshold(vtkm::Float64 value) { this->UpperValue = value; } VTKM_CONT - void SetThresholdBelow(const vtkm::Float64 value); + void SetThresholdBelow(vtkm::Float64 value); VTKM_CONT - void SetThresholdAbove(const vtkm::Float64 value); + void SetThresholdAbove(vtkm::Float64 value); VTKM_CONT - void SetThresholdBetween(const vtkm::Float64 value1, const vtkm::Float64 value2); + void SetThresholdBetween(vtkm::Float64 value1, vtkm::Float64 value2); private: VTKM_CONT diff --git a/vtkm/filter/entity_extraction/testing/CMakeLists.txt b/vtkm/filter/entity_extraction/testing/CMakeLists.txt index b737cb1c0..5f295de87 100644 --- a/vtkm/filter/entity_extraction/testing/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/testing/CMakeLists.txt @@ -14,6 +14,7 @@ set(unit_tests UnitTestExtractPointsFilter.cxx UnitTestExtractStructuredFilter.cxx UnitTestGhostCellRemove.cxx + UnitTestMaskFilter.cxx UnitTestMaskPointsFilter.cxx UnitTestThresholdFilter.cxx UnitTestThresholdPointsFilter.cxx diff --git a/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx b/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx index 3e7168f53..f78cf073b 100644 --- a/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx @@ -19,11 +19,11 @@ namespace { -static vtkm::cont::ArrayHandle StructuredGhostCellArray(vtkm::Id nx, - vtkm::Id ny, - vtkm::Id nz, - int numLayers, - bool addMidGhost = false) +vtkm::cont::ArrayHandle StructuredGhostCellArray(vtkm::Id nx, + vtkm::Id ny, + vtkm::Id nz, + int numLayers, + bool addMidGhost = false) { vtkm::Id numCells = nx * ny; if (nz > 0) @@ -80,19 +80,18 @@ static vtkm::cont::ArrayHandle StructuredGhostCellArray(vtkm::Id nx return ghosts; } -static vtkm::cont::DataSet MakeUniform(vtkm::Id numI, - vtkm::Id numJ, - vtkm::Id numK, - int numLayers, - bool addMidGhost = false) +vtkm::cont::DataSet MakeUniform(vtkm::Id numI, + vtkm::Id numJ, + vtkm::Id numK, + int numLayers, + bool addMidGhost = false) { - vtkm::cont::DataSetBuilderUniform dsb; vtkm::cont::DataSet ds; if (numK == 0) - ds = dsb.Create(vtkm::Id2(numI + 1, numJ + 1)); + ds = vtkm::cont::DataSetBuilderUniform::Create(vtkm::Id2(numI + 1, numJ + 1)); else - ds = dsb.Create(vtkm::Id3(numI + 1, numJ + 1, numK + 1)); + ds = vtkm::cont::DataSetBuilderUniform::Create(vtkm::Id3(numI + 1, numJ + 1, numK + 1)); auto ghosts = StructuredGhostCellArray(numI, numJ, numK, numLayers, addMidGhost); ds.AddCellField("vtkmGhostCells", ghosts); @@ -100,13 +99,12 @@ static vtkm::cont::DataSet MakeUniform(vtkm::Id numI, return ds; } -static vtkm::cont::DataSet MakeRectilinear(vtkm::Id numI, - vtkm::Id numJ, - vtkm::Id numK, - int numLayers, - bool addMidGhost = false) +vtkm::cont::DataSet MakeRectilinear(vtkm::Id numI, + vtkm::Id numJ, + vtkm::Id numK, + int numLayers, + bool addMidGhost = false) { - vtkm::cont::DataSetBuilderRectilinear dsb; vtkm::cont::DataSet ds; std::size_t nx(static_cast(numI + 1)); std::size_t ny(static_cast(numJ + 1)); @@ -118,14 +116,14 @@ static vtkm::cont::DataSet MakeRectilinear(vtkm::Id numI, y[i] = static_cast(i); if (numK == 0) - ds = dsb.Create(x, y); + ds = vtkm::cont::DataSetBuilderRectilinear::Create(x, y); else { std::size_t nz(static_cast(numK + 1)); std::vector z(nz); for (std::size_t i = 0; i < nz; i++) z[i] = static_cast(i); - ds = dsb.Create(x, y, z); + ds = vtkm::cont::DataSetBuilderRectilinear::Create(x, y, z); } auto ghosts = StructuredGhostCellArray(numI, numJ, numK, numLayers, addMidGhost); @@ -166,7 +164,7 @@ static void MakeExplicitCells(const CellSetType& cellSet, } } -static vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, vtkm::Id numJ, vtkm::Id numK, int numLayers) +vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, vtkm::Id numJ, vtkm::Id numK, int numLayers) { using CoordType = vtkm::Vec3f_32; @@ -187,21 +185,22 @@ static vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, vtkm::Id numJ, vtkm::Id n vtkm::cont::ArrayHandle numIndices; vtkm::cont::ArrayHandle shapes; vtkm::cont::DataSet ds; - vtkm::cont::DataSetBuilderExplicit dsb; if (cellSet.IsType>()) { vtkm::Id2 dims(numI, numJ); MakeExplicitCells( cellSet.AsCellSet>(), dims, numIndices, shapes, conn); - ds = dsb.Create(explCoords, vtkm::CellShapeTagQuad(), 4, conn, "coordinates"); + ds = vtkm::cont::DataSetBuilderExplicit::Create( + explCoords, vtkm::CellShapeTagQuad(), 4, conn, "coordinates"); } else if (cellSet.IsType>()) { vtkm::Id3 dims(numI, numJ, numK); MakeExplicitCells( cellSet.AsCellSet>(), dims, numIndices, shapes, conn); - ds = dsb.Create(explCoords, vtkm::CellShapeTagHexahedron(), 8, conn, "coordinates"); + ds = vtkm::cont::DataSetBuilderExplicit::Create( + explCoords, vtkm::CellShapeTagHexahedron(), 8, conn, "coordinates"); } auto ghosts = StructuredGhostCellArray(numI, numJ, numK, numLayers); diff --git a/vtkm/filter/testing/UnitTestMaskFilter.cxx b/vtkm/filter/entity_extraction/testing/UnitTestMaskFilter.cxx similarity index 94% rename from vtkm/filter/testing/UnitTestMaskFilter.cxx rename to vtkm/filter/entity_extraction/testing/UnitTestMaskFilter.cxx index ac05c2850..ea4964e16 100644 --- a/vtkm/filter/testing/UnitTestMaskFilter.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestMaskFilter.cxx @@ -11,7 +11,7 @@ #include #include -#include +#include using vtkm::cont::testing::MakeTestDataSet; @@ -27,7 +27,7 @@ public: vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1(); // Setup and run filter to extract by stride - vtkm::filter::Mask mask; + vtkm::filter::entity_extraction::Mask mask; vtkm::Id stride = 2; mask.SetStride(stride); @@ -50,7 +50,7 @@ public: vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); // Setup and run filter to extract by stride - vtkm::filter::Mask mask; + vtkm::filter::entity_extraction::Mask mask; vtkm::Id stride = 9; mask.SetStride(stride); @@ -71,7 +71,7 @@ public: vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5(); // Setup and run filter to extract by stride - vtkm::filter::Mask mask; + vtkm::filter::entity_extraction::Mask mask; vtkm::Id stride = 2; mask.SetStride(stride); diff --git a/vtkm/filter/entity_extraction/worklet/CMakeLists.txt b/vtkm/filter/entity_extraction/worklet/CMakeLists.txt index 9292c3e9b..b53737f73 100644 --- a/vtkm/filter/entity_extraction/worklet/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/worklet/CMakeLists.txt @@ -13,6 +13,7 @@ set(headers ExtractGeometry.h ExtractStructured.h ExtractPoints.h + Mask.h MaskPoints.h Threshold.h ThresholdPoints.h diff --git a/vtkm/filter/entity_extraction/worklet/ExtractGeometry.h b/vtkm/filter/entity_extraction/worklet/ExtractGeometry.h index 8b3ec2728..17679bdf9 100644 --- a/vtkm/filter/entity_extraction/worklet/ExtractGeometry.h +++ b/vtkm/filter/entity_extraction/worklet/ExtractGeometry.h @@ -10,7 +10,6 @@ #ifndef vtkm_m_worklet_ExtractGeometry_h #define vtkm_m_worklet_ExtractGeometry_h -#include #include #include @@ -18,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -144,8 +143,8 @@ public: vtkm::cont::ArrayHandle passFlags; ExtractCellsByVOI worklet(extractInside, extractBoundaryCells, extractOnlyBoundaryCells); - DispatcherMapTopology dispatcher(worklet); - dispatcher.Invoke(cellSet, coordinates, implicitFunction, passFlags); + vtkm::cont::Invoker invoke; + invoke(worklet, cellSet, coordinates, implicitFunction, passFlags); vtkm::cont::ArrayHandleCounting indices = vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues()); diff --git a/vtkm/filter/entity_extraction/worklet/ExtractPoints.h b/vtkm/filter/entity_extraction/worklet/ExtractPoints.h index 9fab54962..ea1ea85b1 100644 --- a/vtkm/filter/entity_extraction/worklet/ExtractPoints.h +++ b/vtkm/filter/entity_extraction/worklet/ExtractPoints.h @@ -10,17 +10,16 @@ #ifndef vtkm_m_worklet_ExtractPoints_h #define vtkm_m_worklet_ExtractPoints_h -#include -#include - #include #include #include #include -#include +#include #include +#include + namespace vtkm { namespace worklet @@ -41,7 +40,7 @@ public: using ExecutionSignature = _4(_2, _3); VTKM_CONT - ExtractPointsByVOI(bool extractInside) + explicit ExtractPointsByVOI(bool extractInside) : passValue(extractInside) , failValue(!extractInside) { @@ -93,8 +92,8 @@ public: vtkm::cont::ArrayHandle passFlags; ExtractPointsByVOI worklet(extractInside); - DispatcherMapTopology dispatcher(worklet); - dispatcher.Invoke(cellSet, coordinates, implicitFunction, passFlags); + vtkm::cont::Invoker invoke; + invoke(worklet, cellSet, coordinates, implicitFunction, passFlags); vtkm::cont::ArrayHandleCounting indices = vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues()); diff --git a/vtkm/filter/entity_extraction/worklet/ExtractStructured.h b/vtkm/filter/entity_extraction/worklet/ExtractStructured.h index 09b4051f4..f38e0d497 100644 --- a/vtkm/filter/entity_extraction/worklet/ExtractStructured.h +++ b/vtkm/filter/entity_extraction/worklet/ExtractStructured.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -73,7 +74,7 @@ struct ExtractCopy : public vtkm::worklet::WorkletMapField { using ControlSignature = void(FieldIn, FieldOut, WholeArrayIn); - ExtractCopy(const vtkm::Id3& dim) + explicit ExtractCopy(const vtkm::Id3& dim) : XDim(dim[0]) , XYDim(dim[0] * dim[1]) { @@ -178,7 +179,7 @@ private: return outCs; } default: - return UncertainCellSetStructured(); + return {}; } } @@ -438,7 +439,7 @@ private: inOrigin[2] + static_cast(this->VOI.Z.Min) * inSpacing[2]); CoordType outSpacing = inSpacing * static_cast(this->SampleRate); - return CoordsArray(this->OutputDimensions, outOrigin, outSpacing); + return { this->OutputDimensions, outOrigin, outSpacing }; } RectilinearCoordinatesArrayHandle MapCoordinatesRectilinear( @@ -522,8 +523,8 @@ public: result.Allocate(this->ValidPoints.GetNumberOfValues()); ExtractCopy worklet(this->InputDimensions); - DispatcherMapField dispatcher(worklet); - dispatcher.Invoke(this->ValidPoints, result, field); + vtkm::cont::Invoker invoke; + invoke(worklet, this->ValidPoints, result, field); return result; } @@ -538,8 +539,8 @@ public: auto inputCellDimensions = this->InputDimensions - vtkm::Id3(1); ExtractCopy worklet(inputCellDimensions); - DispatcherMapField dispatcher(worklet); - dispatcher.Invoke(this->ValidCells, result, field); + vtkm::cont::Invoker invoke; + invoke(worklet, this->ValidCells, result, field); return result; } diff --git a/vtkm/worklet/Mask.h b/vtkm/filter/entity_extraction/worklet/Mask.h similarity index 96% rename from vtkm/worklet/Mask.h rename to vtkm/filter/entity_extraction/worklet/Mask.h index a41b15563..b96efab9d 100644 --- a/vtkm/worklet/Mask.h +++ b/vtkm/filter/entity_extraction/worklet/Mask.h @@ -10,7 +10,6 @@ #ifndef vtkm_m_worklet_Mask_h #define vtkm_m_worklet_Mask_h -#include #include #include @@ -18,7 +17,6 @@ #include #include #include -#include namespace vtkm { diff --git a/vtkm/filter/entity_extraction/worklet/MaskPoints.h b/vtkm/filter/entity_extraction/worklet/MaskPoints.h index 5eb60d7c0..ed060c32a 100644 --- a/vtkm/filter/entity_extraction/worklet/MaskPoints.h +++ b/vtkm/filter/entity_extraction/worklet/MaskPoints.h @@ -13,7 +13,6 @@ #include #include #include -#include namespace vtkm { diff --git a/vtkm/filter/entity_extraction/worklet/Threshold.h b/vtkm/filter/entity_extraction/worklet/Threshold.h index dffb29e4a..d8ab6c3cd 100644 --- a/vtkm/filter/entity_extraction/worklet/Threshold.h +++ b/vtkm/filter/entity_extraction/worklet/Threshold.h @@ -15,10 +15,8 @@ #include #include -#include #include #include -#include #include #include #include diff --git a/vtkm/filter/entity_extraction/worklet/ThresholdPoints.h b/vtkm/filter/entity_extraction/worklet/ThresholdPoints.h index 4bc20eb9e..ece19b4cb 100644 --- a/vtkm/filter/entity_extraction/worklet/ThresholdPoints.h +++ b/vtkm/filter/entity_extraction/worklet/ThresholdPoints.h @@ -10,12 +10,11 @@ #ifndef vtkm_m_worklet_ThresholdPoints_h #define vtkm_m_worklet_ThresholdPoints_h -#include -#include - #include #include -#include +#include + +#include namespace vtkm { @@ -64,8 +63,8 @@ public: using ThresholdWorklet = ThresholdPointField; ThresholdWorklet worklet(predicate); - DispatcherMapTopology dispatcher(worklet); - dispatcher.Invoke(cellSet, scalars, passFlags); + vtkm::cont::Invoker invoker; + invoker(worklet, cellSet, scalars, passFlags); vtkm::cont::ArrayHandle pointIds; vtkm::cont::ArrayHandleCounting indices = diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index a96df9cad..d154d2a87 100644 --- a/vtkm/filter/testing/CMakeLists.txt +++ b/vtkm/filter/testing/CMakeLists.txt @@ -40,7 +40,6 @@ set(unit_tests UnitTestLagrangianStructuresFilter.cxx UnitTestMapFieldMergeAverage.cxx UnitTestMapFieldPermutation.cxx - UnitTestMaskFilter.cxx UnitTestMeshQualityFilter.cxx UnitTestMIRFilter.cxx UnitTestMultiBlockFilter.cxx diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index 2482a1592..521748a26 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -38,7 +38,6 @@ set(headers LagrangianStructures.h Magnitude.h Contour.h - Mask.h MaskIndices.h MaskNone.h MaskSelect.h diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index c3a185ec1..8084faeaa 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -39,7 +39,6 @@ set(unit_tests UnitTestImageConnectivity.cxx UnitTestKeys.cxx UnitTestMagnitude.cxx - UnitTestMask.cxx UnitTestMaskIndices.cxx UnitTestMaskSelect.cxx UnitTestNormalize.cxx diff --git a/vtkm/worklet/testing/UnitTestMask.cxx b/vtkm/worklet/testing/UnitTestMask.cxx deleted file mode 100644 index e943789b2..000000000 --- a/vtkm/worklet/testing/UnitTestMask.cxx +++ /dev/null @@ -1,119 +0,0 @@ -//============================================================================ -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//============================================================================ - -#include - -#include -#include - -#include -#include - -#include -#include -#include - -using vtkm::cont::testing::MakeTestDataSet; - -class TestingMask -{ -public: - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestUniform2D() const - { - std::cout << "Testing mask cells structured:" << std::endl; - - using CellSetType = vtkm::cont::CellSetStructured<2>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Output data set permutation - vtkm::worklet::Mask maskCells; - OutCellSetType outCellSet = maskCells.Run(cellSet, 2); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - vtkm::cont::ArrayHandle cellFieldArray = maskCells.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for Mask"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 && - cellFieldArray.ReadPortal().Get(7) == 14.f, - "Wrong cell field data"); - } - - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestUniform3D() const - { - std::cout << "Testing mask cells structured:" << std::endl; - - using CellSetType = vtkm::cont::CellSetStructured<3>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Output data set with cell set permuted - vtkm::worklet::Mask maskCells; - OutCellSetType outCellSet = maskCells.Run(cellSet, 9); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - vtkm::cont::ArrayHandle cellFieldArray = maskCells.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 7), "Wrong result for ExtractCells"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 7 && - cellFieldArray.ReadPortal().Get(2) == 18.f, - "Wrong cell field data"); - } - - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestExplicit() const - { - std::cout << "Testing mask cells explicit:" << std::endl; - - using CellSetType = vtkm::cont::CellSetExplicit<>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Output data set with cell set permuted - vtkm::worklet::Mask maskCells; - OutCellSetType outCellSet = maskCells.Run(cellSet, 2); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - vtkm::cont::ArrayHandle cellFieldArray = maskCells.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 2), "Wrong result for ExtractCells"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 && - cellFieldArray.ReadPortal().Get(1) == 120.2f, - "Wrong cell field data"); - } - - void operator()() const - { - this->TestUniform2D(); - this->TestUniform3D(); - this->TestExplicit(); - } -}; - -int UnitTestMask(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestingMask(), argc, argv); -}