From 679f1b00e97360717d4d8288ceab35949ddcfed8 Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Mon, 10 Jan 2022 09:15:30 -0700 Subject: [PATCH] migrate GhostCellRemove and Threshold --- benchmarking/BenchmarkFilters.cxx | 2 +- vtkm/filter/CMakeLists.txt | 3 - vtkm/filter/GhostCellRemove.h | 77 ++---- vtkm/filter/Threshold.cxx | 41 --- vtkm/filter/Threshold.h | 79 +----- vtkm/filter/entity_extraction/CMakeLists.txt | 4 + .../GhostCellRemove.cxx} | 113 ++++---- .../entity_extraction/GhostCellRemove.h | 65 +++++ .../Threshold.cxx} | 79 ++++-- vtkm/filter/entity_extraction/Threshold.h | 66 +++++ .../entity_extraction/testing/CMakeLists.txt | 2 + .../testing/UnitTestGhostCellRemove.cxx | 6 +- .../testing/UnitTestThresholdFilter.cxx | 10 +- .../entity_extraction/worklet/CMakeLists.txt | 1 + .../entity_extraction}/worklet/Threshold.h | 0 vtkm/filter/testing/CMakeLists.txt | 2 - vtkm/filter/testing/RenderTestAmrArrays.cxx | 4 +- vtkm/worklet/CMakeLists.txt | 1 - vtkm/worklet/testing/CMakeLists.txt | 1 - vtkm/worklet/testing/UnitTestThreshold.cxx | 252 ------------------ 20 files changed, 287 insertions(+), 521 deletions(-) delete mode 100644 vtkm/filter/Threshold.cxx rename vtkm/filter/{GhostCellRemove.hxx => entity_extraction/GhostCellRemove.cxx} (83%) create mode 100644 vtkm/filter/entity_extraction/GhostCellRemove.h rename vtkm/filter/{Threshold.hxx => entity_extraction/Threshold.cxx} (53%) create mode 100644 vtkm/filter/entity_extraction/Threshold.h rename vtkm/filter/{ => entity_extraction}/testing/UnitTestGhostCellRemove.cxx (98%) rename vtkm/filter/{ => entity_extraction}/testing/UnitTestThresholdFilter.cxx (96%) rename vtkm/{ => filter/entity_extraction}/worklet/Threshold.h (100%) delete mode 100644 vtkm/worklet/testing/UnitTestThreshold.cxx diff --git a/benchmarking/BenchmarkFilters.cxx b/benchmarking/BenchmarkFilters.cxx index cebfa68e4..076bb2c9a 100644 --- a/benchmarking/BenchmarkFilters.cxx +++ b/benchmarking/BenchmarkFilters.cxx @@ -34,13 +34,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index 130ea9e59..e16f9ab77 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -55,13 +55,11 @@ set(common_header_template_sources FilterParticleAdvection.hxx FilterTemporalParticleAdvection.hxx PointAverage.hxx - Threshold.hxx ) set(common_sources_device CellAverage.cxx PointAverage.cxx - Threshold.cxx ) set(extra_headers @@ -135,7 +133,6 @@ set(extra_header_template_sources Entropy.hxx FieldToColors.hxx GhostCellClassify.hxx - GhostCellRemove.hxx Histogram.hxx ImageConnectivity.hxx ImageDifference.hxx diff --git a/vtkm/filter/GhostCellRemove.h b/vtkm/filter/GhostCellRemove.h index 84806fc5c..59fd8f5fe 100644 --- a/vtkm/filter/GhostCellRemove.h +++ b/vtkm/filter/GhostCellRemove.h @@ -7,79 +7,34 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_GhostCellRemove_h #define vtk_m_filter_GhostCellRemove_h -#include -#include -#include +#include +#include namespace vtkm { namespace filter { -struct GhostCellRemovePolicy : vtkm::filter::PolicyBase +VTKM_DEPRECATED( + 1.8, + "Use vtkm/filter/entity_extraction/GhostCellRemove.h instead of vtkm/filter/GhostCellRemove.h.") +inline void GhostCellRemove_deprecated() {} + +inline void GhostCellRemove_deprecated_warning() { - using FieldTypeList = vtkm::List; + GhostCellRemove_deprecated(); +} + +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::GhostCellRemove.") GhostCellRemove + : public vtkm::filter::entity_extraction::GhostCellRemove +{ + using entity_extraction::GhostCellRemove::GhostCellRemove; }; -/// \brief Removes ghost cells -/// -class GhostCellRemove : public vtkm::filter::FilterDataSetWithField -{ -public: - //currently the GhostCellRemove filter only works on uint8 data. - using SupportedTypes = vtkm::List; - - VTKM_CONT - GhostCellRemove(); - - VTKM_CONT - void RemoveGhostField() { this->RemoveField = true; } - VTKM_CONT - void RemoveAllGhost() { this->RemoveAll = true; } - VTKM_CONT - void RemoveByType(const vtkm::UInt8& vals) - { - this->RemoveAll = false; - this->RemoveVals = vals; - } - VTKM_CONT - bool GetRemoveGhostField() { return this->RemoveField; } - VTKM_CONT - bool GetRemoveAllGhost() const { return this->RemoveAll; } - - VTKM_CONT - bool GetRemoveByType() const { return !this->RemoveAll; } - VTKM_CONT - vtkm::UInt8 GetRemoveType() const { return this->RemoveVals; } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); - - //Map a new field onto the resulting dataset after running the filter - //this call is only valid after DoExecute is run - template - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase policy); - -private: - bool RemoveAll; - bool RemoveField; - vtkm::UInt8 RemoveVals; - vtkm::worklet::Threshold Worklet; -}; } } // namespace vtkm::filter -#ifndef vtk_m_filter_GhostCellRemove_hxx -#include -#endif - -#endif // vtk_m_filter_GhostCellRemove_h +#endif //vtk_m_filter_GhostCellRemove_h diff --git a/vtkm/filter/Threshold.cxx b/vtkm/filter/Threshold.cxx deleted file mode 100644 index 7e9bef692..000000000 --- a/vtkm/filter/Threshold.cxx +++ /dev/null @@ -1,41 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ -#define vtkm_filter_Threshold_cxx -#include - -#include - -namespace vtkm -{ -namespace filter -{ - -bool Threshold::MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field) -{ - if (field.IsFieldPoint() || field.IsFieldGlobal()) - { - //we copy the input handle to the result dataset, reusing the metadata - result.AddField(field); - return true; - } - else if (field.IsFieldCell()) - { - return vtkm::filter::MapFieldPermutation(field, this->Worklet.GetValidCellIds(), result); - } - else - { - return false; - } -} - -//----------------------------------------------------------------------------- -VTKM_FILTER_COMMON_INSTANTIATE_EXECUTE_METHOD(Threshold); -} -} diff --git a/vtkm/filter/Threshold.h b/vtkm/filter/Threshold.h index 25462d2e7..2c544733f 100644 --- a/vtkm/filter/Threshold.h +++ b/vtkm/filter/Threshold.h @@ -7,84 +7,33 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_Threshold_h #define vtk_m_filter_Threshold_h -#include - -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Extracts cells where scalar value in cell satisfies threshold criterion -/// -/// Extracts all cells from any dataset type that -/// satisfy a threshold criterion. A cell satisfies the criterion if the -/// scalar value of every point or cell satisfies the criterion. The -/// criterion takes the form of between two values. The output of this -/// filter is an permutation of the input dataset. -/// -/// You can threshold either on point or cell fields -class VTKM_FILTER_COMMON_EXPORT Threshold : public vtkm::filter::FilterDataSetWithField +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/entity_extraction/Threshold.h instead of vtkm/filter/Threshold.h.") +inline void Threshold_deprecated() {} + +inline void Threshold_deprecated_warning() { -public: - using SupportedTypes = vtkm::TypeListScalarAll; + Threshold_deprecated(); +} - VTKM_CONT - void SetLowerThreshold(vtkm::Float64 value) { this->LowerValue = value; } - VTKM_CONT - void SetUpperThreshold(vtkm::Float64 value) { this->UpperValue = value; } - - VTKM_CONT - vtkm::Float64 GetLowerThreshold() const { return this->LowerValue; } - VTKM_CONT - vtkm::Float64 GetUpperThreshold() const { return this->UpperValue; } - - //If using scalars from point data, all scalars for all points in a cell must - //satisfy the threshold criterion if AllScalars is set. Otherwise, just a - //single scalar value satisfying the threshold criterion will extract the cell. - VTKM_CONT - void SetAllInRange(bool value) { this->ReturnAllInRange = value; } - - VTKM_CONT - bool GetAllInRange() const { return this->ReturnAllInRange; } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); - - //Map a new field onto the resulting dataset after running the filter - //this call is only valid after DoExecute is called - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field); - - template - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase) - { - return this->MapFieldOntoOutput(result, field); - } - -private: - double LowerValue = 0; - double UpperValue = 0; - bool ReturnAllInRange = false; - vtkm::worklet::Threshold Worklet; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::Threshold.") Threshold + : public vtkm::filter::entity_extraction::Threshold +{ + using entity_extraction::Threshold::Threshold; }; -#ifndef vtkm_filter_Threshold_cxx -VTKM_FILTER_COMMON_EXPORT_EXECUTE_METHOD(Threshold); -#endif } } // namespace vtkm::filter -#include - -#endif // vtk_m_filter_Threshold_h +#endif //vtk_m_filter_Threshold_h diff --git a/vtkm/filter/entity_extraction/CMakeLists.txt b/vtkm/filter/entity_extraction/CMakeLists.txt index 04b4de817..c538c04ef 100644 --- a/vtkm/filter/entity_extraction/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/CMakeLists.txt @@ -12,7 +12,9 @@ set(entity_extraction_headers ExtractGeometry.h ExtractPoints.h ExtractStructured.h + GhostCellRemove.h MaskPoints.h + Threshold.h ThresholdPoints.h ) set(entity_extraction_sources_device @@ -20,7 +22,9 @@ set(entity_extraction_sources_device ExtractGeometry.cxx ExtractPoints.cxx ExtractStructured.cxx + GhostCellRemove.cxx MaskPoints.cxx + Threshold.cxx ThresholdPoints.cxx ) diff --git a/vtkm/filter/GhostCellRemove.hxx b/vtkm/filter/entity_extraction/GhostCellRemove.cxx similarity index 83% rename from vtkm/filter/GhostCellRemove.hxx rename to vtkm/filter/entity_extraction/GhostCellRemove.cxx index 9ec766f2c..8c2b454a4 100644 --- a/vtkm/filter/GhostCellRemove.hxx +++ b/vtkm/filter/entity_extraction/GhostCellRemove.cxx @@ -8,19 +8,14 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_filter_GhostCellRemove_hxx -#define vtk_m_filter_GhostCellRemove_hxx -#include - -#include -#include -#include +#include #include -#include +#include #include #include -#include +#include +#include namespace { @@ -285,29 +280,52 @@ namespace vtkm { namespace filter { +namespace +{ +bool DoMapField(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::worklet::Threshold& Worklet) +{ + if (field.IsFieldPoint()) + { + //we copy the input handle to the result dataset, reusing the metadata + result.AddField(field); + return true; + } + else if (field.IsFieldCell()) + { + return vtkm::filter::MapFieldPermutation(field, Worklet.GetValidCellIds(), result); + } + else if (field.IsFieldGlobal()) + { + result.AddField(field); + return true; + } + else + { + return false; + } +} +} // anonymous namespace +namespace entity_extraction +{ //----------------------------------------------------------------------------- -inline VTKM_CONT GhostCellRemove::GhostCellRemove() - : vtkm::filter::FilterDataSetWithField() - , RemoveAll(false) - , RemoveField(false) - , RemoveVals(0) +VTKM_CONT GhostCellRemove::GhostCellRemove() { this->SetActiveField("vtkmGhostCells"); this->SetFieldsToPass("vtkmGhostCells", vtkm::filter::FieldSelection::MODE_EXCLUDE); } //----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute( - const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy) +VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(const vtkm::cont::DataSet& input) { - //get the cells and coordinates of the dataset const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); - vtkm::cont::UnknownCellSet cellOut; + const auto& field = this->GetFieldFromDataSet(input); + + // We are pretty sure the field array is an array of vtkm::UInt8 since it is the only supported + // type. + auto fieldArray = field.GetData().AsArrayHandle>(); //Preserve structured output where possible. if (cells.CanConvert>() || @@ -316,7 +334,7 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute( { vtkm::RangeId3 range; if (CanDoStructuredStrip( - cells, field, this->Invoke, this->GetRemoveAllGhost(), this->GetRemoveType(), range)) + cells, fieldArray, this->Invoke, this->GetRemoveAllGhost(), this->GetRemoveType(), range)) { vtkm::filter::entity_extraction::ExtractStructured extract; extract.SetInvoker(this->Invoke); @@ -334,19 +352,22 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute( } } + vtkm::cont::UnknownCellSet cellOut; + vtkm::worklet::Threshold Worklet; + if (this->GetRemoveAllGhost()) { - cellOut = this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), - field, - fieldMeta.GetAssociation(), - RemoveAllGhosts()); + cellOut = Worklet.Run(cells.ResetCellSetList(), + fieldArray, + field.GetAssociation(), + RemoveAllGhosts()); } else if (this->GetRemoveByType()) { - cellOut = this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), - field, - fieldMeta.GetAssociation(), - RemoveGhostByType(this->GetRemoveType())); + cellOut = Worklet.Run(cells.ResetCellSetList(), + fieldArray, + field.GetAssociation(), + RemoveGhostByType(this->GetRemoveType())); } else { @@ -357,36 +378,12 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute( output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.SetCellSet(cellOut); + auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; + MapFieldsOntoOutput(input, output, mapper); + return output; } -//----------------------------------------------------------------------------- -template -VTKM_CONT bool GhostCellRemove::MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase) -{ - if (field.IsFieldPoint()) - { - //we copy the input handle to the result dataset, reusing the metadata - result.AddField(field); - return true; - } - else if (field.IsFieldCell()) - { - return vtkm::filter::MapFieldPermutation(field, this->Worklet.GetValidCellIds(), result); - } - else if (field.IsFieldGlobal()) - { - result.AddField(field); - return true; - } - else - { - return false; - } } } } - -#endif //vtk_m_filter_GhostCellRemove_hxx diff --git a/vtkm/filter/entity_extraction/GhostCellRemove.h b/vtkm/filter/entity_extraction/GhostCellRemove.h new file mode 100644 index 000000000..ddb744433 --- /dev/null +++ b/vtkm/filter/entity_extraction/GhostCellRemove.h @@ -0,0 +1,65 @@ +//============================================================================ +// 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. +//============================================================================ + +#ifndef vtk_m_filter_entity_extraction_GhostCellRemove_h +#define vtk_m_filter_entity_extraction_GhostCellRemove_h + +#include +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace entity_extraction +{ +/// \brief Removes ghost cells +/// +class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT GhostCellRemove : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT + GhostCellRemove(); + + VTKM_CONT + void RemoveGhostField() { this->RemoveField = true; } + VTKM_CONT + void RemoveAllGhost() { this->RemoveAll = true; } + VTKM_CONT + void RemoveByType(const vtkm::UInt8& vals) + { + this->RemoveAll = false; + this->RemoveVals = vals; + } + VTKM_CONT + bool GetRemoveGhostField() { return this->RemoveField; } + VTKM_CONT + bool GetRemoveAllGhost() const { return this->RemoveAll; } + + VTKM_CONT + bool GetRemoveByType() const { return !this->RemoveAll; } + VTKM_CONT + vtkm::UInt8 GetRemoveType() const { return this->RemoveVals; } + +private: + VTKM_CONT + vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + bool RemoveAll = false; + bool RemoveField = false; + vtkm::UInt8 RemoveVals = 0; +}; + +} // namespace entity_extraction +} // namespace filter +} // namespace vtkm + +#endif // vtk_m_filter_entity_extraction_GhostCellRemove_h diff --git a/vtkm/filter/Threshold.hxx b/vtkm/filter/entity_extraction/Threshold.cxx similarity index 53% rename from vtkm/filter/Threshold.hxx rename to vtkm/filter/entity_extraction/Threshold.cxx index e6c47ec8c..4dac3158b 100644 --- a/vtkm/filter/Threshold.hxx +++ b/vtkm/filter/entity_extraction/Threshold.cxx @@ -7,14 +7,16 @@ // 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 - -#include -#include -#include -#include +#include +#include +#include +namespace vtkm +{ +namespace filter +{ +namespace entity_extraction +{ namespace { @@ -49,36 +51,61 @@ private: vtkm::Float64 Upper; }; +bool DoMapField(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::worklet::Threshold& Worklet) +{ + if (field.IsFieldPoint() || field.IsFieldGlobal()) + { + //we copy the input handle to the result dataset, reusing the metadata + result.AddField(field); + return true; + } + else if (field.IsFieldCell()) + { + return vtkm::filter::MapFieldPermutation(field, Worklet.GetValidCellIds(), result); + } + else + { + return false; + } +} + } // end anon namespace -namespace vtkm -{ -namespace filter -{ - //----------------------------------------------------------------------------- -template -vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy) +vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input) { //get the cells and coordinates of the dataset const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); + const auto& field = this->GetFieldFromDataSet(input); ThresholdRange predicate(this->GetLowerThreshold(), this->GetUpperThreshold()); - vtkm::cont::UnknownCellSet cellOut = - this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), - field, - fieldMeta.GetAssociation(), - predicate, - this->GetAllInRange()); + vtkm::worklet::Threshold Worklet; + vtkm::cont::UnknownCellSet cellOut; + + auto ResolveArrayType = [&, this](const auto& concrete) { + // TODO: document the reason a .ResetCellSetList is needed here. + cellOut = Worklet.Run(cells.ResetCellSetList(), + concrete, + field.GetAssociation(), + predicate, + this->GetAllInRange()); + }; + + const auto& fieldArray = field.GetData(); + fieldArray.CastAndCallForTypes( + ResolveArrayType); vtkm::cont::DataSet output; output.SetCellSet(cellOut); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); + + auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; + MapFieldsOntoOutput(input, output, mapper); + return output; } -} -} -#endif +} // namespace entity_extraction +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/entity_extraction/Threshold.h b/vtkm/filter/entity_extraction/Threshold.h new file mode 100644 index 000000000..e73392259 --- /dev/null +++ b/vtkm/filter/entity_extraction/Threshold.h @@ -0,0 +1,66 @@ +//============================================================================ +// 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. +//============================================================================ + +#ifndef vtk_m_filter_entity_extraction_Threshold_h +#define vtk_m_filter_entity_extraction_Threshold_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace entity_extraction +{ +/// \brief Extracts cells where scalar value in cell satisfies threshold criterion +/// +/// Extracts all cells from any dataset type that +/// satisfy a threshold criterion. A cell satisfies the criterion if the +/// scalar value of every point or cell satisfies the criterion. The +/// criterion takes the form of between two values. The output of this +/// filter is an permutation of the input dataset. +/// +/// You can threshold either on point or cell fields +class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT Threshold : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT + void SetLowerThreshold(vtkm::Float64 value) { this->LowerValue = value; } + VTKM_CONT + void SetUpperThreshold(vtkm::Float64 value) { this->UpperValue = value; } + + VTKM_CONT + vtkm::Float64 GetLowerThreshold() const { return this->LowerValue; } + VTKM_CONT + vtkm::Float64 GetUpperThreshold() const { return this->UpperValue; } + + //If using scalars from point data, all scalars for all points in a cell must + //satisfy the threshold criterion if AllScalars is set. Otherwise, just a + //single scalar value satisfying the threshold criterion will extract the cell. + VTKM_CONT + void SetAllInRange(bool value) { this->ReturnAllInRange = value; } + + VTKM_CONT + bool GetAllInRange() const { return this->ReturnAllInRange; } + +private: + VTKM_CONT + vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + double LowerValue = 0; + double UpperValue = 0; + bool ReturnAllInRange = false; +}; +} // namespace entity_extraction +} // namespace filter +} // namespace vtkm + +#endif // vtk_m_filter_entity_extraction_Threshold_h diff --git a/vtkm/filter/entity_extraction/testing/CMakeLists.txt b/vtkm/filter/entity_extraction/testing/CMakeLists.txt index 43454d99b..b737cb1c0 100644 --- a/vtkm/filter/entity_extraction/testing/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/testing/CMakeLists.txt @@ -13,7 +13,9 @@ set(unit_tests UnitTestExtractGeometryFilter.cxx UnitTestExtractPointsFilter.cxx UnitTestExtractStructuredFilter.cxx + UnitTestGhostCellRemove.cxx UnitTestMaskPointsFilter.cxx + UnitTestThresholdFilter.cxx UnitTestThresholdPointsFilter.cxx ) diff --git a/vtkm/filter/testing/UnitTestGhostCellRemove.cxx b/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx similarity index 98% rename from vtkm/filter/testing/UnitTestGhostCellRemove.cxx rename to vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx index 289fa29f4..3e7168f53 100644 --- a/vtkm/filter/testing/UnitTestGhostCellRemove.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx @@ -14,7 +14,7 @@ #include #include -#include +#include namespace { @@ -247,7 +247,7 @@ void TestGhostCellRemove() std::vector removeType = { "all", "byType" }; for (auto& rt : removeType) { - vtkm::filter::GhostCellRemove ghostCellRemoval; + vtkm::filter::entity_extraction::GhostCellRemove ghostCellRemoval; ghostCellRemoval.RemoveGhostField(); if (rt == "all") @@ -294,7 +294,7 @@ void TestGhostCellRemove() else if (dsType == "rectilinear") ds = MakeRectilinear(nx, ny, nz, layer, true); - vtkm::filter::GhostCellRemove ghostCellRemoval; + vtkm::filter::entity_extraction::GhostCellRemove ghostCellRemoval; ghostCellRemoval.RemoveGhostField(); auto output = ghostCellRemoval.Execute(ds); VTKM_TEST_ASSERT(output.GetCellSet().IsType>(), diff --git a/vtkm/filter/testing/UnitTestThresholdFilter.cxx b/vtkm/filter/entity_extraction/testing/UnitTestThresholdFilter.cxx similarity index 96% rename from vtkm/filter/testing/UnitTestThresholdFilter.cxx rename to vtkm/filter/entity_extraction/testing/UnitTestThresholdFilter.cxx index 5b091a821..09b509407 100644 --- a/vtkm/filter/testing/UnitTestThresholdFilter.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestThresholdFilter.cxx @@ -10,8 +10,8 @@ #include #include -#include #include +#include using vtkm::cont::testing::MakeTestDataSet; @@ -24,7 +24,7 @@ public: void TestRegular2D(bool returnAllInRange) const { vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet0(); - vtkm::filter::Threshold threshold; + vtkm::filter::entity_extraction::Threshold threshold; if (returnAllInRange) { @@ -80,7 +80,7 @@ public: void TestRegular3D(bool returnAllInRange) const { vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet0(); - vtkm::filter::Threshold threshold; + vtkm::filter::entity_extraction::Threshold threshold; if (returnAllInRange) { @@ -141,7 +141,7 @@ public: std::cout << "Testing threshold on 3D explicit dataset" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet1(); - vtkm::filter::Threshold threshold; + vtkm::filter::entity_extraction::Threshold threshold; threshold.SetLowerThreshold(20); threshold.SetUpperThreshold(21); @@ -171,7 +171,7 @@ public: std::cout << "Testing threshold on 3D explicit dataset with empty results" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet1(); - vtkm::filter::Threshold threshold; + vtkm::filter::entity_extraction::Threshold threshold; threshold.SetLowerThreshold(500); threshold.SetUpperThreshold(500.1); diff --git a/vtkm/filter/entity_extraction/worklet/CMakeLists.txt b/vtkm/filter/entity_extraction/worklet/CMakeLists.txt index 868a52030..9292c3e9b 100644 --- a/vtkm/filter/entity_extraction/worklet/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/worklet/CMakeLists.txt @@ -14,6 +14,7 @@ set(headers ExtractStructured.h ExtractPoints.h MaskPoints.h + Threshold.h ThresholdPoints.h ) diff --git a/vtkm/worklet/Threshold.h b/vtkm/filter/entity_extraction/worklet/Threshold.h similarity index 100% rename from vtkm/worklet/Threshold.h rename to vtkm/filter/entity_extraction/worklet/Threshold.h diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index 3214d04fb..a96df9cad 100644 --- a/vtkm/filter/testing/CMakeLists.txt +++ b/vtkm/filter/testing/CMakeLists.txt @@ -32,7 +32,6 @@ set(unit_tests UnitTestGradientExplicit.cxx UnitTestGradientUniform.cxx UnitTestGhostCellClassify.cxx - UnitTestGhostCellRemove.cxx UnitTestHistogramFilter.cxx UnitTestImageConnectivityFilter.cxx UnitTestImageDifferenceFilter.cxx @@ -60,7 +59,6 @@ set(unit_tests UnitTestStreamSurfaceFilter.cxx UnitTestSurfaceNormalsFilter.cxx UnitTestTetrahedralizeFilter.cxx - UnitTestThresholdFilter.cxx UnitTestTriangulateFilter.cxx UnitTestTubeFilter.cxx UnitTestVectorMagnitudeFilter.cxx diff --git a/vtkm/filter/testing/RenderTestAmrArrays.cxx b/vtkm/filter/testing/RenderTestAmrArrays.cxx index 446f158d8..21802b714 100644 --- a/vtkm/filter/testing/RenderTestAmrArrays.cxx +++ b/vtkm/filter/testing/RenderTestAmrArrays.cxx @@ -9,8 +9,8 @@ //============================================================================ #include -#include #include +#include #include #include @@ -30,7 +30,7 @@ void TestAmrArraysExecute(int dim, int numberOfLevels, int cellsPerDimension) // amrDataSet.PrintSummary(std::cout); // Remove blanked cells - vtkm::filter::Threshold threshold; + vtkm::filter::entity_extraction::Threshold threshold; threshold.SetLowerThreshold(0); threshold.SetUpperThreshold(1); threshold.SetActiveField("vtkGhostType"); diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index 683bca8af..2482a1592 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -69,7 +69,6 @@ set(headers StreamSurface.h SurfaceNormals.h Tetrahedralize.h - Threshold.h TriangleWinding.h Triangulate.h Tube.h diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index 1dd4c51c5..c3a185ec1 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -65,7 +65,6 @@ set(unit_tests UnitTestSurfaceNormals.cxx UnitTestTemporalAdvection.cxx UnitTestTetrahedralize.cxx - UnitTestThreshold.cxx UnitTestTriangleWinding.cxx UnitTestTriangulate.cxx UnitTestTube.cxx diff --git a/vtkm/worklet/testing/UnitTestThreshold.cxx b/vtkm/worklet/testing/UnitTestThreshold.cxx deleted file mode 100644 index e8f3e34f1..000000000 --- a/vtkm/worklet/testing/UnitTestThreshold.cxx +++ /dev/null @@ -1,252 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace -{ - -class HasValue -{ -public: - VTKM_CONT - HasValue(vtkm::Float32 value) - : Value(value) - { - } - - template - VTKM_EXEC bool operator()(ScalarType value) const - { - return static_cast(value) == this->Value; - } - -private: - vtkm::Float32 Value; -}; - -class ThresholdRange -{ -public: - VTKM_CONT - ThresholdRange() {} - - ThresholdRange(const vtkm::Float64& lower, const vtkm::Float64& upper) - : Lower(lower) - , Upper(upper) - { - } - - void SetLowerValue(const vtkm::Float64& lower) { Lower = lower; } - void SetUpperValue(const vtkm::Float64& upper) { Upper = upper; } - - template - VTKM_EXEC bool operator()(const T& value) const - { - - return value >= static_cast(this->Lower) && value <= static_cast(this->Upper); - } - - //Needed to work with ArrayHandleVirtual - template - VTKM_EXEC bool operator()( - const vtkm::internal::ArrayPortalValueReference& value) const - { - using T = typename PortalType::ValueType; - return value.Get() >= static_cast(this->Lower) && value.Get() <= static_cast(this->Upper); - } - -private: - vtkm::Float64 Lower; - vtkm::Float64 Upper; -}; - -using vtkm::cont::testing::MakeTestDataSet; - -class TestingThreshold -{ -public: - void TestUniform2D(bool returnAllInRange) const - { - using CellSetType = vtkm::cont::CellSetStructured<2>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - - vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet0(); - - CellSetType cellset; - dataset.GetCellSet().AsCellSet(cellset); - - vtkm::cont::ArrayHandle pointvar; - dataset.GetField("pointvar").GetData().AsArrayHandle(pointvar); - - vtkm::worklet::Threshold threshold; - ThresholdRange predicate; - - if (returnAllInRange) - { - std::cout << "Testing threshold on 2D uniform dataset returning values 'all in range'" - << std::endl; - predicate.SetLowerValue(10); - predicate.SetUpperValue(60); - } - else - { - std::cout << "Testing threshold on 2D uniform dataset returning values 'part in range'" - << std::endl; - predicate.SetLowerValue(60); - predicate.SetUpperValue(61); - } - - OutCellSetType outCellSet = threshold.Run( - cellset, pointvar, vtkm::cont::Field::Association::POINTS, predicate, returnAllInRange); - - if (returnAllInRange) - { - VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 1, "Wrong number of cells"); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - vtkm::cont::ArrayHandle cellFieldArray = threshold.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 1 && - cellFieldArray.ReadPortal().Get(0) == 100.1f, - "Wrong cell field data"); - } - else - { - VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 1, "Wrong number of cells"); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - vtkm::cont::ArrayHandle cellFieldArray = threshold.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 1 && - cellFieldArray.ReadPortal().Get(0) == 200.1f, - "Wrong cell field data"); - } - } - - void TestUniform3D(bool returnAllInRange) const - { - using CellSetType = vtkm::cont::CellSetStructured<3>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet0(); - - CellSetType cellset; - dataset.GetCellSet().AsCellSet(cellset); - - vtkm::cont::ArrayHandle pointvar; - dataset.GetField("pointvar").GetData().AsArrayHandle(pointvar); - - vtkm::worklet::Threshold threshold; - ThresholdRange predicate; - - if (returnAllInRange) - { - std::cout << "Testing threshold on 3D uniform dataset returning values 'all in range'" - << std::endl; - predicate.SetLowerValue(10.1); - predicate.SetUpperValue(180); - } - else - { - std::cout << "Testing threshold on 3D uniform dataset returning values 'part in range'" - << std::endl; - predicate.SetLowerValue(20); - predicate.SetUpperValue(21); - } - - OutCellSetType outCellSet = threshold.Run( - cellset, pointvar, vtkm::cont::Field::Association::POINTS, predicate, returnAllInRange); - - if (returnAllInRange) - { - VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 3, "Wrong number of cells"); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - vtkm::cont::ArrayHandle cellFieldArray = threshold.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 3 && - cellFieldArray.ReadPortal().Get(0) == 100.1f && - cellFieldArray.ReadPortal().Get(1) == 100.2f && - cellFieldArray.ReadPortal().Get(2) == 100.3f, - "Wrong cell field data"); - } - else - { - VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 2, "Wrong number of cells"); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - vtkm::cont::ArrayHandle cellFieldArray = threshold.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 && - cellFieldArray.ReadPortal().Get(0) == 100.1f && - cellFieldArray.ReadPortal().Get(1) == 100.2f, - "Wrong cell field data"); - } - } - - void TestExplicit3D() const - { - std::cout << "Testing threshold on 3D explicit dataset" << std::endl; - - using CellSetType = vtkm::cont::CellSetExplicit<>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet0(); - - CellSetType cellset; - dataset.GetCellSet().AsCellSet(cellset); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - - vtkm::worklet::Threshold threshold; - OutCellSetType outCellSet = - threshold.Run(cellset, cellvar, vtkm::cont::Field::Association::CELL_SET, HasValue(100.1f)); - - VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 1, "Wrong number of cells"); - - vtkm::cont::ArrayHandle cellFieldArray = threshold.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 1 && - cellFieldArray.ReadPortal().Get(0) == 100.1f, - "Wrong cell field data"); - } - - void operator()() const - { - this->TestUniform2D(false); - this->TestUniform2D(true); - this->TestUniform3D(false); - this->TestUniform3D(true); - this->TestExplicit3D(); - } -}; -} - -int UnitTestThreshold(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestingThreshold(), argc, argv); -}