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.
This commit is contained in:
Robert Maynard 2019-08-07 12:54:47 -04:00
parent db6a7c1650
commit 3a7d3cb5ff
43 changed files with 158 additions and 204 deletions

@ -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 <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
vtkm::cont::ArrayHandle<vtkm::Float64> outArray;
vtkm::worklet::DispatcherMapField<vtkm::worklet::PointElevation> 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 <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
vtkm::cont::ArrayHandle<vtkm::Float64> outArray;
this->Invoke(this->Worklet, field, outArray);
...
}
```

@ -27,7 +27,6 @@
#include <vtkm/interop/TransferToOpenGL.h>
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/DispatcherPointNeighborhood.h>
#include <vtkm/worklet/WorkletPointNeighborhood.h>
#include <vtkm/cont/TryExecute.h>
@ -111,9 +110,6 @@ public:
vtkm::filter::PolicyBase<Policy> policy)
{
using DispatcherType = vtkm::worklet::DispatcherPointNeighborhood<UpdateLifeState>;
vtkm::cont::ArrayHandle<vtkm::UInt8> state;
vtkm::cont::ArrayHandle<vtkm::UInt8> prevstate;
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> 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;

@ -8,7 +8,6 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/FieldHistogram.h>
#include <vtkm/cont/Algorithm.h>

@ -13,8 +13,8 @@
#include <vtkm/cont/DataSetBuilderUniform.h>
#include <vtkm/cont/DataSetFieldAdd.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
@ -43,8 +43,8 @@ vtkm::cont::DataSet make_test3DImageData(vtkm::Id3 dims)
vtkm::cont::DataSet ds = Builder::Create(dims);
vtkm::cont::ArrayHandle<vtkm::Vec3f> field;
vtkm::worklet::DispatcherMapField<WaveField> dispatcher;
dispatcher.Invoke(ds.GetCoordinateSystem(), field);
vtkm::cont::Invoker invoke;
invoke(WaveField{}, ds.GetCoordinateSystem(), field);
FieldAdd::AddPointField(ds, "vec_field", field);
return ds;

@ -12,7 +12,6 @@
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/io/writer/VTKDataSetWriter.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/Tube.h>
#include <vtkm/cont/ColorTable.h>

@ -11,7 +11,6 @@
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
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<T> outArray;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> 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 == "")

@ -11,7 +11,6 @@
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm
{
@ -39,8 +38,10 @@ inline VTKM_CONT vtkm::cont::DataSet CellMeasures<IntegrationType>::DoExecute(
const auto& cellset = input.GetCellSet(this->GetActiveCellSetIndex());
vtkm::cont::ArrayHandle<T> outArray;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellMeasure<IntegrationType>> dispatcher;
dispatcher.Invoke(vtkm::filter::ApplyPolicy(cellset, policy), points, outArray);
this->Invoke(vtkm::worklet::CellMeasure<IntegrationType>{},
vtkm::filter::ApplyPolicy(cellset, policy),
points,
outArray);
vtkm::cont::DataSet result;
std::string outputName = this->GetCellMeasureName();

@ -11,9 +11,7 @@
#ifndef vtkm_m_filter_CellSetConnectivity_h
#define vtkm_m_filter_CellSetConnectivity_h
#include <vtkm/filter/FilterCell.h>
#include <vtkm/worklet/connectivities/CellSetConnectivity.h>
namespace vtkm
{

@ -11,9 +11,8 @@
#ifndef vtkm_m_filter_CellSetConnectivity_hxx
#define vtkm_m_filter_CellSetConnectivity_hxx
#include <vtkm/filter/CellSetConnectivity.h>
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/connectivities/CellSetConnectivity.h>
namespace vtkm
{

@ -13,7 +13,6 @@
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm
{

@ -12,8 +12,6 @@
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm
{
namespace filter

@ -9,7 +9,6 @@
//============================================================================
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapField.h>
namespace vtkm
{

@ -20,18 +20,23 @@ namespace filter
namespace detail
{
template <typename T>
struct CrossProductFunctor
{
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> OutArray;
template <typename PrimaryFieldType, typename SecondaryFieldType>
void operator()(const SecondaryFieldType& secondaryField, const PrimaryFieldType& primaryField)
vtkm::cont::Invoker& Invoke;
CrossProductFunctor(vtkm::cont::Invoker& invoke)
: Invoke(invoke)
{
vtkm::worklet::DispatcherMapField<vtkm::worklet::CrossProduct> dispatcher;
dispatcher.Invoke(primaryField,
vtkm::cont::make_ArrayHandleCast<vtkm::Vec<T, 3>>(secondaryField),
this->OutArray);
}
template <typename SecondaryFieldType, typename StorageType, typename T>
void operator()(const SecondaryFieldType& secondaryField,
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& primaryField,
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& output) const
{
this->Invoke(vtkm::worklet::CrossProduct{},
primaryField,
vtkm::cont::make_ArrayHandleCast<vtkm::Vec<T, 3>>(secondaryField),
output);
}
};
@ -56,13 +61,18 @@ inline VTKM_CONT vtkm::cont::DataSet CrossProduct::DoExecute(
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
detail::CrossProductFunctor<T> functor;
detail::CrossProductFunctor functor(this->Invoke);
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> 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());

@ -8,8 +8,6 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/cont/ArrayHandleCast.h>
#include <vtkm/filter/internal/CreateResult.h>
@ -21,18 +19,23 @@ namespace filter
namespace detail
{
template <typename T>
struct DotProductFunctor
{
vtkm::cont::ArrayHandle<T> OutArray;
template <typename PrimaryFieldType, typename SecondaryFieldType>
void operator()(const SecondaryFieldType& secondaryField, const PrimaryFieldType& primaryField)
vtkm::cont::Invoker& Invoke;
DotProductFunctor(vtkm::cont::Invoker& invoke)
: Invoke(invoke)
{
vtkm::worklet::DispatcherMapField<vtkm::worklet::DotProduct> dispatcher;
dispatcher.Invoke(primaryField,
vtkm::cont::make_ArrayHandleCast<vtkm::Vec<T, 3>>(secondaryField),
this->OutArray);
}
template <typename SecondaryFieldType, typename StorageType, typename T>
void operator()(const SecondaryFieldType& secondaryField,
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& primaryField,
vtkm::cont::ArrayHandle<T>& output) const
{
this->Invoke(vtkm::worklet::DotProduct{},
primaryField,
vtkm::cont::make_ArrayHandleCast<vtkm::Vec<T, 3>>(secondaryField),
output);
}
};
@ -57,13 +60,17 @@ inline VTKM_CONT vtkm::cont::DataSet DotProduct::DoExecute(
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
detail::DotProductFunctor<T> functor;
detail::DotProductFunctor functor(this->Invoke);
vtkm::cont::ArrayHandle<T> 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());

@ -8,7 +8,6 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/FieldEntropy.h>
#include <vtkm/filter/internal/CreateResult.h>

@ -13,8 +13,6 @@
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace
{

@ -8,8 +8,6 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/worklet/DispatcherMapField.h>
namespace vtkm
{
namespace filter

@ -13,6 +13,7 @@
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/Field.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/cont/MultiBlock.h>
#include <vtkm/filter/FieldSelection.h>
@ -250,6 +251,14 @@ public:
vtkm::cont::DataSet& output,
const vtkm::filter::PolicyBase<DerivedPolicy>& 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;
};

@ -234,7 +234,8 @@ void CallPostExecute(Derived* self,
//----------------------------------------------------------------------------
template <typename Derived>
inline VTKM_CONT Filter<Derived>::Filter()
: FieldsToPass(vtkm::filter::FieldSelection::MODE_ALL)
: Invoke()
, FieldsToPass(vtkm::filter::FieldSelection::MODE_ALL)
{
}

@ -19,7 +19,6 @@
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
@ -155,8 +154,7 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellClassify::DoExecute(const vtkm::co
vtkm::cont::CellSetStructured<1> cellset1d = cellset.Cast<vtkm::cont::CellSetStructured<1>>();
SetStructuredGhostCells1D structuredGhosts1D(cellset1d.GetCellDimensions());
vtkm::worklet::DispatcherMapField<SetStructuredGhostCells1D> dispatcher(structuredGhosts1D);
dispatcher.Invoke(indexArray, ghosts);
this->Invoke(structuredGhosts1D, indexArray, ghosts);
}
else if (cellset.template IsType<vtkm::cont::CellSetStructured<2>>())
{
@ -165,8 +163,7 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellClassify::DoExecute(const vtkm::co
vtkm::cont::CellSetStructured<2> cellset2d = cellset.Cast<vtkm::cont::CellSetStructured<2>>();
SetStructuredGhostCells2D structuredGhosts2D(cellset2d.GetCellDimensions());
vtkm::worklet::DispatcherMapField<SetStructuredGhostCells2D> dispatcher(structuredGhosts2D);
dispatcher.Invoke(indexArray, ghosts);
this->Invoke(structuredGhosts2D, indexArray, ghosts);
}
else if (cellset.template IsType<vtkm::cont::CellSetStructured<3>>())
{
@ -175,11 +172,12 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellClassify::DoExecute(const vtkm::co
vtkm::cont::CellSetStructured<3> cellset3d = cellset.Cast<vtkm::cont::CellSetStructured<3>>();
SetStructuredGhostCells3D structuredGhosts3D(cellset3d.GetCellDimensions());
vtkm::worklet::DispatcherMapField<SetStructuredGhostCells3D> 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());

@ -16,7 +16,6 @@
#include <vtkm/RangeId3.h>
#include <vtkm/filter/ExtractStructured.h>
#include <vtkm/worklet/CellDeepCopy.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace
{
@ -204,6 +203,7 @@ private:
template <int DIMS, typename T, typename StorageType>
bool CanStrip(const vtkm::cont::ArrayHandle<T, StorageType>& ghostField,
const vtkm::cont::Invoker& invoke,
bool removeAllGhost,
vtkm::UInt8 removeType,
vtkm::RangeId3& range,
@ -219,9 +219,7 @@ bool CanStrip(const vtkm::cont::ArrayHandle<T, StorageType>& ghostField,
minmax.GetPortalControl().Set(4, std::numeric_limits<vtkm::Id>::min());
minmax.GetPortalControl().Set(5, std::numeric_limits<vtkm::Id>::min());
vtkm::worklet::DispatcherMapField<RealMinMax<3>>(
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<T, StorageType>& ghostField,
vtkm::cont::ArrayHandle<vtkm::UInt8> validFlags;
validFlags.Allocate(size);
vtkm::worklet::DispatcherMapField<Validate<DIMS>>(
Validate<DIMS>(cellDims, removeAllGhost, removeType, range))
.Invoke(ghostField, validFlags);
invoke(Validate<DIMS>(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<T, StorageType>& ghostField,
template <typename T, typename StorageType>
bool CanDoStructuredStrip(const vtkm::cont::DynamicCellSet& cells,
const vtkm::cont::ArrayHandle<T, StorageType>& 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<vtkm::cont::CellSetStructured<3>>();
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<T, StorageType>(
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);

@ -8,7 +8,6 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/FieldHistogram.h>
#include <vtkm/cont/Algorithm.h>

@ -13,7 +13,6 @@
#include <vtkm/filter/ImageConnectivity.h>
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapField.h>
namespace vtkm
{

@ -18,7 +18,6 @@
#include <vtkm/cont/DeviceAdapter.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/io/writer/VTKDataSetWriter.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/ParticleAdvection.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/particleadvection/GridEvaluators.h>
@ -35,6 +34,8 @@ static vtkm::cont::ArrayHandle<vtkm::Vec3f_64> BasisParticles;
static vtkm::cont::ArrayHandle<vtkm::Vec3f_64> BasisParticlesOriginal;
static vtkm::cont::ArrayHandle<vtkm::Id> 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 <typename PosType, typename StepType, typename ValidityType>
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<ValidityCheck> 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);
}

@ -14,8 +14,6 @@
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/ScatterCounting.h>
#include <vtkm/worklet/SurfaceNormals.h>
namespace vtkm

@ -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<vtkm::Id> 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<T> outArray;
vtkm::cont::ArrayHandle<CellMetric> cellMetrics = vtkm::cont::make_ArrayHandle(CellTypeMetrics);
std::cout << "cellMetrics: " << cellMetrics.GetNumberOfValues() << "\n";
vtkm::worklet::DispatcherMapTopology<QualityWorklet> 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

@ -73,11 +73,9 @@ inline VTKM_CONT vtkm::cont::DataSet OscillatorSource::DoExecute(
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
vtkm::cont::ArrayHandle<vtkm::Float64> outArray;
vtkm::worklet::DispatcherMapField<vtkm::worklet::OscillatorSource> 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,

@ -11,7 +11,6 @@
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
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<T> outArray;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::PointAverage> 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())

@ -9,7 +9,6 @@
//============================================================================
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapField.h>
namespace vtkm
{
@ -52,11 +51,10 @@ inline VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute(
vtkm::filter::PolicyBase<DerivedPolicy>)
{
vtkm::cont::ArrayHandle<vtkm::Float64> outArray;
vtkm::worklet::DispatcherMapField<vtkm::worklet::PointElevation> 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,

@ -9,7 +9,6 @@
//============================================================================
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapField.h>
namespace vtkm
{
@ -116,9 +115,7 @@ inline VTKM_CONT vtkm::cont::DataSet PointTransform<S>::DoExecute(
vtkm::filter::PolicyBase<DerivedPolicy>)
{
vtkm::cont::ArrayHandle<T> outArray;
vtkm::worklet::DispatcherMapField<vtkm::worklet::PointTransform<S>> dispatcher(this->Worklet);
dispatcher.Invoke(field, outArray);
this->Invoke(this->Worklet, field, outArray);
return internal::CreateResult(inDataSet,
outArray,

@ -13,8 +13,6 @@
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm
{
namespace filter

@ -8,27 +8,16 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/worklet/DispatcherMapField.h>
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 <typename CellSetType>
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;

@ -13,8 +13,6 @@
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace
{

@ -9,7 +9,6 @@
//============================================================================
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/Math.h>
@ -37,9 +36,7 @@ inline VTKM_CONT vtkm::cont::DataSet VectorMagnitude::DoExecute(
using ReturnType = typename ::vtkm::detail::FloatingPointReturnType<T>::Type;
vtkm::cont::ArrayHandle<ReturnType> outArray;
vtkm::worklet::DispatcherMapField<vtkm::worklet::Magnitude> dispatcher(this->Worklet);
dispatcher.Invoke(field, outArray);
this->Invoke(this->Worklet, field, outArray);
return internal::CreateResult(inDataSet,
outArray,

@ -9,9 +9,6 @@
//============================================================================
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/filter/WarpScalar.h>
namespace vtkm
{

@ -9,9 +9,6 @@
//============================================================================
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/filter/WarpVector.h>
namespace vtkm
{

@ -8,14 +8,10 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm
{
namespace filter
@ -52,11 +48,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPCompressor1D::DoExecute(
const vtkm::filter::FieldMetadata&,
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
// 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.

@ -8,14 +8,10 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm
{
namespace filter
@ -51,11 +47,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPCompressor2D::DoExecute(
const vtkm::filter::FieldMetadata&,
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
// 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.

@ -8,14 +8,10 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm
{
namespace filter
@ -51,11 +47,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPCompressor3D::DoExecute(
const vtkm::filter::FieldMetadata&,
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
// 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.

@ -8,14 +8,10 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm
{
namespace filter
@ -48,11 +44,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPDecompressor1D::DoExecute(
const vtkm::filter::FieldMetadata&,
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
// 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.

@ -8,14 +8,10 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm
{
namespace filter
@ -49,11 +45,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPDecompressor2D::DoExecute(
const vtkm::filter::FieldMetadata&,
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
// 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.

@ -8,14 +8,10 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm
{
namespace filter
@ -48,11 +44,6 @@ inline VTKM_CONT vtkm::cont::DataSet ZFPDecompressor3D::DoExecute(
const vtkm::filter::FieldMetadata&,
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
// 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.

@ -15,7 +15,6 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WaveletGenerator.h>
namespace