From 3a7d3cb5ff16422dd16f50a8b12b55fa75b19f13 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 7 Aug 2019 12:54:47 -0400 Subject: [PATCH] VTK-m filters now launch all worklets via a vtkm::cont::Invoker This has been done as to showcase the recommend best practices for new VTK-m contributors. --- docs/changelog/invoker-used-by-filters.md | 43 +++++++++++++++++++ examples/game_of_life/GameOfLife.cxx | 7 +-- examples/histogram/HistogramMPI.hxx | 1 - examples/multi_backend/IOGenerator.cxx | 6 +-- .../PolyLineArchimedeanHelix.cxx | 1 - vtkm/filter/CellAverage.hxx | 5 +-- vtkm/filter/CellMeasures.hxx | 7 +-- vtkm/filter/CellSetConnectivity.h | 2 - vtkm/filter/CellSetConnectivity.hxx | 3 +- vtkm/filter/ClipWithField.hxx | 1 - vtkm/filter/ClipWithImplicitFunction.hxx | 2 - vtkm/filter/CoordinateSystemTransform.hxx | 1 - vtkm/filter/CrossProduct.hxx | 36 ++++++++++------ vtkm/filter/DotProduct.hxx | 37 +++++++++------- vtkm/filter/Entropy.hxx | 1 - vtkm/filter/ExtractGeometry.hxx | 2 - vtkm/filter/ExtractStructured.hxx | 2 - vtkm/filter/Filter.h | 9 ++++ vtkm/filter/Filter.hxx | 3 +- vtkm/filter/GhostCellClassify.hxx | 12 +++--- vtkm/filter/GhostCellRemove.hxx | 25 +++++------ vtkm/filter/Histogram.hxx | 1 - vtkm/filter/ImageConnectivity.hxx | 1 - vtkm/filter/Lagrangian.hxx | 15 ++++--- vtkm/filter/MarchingCubes.hxx | 2 - vtkm/filter/MeshQuality.hxx | 22 ++++++---- vtkm/filter/OscillatorSource.hxx | 4 +- vtkm/filter/PointAverage.hxx | 6 +-- vtkm/filter/PointElevation.hxx | 4 +- vtkm/filter/PointTransform.hxx | 5 +-- vtkm/filter/SplitSharpEdges.hxx | 2 - vtkm/filter/Tetrahedralize.hxx | 26 +++-------- vtkm/filter/Threshold.hxx | 2 - vtkm/filter/VectorMagnitude.hxx | 5 +-- vtkm/filter/WarpScalar.hxx | 3 -- vtkm/filter/WarpVector.hxx | 3 -- vtkm/filter/ZFPCompressor1D.hxx | 9 ---- vtkm/filter/ZFPCompressor2D.hxx | 9 ---- vtkm/filter/ZFPCompressor3D.hxx | 9 ---- vtkm/filter/ZFPDecompressor1D.hxx | 9 ---- vtkm/filter/ZFPDecompressor2D.hxx | 9 ---- vtkm/filter/ZFPDecompressor3D.hxx | 9 ---- .../testing/UnitTestSplitSharpEdgesFilter.cxx | 1 - 43 files changed, 158 insertions(+), 204 deletions(-) create mode 100644 docs/changelog/invoker-used-by-filters.md diff --git a/docs/changelog/invoker-used-by-filters.md b/docs/changelog/invoker-used-by-filters.md new file mode 100644 index 000000000..98a8458c4 --- /dev/null +++ b/docs/changelog/invoker-used-by-filters.md @@ -0,0 +1,43 @@ +# Invoker now a member of all vtkm::filters + +To simplify how vtkm filters are written we have made each vtkm::filter +have a `vtkm::cont::Invoker` as member variable. The goal with this change +is provide an uniform API for launching all worklets from within a filter. + +Lets consider the PointElevation filter. Previous to these changes the +`DoExecute` would need to construct the correct dispatcher with the +correct parameters as seen below: + +```cpp +template +inline VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute( + const vtkm::cont::DataSet& inDataSet, + const vtkm::cont::ArrayHandle& field, + const vtkm::filter::FieldMetadata& fieldMetadata, + vtkm::filter::PolicyBase) +{ + vtkm::cont::ArrayHandle outArray; + + vtkm::worklet::DispatcherMapField dispatcher(this->Worklet); + dispatcher.Invoke(field, outArray); + ... +} +``` + +With these changes the filter can instead use `this->Invoke` and have +the correct dispatcher executed. This makes it easier to teach and +learn how to write new filters. +```cpp +template +inline VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute( + const vtkm::cont::DataSet& inDataSet, + const vtkm::cont::ArrayHandle& field, + const vtkm::filter::FieldMetadata& fieldMetadata, + vtkm::filter::PolicyBase) +{ + vtkm::cont::ArrayHandle outArray; + + this->Invoke(this->Worklet, field, outArray); + ... +} +``` diff --git a/examples/game_of_life/GameOfLife.cxx b/examples/game_of_life/GameOfLife.cxx index 985c6deb6..1a2a6afe6 100644 --- a/examples/game_of_life/GameOfLife.cxx +++ b/examples/game_of_life/GameOfLife.cxx @@ -27,7 +27,6 @@ #include #include -#include #include #include @@ -111,9 +110,6 @@ public: vtkm::filter::PolicyBase policy) { - using DispatcherType = vtkm::worklet::DispatcherPointNeighborhood; - - vtkm::cont::ArrayHandle state; vtkm::cont::ArrayHandle prevstate; vtkm::cont::ArrayHandle colors; @@ -125,8 +121,7 @@ public: input.GetField("state", vtkm::cont::Field::Association::POINTS).GetData().CopyTo(prevstate); //Update the game state - DispatcherType dispatcher; - dispatcher.Invoke(vtkm::filter::ApplyPolicy(cells, policy), prevstate, state, colors); + this->Invoke(vtkm::filter::ApplyPolicy(cells, policy), prevstate, state, colors); //save the results vtkm::cont::DataSet output; diff --git a/examples/histogram/HistogramMPI.hxx b/examples/histogram/HistogramMPI.hxx index 3a550785d..173ffc35d 100644 --- a/examples/histogram/HistogramMPI.hxx +++ b/examples/histogram/HistogramMPI.hxx @@ -8,7 +8,6 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include #include #include diff --git a/examples/multi_backend/IOGenerator.cxx b/examples/multi_backend/IOGenerator.cxx index 5b751a56f..a20e87a34 100644 --- a/examples/multi_backend/IOGenerator.cxx +++ b/examples/multi_backend/IOGenerator.cxx @@ -13,8 +13,8 @@ #include #include +#include -#include #include #include @@ -43,8 +43,8 @@ vtkm::cont::DataSet make_test3DImageData(vtkm::Id3 dims) vtkm::cont::DataSet ds = Builder::Create(dims); vtkm::cont::ArrayHandle field; - vtkm::worklet::DispatcherMapField dispatcher; - dispatcher.Invoke(ds.GetCoordinateSystem(), field); + vtkm::cont::Invoker invoke; + invoke(WaveField{}, ds.GetCoordinateSystem(), field); FieldAdd::AddPointField(ds, "vec_field", field); return ds; diff --git a/examples/polyline_archimedean_helix/PolyLineArchimedeanHelix.cxx b/examples/polyline_archimedean_helix/PolyLineArchimedeanHelix.cxx index 8ca5e6a48..24f6757ce 100644 --- a/examples/polyline_archimedean_helix/PolyLineArchimedeanHelix.cxx +++ b/examples/polyline_archimedean_helix/PolyLineArchimedeanHelix.cxx @@ -12,7 +12,6 @@ #include #include #include -#include #include #include diff --git a/vtkm/filter/CellAverage.hxx b/vtkm/filter/CellAverage.hxx index 5900e91fc..3b888e871 100644 --- a/vtkm/filter/CellAverage.hxx +++ b/vtkm/filter/CellAverage.hxx @@ -11,7 +11,6 @@ #include #include #include -#include namespace vtkm { @@ -44,9 +43,7 @@ inline VTKM_CONT vtkm::cont::DataSet CellAverage::DoExecute( //If the input is implicit, we should know what to fall back to vtkm::cont::ArrayHandle outArray; - vtkm::worklet::DispatcherMapTopology dispatcher(this->Worklet); - - dispatcher.Invoke(vtkm::filter::ApplyPolicy(cellSet, policy), inField, outArray); + this->Invoke(this->Worklet, vtkm::filter::ApplyPolicy(cellSet, policy), inField, outArray); std::string outputName = this->GetOutputFieldName(); if (outputName == "") diff --git a/vtkm/filter/CellMeasures.hxx b/vtkm/filter/CellMeasures.hxx index 03ad85682..9dd5f54d8 100644 --- a/vtkm/filter/CellMeasures.hxx +++ b/vtkm/filter/CellMeasures.hxx @@ -11,7 +11,6 @@ #include #include #include -#include namespace vtkm { @@ -39,8 +38,10 @@ inline VTKM_CONT vtkm::cont::DataSet CellMeasures::DoExecute( const auto& cellset = input.GetCellSet(this->GetActiveCellSetIndex()); vtkm::cont::ArrayHandle outArray; - vtkm::worklet::DispatcherMapTopology> dispatcher; - dispatcher.Invoke(vtkm::filter::ApplyPolicy(cellset, policy), points, outArray); + this->Invoke(vtkm::worklet::CellMeasure{}, + vtkm::filter::ApplyPolicy(cellset, policy), + points, + outArray); vtkm::cont::DataSet result; std::string outputName = this->GetCellMeasureName(); diff --git a/vtkm/filter/CellSetConnectivity.h b/vtkm/filter/CellSetConnectivity.h index f96325734..3bd0f8438 100644 --- a/vtkm/filter/CellSetConnectivity.h +++ b/vtkm/filter/CellSetConnectivity.h @@ -11,9 +11,7 @@ #ifndef vtkm_m_filter_CellSetConnectivity_h #define vtkm_m_filter_CellSetConnectivity_h - #include -#include namespace vtkm { diff --git a/vtkm/filter/CellSetConnectivity.hxx b/vtkm/filter/CellSetConnectivity.hxx index ba0fdca77..e1ac6e685 100644 --- a/vtkm/filter/CellSetConnectivity.hxx +++ b/vtkm/filter/CellSetConnectivity.hxx @@ -11,9 +11,8 @@ #ifndef vtkm_m_filter_CellSetConnectivity_hxx #define vtkm_m_filter_CellSetConnectivity_hxx -#include #include -#include +#include namespace vtkm { diff --git a/vtkm/filter/ClipWithField.hxx b/vtkm/filter/ClipWithField.hxx index 47dfdbf21..430b7e4d7 100644 --- a/vtkm/filter/ClipWithField.hxx +++ b/vtkm/filter/ClipWithField.hxx @@ -13,7 +13,6 @@ #include #include #include -#include namespace vtkm { diff --git a/vtkm/filter/ClipWithImplicitFunction.hxx b/vtkm/filter/ClipWithImplicitFunction.hxx index e9f68d601..15b94aa5d 100644 --- a/vtkm/filter/ClipWithImplicitFunction.hxx +++ b/vtkm/filter/ClipWithImplicitFunction.hxx @@ -12,8 +12,6 @@ #include #include -#include - namespace vtkm { namespace filter diff --git a/vtkm/filter/CoordinateSystemTransform.hxx b/vtkm/filter/CoordinateSystemTransform.hxx index f9dbf78c7..11bf055aa 100644 --- a/vtkm/filter/CoordinateSystemTransform.hxx +++ b/vtkm/filter/CoordinateSystemTransform.hxx @@ -9,7 +9,6 @@ //============================================================================ #include -#include namespace vtkm { diff --git a/vtkm/filter/CrossProduct.hxx b/vtkm/filter/CrossProduct.hxx index 6c6341c52..2ef8d9342 100644 --- a/vtkm/filter/CrossProduct.hxx +++ b/vtkm/filter/CrossProduct.hxx @@ -20,18 +20,23 @@ namespace filter namespace detail { -template struct CrossProductFunctor { - vtkm::cont::ArrayHandle> OutArray; - - template - void operator()(const SecondaryFieldType& secondaryField, const PrimaryFieldType& primaryField) + vtkm::cont::Invoker& Invoke; + CrossProductFunctor(vtkm::cont::Invoker& invoke) + : Invoke(invoke) { - vtkm::worklet::DispatcherMapField dispatcher; - dispatcher.Invoke(primaryField, - vtkm::cont::make_ArrayHandleCast>(secondaryField), - this->OutArray); + } + + template + void operator()(const SecondaryFieldType& secondaryField, + const vtkm::cont::ArrayHandle, StorageType>& primaryField, + vtkm::cont::ArrayHandle>& output) const + { + this->Invoke(vtkm::worklet::CrossProduct{}, + primaryField, + vtkm::cont::make_ArrayHandleCast>(secondaryField), + output); } }; @@ -56,13 +61,18 @@ inline VTKM_CONT vtkm::cont::DataSet CrossProduct::DoExecute( const vtkm::filter::FieldMetadata& fieldMetadata, vtkm::filter::PolicyBase policy) { - detail::CrossProductFunctor functor; + + detail::CrossProductFunctor functor(this->Invoke); + vtkm::cont::ArrayHandle> output; try { if (this->UseCoordinateSystemAsSecondaryField) { vtkm::cont::CastAndCall( - inDataSet.GetCoordinateSystem(this->GetSecondaryCoordinateSystemIndex()), functor, field); + inDataSet.GetCoordinateSystem(this->GetSecondaryCoordinateSystemIndex()), + functor, + field, + output); } else { @@ -73,7 +83,7 @@ inline VTKM_CONT vtkm::cont::DataSet CrossProduct::DoExecute( policy, Traits()) .ResetTypes(TypeList()) - .CastAndCall(functor, field); + .CastAndCall(functor, field, output); } } catch (const vtkm::cont::Error&) @@ -83,7 +93,7 @@ inline VTKM_CONT vtkm::cont::DataSet CrossProduct::DoExecute( return internal::CreateResult(inDataSet, - functor.OutArray, + output, this->GetOutputFieldName(), fieldMetadata.GetAssociation(), fieldMetadata.GetCellSetName()); diff --git a/vtkm/filter/DotProduct.hxx b/vtkm/filter/DotProduct.hxx index 790fd0d87..3f96b9862 100644 --- a/vtkm/filter/DotProduct.hxx +++ b/vtkm/filter/DotProduct.hxx @@ -8,8 +8,6 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include - #include #include @@ -21,18 +19,23 @@ namespace filter namespace detail { -template struct DotProductFunctor { - vtkm::cont::ArrayHandle OutArray; - - template - void operator()(const SecondaryFieldType& secondaryField, const PrimaryFieldType& primaryField) + vtkm::cont::Invoker& Invoke; + DotProductFunctor(vtkm::cont::Invoker& invoke) + : Invoke(invoke) { - vtkm::worklet::DispatcherMapField dispatcher; - dispatcher.Invoke(primaryField, - vtkm::cont::make_ArrayHandleCast>(secondaryField), - this->OutArray); + } + + template + void operator()(const SecondaryFieldType& secondaryField, + const vtkm::cont::ArrayHandle, StorageType>& primaryField, + vtkm::cont::ArrayHandle& output) const + { + this->Invoke(vtkm::worklet::DotProduct{}, + primaryField, + vtkm::cont::make_ArrayHandleCast>(secondaryField), + output); } }; @@ -57,13 +60,17 @@ inline VTKM_CONT vtkm::cont::DataSet DotProduct::DoExecute( const vtkm::filter::FieldMetadata& fieldMetadata, vtkm::filter::PolicyBase policy) { - detail::DotProductFunctor functor; + detail::DotProductFunctor functor(this->Invoke); + vtkm::cont::ArrayHandle output; try { if (this->UseCoordinateSystemAsSecondaryField) { vtkm::cont::CastAndCall( - inDataSet.GetCoordinateSystem(this->GetSecondaryCoordinateSystemIndex()), functor, field); + inDataSet.GetCoordinateSystem(this->GetSecondaryCoordinateSystemIndex()), + functor, + field, + output); } else { @@ -74,7 +81,7 @@ inline VTKM_CONT vtkm::cont::DataSet DotProduct::DoExecute( policy, Traits()) .ResetTypes(TypeList()) - .CastAndCall(functor, field); + .CastAndCall(functor, field, output); } } catch (const vtkm::cont::Error&) @@ -83,7 +90,7 @@ inline VTKM_CONT vtkm::cont::DataSet DotProduct::DoExecute( } return internal::CreateResult(inDataSet, - functor.OutArray, + output, this->GetOutputFieldName(), fieldMetadata.GetAssociation(), fieldMetadata.GetCellSetName()); diff --git a/vtkm/filter/Entropy.hxx b/vtkm/filter/Entropy.hxx index c7787b4d6..7df495542 100644 --- a/vtkm/filter/Entropy.hxx +++ b/vtkm/filter/Entropy.hxx @@ -8,7 +8,6 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include #include #include diff --git a/vtkm/filter/ExtractGeometry.hxx b/vtkm/filter/ExtractGeometry.hxx index f4843317a..41a53a39a 100644 --- a/vtkm/filter/ExtractGeometry.hxx +++ b/vtkm/filter/ExtractGeometry.hxx @@ -13,8 +13,6 @@ #include #include -#include - namespace { diff --git a/vtkm/filter/ExtractStructured.hxx b/vtkm/filter/ExtractStructured.hxx index 63efa7178..033390ac7 100644 --- a/vtkm/filter/ExtractStructured.hxx +++ b/vtkm/filter/ExtractStructured.hxx @@ -8,8 +8,6 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include - namespace vtkm { namespace filter diff --git a/vtkm/filter/Filter.h b/vtkm/filter/Filter.h index 7ee06a716..cfb6fafc5 100644 --- a/vtkm/filter/Filter.h +++ b/vtkm/filter/Filter.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -250,6 +251,14 @@ public: vtkm::cont::DataSet& output, const vtkm::filter::PolicyBase& policy); + /// Specify the vtkm::cont::Invoker to be used to execute worklets by + /// this filter instance. Overriding the default allows callers to control + /// which device adapters a filter uses. + void SetInvoker(vtkm::cont::Invoker inv) { this->Invoke = inv; } + +protected: + vtkm::cont::Invoker Invoke; + private: vtkm::filter::FieldSelection FieldsToPass; }; diff --git a/vtkm/filter/Filter.hxx b/vtkm/filter/Filter.hxx index 1eeda4fcf..dca785e11 100644 --- a/vtkm/filter/Filter.hxx +++ b/vtkm/filter/Filter.hxx @@ -234,7 +234,8 @@ void CallPostExecute(Derived* self, //---------------------------------------------------------------------------- template inline VTKM_CONT Filter::Filter() - : FieldsToPass(vtkm::filter::FieldSelection::MODE_ALL) + : Invoke() + , FieldsToPass(vtkm::filter::FieldSelection::MODE_ALL) { } diff --git a/vtkm/filter/GhostCellClassify.hxx b/vtkm/filter/GhostCellClassify.hxx index d23d54064..018bfee7d 100644 --- a/vtkm/filter/GhostCellClassify.hxx +++ b/vtkm/filter/GhostCellClassify.hxx @@ -19,7 +19,6 @@ #include -#include #include @@ -155,8 +154,7 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellClassify::DoExecute(const vtkm::co vtkm::cont::CellSetStructured<1> cellset1d = cellset.Cast>(); SetStructuredGhostCells1D structuredGhosts1D(cellset1d.GetCellDimensions()); - vtkm::worklet::DispatcherMapField dispatcher(structuredGhosts1D); - dispatcher.Invoke(indexArray, ghosts); + this->Invoke(structuredGhosts1D, indexArray, ghosts); } else if (cellset.template IsType>()) { @@ -165,8 +163,7 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellClassify::DoExecute(const vtkm::co vtkm::cont::CellSetStructured<2> cellset2d = cellset.Cast>(); SetStructuredGhostCells2D structuredGhosts2D(cellset2d.GetCellDimensions()); - vtkm::worklet::DispatcherMapField dispatcher(structuredGhosts2D); - dispatcher.Invoke(indexArray, ghosts); + this->Invoke(structuredGhosts2D, indexArray, ghosts); } else if (cellset.template IsType>()) { @@ -175,11 +172,12 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellClassify::DoExecute(const vtkm::co vtkm::cont::CellSetStructured<3> cellset3d = cellset.Cast>(); SetStructuredGhostCells3D structuredGhosts3D(cellset3d.GetCellDimensions()); - vtkm::worklet::DispatcherMapField dispatcher(structuredGhosts3D); - dispatcher.Invoke(indexArray, ghosts); + this->Invoke(structuredGhosts3D, indexArray, ghosts); } else + { throw vtkm::cont::ErrorFilterExecution("Unsupported cellset type for GhostCellClassify."); + } vtkm::cont::DataSet output = internal::CreateResult( input, ghosts, "vtkmGhostCells", vtkm::cont::Field::Association::CELL_SET, cellset.GetName()); diff --git a/vtkm/filter/GhostCellRemove.hxx b/vtkm/filter/GhostCellRemove.hxx index ee74613f6..b98f57d42 100644 --- a/vtkm/filter/GhostCellRemove.hxx +++ b/vtkm/filter/GhostCellRemove.hxx @@ -16,7 +16,6 @@ #include #include #include -#include namespace { @@ -204,6 +203,7 @@ private: template bool CanStrip(const vtkm::cont::ArrayHandle& ghostField, + const vtkm::cont::Invoker& invoke, bool removeAllGhost, vtkm::UInt8 removeType, vtkm::RangeId3& range, @@ -219,9 +219,7 @@ bool CanStrip(const vtkm::cont::ArrayHandle& ghostField, minmax.GetPortalControl().Set(4, std::numeric_limits::min()); minmax.GetPortalControl().Set(5, std::numeric_limits::min()); - vtkm::worklet::DispatcherMapField>( - RealMinMax<3>(cellDims, removeAllGhost, removeType)) - .Invoke(ghostField, minmax); + invoke(RealMinMax<3>(cellDims, removeAllGhost, removeType), ghostField, minmax); auto portal = minmax.GetPortalConstControl(); range = vtkm::RangeId3( @@ -230,9 +228,7 @@ bool CanStrip(const vtkm::cont::ArrayHandle& ghostField, vtkm::cont::ArrayHandle validFlags; validFlags.Allocate(size); - vtkm::worklet::DispatcherMapField>( - Validate(cellDims, removeAllGhost, removeType, range)) - .Invoke(ghostField, validFlags); + invoke(Validate(cellDims, removeAllGhost, removeType, range), ghostField, validFlags); vtkm::UInt8 res = vtkm::cont::Algorithm::Reduce(validFlags, vtkm::UInt8(0), vtkm::Maximum()); return res == 0; @@ -241,6 +237,7 @@ bool CanStrip(const vtkm::cont::ArrayHandle& ghostField, template bool CanDoStructuredStrip(const vtkm::cont::DynamicCellSet& cells, const vtkm::cont::ArrayHandle& ghostField, + const vtkm::cont::Invoker& invoke, bool removeAllGhost, vtkm::UInt8 removeType, vtkm::RangeId3& range) @@ -255,8 +252,7 @@ bool CanDoStructuredStrip(const vtkm::cont::DynamicCellSet& cells, cellDims[0] = d; vtkm::Id sz = d; - canDo = - CanStrip<1, T, StorageType>(ghostField, removeAllGhost, removeType, range, cellDims, sz); + canDo = CanStrip<1>(ghostField, invoke, removeAllGhost, removeType, range, cellDims, sz); } else if (cells.IsSameType(vtkm::cont::CellSetStructured<2>())) { @@ -265,16 +261,14 @@ bool CanDoStructuredStrip(const vtkm::cont::DynamicCellSet& cells, cellDims[0] = d[0]; cellDims[1] = d[1]; vtkm::Id sz = cellDims[0] * cellDims[1]; - canDo = - CanStrip<2, T, StorageType>(ghostField, removeAllGhost, removeType, range, cellDims, sz); + canDo = CanStrip<2>(ghostField, invoke, removeAllGhost, removeType, range, cellDims, sz); } else if (cells.IsSameType(vtkm::cont::CellSetStructured<3>())) { auto cells3D = cells.Cast>(); cellDims = cells3D.GetCellDimensions(); vtkm::Id sz = cellDims[0] * cellDims[1] * cellDims[2]; - canDo = - CanStrip<3, T, StorageType>(ghostField, removeAllGhost, removeType, range, cellDims, sz); + canDo = CanStrip<3>(ghostField, invoke, removeAllGhost, removeType, range, cellDims, sz); } return canDo; @@ -317,10 +311,11 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute( cells.IsSameType(vtkm::cont::CellSetStructured<3>())) { vtkm::RangeId3 range; - if (CanDoStructuredStrip( - cells, field, this->GetRemoveAllGhost(), this->GetRemoveType(), range)) + if (CanDoStructuredStrip( + cells, field, this->Invoke, this->GetRemoveAllGhost(), this->GetRemoveType(), range)) { vtkm::filter::ExtractStructured extract; + extract.SetInvoker(this->Invoke); vtkm::RangeId3 erange( range.X.Min, range.X.Max + 2, range.Y.Min, range.Y.Max + 2, range.Z.Min, range.Z.Max + 2); vtkm::Id3 sample(1, 1, 1); diff --git a/vtkm/filter/Histogram.hxx b/vtkm/filter/Histogram.hxx index c11dbd351..620443220 100644 --- a/vtkm/filter/Histogram.hxx +++ b/vtkm/filter/Histogram.hxx @@ -8,7 +8,6 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include #include #include diff --git a/vtkm/filter/ImageConnectivity.hxx b/vtkm/filter/ImageConnectivity.hxx index 0d05461a8..36a79f5bd 100644 --- a/vtkm/filter/ImageConnectivity.hxx +++ b/vtkm/filter/ImageConnectivity.hxx @@ -13,7 +13,6 @@ #include #include -#include namespace vtkm { diff --git a/vtkm/filter/Lagrangian.hxx b/vtkm/filter/Lagrangian.hxx index fc079b5d7..effde3490 100644 --- a/vtkm/filter/Lagrangian.hxx +++ b/vtkm/filter/Lagrangian.hxx @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +34,8 @@ static vtkm::cont::ArrayHandle BasisParticles; static vtkm::cont::ArrayHandle BasisParticlesOriginal; static vtkm::cont::ArrayHandle BasisParticlesValidity; +namespace +{ class ValidityCheck : public vtkm::worklet::WorkletMapField { public: @@ -42,7 +43,10 @@ public: using ExecutionSignature = void(_1, _2, _3); using InputDomain = _1; - inline VTKM_CONT void SetBounds(vtkm::Bounds b) { bounds = b; } + ValidityCheck(vtkm::Bounds b) + : bounds(b) + { + } template VTKM_EXEC void operator()(const PosType& end_point, @@ -71,6 +75,7 @@ public: private: vtkm::Bounds bounds; }; +} namespace vtkm { @@ -310,10 +315,8 @@ inline VTKM_CONT vtkm::cont::DataSet Lagrangian::DoExecute( } else { - ValidityCheck check; - check.SetBounds(bounds); - vtkm::worklet::DispatcherMapField dispatcher(check); - dispatcher.Invoke(particle_positions, particle_stepstaken, BasisParticlesValidity); + ValidityCheck check(bounds); + this->Invoke(check, particle_positions, particle_stepstaken, BasisParticlesValidity); vtkm::cont::ArrayCopy(particle_positions, BasisParticles); } diff --git a/vtkm/filter/MarchingCubes.hxx b/vtkm/filter/MarchingCubes.hxx index a25ddb782..a40491137 100644 --- a/vtkm/filter/MarchingCubes.hxx +++ b/vtkm/filter/MarchingCubes.hxx @@ -14,8 +14,6 @@ #include #include -#include -#include #include namespace vtkm diff --git a/vtkm/filter/MeshQuality.hxx b/vtkm/filter/MeshQuality.hxx index 9f222fed9..663d1dab6 100644 --- a/vtkm/filter/MeshQuality.hxx +++ b/vtkm/filter/MeshQuality.hxx @@ -22,9 +22,8 @@ #include "vtkm/cont/ErrorFilterExecution.h" #include "vtkm/cont/Field.h" #include "vtkm/filter/internal/CreateResult.h" -#include "vtkm/worklet/DispatcherMapTopology.h" -#define DEBUG_PRINT +// #define DEBUG_PRINT namespace vtkm { @@ -101,24 +100,25 @@ inline VTKM_CONT vtkm::cont::DataSet MeshQuality::DoExecute( uniqueCellCounts, vtkm::Add()); - std::cout << "uniqueCellCounts: " << uniqueCellCounts.GetNumberOfValues() << "\n"; - const vtkm::Id numUniqueShapes = uniqueCellShapes.GetNumberOfValues(); auto uniqueCellShapesPortal = uniqueCellShapes.GetPortalConstControl(); auto numCellsPerShapePortal = uniqueCellCounts.GetPortalConstControl(); std::vector tempCounts(vtkm::NUMBER_OF_CELL_SHAPES); for (vtkm::Id i = 0; i < numUniqueShapes; i++) + { tempCounts[uniqueCellShapesPortal.Get(i)] = numCellsPerShapePortal.Get(i); + } IdHandle cellShapeCounts = vtkm::cont::make_ArrayHandle(tempCounts); - std::cout << "cellShapeCounts: " << cellShapeCounts.GetNumberOfValues() << "\n"; //Invoke the MeshQuality worklet vtkm::cont::ArrayHandle outArray; vtkm::cont::ArrayHandle cellMetrics = vtkm::cont::make_ArrayHandle(CellTypeMetrics); - std::cout << "cellMetrics: " << cellMetrics.GetNumberOfValues() << "\n"; - vtkm::worklet::DispatcherMapTopology dispatcher; - dispatcher.Invoke( - vtkm::filter::ApplyPolicy(cellSet, policy), cellShapeCounts, cellMetrics, points, outArray); + this->Invoke(QualityWorklet{}, + vtkm::filter::ApplyPolicy(cellSet, policy), + cellShapeCounts, + cellMetrics, + points, + outArray); //Build the output dataset: a separate field for each cell type that has a specified metric vtkm::cont::DataSet result; @@ -228,6 +228,7 @@ inline VTKM_CONT vtkm::cont::DataSet MeshQuality::DoExecute( shapeMeshQuality, vtkm::CopyFlag::On)); +#ifdef DEBUG_PRINT std::cout << "-----------------------------------------------------\n" << "Mesh quality of " << fieldName << ":\n" << "Number of cells: " << cellCount << "\n" @@ -236,14 +237,17 @@ inline VTKM_CONT vtkm::cont::DataSet MeshQuality::DoExecute( << "Minimum: " << statinfo.minimum << "\n" << "Maximum: " << statinfo.maximum << "\n" << "-----------------------------------------------------\n"; +#endif } +#ifdef DEBUG_PRINT auto metricValsPortal = outArray.GetPortalConstControl(); std::cout << "-----------------------------------------------------\n" << "Metric values - all cells:\n"; for (vtkm::Id v = 0; v < outArray.GetNumberOfValues(); v++) std::cout << metricValsPortal.Get(v) << "\n"; std::cout << "-----------------------------------------------------\n"; +#endif //Append the metric values of all cells into the output //dataset as a new field diff --git a/vtkm/filter/OscillatorSource.hxx b/vtkm/filter/OscillatorSource.hxx index 9e54de9f9..8cf7efccb 100644 --- a/vtkm/filter/OscillatorSource.hxx +++ b/vtkm/filter/OscillatorSource.hxx @@ -73,11 +73,9 @@ inline VTKM_CONT vtkm::cont::DataSet OscillatorSource::DoExecute( const vtkm::filter::PolicyBase&) { vtkm::cont::ArrayHandle outArray; - vtkm::worklet::DispatcherMapField dispatcher(this->Worklet); - //todo, we need to use the policy to determine the valid conversions //that the dispatcher should do - dispatcher.Invoke(field, outArray); + this->Invoke(this->Worklet, field, outArray); return internal::CreateResult(inDataSet, outArray, diff --git a/vtkm/filter/PointAverage.hxx b/vtkm/filter/PointAverage.hxx index 1b0fb9dfa..f5533e5f9 100644 --- a/vtkm/filter/PointAverage.hxx +++ b/vtkm/filter/PointAverage.hxx @@ -11,7 +11,6 @@ #include #include #include -#include namespace vtkm { @@ -43,10 +42,7 @@ inline VTKM_CONT vtkm::cont::DataSet PointAverage::DoExecute( //todo: we need to ask the policy what storage type we should be using //If the input is implicit, we should know what to fall back to vtkm::cont::ArrayHandle outArray; - - vtkm::worklet::DispatcherMapTopology dispatcher(this->Worklet); - - dispatcher.Invoke(vtkm::filter::ApplyPolicy(cellSet, policy), inField, outArray); + this->Invoke(this->Worklet, vtkm::filter::ApplyPolicy(cellSet, policy), inField, outArray); std::string outputName = this->GetOutputFieldName(); if (outputName.empty()) diff --git a/vtkm/filter/PointElevation.hxx b/vtkm/filter/PointElevation.hxx index 3cef5e032..20d6aee12 100644 --- a/vtkm/filter/PointElevation.hxx +++ b/vtkm/filter/PointElevation.hxx @@ -9,7 +9,6 @@ //============================================================================ #include -#include namespace vtkm { @@ -52,11 +51,10 @@ inline VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute( vtkm::filter::PolicyBase) { vtkm::cont::ArrayHandle outArray; - vtkm::worklet::DispatcherMapField dispatcher(this->Worklet); //todo, we need to use the policy to determine the valid conversions //that the dispatcher should do - dispatcher.Invoke(field, outArray); + this->Invoke(this->Worklet, field, outArray); return internal::CreateResult(inDataSet, outArray, diff --git a/vtkm/filter/PointTransform.hxx b/vtkm/filter/PointTransform.hxx index 38ca72d92..9b30be9ba 100644 --- a/vtkm/filter/PointTransform.hxx +++ b/vtkm/filter/PointTransform.hxx @@ -9,7 +9,6 @@ //============================================================================ #include -#include namespace vtkm { @@ -116,9 +115,7 @@ inline VTKM_CONT vtkm::cont::DataSet PointTransform::DoExecute( vtkm::filter::PolicyBase) { vtkm::cont::ArrayHandle outArray; - vtkm::worklet::DispatcherMapField> dispatcher(this->Worklet); - - dispatcher.Invoke(field, outArray); + this->Invoke(this->Worklet, field, outArray); return internal::CreateResult(inDataSet, outArray, diff --git a/vtkm/filter/SplitSharpEdges.hxx b/vtkm/filter/SplitSharpEdges.hxx index d93152038..57dd5117e 100644 --- a/vtkm/filter/SplitSharpEdges.hxx +++ b/vtkm/filter/SplitSharpEdges.hxx @@ -13,8 +13,6 @@ #include #include -#include - namespace vtkm { namespace filter diff --git a/vtkm/filter/Tetrahedralize.hxx b/vtkm/filter/Tetrahedralize.hxx index fec98ab8a..b4543b656 100644 --- a/vtkm/filter/Tetrahedralize.hxx +++ b/vtkm/filter/Tetrahedralize.hxx @@ -8,27 +8,16 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include - namespace { - -class DeduceCellSet +struct DeduceCellSet { - mutable vtkm::worklet::Tetrahedralize Worklet; - vtkm::cont::CellSetSingleType<>& OutCellSet; - -public: - DeduceCellSet(vtkm::worklet::Tetrahedralize worklet, vtkm::cont::CellSetSingleType<>& outCellSet) - : Worklet(worklet) - , OutCellSet(outCellSet) - { - } - template - void operator()(const CellSetType& cellset) const + void operator()(const CellSetType& cellset, + vtkm::worklet::Tetrahedralize& worklet, + vtkm::cont::CellSetSingleType<>& outCellSet) const { - this->OutCellSet = Worklet.Run(cellset); + outCellSet = worklet.Run(cellset); } }; } @@ -54,9 +43,8 @@ inline VTKM_CONT vtkm::cont::DataSet Tetrahedralize::DoExecute( const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(this->GetActiveCellSetIndex()); vtkm::cont::CellSetSingleType<> outCellSet; - DeduceCellSet tetrahedralize(this->Worklet, outCellSet); - - vtkm::cont::CastAndCall(vtkm::filter::ApplyPolicy(cells, policy), tetrahedralize); + vtkm::cont::CastAndCall( + vtkm::filter::ApplyPolicy(cells, policy), DeduceCellSet{}, this->Worklet, outCellSet); // create the output dataset vtkm::cont::DataSet output; diff --git a/vtkm/filter/Threshold.hxx b/vtkm/filter/Threshold.hxx index febc617b2..de9883c43 100644 --- a/vtkm/filter/Threshold.hxx +++ b/vtkm/filter/Threshold.hxx @@ -13,8 +13,6 @@ #include #include -#include - namespace { diff --git a/vtkm/filter/VectorMagnitude.hxx b/vtkm/filter/VectorMagnitude.hxx index fdae3ebb5..6da19ca80 100644 --- a/vtkm/filter/VectorMagnitude.hxx +++ b/vtkm/filter/VectorMagnitude.hxx @@ -9,7 +9,6 @@ //============================================================================ #include -#include #include @@ -37,9 +36,7 @@ inline VTKM_CONT vtkm::cont::DataSet VectorMagnitude::DoExecute( using ReturnType = typename ::vtkm::detail::FloatingPointReturnType::Type; vtkm::cont::ArrayHandle outArray; - vtkm::worklet::DispatcherMapField dispatcher(this->Worklet); - - dispatcher.Invoke(field, outArray); + this->Invoke(this->Worklet, field, outArray); return internal::CreateResult(inDataSet, outArray, diff --git a/vtkm/filter/WarpScalar.hxx b/vtkm/filter/WarpScalar.hxx index 83672de25..3842b4d0d 100644 --- a/vtkm/filter/WarpScalar.hxx +++ b/vtkm/filter/WarpScalar.hxx @@ -9,9 +9,6 @@ //============================================================================ #include -#include - -#include namespace vtkm { diff --git a/vtkm/filter/WarpVector.hxx b/vtkm/filter/WarpVector.hxx index 620f87240..be0ec6232 100644 --- a/vtkm/filter/WarpVector.hxx +++ b/vtkm/filter/WarpVector.hxx @@ -9,9 +9,6 @@ //============================================================================ #include -#include - -#include namespace vtkm { diff --git a/vtkm/filter/ZFPCompressor1D.hxx b/vtkm/filter/ZFPCompressor1D.hxx index 524e2c88e..81983ea4b 100644 --- a/vtkm/filter/ZFPCompressor1D.hxx +++ b/vtkm/filter/ZFPCompressor1D.hxx @@ -8,14 +8,10 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include -#include #include #include #include -#include - namespace vtkm { namespace filter @@ -52,11 +48,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPCompressor1D::DoExecute( const vtkm::filter::FieldMetadata&, const vtkm::filter::PolicyBase&) { - // if (fieldMeta.IsPointField() == false) - // { - // throw vtkm::cont::ErrorFilterExecution("Point field expected."); - // } - // Check the fields of the dataset to see what kinds of fields are present so // we can free the mapping arrays that won't be needed. A point field must // exist for this algorithm, so just check cells. diff --git a/vtkm/filter/ZFPCompressor2D.hxx b/vtkm/filter/ZFPCompressor2D.hxx index 118f0e031..3cc0818f6 100644 --- a/vtkm/filter/ZFPCompressor2D.hxx +++ b/vtkm/filter/ZFPCompressor2D.hxx @@ -8,14 +8,10 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include -#include #include #include #include -#include - namespace vtkm { namespace filter @@ -51,11 +47,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPCompressor2D::DoExecute( const vtkm::filter::FieldMetadata&, const vtkm::filter::PolicyBase&) { - // if (fieldMeta.IsPointField() == false) - // { - // throw vtkm::cont::ErrorFilterExecution("Point field expected."); - // } - // Check the fields of the dataset to see what kinds of fields are present so // we can free the mapping arrays that won't be needed. A point field must // exist for this algorithm, so just check cells. diff --git a/vtkm/filter/ZFPCompressor3D.hxx b/vtkm/filter/ZFPCompressor3D.hxx index f632aab95..3d8f54fff 100644 --- a/vtkm/filter/ZFPCompressor3D.hxx +++ b/vtkm/filter/ZFPCompressor3D.hxx @@ -8,14 +8,10 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include -#include #include #include #include -#include - namespace vtkm { namespace filter @@ -51,11 +47,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPCompressor3D::DoExecute( const vtkm::filter::FieldMetadata&, const vtkm::filter::PolicyBase&) { - // if (fieldMeta.IsPointField() == false) - // { - // throw vtkm::cont::ErrorFilterExecution("Point field expected."); - // } - // Check the fields of the dataset to see what kinds of fields are present so // we can free the mapping arrays that won't be needed. A point field must // exist for this algorithm, so just check cells. diff --git a/vtkm/filter/ZFPDecompressor1D.hxx b/vtkm/filter/ZFPDecompressor1D.hxx index 1f10e593a..808bc75dd 100644 --- a/vtkm/filter/ZFPDecompressor1D.hxx +++ b/vtkm/filter/ZFPDecompressor1D.hxx @@ -8,14 +8,10 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include -#include #include #include #include -#include - namespace vtkm { namespace filter @@ -48,11 +44,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPDecompressor1D::DoExecute( const vtkm::filter::FieldMetadata&, const vtkm::filter::PolicyBase&) { - // if (fieldMeta.IsPointField() == false) - // { - // throw vtkm::cont::ErrorFilterExecution("Point field expected."); - // } - // Check the fields of the dataset to see what kinds of fields are present so // we can free the mapping arrays that won't be needed. A point field must // exist for this algorithm, so just check cells. diff --git a/vtkm/filter/ZFPDecompressor2D.hxx b/vtkm/filter/ZFPDecompressor2D.hxx index 8d934c039..855f4298f 100644 --- a/vtkm/filter/ZFPDecompressor2D.hxx +++ b/vtkm/filter/ZFPDecompressor2D.hxx @@ -8,14 +8,10 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include -#include #include #include #include -#include - namespace vtkm { namespace filter @@ -49,11 +45,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPDecompressor2D::DoExecute( const vtkm::filter::FieldMetadata&, const vtkm::filter::PolicyBase&) { - // if (fieldMeta.IsPointField() == false) - // { - // throw vtkm::cont::ErrorFilterExecution("Point field expected."); - // } - // Check the fields of the dataset to see what kinds of fields are present so // we can free the mapping arrays that won't be needed. A point field must // exist for this algorithm, so just check cells. diff --git a/vtkm/filter/ZFPDecompressor3D.hxx b/vtkm/filter/ZFPDecompressor3D.hxx index 363889b7c..fdc108b42 100644 --- a/vtkm/filter/ZFPDecompressor3D.hxx +++ b/vtkm/filter/ZFPDecompressor3D.hxx @@ -8,14 +8,10 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include -#include #include #include #include -#include - namespace vtkm { namespace filter @@ -48,11 +44,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPDecompressor3D::DoExecute( const vtkm::filter::FieldMetadata&, const vtkm::filter::PolicyBase&) { - // if (fieldMeta.IsPointField() == false) - // { - // throw vtkm::cont::ErrorFilterExecution("Point field expected."); - // } - // Check the fields of the dataset to see what kinds of fields are present so // we can free the mapping arrays that won't be needed. A point field must // exist for this algorithm, so just check cells. diff --git a/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx b/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx index 88d9421dd..be6d1e8b8 100644 --- a/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx +++ b/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx @@ -15,7 +15,6 @@ #include #include -#include #include namespace