vtk-m/vtkm/filter/Threshold.hxx

85 lines
2.6 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.
//============================================================================
#ifndef vtk_m_filter_Threshold_hxx
#define vtk_m_filter_Threshold_hxx
2016-01-19 14:59:31 +00:00
#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
{
2017-05-18 14:29:41 +00:00
return value >= static_cast<T>(this->Lower) && value <= static_cast<T>(this->Upper);
2016-01-19 14:59:31 +00:00
}
//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);
}
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>
vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
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, *this),
field,
fieldMeta.GetAssociation(),
predicate,
this->GetAllInRange());
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
}
}
}
#endif