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.
|
|
|
|
//============================================================================
|
|
|
|
|
2017-03-03 22:17:43 +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
|
|
|
|
{
|
|
|
|
|
2016-02-15 16:49:48 +00:00
|
|
|
class ThresholdRange
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-10-19 22:42:58 +00:00
|
|
|
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:
|
2016-02-15 16:49:48 +00:00
|
|
|
vtkm::Float64 Lower;
|
|
|
|
vtkm::Float64 Upper;
|
2016-01-19 14:59:31 +00:00
|
|
|
};
|
|
|
|
|
2017-06-16 21:27:47 +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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename T, typename StorageType, typename DerivedPolicy>
|
2018-04-02 21:58:21 +00:00
|
|
|
inline VTKM_CONT vtkm::cont::DataSet Threshold::DoExecute(
|
2017-05-26 17:53:28 +00:00
|
|
|
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,
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::filter::PolicyBase<DerivedPolicy> policy)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
|
|
|
//get the cells and coordinates of the dataset
|
2019-08-13 17:08:54 +00:00
|
|
|
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet();
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2017-06-16 21:27:47 +00:00
|
|
|
ThresholdRange predicate(this->GetLowerThreshold(), this->GetUpperThreshold());
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::cont::DynamicCellSet cellOut = this->Worklet.Run(
|
|
|
|
vtkm::filter::ApplyPolicy(cells, policy), field, fieldMeta.GetAssociation(), predicate);
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
vtkm::cont::DataSet output;
|
2019-08-13 17:08:54 +00:00
|
|
|
output.SetCellSet(cellOut);
|
2017-05-18 14:29:41 +00:00
|
|
|
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
|
2018-04-02 21:58:21 +00:00
|
|
|
return output;
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename T, typename StorageType, typename DerivedPolicy>
|
2018-04-02 21:58:21 +00:00
|
|
|
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,
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::filter::PolicyBase<DerivedPolicy>)
|
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
|
2018-04-02 21:58:21 +00:00
|
|
|
result.AddField(fieldMeta.AsField(input));
|
2016-01-19 14:59:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-06-16 21:27:47 +00:00
|
|
|
else if (fieldMeta.IsCellField())
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::cont::ArrayHandle<T> out = this->Worklet.ProcessCellField(input);
|
2018-04-02 21:58:21 +00:00
|
|
|
result.AddField(fieldMeta.AsField(out));
|
2016-01-19 14:59:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-06-16 21:27:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|