mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 02:25:42 +00:00
Merge topic 'simplify_threshold_implementation'
a92ad22c7 Improve Threshold runtime and compile performance Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Allison Vacanti <allison.vacanti@kitware.com> Merge-request: !1909
This commit is contained in:
commit
462aacebb3
@ -31,9 +31,19 @@ public:
|
||||
template <typename T>
|
||||
VTKM_EXEC bool operator()(const T& value) const
|
||||
{
|
||||
|
||||
return value >= static_cast<T>(this->Lower) && value <= static_cast<T>(this->Upper);
|
||||
}
|
||||
|
||||
//Needed to work with ArrayHandleVirtual
|
||||
template <typename PortalType>
|
||||
VTKM_EXEC bool operator()(
|
||||
const vtkm::internal::ArrayPortalValueReference<PortalType>& value) const
|
||||
{
|
||||
using T = typename PortalType::ValueType;
|
||||
return value.Get() >= static_cast<T>(this->Lower) && value.Get() <= static_cast<T>(this->Upper);
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Float64 Lower;
|
||||
vtkm::Float64 Upper;
|
||||
|
@ -29,10 +29,6 @@ namespace worklet
|
||||
class ExtractGeometry
|
||||
{
|
||||
public:
|
||||
struct BoolType : vtkm::ListTagBase<bool>
|
||||
{
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// Worklet to identify cells within volume of interest
|
||||
class ExtractCellsByVOI : public vtkm::worklet::WorkletVisitCellsWithPoints
|
||||
|
@ -28,10 +28,6 @@ namespace worklet
|
||||
class ExtractPoints
|
||||
{
|
||||
public:
|
||||
struct BoolType : vtkm::ListTagBase<bool>
|
||||
{
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// Worklet to identify points within volume of interest
|
||||
class ExtractPointsByVOI : public vtkm::worklet::WorkletVisitPointsWithCells
|
||||
|
@ -29,10 +29,6 @@ namespace worklet
|
||||
class Mask
|
||||
{
|
||||
public:
|
||||
struct BoolType : vtkm::ListTagBase<bool>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename CellSetType>
|
||||
vtkm::cont::CellSetPermutation<CellSetType> Run(const CellSetType& cellSet, const vtkm::Id stride)
|
||||
{
|
||||
|
@ -11,8 +11,8 @@
|
||||
#define vtkm_m_worklet_Threshold_h
|
||||
|
||||
#include <vtkm/worklet/CellDeepCopy.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/DispatcherMapTopology.h>
|
||||
#include <vtkm/worklet/WorkletMapTopology.h>
|
||||
|
||||
#include <vtkm/cont/Algorithm.h>
|
||||
#include <vtkm/cont/ArrayCopy.h>
|
||||
@ -37,10 +37,6 @@ public:
|
||||
Cell
|
||||
};
|
||||
|
||||
struct BoolType : vtkm::ListTagBase<bool>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename UnaryPredicate>
|
||||
class ThresholdByPointField : public vtkm::worklet::WorkletVisitCellsWithPoints
|
||||
{
|
||||
@ -76,36 +72,20 @@ public:
|
||||
UnaryPredicate Predicate;
|
||||
};
|
||||
|
||||
template <typename UnaryPredicate>
|
||||
class ThresholdByCellField : public vtkm::worklet::WorkletVisitCellsWithPoints
|
||||
struct ThresholdCopy : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
using ControlSignature = void(CellSetIn cellset, FieldInCell scalars, FieldOut passFlags);
|
||||
using ControlSignature = void(FieldIn, FieldOut, WholeArrayIn);
|
||||
|
||||
using ExecutionSignature = _3(_2);
|
||||
|
||||
VTKM_CONT
|
||||
ThresholdByCellField()
|
||||
: Predicate()
|
||||
template <typename ScalarType, typename WholeFieldIn>
|
||||
VTKM_EXEC void operator()(vtkm::Id& index,
|
||||
ScalarType& output,
|
||||
const WholeFieldIn& inputField) const
|
||||
{
|
||||
output = inputField.Get(index);
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
explicit ThresholdByCellField(const UnaryPredicate& predicate)
|
||||
: Predicate(predicate)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ScalarType>
|
||||
VTKM_EXEC bool operator()(const ScalarType& scalar) const
|
||||
{
|
||||
return this->Predicate(scalar);
|
||||
}
|
||||
|
||||
private:
|
||||
UnaryPredicate Predicate;
|
||||
};
|
||||
|
||||
|
||||
template <typename CellSetType, typename ValueType, typename StorageType, typename UnaryPredicate>
|
||||
vtkm::cont::CellSetPermutation<CellSetType> Run(
|
||||
const CellSetType& cellSet,
|
||||
@ -115,25 +95,29 @@ public:
|
||||
{
|
||||
using OutputType = vtkm::cont::CellSetPermutation<CellSetType>;
|
||||
|
||||
vtkm::cont::ArrayHandle<bool> passFlags;
|
||||
switch (fieldType)
|
||||
{
|
||||
case vtkm::cont::Field::Association::POINTS:
|
||||
{
|
||||
using ThresholdWorklet = ThresholdByPointField<UnaryPredicate>;
|
||||
vtkm::cont::ArrayHandle<bool> passFlags;
|
||||
|
||||
ThresholdWorklet worklet(predicate);
|
||||
DispatcherMapTopology<ThresholdWorklet> dispatcher(worklet);
|
||||
dispatcher.Invoke(cellSet, field, passFlags);
|
||||
|
||||
vtkm::cont::Algorithm::CopyIf(vtkm::cont::ArrayHandleIndex(passFlags.GetNumberOfValues()),
|
||||
passFlags,
|
||||
this->ValidCellIds);
|
||||
|
||||
break;
|
||||
}
|
||||
case vtkm::cont::Field::Association::CELL_SET:
|
||||
{
|
||||
using ThresholdWorklet = ThresholdByCellField<UnaryPredicate>;
|
||||
|
||||
ThresholdWorklet worklet(predicate);
|
||||
DispatcherMapTopology<ThresholdWorklet> dispatcher(worklet);
|
||||
dispatcher.Invoke(cellSet, field, passFlags);
|
||||
vtkm::cont::Algorithm::CopyIf(vtkm::cont::ArrayHandleIndex(field.GetNumberOfValues()),
|
||||
field,
|
||||
this->ValidCellIds,
|
||||
predicate);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -141,9 +125,6 @@ public:
|
||||
throw vtkm::cont::ErrorBadValue("Expecting point or cell field.");
|
||||
}
|
||||
|
||||
vtkm::cont::Algorithm::CopyIf(
|
||||
vtkm::cont::ArrayHandleIndex(passFlags.GetNumberOfValues()), passFlags, this->ValidCellIds);
|
||||
|
||||
return OutputType(this->ValidCellIds, cellSet);
|
||||
}
|
||||
|
||||
@ -195,14 +176,11 @@ public:
|
||||
|
||||
template <typename ValueType, typename StorageTag>
|
||||
vtkm::cont::ArrayHandle<ValueType> ProcessCellField(
|
||||
const vtkm::cont::ArrayHandle<ValueType, StorageTag> in) const
|
||||
const vtkm::cont::ArrayHandle<ValueType, StorageTag>& in) const
|
||||
{
|
||||
// Use a temporary permutation array to simplify the mapping:
|
||||
auto tmp = vtkm::cont::make_ArrayHandlePermutation(this->ValidCellIds, in);
|
||||
|
||||
// Copy into an array with default storage:
|
||||
vtkm::cont::ArrayHandle<ValueType> result;
|
||||
vtkm::cont::ArrayCopy(tmp, result);
|
||||
DispatcherMapField<ThresholdCopy> dispatcher;
|
||||
dispatcher.Invoke(this->ValidCellIds, result, in);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -25,10 +25,6 @@ namespace worklet
|
||||
class ThresholdPoints
|
||||
{
|
||||
public:
|
||||
struct BoolType : vtkm::ListTagBase<bool>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename UnaryPredicate>
|
||||
class ThresholdPointField : public vtkm::worklet::WorkletVisitPointsWithCells
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user