Merge topic 'dynamic-threshold-call-to-worklet'

bd742fc6 Allow Threshold::Run to work on dynamic cell sets

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Sujin Philip <sujin.philip@kitware.com>
Merge-request: !925
This commit is contained in:
Kenneth Moreland 2017-09-19 14:53:36 +00:00 committed by Kitware Robot
commit 2fa3a868bd
3 changed files with 66 additions and 44 deletions

@ -59,7 +59,7 @@ public:
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
DeviceAdapter tag);
//Map a new field onto the resulting dataset after running the filter
//this call is only valid
@ -68,7 +68,7 @@ public:
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
DeviceAdapter tag);
private:
double LowerValue;

@ -49,36 +49,6 @@ private:
vtkm::Float64 Upper;
};
template <typename ValueType, typename StorageTag, typename DeviceTag>
struct CallWorklet
{
vtkm::cont::DynamicCellSet& Output;
vtkm::worklet::Threshold& Worklet;
const vtkm::cont::ArrayHandle<ValueType, StorageTag>& Field;
const vtkm::cont::Field::AssociationEnum FieldType;
const ThresholdRange& Predicate;
CallWorklet(vtkm::cont::DynamicCellSet& output,
vtkm::worklet::Threshold& worklet,
const vtkm::cont::ArrayHandle<ValueType, StorageTag>& field,
const vtkm::cont::Field::AssociationEnum fieldType,
const ThresholdRange& predicate)
: Output(output)
, Worklet(worklet)
, Field(field)
, FieldType(fieldType)
, Predicate(predicate)
{
}
template <typename CellSetType>
void operator()(const CellSetType& cellSet) const
{
this->Output =
this->Worklet.Run(cellSet, this->Field, this->FieldType, this->Predicate, DeviceTag());
}
};
} // end anon namespace
namespace vtkm
@ -101,22 +71,21 @@ inline VTKM_CONT vtkm::filter::Result Threshold::DoExecute(
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter&)
DeviceAdapter)
{
using Worker = CallWorklet<T, StorageType, DeviceAdapter>;
//get the cells and coordinates of the dataset
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(this->GetActiveCellSetIndex());
vtkm::cont::DynamicCellSet cellOut;
ThresholdRange predicate(this->GetLowerThreshold(), this->GetUpperThreshold());
Worker worker(cellOut, this->Worklet, field, fieldMeta.GetAssociation(), predicate);
vtkm::filter::ApplyPolicy(cells, policy).CastAndCall(worker);
vtkm::cont::DynamicCellSet cellOut = this->Worklet.Run(vtkm::filter::ApplyPolicy(cells, policy),
field,
fieldMeta.GetAssociation(),
predicate,
DeviceAdapter());
vtkm::cont::DataSet output;
output.AddCellSet(cellOut);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
output.AddCellSet(worker.Output);
return output;
}
@ -127,7 +96,7 @@ inline VTKM_CONT bool Threshold::DoMapField(vtkm::filter::Result& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter& device)
DeviceAdapter device)
{
if (fieldMeta.IsPointField())
{

@ -29,6 +29,7 @@
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/DynamicArrayHandle.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/Field.h>
namespace vtkm
@ -128,10 +129,9 @@ public:
const vtkm::cont::ArrayHandle<ValueType, StorageType>& field,
const vtkm::cont::Field::AssociationEnum fieldType,
const UnaryPredicate& predicate,
DeviceAdapter device)
DeviceAdapter)
{
(void)device;
typedef vtkm::cont::CellSetPermutation<CellSetType> OutputType;
using OutputType = vtkm::cont::CellSetPermutation<CellSetType>;
vtkm::cont::ArrayHandle<bool> passFlags;
switch (fieldType)
@ -167,6 +167,59 @@ public:
return OutputType(this->ValidCellIds, cellSet, cellSet.GetName());
}
template <typename CellSetList, typename FieldArrayType, typename UnaryPredicate, typename Device>
struct CallWorklet
{
vtkm::cont::DynamicCellSet& Output;
vtkm::worklet::Threshold& Worklet;
const FieldArrayType& Field;
const vtkm::cont::Field::AssociationEnum FieldType;
const UnaryPredicate& Predicate;
CallWorklet(vtkm::cont::DynamicCellSet& output,
vtkm::worklet::Threshold& worklet,
const FieldArrayType& field,
const vtkm::cont::Field::AssociationEnum fieldType,
const UnaryPredicate& predicate)
: Output(output)
, Worklet(worklet)
, Field(field)
, FieldType(fieldType)
, Predicate(predicate)
{
}
template <typename CellSetType>
void operator()(const CellSetType& cellSet) const
{
this->Output =
this->Worklet.Run(cellSet, this->Field, this->FieldType, this->Predicate, Device());
}
};
template <typename CellSetList,
typename ValueType,
typename StorageType,
typename UnaryPredicate,
typename Device>
vtkm::cont::DynamicCellSet Run(const vtkm::cont::DynamicCellSetBase<CellSetList>& cellSet,
const vtkm::cont::ArrayHandle<ValueType, StorageType>& field,
const vtkm::cont::Field::AssociationEnum fieldType,
const UnaryPredicate& predicate,
Device)
{
using Worker = CallWorklet<CellSetList,
vtkm::cont::ArrayHandle<ValueType, StorageType>,
UnaryPredicate,
Device>;
vtkm::cont::DynamicCellSet output;
Worker worker(output, *this, field, fieldType, predicate);
cellSet.CastAndCall(worker);
return output;
}
template <typename ValueType, typename StorageTag, typename DeviceTag>
vtkm::cont::ArrayHandle<ValueType> ProcessCellField(
const vtkm::cont::ArrayHandle<ValueType, StorageTag> in,