vtk-m2/vtkm/filter/Threshold.hxx

69 lines
2.0 KiB
C++
Raw Normal View History

2016-01-19 14:59:31 +00:00
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
2016-01-19 14:59:31 +00:00
// 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.
//============================================================================
#include <vtkm/cont/ArrayHandleCounting.h>
2016-01-19 14:59:31 +00:00
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CellSetPermutation.h>
2017-05-18 14:51:24 +00:00
#include <vtkm/cont/DynamicCellSet.h>
2016-01-19 14:59:31 +00:00
namespace
{
class ThresholdRange
2016-01-19 14:59:31 +00:00
{
public:
VTKM_CONT
2017-05-18 14:29:41 +00:00
ThresholdRange(const vtkm::Float64& lower, const vtkm::Float64& upper)
: Lower(lower)
, Upper(upper)
2016-01-19 14:59:31 +00:00
{
2017-05-18 14:29:41 +00:00
}
template <typename T>
VTKM_EXEC bool operator()(const T& value) const
{
return value >= static_cast<T>(this->Lower) && value <= static_cast<T>(this->Upper);
2016-01-19 14:59:31 +00:00
}
private:
vtkm::Float64 Lower;
vtkm::Float64 Upper;
2016-01-19 14:59:31 +00:00
};
} // end anon namespace
2016-01-19 14:59:31 +00:00
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace filter
{
2016-01-19 14:59:31 +00:00
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet Threshold::DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
2017-05-18 14:29:41 +00:00
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
2016-01-19 14:59:31 +00:00
{
//get the cells and coordinates of the dataset
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet();
2016-01-19 14:59:31 +00:00
ThresholdRange predicate(this->GetLowerThreshold(), this->GetUpperThreshold());
vtkm::cont::DynamicCellSet cellOut = this->Worklet.Run(
vtkm::filter::ApplyPolicyCellSet(cells, policy), field, fieldMeta.GetAssociation(), predicate);
2016-01-19 14:59:31 +00:00
vtkm::cont::DataSet output;
output.SetCellSet(cellOut);
2017-05-18 14:29:41 +00:00
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
return output;
2016-01-19 14:59:31 +00:00
}
}
}