diff --git a/vtkm/filter/Threshold.h b/vtkm/filter/Threshold.h index 71aff41ed..4c4ecc418 100644 --- a/vtkm/filter/Threshold.h +++ b/vtkm/filter/Threshold.h @@ -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 VTKM_CONT_EXPORT @@ -59,7 +63,8 @@ public: private: - double ThresholdValue; + double LowerValue; + double UpperValue; vtkm::cont::ArrayHandle ValidCellIds; }; diff --git a/vtkm/filter/Threshold.hxx b/vtkm/filter/Threshold.hxx index d516d3b5b..45c4729c5 100644 --- a/vtkm/filter/Threshold.hxx +++ b/vtkm/filter/Threshold.hxx @@ -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 VTKM_EXEC_EXPORT bool operator()(const T& value) const { - return value == static_cast(this->Value); + return value >= static_cast(this->Lower) && + value <= static_cast(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(), - 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 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 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 dispatcher(worklet); dispatcher.Invoke(vtkm::filter::Convert(cells, policy), field, passFlags); diff --git a/vtkm/filter/testing/UnitTestThresholdFilter.cxx b/vtkm/filter/testing/UnitTestThresholdFilter.cxx index bba9e3ce0..50434a7f1 100644 --- a/vtkm/filter/testing/UnitTestThresholdFilter.cxx +++ b/vtkm/filter/testing/UnitTestThresholdFilter.cxx @@ -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");