vtk-m/vtkm/filter/Threshold.hxx

119 lines
4.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.
// 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.
//
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
2016-01-19 14:59:31 +00:00
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
2016-01-19 14:59:31 +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.
//============================================================================
#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
#include <vtkm/worklet/DispatcherMapTopology.h>
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
//-----------------------------------------------------------------------------
2017-05-18 14:29:41 +00:00
inline VTKM_CONT Threshold::Threshold()
: vtkm::filter::FilterDataSetWithField<Threshold>()
, LowerValue(0)
, UpperValue(0)
2016-01-19 14:59:31 +00:00
{
}
//-----------------------------------------------------------------------------
2017-05-18 14:29:41 +00:00
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
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,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
DeviceAdapter)
2016-01-19 14:59:31 +00:00
{
//get the cells and coordinates of the dataset
2017-05-18 14:29:41 +00:00
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(this->GetActiveCellSetIndex());
2016-01-19 14:59:31 +00:00
ThresholdRange predicate(this->GetLowerThreshold(), this->GetUpperThreshold());
vtkm::cont::DynamicCellSet cellOut = this->Worklet.Run(vtkm::filter::ApplyPolicy(cells, policy),
field,
fieldMeta.GetAssociation(),
predicate,
DeviceAdapter());
2016-01-19 14:59:31 +00:00
vtkm::cont::DataSet output;
output.AddCellSet(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
}
//-----------------------------------------------------------------------------
2017-05-18 14:29:41 +00:00
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
inline VTKM_CONT bool Threshold::DoMapField(vtkm::cont::DataSet& result,
2017-05-18 14:29:41 +00:00
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
DeviceAdapter device)
2016-01-19 14:59:31 +00:00
{
2017-05-18 14:29:41 +00:00
if (fieldMeta.IsPointField())
2016-01-19 14:59:31 +00:00
{
//we copy the input handle to the result dataset, reusing the metadata
result.AddField(fieldMeta.AsField(input));
2016-01-19 14:59:31 +00:00
return true;
}
else if (fieldMeta.IsCellField())
2016-01-19 14:59:31 +00:00
{
vtkm::cont::ArrayHandle<T> out = this->Worklet.ProcessCellField(input, device);
result.AddField(fieldMeta.AsField(out));
2016-01-19 14:59:31 +00:00
return true;
}
else
{
return false;
}
2016-01-19 14:59:31 +00:00
}
}
}