mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-18 18:15:44 +00:00
Switch filter::threshold over to have a lower and upper bounds.
This commit is contained in:
parent
bcee827097
commit
8e72ec8ea4
@ -34,10 +34,14 @@ public:
|
||||
Threshold();
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void SetThresholdValue(vtkm::Float64 value){ this->ThresholdValue = value; }
|
||||
void SetLowerThreshold(vtkm::Float64 value){ this->LowerValue = value; }
|
||||
VTKM_CONT_EXPORT
|
||||
void SetUpperThreshold(vtkm::Float64 value){ this->UpperValue = value; }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Float64 GetThresholdValue() const { return this->ThresholdValue; }
|
||||
vtkm::Float64 GetLowerThreshold() const { return this->LowerValue; }
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Float64 GetUpperThreshold() const { return this->UpperValue; }
|
||||
|
||||
template<typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
|
||||
VTKM_CONT_EXPORT
|
||||
@ -59,7 +63,8 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
double ThresholdValue;
|
||||
double LowerValue;
|
||||
double UpperValue;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> ValidCellIds;
|
||||
};
|
||||
|
||||
|
@ -27,22 +27,27 @@
|
||||
namespace
|
||||
{
|
||||
|
||||
class HasValue
|
||||
class ThresholdRange
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
HasValue(const vtkm::Float64& value) : Value(value)
|
||||
ThresholdRange(const vtkm::Float64& lower,
|
||||
const vtkm::Float64& upper) :
|
||||
Lower(lower),
|
||||
Upper(upper)
|
||||
{ }
|
||||
|
||||
template<typename T>
|
||||
VTKM_EXEC_EXPORT
|
||||
bool operator()(const T& value) const
|
||||
{
|
||||
return value == static_cast<T>(this->Value);
|
||||
return value >= static_cast<T>(this->Lower) &&
|
||||
value <= static_cast<T>(this->Upper);
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Float64 Value;
|
||||
vtkm::Float64 Lower;
|
||||
vtkm::Float64 Upper;
|
||||
};
|
||||
|
||||
class AddPermutationCellSet
|
||||
@ -79,7 +84,8 @@ namespace filter {
|
||||
//-----------------------------------------------------------------------------
|
||||
Threshold::Threshold():
|
||||
vtkm::filter::DataSetWithFieldFilter<Threshold>(),
|
||||
ThresholdValue(0),
|
||||
LowerValue(0),
|
||||
UpperValue(0),
|
||||
ValidCellIds()
|
||||
{
|
||||
|
||||
@ -100,12 +106,12 @@ vtkm::filter::DataSetResult Threshold::DoExecute(const vtkm::cont::DataSet& inpu
|
||||
const vtkm::cont::DynamicCellSet& cells =
|
||||
input.GetCellSet(this->GetActiveCellSetIndex());
|
||||
|
||||
HasValue predicate( this->GetThresholdValue() );
|
||||
ThresholdRange predicate( this->GetLowerThreshold(), this->GetUpperThreshold() );
|
||||
vtkm::cont::ArrayHandle<bool> passFlags;
|
||||
if(fieldMeta.IsPointField())
|
||||
{
|
||||
typedef vtkm::worklet::Threshold Worklets;
|
||||
typedef Worklets::ThresholdByPointField< HasValue > ThresholdWorklet;
|
||||
typedef Worklets::ThresholdByPointField< ThresholdRange > ThresholdWorklet;
|
||||
ThresholdWorklet worklet(predicate);
|
||||
vtkm::worklet::DispatcherMapTopology<ThresholdWorklet, DeviceAdapter> dispatcher(worklet);
|
||||
dispatcher.Invoke(vtkm::filter::Convert(cells, policy), field, passFlags);
|
||||
@ -113,7 +119,7 @@ vtkm::filter::DataSetResult Threshold::DoExecute(const vtkm::cont::DataSet& inpu
|
||||
else if(fieldMeta.IsCellField())
|
||||
{
|
||||
typedef vtkm::worklet::Threshold Worklets;
|
||||
typedef Worklets::ThresholdByCellField< HasValue > ThresholdWorklet;
|
||||
typedef Worklets::ThresholdByCellField< ThresholdRange > ThresholdWorklet;
|
||||
ThresholdWorklet worklet(predicate);
|
||||
vtkm::worklet::DispatcherMapTopology<ThresholdWorklet, DeviceAdapter> dispatcher(worklet);
|
||||
dispatcher.Invoke(vtkm::filter::Convert(cells, policy), field, passFlags);
|
||||
|
@ -40,7 +40,8 @@ public:
|
||||
vtkm::filter::Threshold threshold;
|
||||
vtkm::filter::DataSetResult result;
|
||||
|
||||
threshold.SetThresholdValue(60.1);
|
||||
threshold.SetLowerThreshold(60.1);
|
||||
threshold.SetUpperThreshold(60.1);
|
||||
result = threshold.Execute(dataset, dataset.GetField("pointvar"));
|
||||
|
||||
threshold.MapFieldOntoOutput(result, dataset.GetField("cellvar") );
|
||||
@ -69,7 +70,8 @@ public:
|
||||
vtkm::filter::Threshold threshold;
|
||||
vtkm::filter::DataSetResult result;
|
||||
|
||||
threshold.SetThresholdValue(20.1);
|
||||
threshold.SetLowerThreshold(20.1);
|
||||
threshold.SetUpperThreshold(20.1);
|
||||
result = threshold.Execute(dataset, std::string("pointvar"));
|
||||
|
||||
threshold.MapFieldOntoOutput(result, dataset.GetField("cellvar") );
|
||||
@ -99,7 +101,8 @@ public:
|
||||
vtkm::filter::Threshold threshold;
|
||||
vtkm::filter::DataSetResult result;
|
||||
|
||||
threshold.SetThresholdValue(20.1);
|
||||
threshold.SetLowerThreshold(20.1);
|
||||
threshold.SetUpperThreshold(20.1);
|
||||
result = threshold.Execute(dataset, std::string("pointvar"));
|
||||
|
||||
threshold.MapFieldOntoOutput(result, dataset.GetField("cellvar") );
|
||||
@ -129,7 +132,8 @@ public:
|
||||
vtkm::filter::Threshold threshold;
|
||||
vtkm::filter::DataSetResult result;
|
||||
|
||||
threshold.SetThresholdValue(500.1);
|
||||
threshold.SetLowerThreshold(500.1);
|
||||
threshold.SetUpperThreshold(500.1);
|
||||
result = threshold.Execute(dataset, std::string("pointvar"));
|
||||
|
||||
VTKM_TEST_ASSERT(result.IsValid(), "threshold algorithm should return true");
|
||||
|
Loading…
Reference in New Issue
Block a user