2015-10-12 18:37:59 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2015-10-12 18:37:59 +00:00
|
|
|
// Copyright 2015 UT-Battelle, LLC.
|
|
|
|
// Copyright 2015 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2015-10-12 18:37:59 +00:00
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtkm_m_worklet_Threshold_h
|
|
|
|
#define vtkm_m_worklet_Threshold_h
|
|
|
|
|
|
|
|
#include <vtkm/worklet/DispatcherMapTopology.h>
|
|
|
|
#include <vtkm/worklet/WorkletMapTopology.h>
|
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
#include <vtkm/cont/Algorithm.h>
|
|
|
|
#include <vtkm/cont/ArrayCopy.h>
|
2015-10-12 18:37:59 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2017-03-03 22:17:43 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleCounting.h>
|
2015-10-12 18:37:59 +00:00
|
|
|
#include <vtkm/cont/ArrayHandlePermutation.h>
|
|
|
|
#include <vtkm/cont/CellSetPermutation.h>
|
2017-09-13 21:58:25 +00:00
|
|
|
#include <vtkm/cont/DynamicCellSet.h>
|
2015-10-12 18:37:59 +00:00
|
|
|
#include <vtkm/cont/Field.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2015-10-12 18:37:59 +00:00
|
|
|
|
|
|
|
class Threshold
|
|
|
|
{
|
|
|
|
public:
|
2017-06-16 21:27:47 +00:00
|
|
|
enum class FieldType
|
|
|
|
{
|
|
|
|
Point,
|
|
|
|
Cell
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct BoolType : vtkm::ListTagBase<bool>
|
|
|
|
{
|
|
|
|
};
|
2015-10-12 18:37:59 +00:00
|
|
|
|
|
|
|
template <typename UnaryPredicate>
|
2015-10-22 00:09:58 +00:00
|
|
|
class ThresholdByPointField : public vtkm::worklet::WorkletMapPointToCell
|
2015-10-12 18:37:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-10 18:59:25 +00:00
|
|
|
using ControlSignature = void(CellSetIn cellset, FieldInPoint scalars, FieldOutCell passFlags);
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2018-05-25 21:18:41 +00:00
|
|
|
using ExecutionSignature = _3(_2, PointCount);
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ThresholdByPointField()
|
|
|
|
: Predicate()
|
|
|
|
{
|
|
|
|
}
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
explicit ThresholdByPointField(const UnaryPredicate& predicate)
|
2015-10-12 18:37:59 +00:00
|
|
|
: Predicate(predicate)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
}
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ScalarsVecType>
|
|
|
|
VTKM_EXEC bool operator()(const ScalarsVecType& scalars, vtkm::Id count) const
|
2015-10-12 18:37:59 +00:00
|
|
|
{
|
|
|
|
bool pass = false;
|
|
|
|
for (vtkm::IdComponent i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
pass |= this->Predicate(scalars[i]);
|
|
|
|
}
|
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
UnaryPredicate Predicate;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename UnaryPredicate>
|
2015-10-22 00:09:58 +00:00
|
|
|
class ThresholdByCellField : public vtkm::worklet::WorkletMapPointToCell
|
2015-10-12 18:37:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-10 18:59:25 +00:00
|
|
|
using ControlSignature = void(CellSetIn cellset, FieldInTo scalars, FieldOut passFlags);
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2018-05-25 21:18:41 +00:00
|
|
|
using ExecutionSignature = _3(_2);
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ThresholdByCellField()
|
|
|
|
: Predicate()
|
|
|
|
{
|
|
|
|
}
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
explicit ThresholdByCellField(const UnaryPredicate& predicate)
|
2015-10-12 18:37:59 +00:00
|
|
|
: Predicate(predicate)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
}
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ScalarType>
|
|
|
|
VTKM_EXEC bool operator()(const ScalarType& scalar) const
|
2015-10-12 18:37:59 +00:00
|
|
|
{
|
|
|
|
return this->Predicate(scalar);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
UnaryPredicate Predicate;
|
|
|
|
};
|
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename CellSetType, typename ValueType, typename StorageType, typename UnaryPredicate>
|
2017-06-16 21:27:47 +00:00
|
|
|
vtkm::cont::CellSetPermutation<CellSetType> Run(
|
|
|
|
const CellSetType& cellSet,
|
|
|
|
const vtkm::cont::ArrayHandle<ValueType, StorageType>& field,
|
2018-05-18 20:10:15 +00:00
|
|
|
const vtkm::cont::Field::Association fieldType,
|
2018-08-30 15:53:18 +00:00
|
|
|
const UnaryPredicate& predicate)
|
2015-10-12 18:37:59 +00:00
|
|
|
{
|
2017-09-13 21:58:25 +00:00
|
|
|
using OutputType = vtkm::cont::CellSetPermutation<CellSetType>;
|
2015-10-12 18:37:59 +00:00
|
|
|
|
|
|
|
vtkm::cont::ArrayHandle<bool> passFlags;
|
2017-06-16 21:27:47 +00:00
|
|
|
switch (fieldType)
|
2015-10-12 18:37:59 +00:00
|
|
|
{
|
2018-05-18 20:10:15 +00:00
|
|
|
case vtkm::cont::Field::Association::POINTS:
|
2015-10-12 18:37:59 +00:00
|
|
|
{
|
2018-02-22 13:29:13 +00:00
|
|
|
using ThresholdWorklet = ThresholdByPointField<UnaryPredicate>;
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
ThresholdWorklet worklet(predicate);
|
2018-08-28 20:36:50 +00:00
|
|
|
DispatcherMapTopology<ThresholdWorklet> dispatcher(worklet);
|
2017-05-18 14:29:41 +00:00
|
|
|
dispatcher.Invoke(cellSet, field, passFlags);
|
|
|
|
break;
|
2015-10-12 18:37:59 +00:00
|
|
|
}
|
2018-05-18 20:10:15 +00:00
|
|
|
case vtkm::cont::Field::Association::CELL_SET:
|
2015-10-12 18:37:59 +00:00
|
|
|
{
|
2018-02-22 13:29:13 +00:00
|
|
|
using ThresholdWorklet = ThresholdByCellField<UnaryPredicate>;
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
ThresholdWorklet worklet(predicate);
|
2018-08-28 20:36:50 +00:00
|
|
|
DispatcherMapTopology<ThresholdWorklet> dispatcher(worklet);
|
2017-05-18 14:29:41 +00:00
|
|
|
dispatcher.Invoke(cellSet, field, passFlags);
|
|
|
|
break;
|
2015-10-12 18:37:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
default:
|
|
|
|
throw vtkm::cont::ErrorBadValue("Expecting point or cell field.");
|
2015-10-12 18:37:59 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 22:17:43 +00:00
|
|
|
vtkm::cont::ArrayHandleCounting<vtkm::Id> indices =
|
|
|
|
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues());
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::cont::Algorithm::CopyIf(indices, passFlags, this->ValidCellIds);
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2016-05-13 18:26:59 +00:00
|
|
|
return OutputType(this->ValidCellIds, cellSet, cellSet.GetName());
|
2015-10-12 18:37:59 +00:00
|
|
|
}
|
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename CellSetList, typename FieldArrayType, typename UnaryPredicate>
|
2017-09-13 21:58:25 +00:00
|
|
|
struct CallWorklet
|
|
|
|
{
|
|
|
|
vtkm::cont::DynamicCellSet& Output;
|
|
|
|
vtkm::worklet::Threshold& Worklet;
|
|
|
|
const FieldArrayType& Field;
|
2018-05-18 20:10:15 +00:00
|
|
|
const vtkm::cont::Field::Association FieldType;
|
2017-09-13 21:58:25 +00:00
|
|
|
const UnaryPredicate& Predicate;
|
|
|
|
|
|
|
|
CallWorklet(vtkm::cont::DynamicCellSet& output,
|
|
|
|
vtkm::worklet::Threshold& worklet,
|
|
|
|
const FieldArrayType& field,
|
2018-05-18 20:10:15 +00:00
|
|
|
const vtkm::cont::Field::Association fieldType,
|
2017-09-13 21:58:25 +00:00
|
|
|
const UnaryPredicate& predicate)
|
|
|
|
: Output(output)
|
|
|
|
, Worklet(worklet)
|
|
|
|
, Field(field)
|
|
|
|
, FieldType(fieldType)
|
|
|
|
, Predicate(predicate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename CellSetType>
|
|
|
|
void operator()(const CellSetType& cellSet) const
|
|
|
|
{
|
2018-08-30 15:53:18 +00:00
|
|
|
this->Output = this->Worklet.Run(cellSet, this->Field, this->FieldType, this->Predicate);
|
2017-09-13 21:58:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename CellSetList, typename ValueType, typename StorageType, typename UnaryPredicate>
|
2017-09-13 21:58:25 +00:00
|
|
|
vtkm::cont::DynamicCellSet Run(const vtkm::cont::DynamicCellSetBase<CellSetList>& cellSet,
|
|
|
|
const vtkm::cont::ArrayHandle<ValueType, StorageType>& field,
|
2018-05-18 20:10:15 +00:00
|
|
|
const vtkm::cont::Field::Association fieldType,
|
2018-08-30 15:53:18 +00:00
|
|
|
const UnaryPredicate& predicate)
|
2017-09-13 21:58:25 +00:00
|
|
|
{
|
2018-08-30 15:53:18 +00:00
|
|
|
using Worker =
|
|
|
|
CallWorklet<CellSetList, vtkm::cont::ArrayHandle<ValueType, StorageType>, UnaryPredicate>;
|
2017-09-13 21:58:25 +00:00
|
|
|
|
|
|
|
vtkm::cont::DynamicCellSet output;
|
|
|
|
Worker worker(output, *this, field, fieldType, predicate);
|
|
|
|
cellSet.CastAndCall(worker);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename ValueType, typename StorageTag>
|
2017-06-16 21:27:47 +00:00
|
|
|
vtkm::cont::ArrayHandle<ValueType> ProcessCellField(
|
2018-08-30 15:53:18 +00:00
|
|
|
const vtkm::cont::ArrayHandle<ValueType, StorageTag> in) const
|
2015-10-12 18:37:59 +00:00
|
|
|
{
|
2017-06-16 21:27:47 +00:00
|
|
|
// Use a temporary permutation array to simplify the mapping:
|
|
|
|
auto tmp = vtkm::cont::make_ArrayHandlePermutation(this->ValidCellIds, in);
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2017-06-16 21:27:47 +00:00
|
|
|
// Copy into an array with default storage:
|
|
|
|
vtkm::cont::ArrayHandle<ValueType> result;
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::cont::ArrayCopy(tmp, result);
|
2015-10-12 18:37:59 +00:00
|
|
|
|
2017-06-16 21:27:47 +00:00
|
|
|
return result;
|
2015-10-12 18:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> ValidCellIds;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
|
|
|
#endif // vtkm_m_worklet_Threshold_h
|