From a6dcac2cb1a34a5b5199a87f38f479b625c950ec Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 7 Jan 2022 11:26:19 -0500 Subject: [PATCH 1/7] Fix build with MinGW Co-authored-by: Vicente Adolfo Bolea Sanchez --- vtkm/cont/testing/Testing.cxx | 4 ++-- vtkm/internal/Configure.h.in | 5 +++++ vtkm/io/FileUtils.cxx | 10 +++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/vtkm/cont/testing/Testing.cxx b/vtkm/cont/testing/Testing.cxx index f3dc57c2f..c4680f982 100644 --- a/vtkm/cont/testing/Testing.cxx +++ b/vtkm/cont/testing/Testing.cxx @@ -66,7 +66,7 @@ std::string Testing::WriteDirPath(const std::string& filename) void Testing::SetEnv(const std::string& var, const std::string& value) { static std::vector> envVars{}; -#ifdef _MSC_VER +#ifdef _WIN32 auto iter = envVars.emplace(envVars.end(), var, value); _putenv_s(iter->first.c_str(), iter->second.c_str()); #else @@ -76,7 +76,7 @@ void Testing::SetEnv(const std::string& var, const std::string& value) void Testing::UnsetEnv(const std::string& var) { -#ifdef _MSC_VER +#ifdef _WIN32 SetEnv(var, ""); #else unsetenv(var.c_str()); diff --git a/vtkm/internal/Configure.h.in b/vtkm/internal/Configure.h.in index 9f0f66ac0..d75c2d5fa 100644 --- a/vtkm/internal/Configure.h.in +++ b/vtkm/internal/Configure.h.in @@ -49,6 +49,11 @@ //compliance #define VTKM_CLANG +#elif defined(__MINGW32__) +//Check for MinGW before GCC, since MinGW will be otherwise categorized +//as VTKM_GCC +#define VTKM_MINGW + #elif defined(__GNUC__) // Several compilers pretend to be GCC but have minor differences. Try to // compensate for that, by checking for those compilers first diff --git a/vtkm/io/FileUtils.cxx b/vtkm/io/FileUtils.cxx index e8c1785e4..7c252fa5e 100644 --- a/vtkm/io/FileUtils.cxx +++ b/vtkm/io/FileUtils.cxx @@ -17,7 +17,7 @@ #include #include -#ifdef _MSC_VER +#ifdef _WIN32 #include #endif @@ -42,7 +42,7 @@ std::string Filename(const std::string& filePath) // std::filesystem::path path(filePath); // return path.filename(); -#ifdef _MSC_VER +#ifdef _WIN32 auto lastSlashPos = filePath.rfind(GetWindowsPathSeperator(filePath)); #else auto lastSlashPos = filePath.rfind('/'); @@ -60,7 +60,7 @@ std::string ParentPath(const std::string& filePath) // std::filesystem::path path(filePath); // return path.parent_path(); -#ifdef _MSC_VER +#ifdef _WIN32 auto lastSlashPos = filePath.rfind(GetWindowsPathSeperator(filePath)); #else auto lastSlashPos = filePath.rfind('/'); @@ -88,7 +88,7 @@ bool CreateDirectoriesFromFilePath(const std::string& filePath) return false; } -#ifdef _MSC_VER +#ifdef _WIN32 auto ret = _mkdir(dir.c_str()); #else mode_t mode = 0755; @@ -145,7 +145,7 @@ std::string MergePaths(const std::string& filePathPrefix, const std::string& fil return prefix; } -#ifdef _MSC_VER +#ifdef _WIN32 prefixPathSeperator = GetWindowsPathSeperator(prefix); suffixPathSeperator = suffix[0] == '/' || suffix[0] == '\\' ? suffix[0] : prefixPathSeperator; #endif From e3703b09cf0b93e84657825640da852b30b548bf Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Sun, 9 Jan 2022 13:06:47 -0700 Subject: [PATCH 2/7] migrate ExtractGeometry --- vtkm/filter/CMakeLists.txt | 2 - vtkm/filter/ExtractGeometry.cxx | 60 ----- vtkm/filter/ExtractGeometry.h | 101 ++----- vtkm/filter/entity_extraction/CMakeLists.txt | 2 + .../ExtractGeometry.cxx} | 61 +++-- .../entity_extraction/ExtractGeometry.h | 97 +++++++ .../entity_extraction/testing/CMakeLists.txt | 1 + .../testing/UnitTestExtractGeometryFilter.cxx | 10 +- .../entity_extraction/worklet/CMakeLists.txt | 1 + .../worklet/ExtractGeometry.h | 0 vtkm/filter/testing/CMakeLists.txt | 1 - vtkm/worklet/CMakeLists.txt | 1 - vtkm/worklet/testing/CMakeLists.txt | 1 - .../testing/UnitTestExtractGeometry.cxx | 255 ------------------ 14 files changed, 165 insertions(+), 428 deletions(-) delete mode 100644 vtkm/filter/ExtractGeometry.cxx rename vtkm/filter/{ExtractGeometry.hxx => entity_extraction/ExtractGeometry.cxx} (68%) create mode 100644 vtkm/filter/entity_extraction/ExtractGeometry.h rename vtkm/filter/{ => entity_extraction}/testing/UnitTestExtractGeometryFilter.cxx (93%) rename vtkm/{ => filter/entity_extraction}/worklet/ExtractGeometry.h (100%) delete mode 100644 vtkm/worklet/testing/UnitTestExtractGeometry.cxx diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index d84216975..dd93b44c2 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -48,7 +48,6 @@ set(common_headers set(common_header_template_sources CellAverage.hxx CellMeasures.hxx - ExtractGeometry.hxx ExtractStructured.hxx FilterDataSet.hxx FilterDataSetWithField.hxx @@ -62,7 +61,6 @@ set(common_header_template_sources set(common_sources_device CellAverage.cxx - ExtractGeometry.cxx ExtractStructured.cxx PointAverage.cxx Threshold.cxx diff --git a/vtkm/filter/ExtractGeometry.cxx b/vtkm/filter/ExtractGeometry.cxx deleted file mode 100644 index 2ad4287a8..000000000 --- a/vtkm/filter/ExtractGeometry.cxx +++ /dev/null @@ -1,60 +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_ExtractGeometry_cxx - -#include -#include - -#include - -namespace vtkm -{ -namespace filter -{ - -//----------------------------------------------------------------------------- -ExtractGeometry::ExtractGeometry() - : vtkm::filter::FilterDataSet() - , ExtractInside(true) - , ExtractBoundaryCells(false) - , ExtractOnlyBoundaryCells(false) -{ -} - -bool ExtractGeometry::MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field) -{ - if (field.IsFieldPoint()) - { - result.AddField(field); - return true; - } - else if (field.IsFieldCell()) - { - vtkm::cont::ArrayHandle permutation = this->Worklet.GetValidCellIds(); - return vtkm::filter::MapFieldPermutation(field, permutation, result); - } - else if (field.IsFieldGlobal()) - { - result.AddField(field); - return true; - } - else - { - return false; - } -} - -//----------------------------------------------------------------------------- -template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractGeometry::DoExecute( - const vtkm::cont::DataSet& inData, - vtkm::filter::PolicyBase policy); -} -} // namespace vtkm::filter diff --git a/vtkm/filter/ExtractGeometry.h b/vtkm/filter/ExtractGeometry.h index a203aa1ce..869863c83 100644 --- a/vtkm/filter/ExtractGeometry.h +++ b/vtkm/filter/ExtractGeometry.h @@ -7,105 +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_ExtractGeometry_h #define vtk_m_filter_ExtractGeometry_h -#include - -#include -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Extract a subset of geometry based on an implicit function -/// -/// Extracts from its input geometry all cells that are either -/// completely inside or outside of a specified implicit function. Any type of -/// data can be input to this filter. -/// -/// To use this filter you must specify an implicit function. You must also -/// specify whether to extract cells laying inside or outside of the implicit -/// function. (The inside of an implicit function is the negative values -/// region.) An option exists to extract cells that are neither inside or -/// outside (i.e., boundary). -/// -/// This differs from Clip in that Clip will subdivide boundary cells into new -/// cells, while this filter will not, producing a more 'crinkly' output. -/// -class VTKM_FILTER_COMMON_EXPORT ExtractGeometry - : public vtkm::filter::FilterDataSet +VTKM_DEPRECATED( + 1.8, + "Use vtkm/filter/entity_extraction/ExtractGeometry.h instead of vtkm/filter/ExtractGeometry.h.") +inline void ExtractGeometry_deprecated() {} + +inline void ExtractGeometry_deprecated_warning() { -public: - //currently the ExtractGeometry filter only works on scalar data. - using SupportedTypes = TypeListScalarAll; + ExtractGeometry_deprecated(); +} - VTKM_CONT ExtractGeometry(); - - // Set the volume of interest to extract - void SetImplicitFunction(const vtkm::ImplicitFunctionGeneral& func) { this->Function = func; } - - const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; } - - VTKM_CONT - bool GetExtractInside() { return this->ExtractInside; } - VTKM_CONT - void SetExtractInside(bool value) { this->ExtractInside = value; } - VTKM_CONT - void ExtractInsideOn() { this->ExtractInside = true; } - VTKM_CONT - void ExtractInsideOff() { this->ExtractInside = false; } - - VTKM_CONT - bool GetExtractBoundaryCells() { return this->ExtractBoundaryCells; } - VTKM_CONT - void SetExtractBoundaryCells(bool value) { this->ExtractBoundaryCells = value; } - VTKM_CONT - void ExtractBoundaryCellsOn() { this->ExtractBoundaryCells = true; } - VTKM_CONT - void ExtractBoundaryCellsOff() { this->ExtractBoundaryCells = false; } - - VTKM_CONT - bool GetExtractOnlyBoundaryCells() { return this->ExtractOnlyBoundaryCells; } - VTKM_CONT - void SetExtractOnlyBoundaryCells(bool value) { this->ExtractOnlyBoundaryCells = value; } - VTKM_CONT - void ExtractOnlyBoundaryCellsOn() { this->ExtractOnlyBoundaryCells = true; } - VTKM_CONT - void ExtractOnlyBoundaryCellsOff() { this->ExtractOnlyBoundaryCells = false; } - - template - vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy); - - 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: - bool ExtractInside; - bool ExtractBoundaryCells; - bool ExtractOnlyBoundaryCells; - vtkm::ImplicitFunctionGeneral Function; - vtkm::worklet::ExtractGeometry Worklet; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::ExtractGeometry.") ExtractGeometry + : public vtkm::filter::entity_extraction::ExtractGeometry +{ + using entity_extraction::ExtractGeometry::ExtractGeometry; }; -#ifndef vtkm_filter_ExtractGeometry_cxx -extern template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractGeometry::DoExecute( - const vtkm::cont::DataSet&, - vtkm::filter::PolicyBase); -#endif } } // namespace vtkm::filter -#endif // vtk_m_filter_ExtractGeometry_h +#endif //vtk_m_filter_ExtractGeometry_h diff --git a/vtkm/filter/entity_extraction/CMakeLists.txt b/vtkm/filter/entity_extraction/CMakeLists.txt index 0b6a587ba..49e64418a 100644 --- a/vtkm/filter/entity_extraction/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/CMakeLists.txt @@ -9,12 +9,14 @@ ##============================================================================ set(entity_extraction_headers ExternalFaces.h + ExtractGeometry.h ExtractPoints.h MaskPoints.h ThresholdPoints.h ) set(entity_extraction_sources_device ExternalFaces.cxx + ExtractGeometry.cxx ExtractPoints.cxx MaskPoints.cxx ThresholdPoints.cxx diff --git a/vtkm/filter/ExtractGeometry.hxx b/vtkm/filter/entity_extraction/ExtractGeometry.cxx similarity index 68% rename from vtkm/filter/ExtractGeometry.hxx rename to vtkm/filter/entity_extraction/ExtractGeometry.cxx index 2cf06822c..ae3ea033d 100644 --- a/vtkm/filter/ExtractGeometry.hxx +++ b/vtkm/filter/entity_extraction/ExtractGeometry.cxx @@ -1,4 +1,5 @@ //============================================================================ +//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. @@ -7,18 +8,15 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - -#ifndef vtk_m_filter_ExtractGeometry_hxx -#define vtk_m_filter_ExtractGeometry_hxx - -#include -#include #include #include +#include +#include +#include + namespace { - struct CallWorker { vtkm::cont::UnknownCellSet& Output; @@ -57,41 +55,70 @@ struct CallWorker this->ExtractOnlyBoundaryCells); } }; - } // end anon namespace namespace vtkm { namespace filter { - +namespace entity_extraction +{ //----------------------------------------------------------------------------- -template -vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy) +vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input) { // extract the input cell set and coordinates const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); const vtkm::cont::CoordinateSystem& coords = input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()); + vtkm::worklet::ExtractGeometry Worklet; vtkm::cont::UnknownCellSet outCells; CallWorker worker(outCells, - this->Worklet, + Worklet, coords, this->Function, this->ExtractInside, this->ExtractBoundaryCells, this->ExtractOnlyBoundaryCells); - vtkm::filter::ApplyPolicyCellSet(cells, policy, *this).CastAndCall(worker); + cells.CastAndCallForTypes(worker); // create the output dataset vtkm::cont::DataSet output; output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.SetCellSet(outCells); + + auto mapper = [&, this](auto& result, const auto& f) { + this->MapFieldOntoOutput(result, f, Worklet); + }; + MapFieldsOntoOutput(input, output, mapper); + return output; } -} -} -#endif +bool ExtractGeometry::MapFieldOntoOutput(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::worklet::ExtractGeometry& Worklet) +{ + if (field.IsFieldPoint()) + { + result.AddField(field); + return true; + } + else if (field.IsFieldCell()) + { + vtkm::cont::ArrayHandle permutation = Worklet.GetValidCellIds(); + return vtkm::filter::MapFieldPermutation(field, permutation, result); + } + else if (field.IsFieldGlobal()) + { + result.AddField(field); + return true; + } + else + { + return false; + } +} +} // namespace entity_extraction +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/entity_extraction/ExtractGeometry.h b/vtkm/filter/entity_extraction/ExtractGeometry.h new file mode 100644 index 000000000..9def91d15 --- /dev/null +++ b/vtkm/filter/entity_extraction/ExtractGeometry.h @@ -0,0 +1,97 @@ +//============================================================================ +// 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_fulter_entity_extraction_ExtractGeometry_h +#define vtk_m_fulter_entity_extraction_ExtractGeometry_h + +#include +#include +#include + +namespace vtkm +{ +namespace worklet +{ +// Forward declaration for the worklet so we don't need to include the worklet header file +// which would require user code to be compilerd by device compiler. +class ExtractGeometry; +} +namespace filter +{ +namespace entity_extraction +{ +/// \brief Extract a subset of geometry based on an implicit function +/// +/// Extracts from its input geometry all cells that are either +/// completely inside or outside of a specified implicit function. Any type of +/// data can be input to this filter. +/// +/// To use this filter you must specify an implicit function. You must also +/// specify whether to extract cells laying inside or outside of the implicit +/// function. (The inside of an implicit function is the negative values +/// region.) An option exists to extract cells that are neither inside or +/// outside (i.e., boundary). +/// +/// This differs from Clip in that Clip will subdivide boundary cells into new +/// cells, while this filter will not, producing a more 'crinkly' output. +/// +class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT ExtractGeometry : public vtkm::filter::NewFilterField +{ +public: + // Set the volume of interest to extract + void SetImplicitFunction(const vtkm::ImplicitFunctionGeneral& func) { this->Function = func; } + + const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; } + + VTKM_CONT + bool GetExtractInside() { return this->ExtractInside; } + VTKM_CONT + void SetExtractInside(bool value) { this->ExtractInside = value; } + VTKM_CONT + void ExtractInsideOn() { this->ExtractInside = true; } + VTKM_CONT + void ExtractInsideOff() { this->ExtractInside = false; } + + VTKM_CONT + bool GetExtractBoundaryCells() { return this->ExtractBoundaryCells; } + VTKM_CONT + void SetExtractBoundaryCells(bool value) { this->ExtractBoundaryCells = value; } + VTKM_CONT + void ExtractBoundaryCellsOn() { this->ExtractBoundaryCells = true; } + VTKM_CONT + void ExtractBoundaryCellsOff() { this->ExtractBoundaryCells = false; } + + VTKM_CONT + bool GetExtractOnlyBoundaryCells() { return this->ExtractOnlyBoundaryCells; } + VTKM_CONT + void SetExtractOnlyBoundaryCells(bool value) { this->ExtractOnlyBoundaryCells = value; } + VTKM_CONT + void ExtractOnlyBoundaryCellsOn() { this->ExtractOnlyBoundaryCells = true; } + VTKM_CONT + void ExtractOnlyBoundaryCellsOff() { this->ExtractOnlyBoundaryCells = false; } + +private: + VTKM_CONT + vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::worklet::ExtractGeometry&); + + bool ExtractInside = true; + bool ExtractBoundaryCells = false; + bool ExtractOnlyBoundaryCells = false; + vtkm::ImplicitFunctionGeneral Function; +}; +} +} +} // namespace vtkm::filter + +#endif // vtk_m_fulter_entity_extraction_ExtractGeometry_h diff --git a/vtkm/filter/entity_extraction/testing/CMakeLists.txt b/vtkm/filter/entity_extraction/testing/CMakeLists.txt index 60c6256c1..0f2064995 100644 --- a/vtkm/filter/entity_extraction/testing/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/testing/CMakeLists.txt @@ -10,6 +10,7 @@ set(unit_tests UnitTestExternalFacesFilter.cxx + UnitTestExtractGeometryFilter.cxx UnitTestExtractPointsFilter.cxx UnitTestMaskPointsFilter.cxx UnitTestThresholdPointsFilter.cxx diff --git a/vtkm/filter/testing/UnitTestExtractGeometryFilter.cxx b/vtkm/filter/entity_extraction/testing/UnitTestExtractGeometryFilter.cxx similarity index 93% rename from vtkm/filter/testing/UnitTestExtractGeometryFilter.cxx rename to vtkm/filter/entity_extraction/testing/UnitTestExtractGeometryFilter.cxx index 5ca1588aa..e2ecd88e2 100644 --- a/vtkm/filter/testing/UnitTestExtractGeometryFilter.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestExtractGeometryFilter.cxx @@ -11,7 +11,7 @@ #include #include -#include +#include using vtkm::cont::testing::MakeTestDataSet; @@ -32,7 +32,7 @@ public: vtkm::Box box(minPoint, maxPoint); // Setup and run filter to extract by volume of interest - vtkm::filter::ExtractGeometry extractGeometry; + vtkm::filter::entity_extraction::ExtractGeometry extractGeometry; extractGeometry.SetImplicitFunction(box); extractGeometry.SetExtractInside(true); extractGeometry.SetExtractBoundaryCells(false); @@ -59,7 +59,7 @@ public: vtkm::Box box(minPoint, maxPoint); // Setup and run filter to extract by volume of interest - vtkm::filter::ExtractGeometry extractGeometry; + vtkm::filter::entity_extraction::ExtractGeometry extractGeometry; extractGeometry.SetImplicitFunction(box); extractGeometry.SetExtractInside(false); extractGeometry.SetExtractBoundaryCells(false); @@ -86,7 +86,7 @@ public: vtkm::Box box(minPoint, maxPoint); // Setup and run filter to extract by volume of interest - vtkm::filter::ExtractGeometry extractGeometry; + vtkm::filter::entity_extraction::ExtractGeometry extractGeometry; extractGeometry.SetImplicitFunction(box); extractGeometry.SetExtractInside(true); extractGeometry.SetExtractBoundaryCells(true); @@ -112,7 +112,7 @@ public: vtkm::Box box(minPoint, maxPoint); // Setup and run filter to extract by volume of interest - vtkm::filter::ExtractGeometry extractGeometry; + vtkm::filter::entity_extraction::ExtractGeometry extractGeometry; extractGeometry.SetImplicitFunction(box); extractGeometry.SetExtractInside(true); extractGeometry.SetExtractBoundaryCells(true); diff --git a/vtkm/filter/entity_extraction/worklet/CMakeLists.txt b/vtkm/filter/entity_extraction/worklet/CMakeLists.txt index c3f664974..702e975a1 100644 --- a/vtkm/filter/entity_extraction/worklet/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/worklet/CMakeLists.txt @@ -10,6 +10,7 @@ set(headers ExternalFaces.h + ExtractGeometry.h ExtractPoints.h MaskPoints.h ThresholdPoints.h diff --git a/vtkm/worklet/ExtractGeometry.h b/vtkm/filter/entity_extraction/worklet/ExtractGeometry.h similarity index 100% rename from vtkm/worklet/ExtractGeometry.h rename to vtkm/filter/entity_extraction/worklet/ExtractGeometry.h diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index 7ce02c4a1..8341df1ee 100644 --- a/vtkm/filter/testing/CMakeLists.txt +++ b/vtkm/filter/testing/CMakeLists.txt @@ -26,7 +26,6 @@ set(unit_tests UnitTestCoordinateSystemTransform.cxx UnitTestCrossProductFilter.cxx UnitTestEntropyFilter.cxx - UnitTestExtractGeometryFilter.cxx UnitTestExtractStructuredFilter.cxx UnitTestFieldMetadata.cxx UnitTestFieldSelection.cxx diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index 9ee231811..be0b7a95c 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -27,7 +27,6 @@ set(headers DispatcherPointNeighborhood.h DispatcherReduceByKey.h DotProduct.h - ExtractGeometry.h ExtractStructured.h FieldEntropy.h FieldHistogram.h diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index 210f1bbc1..d506b3b32 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -32,7 +32,6 @@ set(unit_tests UnitTestCrossProduct.cxx UnitTestDescriptiveStatistics.cxx UnitTestDotProduct.cxx - UnitTestExtractGeometry.cxx UnitTestExtractStructured.cxx UnitTestFieldHistogram.cxx UnitTestFieldStatistics.cxx diff --git a/vtkm/worklet/testing/UnitTestExtractGeometry.cxx b/vtkm/worklet/testing/UnitTestExtractGeometry.cxx deleted file mode 100644 index 3a4106364..000000000 --- a/vtkm/worklet/testing/UnitTestExtractGeometry.cxx +++ /dev/null @@ -1,255 +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 - -using vtkm::cont::testing::MakeTestDataSet; - -class TestingExtractGeometry -{ -public: - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestExplicitById() const - { - std::cout << "Testing extract cell explicit by id:" << std::endl; - - using CellSetType = vtkm::cont::CellSetExplicit<>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Cells to extract - vtkm::cont::ArrayHandle cellIds = vtkm::cont::make_ArrayHandle({ 1, 2 }); - const vtkm::Id nCells = cellIds.GetNumberOfValues(); - - // Output data set with cell set containing extracted cells and all points - vtkm::worklet::ExtractGeometry extractGeometry; - OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds); - - auto cellvar = - dataset.GetField("cellvar").GetData().AsArrayHandle>(); - auto cellFieldArray = extractGeometry.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells), - "Wrong result for ExtractCells"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells && - cellFieldArray.ReadPortal().Get(0) == 110.f, - "Wrong cell field data"); - } - - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestExplicitByBox() const - { - std::cout << "Testing extract cells with implicit function (box) on explicit:" << std::endl; - - using CellSetType = vtkm::cont::CellSetExplicit<>; - - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Implicit function - vtkm::Vec3f minPoint(0.5f, 0.0f, 0.0f); - vtkm::Vec3f maxPoint(2.0f, 2.0f, 2.0f); - - bool extractInside = true; - bool extractBoundaryCells = false; - bool extractOnlyBoundaryCells = false; - - // Output data set with cell set containing extracted cells and all points - vtkm::worklet::ExtractGeometry extractGeometry; - vtkm::cont::UnknownCellSet outCellSet = - extractGeometry.Run(cellSet, - dataset.GetCoordinateSystem("coordinates"), - vtkm::Box(minPoint, maxPoint), - extractInside, - extractBoundaryCells, - extractOnlyBoundaryCells); - - auto cellvar = - dataset.GetField("cellvar").GetData().AsArrayHandle>(); - auto cellFieldArray = extractGeometry.ProcessCellField(cellvar); - - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 2), "Wrong result for ExtractCells"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 && - cellFieldArray.ReadPortal().Get(1) == 120.2f, - "Wrong cell field data"); - } - - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestUniformById2D() const - { - std::cout << "Testing extract cells structured by id:" << std::endl; - - using CellSetType = vtkm::cont::CellSetStructured<2>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - - - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Cells to extract - vtkm::cont::ArrayHandle cellIds = - vtkm::cont::make_ArrayHandle({ 0, 4, 5, 10, 15 }); - const vtkm::Id nCells = cellIds.GetNumberOfValues(); - - // Output data set permutation of with only extracted cells - vtkm::worklet::ExtractGeometry extractGeometry; - OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds); - - auto cellvar = - dataset.GetField("cellvar").GetData().AsArrayHandle>(); - auto cellFieldArray = extractGeometry.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells), - "Wrong result for ExtractCells"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells && - cellFieldArray.ReadPortal().Get(1) == 4.f, - "Wrong cell field data"); - } - - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestUniformById3D() const - { - std::cout << "Testing extract cells structured by id:" << std::endl; - - using CellSetType = vtkm::cont::CellSetStructured<3>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Cells to extract - vtkm::cont::ArrayHandle cellIds = - vtkm::cont::make_ArrayHandle({ 0, 4, 5, 10, 15 }); - const vtkm::Id nCells = cellIds.GetNumberOfValues(); - - // Output data set with cell set containing extracted cells and all points - vtkm::worklet::ExtractGeometry extractGeometry; - OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds); - - auto cellvar = - dataset.GetField("cellvar").GetData().AsArrayHandle>(); - auto cellFieldArray = extractGeometry.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells), - "Wrong result for ExtractCells"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells && - cellFieldArray.ReadPortal().Get(2) == 5.f, - "Wrong cell field data"); - } - - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestUniformByBox() const - { - std::cout << "Testing extract cells with implicit function (box):" << std::endl; - - using CellSetType = vtkm::cont::CellSetStructured<3>; - - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Implicit function - vtkm::Vec3f minPoint(1.0f, 1.0f, 1.0f); - vtkm::Vec3f maxPoint(3.0f, 3.0f, 3.0f); - - bool extractInside = true; - bool extractBoundaryCells = false; - bool extractOnlyBoundaryCells = false; - - // Output data set with cell set containing extracted points - vtkm::worklet::ExtractGeometry extractGeometry; - vtkm::cont::UnknownCellSet outCellSet = - extractGeometry.Run(cellSet, - dataset.GetCoordinateSystem("coords"), - vtkm::Box(minPoint, maxPoint), - extractInside, - extractBoundaryCells, - extractOnlyBoundaryCells); - - auto cellvar = - dataset.GetField("cellvar").GetData().AsArrayHandle>(); - auto cellFieldArray = extractGeometry.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for ExtractCells"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 && - cellFieldArray.ReadPortal().Get(0) == 21.f, - "Wrong cell field data"); - } - - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestUniformBySphere() const - { - std::cout << "Testing extract cells with implicit function (sphere):" << std::endl; - - using CellSetType = vtkm::cont::CellSetStructured<3>; - - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Implicit function - vtkm::Vec3f center(2.f, 2.f, 2.f); - vtkm::FloatDefault radius(1.8f); - - bool extractInside = true; - bool extractBoundaryCells = false; - bool extractOnlyBoundaryCells = false; - - // Output data set with cell set containing extracted cells - vtkm::worklet::ExtractGeometry extractGeometry; - vtkm::cont::UnknownCellSet outCellSet = - extractGeometry.Run(cellSet, - dataset.GetCoordinateSystem("coords"), - vtkm::Sphere(center, radius), - extractInside, - extractBoundaryCells, - extractOnlyBoundaryCells); - - auto cellvar = - dataset.GetField("cellvar").GetData().AsArrayHandle>(); - auto cellFieldArray = extractGeometry.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for ExtractCells"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 && - cellFieldArray.ReadPortal().Get(1) == 22.f, - "Wrong cell field data"); - } - - void operator()() const - { - this->TestUniformById2D(); - this->TestUniformById3D(); - this->TestUniformBySphere(); - this->TestUniformByBox(); - this->TestExplicitById(); - this->TestExplicitByBox(); - } -}; - -int UnitTestExtractGeometry(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestingExtractGeometry(), argc, argv); -} From 7e08f4fb1b4bd2e045f975cb35e44f0467c80a11 Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Sun, 9 Jan 2022 15:15:39 -0700 Subject: [PATCH 3/7] Migrate ExtractStructured DoMapField add back deprecated ExtractStructured.h --- vtkm/filter/CMakeLists.txt | 2 - vtkm/filter/ExtractStructured.cxx | 68 ---- vtkm/filter/ExtractStructured.h | 125 +------ vtkm/filter/ExtractStructured.hxx | 52 --- vtkm/filter/GhostCellRemove.hxx | 4 +- vtkm/filter/entity_extraction/CMakeLists.txt | 2 + .../entity_extraction/ExtractGeometry.cxx | 66 ++-- .../entity_extraction/ExtractGeometry.h | 4 - .../entity_extraction/ExtractPoints.cxx | 45 +-- vtkm/filter/entity_extraction/ExtractPoints.h | 3 - .../entity_extraction/ExtractStructured.cxx | 88 +++++ .../entity_extraction/ExtractStructured.h | 98 +++++ vtkm/filter/entity_extraction/MaskPoints.cxx | 87 ++--- vtkm/filter/entity_extraction/MaskPoints.h | 2 - .../entity_extraction/ThresholdPoints.cxx | 45 +-- .../entity_extraction/ThresholdPoints.h | 2 - .../entity_extraction/testing/CMakeLists.txt | 1 + .../UnitTestExtractStructuredFilter.cxx | 26 +- .../entity_extraction/worklet/CMakeLists.txt | 1 + .../worklet/ExtractStructured.h | 0 vtkm/filter/testing/CMakeLists.txt | 1 - vtkm/worklet/CMakeLists.txt | 1 - vtkm/worklet/testing/CMakeLists.txt | 1 - .../testing/UnitTestExtractStructured.cxx | 339 ------------------ 24 files changed, 348 insertions(+), 715 deletions(-) delete mode 100644 vtkm/filter/ExtractStructured.cxx delete mode 100644 vtkm/filter/ExtractStructured.hxx create mode 100644 vtkm/filter/entity_extraction/ExtractStructured.cxx create mode 100644 vtkm/filter/entity_extraction/ExtractStructured.h rename vtkm/filter/{ => entity_extraction}/testing/UnitTestExtractStructuredFilter.cxx (96%) rename vtkm/{ => filter/entity_extraction}/worklet/ExtractStructured.h (100%) delete mode 100644 vtkm/worklet/testing/UnitTestExtractStructured.cxx diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index dd93b44c2..130ea9e59 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -48,7 +48,6 @@ set(common_headers set(common_header_template_sources CellAverage.hxx CellMeasures.hxx - ExtractStructured.hxx FilterDataSet.hxx FilterDataSetWithField.hxx FilterField.hxx @@ -61,7 +60,6 @@ set(common_header_template_sources set(common_sources_device CellAverage.cxx - ExtractStructured.cxx PointAverage.cxx Threshold.cxx ) diff --git a/vtkm/filter/ExtractStructured.cxx b/vtkm/filter/ExtractStructured.cxx deleted file mode 100644 index 17145b549..000000000 --- a/vtkm/filter/ExtractStructured.cxx +++ /dev/null @@ -1,68 +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_ExtractStructured_cxx -#include -#include - -#include - -namespace vtkm -{ -namespace filter -{ - -//----------------------------------------------------------------------------- -ExtractStructured::ExtractStructured() - : vtkm::filter::FilterDataSet() - , VOI(vtkm::RangeId3(0, -1, 0, -1, 0, -1)) - , SampleRate(vtkm::Id3(1, 1, 1)) - , IncludeBoundary(false) - , IncludeOffset(false) - , Worklet() -{ -} - -//----------------------------------------------------------------------------- -bool ExtractStructured::MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field) -{ - if (field.IsFieldPoint()) - { - return vtkm::filter::MapFieldPermutation(field, this->PointFieldMap, result); - } - else if (field.IsFieldCell()) - { - return vtkm::filter::MapFieldPermutation(field, this->CellFieldMap, result); - } - else if (field.IsFieldGlobal()) - { - result.AddField(field); - return true; - } - else - { - return false; - } -} - -//----------------------------------------------------------------------------- -void ExtractStructured::PostExecute(const vtkm::cont::PartitionedDataSet&, - vtkm::cont::PartitionedDataSet&) -{ - this->CellFieldMap.ReleaseResources(); - this->PointFieldMap.ReleaseResources(); -} - -//----------------------------------------------------------------------------- -template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractStructured::DoExecute( - const vtkm::cont::DataSet& inData, - vtkm::filter::PolicyBase policy); -} -} diff --git a/vtkm/filter/ExtractStructured.h b/vtkm/filter/ExtractStructured.h index c8e392438..a92bddd6b 100644 --- a/vtkm/filter/ExtractStructured.h +++ b/vtkm/filter/ExtractStructured.h @@ -7,126 +7,35 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_ExtractStructured_h #define vtk_m_filter_ExtractStructured_h -#include - -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Select piece (e.g., volume of interest) and/or subsample structured points dataset -/// -/// Select or subsample a portion of an input structured dataset. The selected -/// portion of interested is referred to as the Volume Of Interest, or VOI. -/// The output of this filter is a structured dataset. The filter treats input -/// data of any topological dimension (i.e., point, line, plane, or volume) and -/// can generate output data of any topological dimension. -/// -/// To use this filter set the VOI ivar which are i-j-k min/max indices that -/// specify a rectangular region in the data. (Note that these are 0-offset.) -/// You can also specify a sampling rate to subsample the data. -/// -/// Typical applications of this filter are to extract a slice from a volume -/// for image processing, subsampling large volumes to reduce data size, or -/// extracting regions of a volume with interesting data. -/// -class VTKM_FILTER_COMMON_EXPORT ExtractStructured - : public vtkm::filter::FilterDataSet + +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/entity_extraction/ExtractStructured.h instead of " + "vtkm/filter/ExtractStructured.h.") +inline void ExtractStructured_deprecated() {} + +inline void ExtractStructured_deprecated_warning() { -public: - ExtractStructured(); + ExtractStructured_deprecated(); +} - // Set the bounding box for the volume of interest - VTKM_CONT - vtkm::RangeId3 GetVOI() const { return this->VOI; } - - VTKM_CONT - void SetVOI(vtkm::Id i0, vtkm::Id i1, vtkm::Id j0, vtkm::Id j1, vtkm::Id k0, vtkm::Id k1) - { - this->VOI = vtkm::RangeId3(i0, i1, j0, j1, k0, k1); - } - VTKM_CONT - void SetVOI(vtkm::Id extents[6]) { this->VOI = vtkm::RangeId3(extents); } - VTKM_CONT - void SetVOI(vtkm::Id3 minPoint, vtkm::Id3 maxPoint) - { - this->VOI = vtkm::RangeId3(minPoint, maxPoint); - } - VTKM_CONT - void SetVOI(const vtkm::RangeId3& voi) { this->VOI = voi; } - - /// Get the Sampling rate - VTKM_CONT - vtkm::Id3 GetSampleRate() const { return this->SampleRate; } - - /// Set the Sampling rate - VTKM_CONT - void SetSampleRate(vtkm::Id i, vtkm::Id j, vtkm::Id k) { this->SampleRate = vtkm::Id3(i, j, k); } - - /// Set the Sampling rate - VTKM_CONT - void SetSampleRate(vtkm::Id3 sampleRate) { this->SampleRate = sampleRate; } - - /// Get if we should include the outer boundary on a subsample - VTKM_CONT - bool GetIncludeBoundary() { return this->IncludeBoundary; } - /// Set if we should include the outer boundary on a subsample - VTKM_CONT - void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; } - - VTKM_CONT - void SetIncludeOffset(bool value) { this->IncludeOffset = value; } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy); - - 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); - } - - - VTKM_CONT void PostExecute(const vtkm::cont::PartitionedDataSet&, - vtkm::cont::PartitionedDataSet&); - - template - VTKM_CONT void PostExecute(const vtkm::cont::PartitionedDataSet& input, - vtkm::cont::PartitionedDataSet& output, - const vtkm::filter::PolicyBase&) - { - this->PostExecute(input, output); - } - -private: - vtkm::RangeId3 VOI; - vtkm::Id3 SampleRate = { 1, 1, 1 }; - bool IncludeBoundary; - bool IncludeOffset; - vtkm::worklet::ExtractStructured Worklet; - - vtkm::cont::ArrayHandle CellFieldMap; - vtkm::cont::ArrayHandle PointFieldMap; +class VTKM_DEPRECATED(1.8, + "Use vtkm::filter::entity_extraction::ExtractStructured.") ExtractStructured + : public vtkm::filter::entity_extraction::ExtractStructured +{ + using entity_extraction::ExtractStructured::ExtractStructured; }; -#ifndef vtkm_filter_ExtractStructured_cxx -extern template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractStructured::DoExecute( - const vtkm::cont::DataSet&, - vtkm::filter::PolicyBase); -#endif } } // namespace vtkm::filter - -#endif // vtk_m_filter_ExtractStructured_h +#endif //vtk_m_filter_ExtractStructured_h diff --git a/vtkm/filter/ExtractStructured.hxx b/vtkm/filter/ExtractStructured.hxx deleted file mode 100644 index 96247ca25..000000000 --- a/vtkm/filter/ExtractStructured.hxx +++ /dev/null @@ -1,52 +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. -//============================================================================ - -#ifndef vtk_m_filter_ExtractStructured_hxx -#define vtk_m_filter_ExtractStructured_hxx -#include - -namespace vtkm -{ -namespace filter -{ -//----------------------------------------------------------------------------- -template -vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy) -{ - const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); - const vtkm::cont::CoordinateSystem& coordinates = input.GetCoordinateSystem(); - - auto cellset = this->Worklet.Run(vtkm::filter::ApplyPolicyCellSetStructured(cells, policy, *this), - this->VOI, - this->SampleRate, - this->IncludeBoundary, - this->IncludeOffset); - - auto coords = this->Worklet.MapCoordinates(coordinates); - vtkm::cont::CoordinateSystem outputCoordinates(coordinates.GetName(), coords); - - vtkm::cont::DataSet output; - output.SetCellSet(vtkm::cont::UnknownCellSet(cellset)); - output.AddCoordinateSystem(outputCoordinates); - - // Create map arrays for mapping fields. Could potentially save some time to first check to see - // if these arrays would be used. - this->CellFieldMap = - this->Worklet.ProcessCellField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfCells())); - this->PointFieldMap = - this->Worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints())); - - return output; -} -} -} - -#endif diff --git a/vtkm/filter/GhostCellRemove.hxx b/vtkm/filter/GhostCellRemove.hxx index c01c46dce..9ec766f2c 100644 --- a/vtkm/filter/GhostCellRemove.hxx +++ b/vtkm/filter/GhostCellRemove.hxx @@ -18,8 +18,8 @@ #include #include -#include #include +#include #include namespace @@ -318,7 +318,7 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute( if (CanDoStructuredStrip( cells, field, this->Invoke, this->GetRemoveAllGhost(), this->GetRemoveType(), range)) { - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; extract.SetInvoker(this->Invoke); vtkm::RangeId3 erange( range.X.Min, range.X.Max + 2, range.Y.Min, range.Y.Max + 2, range.Z.Min, range.Z.Max + 2); diff --git a/vtkm/filter/entity_extraction/CMakeLists.txt b/vtkm/filter/entity_extraction/CMakeLists.txt index 49e64418a..04b4de817 100644 --- a/vtkm/filter/entity_extraction/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/CMakeLists.txt @@ -11,6 +11,7 @@ set(entity_extraction_headers ExternalFaces.h ExtractGeometry.h ExtractPoints.h + ExtractStructured.h MaskPoints.h ThresholdPoints.h ) @@ -18,6 +19,7 @@ set(entity_extraction_sources_device ExternalFaces.cxx ExtractGeometry.cxx ExtractPoints.cxx + ExtractStructured.cxx MaskPoints.cxx ThresholdPoints.cxx ) diff --git a/vtkm/filter/entity_extraction/ExtractGeometry.cxx b/vtkm/filter/entity_extraction/ExtractGeometry.cxx index ae3ea033d..9737ffdd2 100644 --- a/vtkm/filter/entity_extraction/ExtractGeometry.cxx +++ b/vtkm/filter/entity_extraction/ExtractGeometry.cxx @@ -15,6 +15,15 @@ #include #include +namespace +{ + +} // end anon namespace + +namespace vtkm +{ +namespace filter +{ namespace { struct CallWorker @@ -55,12 +64,33 @@ struct CallWorker this->ExtractOnlyBoundaryCells); } }; -} // end anon namespace -namespace vtkm -{ -namespace filter +bool DoMapField(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::worklet::ExtractGeometry& Worklet) { + if (field.IsFieldPoint()) + { + result.AddField(field); + return true; + } + else if (field.IsFieldCell()) + { + vtkm::cont::ArrayHandle permutation = Worklet.GetValidCellIds(); + return vtkm::filter::MapFieldPermutation(field, permutation, result); + } + else if (field.IsFieldGlobal()) + { + result.AddField(field); + return true; + } + else + { + return false; + } +} +} // anonymous namespace + namespace entity_extraction { //----------------------------------------------------------------------------- @@ -87,38 +117,12 @@ vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input) output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.SetCellSet(outCells); - auto mapper = [&, this](auto& result, const auto& f) { - this->MapFieldOntoOutput(result, f, Worklet); - }; + auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; MapFieldsOntoOutput(input, output, mapper); return output; } -bool ExtractGeometry::MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - const vtkm::worklet::ExtractGeometry& Worklet) -{ - if (field.IsFieldPoint()) - { - result.AddField(field); - return true; - } - else if (field.IsFieldCell()) - { - vtkm::cont::ArrayHandle permutation = Worklet.GetValidCellIds(); - return vtkm::filter::MapFieldPermutation(field, permutation, result); - } - else if (field.IsFieldGlobal()) - { - result.AddField(field); - return true; - } - else - { - return false; - } -} } // namespace entity_extraction } // namespace filter } // namespace vtkm diff --git a/vtkm/filter/entity_extraction/ExtractGeometry.h b/vtkm/filter/entity_extraction/ExtractGeometry.h index 9def91d15..46850b8f8 100644 --- a/vtkm/filter/entity_extraction/ExtractGeometry.h +++ b/vtkm/filter/entity_extraction/ExtractGeometry.h @@ -81,10 +81,6 @@ private: VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - const vtkm::worklet::ExtractGeometry&); - bool ExtractInside = true; bool ExtractBoundaryCells = false; bool ExtractOnlyBoundaryCells = false; diff --git a/vtkm/filter/entity_extraction/ExtractPoints.cxx b/vtkm/filter/entity_extraction/ExtractPoints.cxx index fff661373..344f4946b 100644 --- a/vtkm/filter/entity_extraction/ExtractPoints.cxx +++ b/vtkm/filter/entity_extraction/ExtractPoints.cxx @@ -17,6 +17,28 @@ namespace vtkm { namespace filter { +namespace +{ +bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field) +{ + // point data is copied as is because it was not collapsed + if (field.IsFieldPoint()) + { + result.AddField(field); + return true; + } + else if (field.IsFieldGlobal()) + { + result.AddField(field); + return true; + } + else + { + // cell data does not apply + return false; + } +} +} namespace entity_extraction { //----------------------------------------------------------------------------- @@ -40,7 +62,7 @@ vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& input) output.SetCellSet(outCellSet); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&, this](auto& result, const auto& f) { this->MapFieldOntoOutput(result, f); }; + auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); }; this->MapFieldsOntoOutput(input, output, mapper); // compact the unused points in the output dataset @@ -57,27 +79,6 @@ vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& input) } } -//----------------------------------------------------------------------------- -VTKM_CONT bool ExtractPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field) -{ - // point data is copied as is because it was not collapsed - if (field.IsFieldPoint()) - { - result.AddField(field); - return true; - } - else if (field.IsFieldGlobal()) - { - result.AddField(field); - return true; - } - else - { - // cell data does not apply - return false; - } -} } // namespace entity_extraction } // namespace filter } // namespace vtkm diff --git a/vtkm/filter/entity_extraction/ExtractPoints.h b/vtkm/filter/entity_extraction/ExtractPoints.h index e8def5d69..fe850c7cd 100644 --- a/vtkm/filter/entity_extraction/ExtractPoints.h +++ b/vtkm/filter/entity_extraction/ExtractPoints.h @@ -63,9 +63,6 @@ private: VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; - //Map a new field onto the resulting dataset after running the filter - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field); - bool ExtractInside = true; vtkm::ImplicitFunctionGeneral Function; diff --git a/vtkm/filter/entity_extraction/ExtractStructured.cxx b/vtkm/filter/entity_extraction/ExtractStructured.cxx new file mode 100644 index 000000000..c69c8dab5 --- /dev/null +++ b/vtkm/filter/entity_extraction/ExtractStructured.cxx @@ -0,0 +1,88 @@ +//============================================================================ +// 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 + +namespace vtkm +{ +namespace filter +{ +namespace +{ +VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::cont::ArrayHandle& CellFieldMap, + const vtkm::cont::ArrayHandle& PointFieldMap) +{ + if (field.IsFieldPoint()) + { + return vtkm::filter::MapFieldPermutation(field, PointFieldMap, result); + } + else if (field.IsFieldCell()) + { + return vtkm::filter::MapFieldPermutation(field, CellFieldMap, result); + } + else if (field.IsFieldGlobal()) + { + result.AddField(field); + return true; + } + else + { + return false; + } +} + +} // anonymous namespace + +namespace entity_extraction +{ +//----------------------------------------------------------------------------- +vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& input) +{ + const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); + const vtkm::cont::CoordinateSystem& coordinates = input.GetCoordinateSystem(); + + vtkm::worklet::ExtractStructured Worklet; + auto cellset = Worklet.Run(cells.ResetCellSetList(), + this->VOI, + this->SampleRate, + this->IncludeBoundary, + this->IncludeOffset); + + auto coords = Worklet.MapCoordinates(coordinates); + vtkm::cont::CoordinateSystem outputCoordinates(coordinates.GetName(), coords); + + vtkm::cont::DataSet output; + output.SetCellSet(vtkm::cont::UnknownCellSet(cellset)); + output.AddCoordinateSystem(outputCoordinates); + + // Create map arrays for mapping fields. Could potentially save some time to first check to see + // if these arrays would be used. + auto CellFieldMap = + Worklet.ProcessCellField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfCells())); + auto PointFieldMap = + Worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints())); + + auto mapper = [&, this](auto& result, const auto& f) { + DoMapField(result, f, CellFieldMap, PointFieldMap); + }; + MapFieldsOntoOutput(input, output, mapper); + + return output; +} + +} // namespace entity_extraction +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/entity_extraction/ExtractStructured.h b/vtkm/filter/entity_extraction/ExtractStructured.h new file mode 100644 index 000000000..081db8747 --- /dev/null +++ b/vtkm/filter/entity_extraction/ExtractStructured.h @@ -0,0 +1,98 @@ +//============================================================================ +// 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_ExtractStructured_h +#define vtk_m_filter_entity_extraction_ExtractStructured_h + +#include +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace entity_extraction +{ +/// \brief Select piece (e.g., volume of interest) and/or subsample structured points dataset +/// +/// Select or subsample a portion of an input structured dataset. The selected +/// portion of interested is referred to as the Volume Of Interest, or VOI. +/// The output of this filter is a structured dataset. The filter treats input +/// data of any topological dimension (i.e., point, line, plane, or volume) and +/// can generate output data of any topological dimension. +/// +/// To use this filter set the VOI ivar which are i-j-k min/max indices that +/// specify a rectangular region in the data. (Note that these are 0-offset.) +/// You can also specify a sampling rate to subsample the data. +/// +/// Typical applications of this filter are to extract a slice from a volume +/// for image processing, subsampling large volumes to reduce data size, or +/// extracting regions of a volume with interesting data. +/// +class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT ExtractStructured : public vtkm::filter::NewFilterField +{ +public: + // Set the bounding box for the volume of interest + VTKM_CONT + vtkm::RangeId3 GetVOI() const { return this->VOI; } + + VTKM_CONT + void SetVOI(vtkm::Id i0, vtkm::Id i1, vtkm::Id j0, vtkm::Id j1, vtkm::Id k0, vtkm::Id k1) + { + this->VOI = vtkm::RangeId3(i0, i1, j0, j1, k0, k1); + } + VTKM_CONT + void SetVOI(vtkm::Id extents[6]) { this->VOI = vtkm::RangeId3(extents); } + VTKM_CONT + void SetVOI(vtkm::Id3 minPoint, vtkm::Id3 maxPoint) + { + this->VOI = vtkm::RangeId3(minPoint, maxPoint); + } + VTKM_CONT + void SetVOI(const vtkm::RangeId3& voi) { this->VOI = voi; } + + /// Get the Sampling rate + VTKM_CONT + vtkm::Id3 GetSampleRate() const { return this->SampleRate; } + + /// Set the Sampling rate + VTKM_CONT + void SetSampleRate(vtkm::Id i, vtkm::Id j, vtkm::Id k) { this->SampleRate = vtkm::Id3(i, j, k); } + + /// Set the Sampling rate + VTKM_CONT + void SetSampleRate(vtkm::Id3 sampleRate) { this->SampleRate = sampleRate; } + + /// Get if we should include the outer boundary on a subsample + VTKM_CONT + bool GetIncludeBoundary() { return this->IncludeBoundary; } + /// Set if we should include the outer boundary on a subsample + VTKM_CONT + void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; } + + VTKM_CONT + void SetIncludeOffset(bool value) { this->IncludeOffset = value; } + +private: + VTKM_CONT + vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + vtkm::RangeId3 VOI = vtkm::RangeId3(0, -1, 0, -1, 0, -1); + vtkm::Id3 SampleRate = { 1, 1, 1 }; + bool IncludeBoundary = false; + bool IncludeOffset = false; +}; + +} // namespace entity_extraction +} // namespace filter +} // namespace vtkm + +#endif // vtk_m_filter_entity_extraction_ExtractStructured_h diff --git a/vtkm/filter/entity_extraction/MaskPoints.cxx b/vtkm/filter/entity_extraction/MaskPoints.cxx index dd61fa211..7693d0f60 100644 --- a/vtkm/filter/entity_extraction/MaskPoints.cxx +++ b/vtkm/filter/entity_extraction/MaskPoints.cxx @@ -12,49 +12,9 @@ #include #include -namespace vtkm +namespace { -namespace filter -{ -namespace entity_extraction -{ -//----------------------------------------------------------------------------- -VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute(const vtkm::cont::DataSet& input) -{ - // extract the input cell set - const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); - - // run the worklet on the cell set and input field - vtkm::cont::CellSetSingleType<> outCellSet; - vtkm::worklet::MaskPoints worklet; - - outCellSet = worklet.Run(cells, this->Stride); - - // create the output dataset - vtkm::cont::DataSet output; - output.SetCellSet(outCellSet); - output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - - auto mapper = [&, this](auto& result, const auto& f) { this->MapFieldOntoOutput(result, f); }; - this->MapFieldsOntoOutput(input, output, mapper); - - // compact the unused points in the output dataset - if (this->CompactPoints) - { - vtkm::filter::clean_grid::CleanGrid compactor; - compactor.SetCompactPointFields(true); - compactor.SetMergePoints(false); - return compactor.Execute(output); - } - else - { - return output; - } -} - -//----------------------------------------------------------------------------- -VTKM_CONT bool MaskPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field) +bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field) { // point data is copied as is because it was not collapsed if (field.IsFieldPoint()) @@ -73,6 +33,49 @@ VTKM_CONT bool MaskPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result, return false; } } +} // anonymous namespace + +namespace vtkm +{ +namespace filter +{ +namespace entity_extraction +{ + +//----------------------------------------------------------------------------- +VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute(const vtkm::cont::DataSet& input) +{ + // extract the input cell set + const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); + + // run the worklet on the cell set and input field + vtkm::cont::CellSetSingleType<> outCellSet; + vtkm::worklet::MaskPoints worklet; + + outCellSet = worklet.Run(cells, this->Stride); + + // create the output dataset + vtkm::cont::DataSet output; + output.SetCellSet(outCellSet); + output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); + + auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); }; + this->MapFieldsOntoOutput(input, output, mapper); + + // compact the unused points in the output dataset + if (this->CompactPoints) + { + vtkm::filter::clean_grid::CleanGrid compactor; + compactor.SetCompactPointFields(true); + compactor.SetMergePoints(false); + return compactor.Execute(output); + } + else + { + return output; + } +} + } // namespace entity_extraction } // namespace filter } // namespace vtkm diff --git a/vtkm/filter/entity_extraction/MaskPoints.h b/vtkm/filter/entity_extraction/MaskPoints.h index 6c8520b2b..fd78043a6 100644 --- a/vtkm/filter/entity_extraction/MaskPoints.h +++ b/vtkm/filter/entity_extraction/MaskPoints.h @@ -42,8 +42,6 @@ private: VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field); - vtkm::Id Stride = 1; bool CompactPoints = true; }; diff --git a/vtkm/filter/entity_extraction/ThresholdPoints.cxx b/vtkm/filter/entity_extraction/ThresholdPoints.cxx index 8276ab98b..d5435816b 100644 --- a/vtkm/filter/entity_extraction/ThresholdPoints.cxx +++ b/vtkm/filter/entity_extraction/ThresholdPoints.cxx @@ -77,12 +77,34 @@ private: vtkm::Float64 Lower; vtkm::Float64 Upper; }; + +bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field) +{ + // point data is copied as is because it was not collapsed + if (field.IsFieldPoint()) + { + result.AddField(field); + return true; + } + else if (field.IsFieldGlobal()) + { + result.AddField(field); + return true; + } + else + { + // cell data does not apply + return false; + } } +} // anonymous namespace + namespace vtkm { namespace filter { + namespace entity_extraction { //----------------------------------------------------------------------------- @@ -156,7 +178,7 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS output.SetCellSet(outCellSet); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&, this](auto& result, const auto& f) { this->MapFieldOntoOutput(result, f); }; + auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); }; this->MapFieldsOntoOutput(input, output, mapper); // compact the unused points in the output dataset @@ -173,27 +195,6 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS } } -//----------------------------------------------------------------------------- -VTKM_CONT bool ThresholdPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field) -{ - // point data is copied as is because it was not collapsed - if (field.IsFieldPoint()) - { - result.AddField(field); - return true; - } - else if (field.IsFieldGlobal()) - { - result.AddField(field); - return true; - } - else - { - // cell data does not apply - return false; - } -} } // namespace entity_extraction } // namespace filter } // namespace vtkm diff --git a/vtkm/filter/entity_extraction/ThresholdPoints.h b/vtkm/filter/entity_extraction/ThresholdPoints.h index 93de92a24..a2cda39ee 100644 --- a/vtkm/filter/entity_extraction/ThresholdPoints.h +++ b/vtkm/filter/entity_extraction/ThresholdPoints.h @@ -51,8 +51,6 @@ private: VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field); - constexpr static int THRESHOLD_BELOW = 0; constexpr static int THRESHOLD_ABOVE = 1; constexpr static int THRESHOLD_BETWEEN = 2; diff --git a/vtkm/filter/entity_extraction/testing/CMakeLists.txt b/vtkm/filter/entity_extraction/testing/CMakeLists.txt index 0f2064995..43454d99b 100644 --- a/vtkm/filter/entity_extraction/testing/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/testing/CMakeLists.txt @@ -12,6 +12,7 @@ set(unit_tests UnitTestExternalFacesFilter.cxx UnitTestExtractGeometryFilter.cxx UnitTestExtractPointsFilter.cxx + UnitTestExtractStructuredFilter.cxx UnitTestMaskPointsFilter.cxx UnitTestThresholdPointsFilter.cxx ) diff --git a/vtkm/filter/testing/UnitTestExtractStructuredFilter.cxx b/vtkm/filter/entity_extraction/testing/UnitTestExtractStructuredFilter.cxx similarity index 96% rename from vtkm/filter/testing/UnitTestExtractStructuredFilter.cxx rename to vtkm/filter/entity_extraction/testing/UnitTestExtractStructuredFilter.cxx index aeb37dc37..32f23ce55 100644 --- a/vtkm/filter/testing/UnitTestExtractStructuredFilter.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestExtractStructuredFilter.cxx @@ -11,7 +11,7 @@ #include #include -#include +#include using vtkm::cont::testing::MakeTestDataSet; @@ -29,7 +29,7 @@ public: vtkm::RangeId3 range(1, 4, 1, 4, 0, 1); vtkm::Id3 sample(1, 1, 1); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; extract.SetVOI(range); extract.SetSampleRate(sample); @@ -63,7 +63,7 @@ public: std::cout << "Testing extract structured uniform" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // VOI within dataset extract.SetVOI(1, 4, 1, 4, 1, 4); @@ -99,7 +99,7 @@ public: std::cout << "Testing extract structured uniform" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // VOI surrounds dataset vtkm::Id3 minPoint(-1, -1, -1); @@ -136,7 +136,7 @@ public: { std::cout << "Testing extract structured uniform" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // VOI surrounds dataset vtkm::RangeId3 range(-1, 3, -1, 3, -1, 3); @@ -173,7 +173,7 @@ public: { std::cout << "Testing extract structured uniform" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // RangeId3 intersects dataset on far boundary vtkm::RangeId3 range(1, 8, 1, 8, 1, 8); @@ -211,7 +211,7 @@ public: std::cout << "Testing extract structured uniform" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // RangeId3 intersects dataset without corner vtkm::RangeId3 range(2, 8, 1, 4, 1, 4); @@ -249,7 +249,7 @@ public: std::cout << "Testing extract structured uniform" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // RangeId3 intersects dataset with plane vtkm::RangeId3 range(2, 8, 1, 2, 1, 4); @@ -287,7 +287,7 @@ public: std::cout << "Testing extract structured uniform" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // RangeId3 within data set with sampling vtkm::RangeId3 range(0, 5, 0, 5, 1, 4); @@ -325,7 +325,7 @@ public: std::cout << "Testing extract structured uniform" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // RangeId3 within data set with sampling vtkm::RangeId3 range(0, 5, 0, 5, 1, 4); @@ -361,7 +361,7 @@ public: { std::cout << "Testing extract structured uniform" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // RangeId3 within data set with sampling vtkm::RangeId3 range(0, 5, 0, 5, 1, 4); @@ -401,7 +401,7 @@ public: std::cout << "Testing extract structured rectilinear" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DRectilinearDataSet0(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // RangeId3 vtkm::RangeId3 range(0, 2, 0, 2, 0, 1); @@ -438,7 +438,7 @@ public: std::cout << "Testing extract structured rectilinear" << std::endl; vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DRectilinearDataSet0(); - vtkm::filter::ExtractStructured extract; + vtkm::filter::entity_extraction::ExtractStructured extract; // RangeId3 and subsample vtkm::RangeId3 range(0, 2, 0, 2, 0, 2); diff --git a/vtkm/filter/entity_extraction/worklet/CMakeLists.txt b/vtkm/filter/entity_extraction/worklet/CMakeLists.txt index 702e975a1..868a52030 100644 --- a/vtkm/filter/entity_extraction/worklet/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/worklet/CMakeLists.txt @@ -11,6 +11,7 @@ set(headers ExternalFaces.h ExtractGeometry.h + ExtractStructured.h ExtractPoints.h MaskPoints.h ThresholdPoints.h diff --git a/vtkm/worklet/ExtractStructured.h b/vtkm/filter/entity_extraction/worklet/ExtractStructured.h similarity index 100% rename from vtkm/worklet/ExtractStructured.h rename to vtkm/filter/entity_extraction/worklet/ExtractStructured.h diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index 8341df1ee..3214d04fb 100644 --- a/vtkm/filter/testing/CMakeLists.txt +++ b/vtkm/filter/testing/CMakeLists.txt @@ -26,7 +26,6 @@ set(unit_tests UnitTestCoordinateSystemTransform.cxx UnitTestCrossProductFilter.cxx UnitTestEntropyFilter.cxx - UnitTestExtractStructuredFilter.cxx UnitTestFieldMetadata.cxx UnitTestFieldSelection.cxx UnitTestFieldToColors.cxx diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index be0b7a95c..683bca8af 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -27,7 +27,6 @@ set(headers DispatcherPointNeighborhood.h DispatcherReduceByKey.h DotProduct.h - ExtractStructured.h FieldEntropy.h FieldHistogram.h FieldStatistics.h diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index d506b3b32..1dd4c51c5 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -32,7 +32,6 @@ set(unit_tests UnitTestCrossProduct.cxx UnitTestDescriptiveStatistics.cxx UnitTestDotProduct.cxx - UnitTestExtractStructured.cxx UnitTestFieldHistogram.cxx UnitTestFieldStatistics.cxx UnitTestGraphConnectivity.cxx diff --git a/vtkm/worklet/testing/UnitTestExtractStructured.cxx b/vtkm/worklet/testing/UnitTestExtractStructured.cxx deleted file mode 100644 index de000e2a1..000000000 --- a/vtkm/worklet/testing/UnitTestExtractStructured.cxx +++ /dev/null @@ -1,339 +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 - -using vtkm::cont::testing::MakeTestDataSet; - -class TestingExtractStructured -{ -public: - void TestUniform2D() const - { - std::cout << "Testing extract structured uniform 2D" << std::endl; - using CellSetType = vtkm::cont::CellSetStructured<2>; - - // Create the input uniform cell set - vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DUniformDataSet1(); - CellSetType cellSet; - dataSet.GetCellSet().AsCellSet(cellSet); - - // RangeId3 and subsample - vtkm::RangeId3 range(1, 4, 1, 4, 0, 1); - vtkm::Id3 sample(1, 1, 1); - bool includeBoundary = false; - bool includeOffset = false; - - vtkm::worklet::ExtractStructured worklet; - auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 9), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4), - "Wrong result for ExtractStructured worklet"); - } - - void TestUniform3D() const - { - std::cout << "Testing extract structured uniform 3D" << std::endl; - using CellSetType = vtkm::cont::CellSetStructured<3>; - - // Create the input uniform cell set - vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet1(); - CellSetType cellSet; - dataSet.GetCellSet().AsCellSet(cellSet); - - vtkm::worklet::ExtractStructured worklet; - vtkm::worklet::ExtractStructured::UncertainCellSetStructured outCellSet; - - // RangeId3 within dataset - vtkm::RangeId3 range0(1, 4, 1, 4, 1, 4); - vtkm::Id3 sample(1, 1, 1); - bool includeBoundary = false; - bool includeOffset = false; - - outCellSet = worklet.Run(cellSet, range0, sample, includeBoundary, includeOffset); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), - "Wrong result for ExtractStructured worklet"); - - // RangeId3 surrounds dataset - vtkm::RangeId3 range1(-1, 8, -1, 8, -1, 8); - outCellSet = worklet.Run(cellSet, range1, sample, includeBoundary, includeOffset); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 125), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 64), - "Wrong result for ExtractStructured worklet"); - - // RangeId3 intersects dataset on near boundary - vtkm::RangeId3 range2(-1, 3, -1, 3, -1, 3); - outCellSet = worklet.Run(cellSet, range2, sample, includeBoundary, includeOffset); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), - "Wrong result for ExtractStructured worklet"); - - // RangeId3 intersects dataset on far boundary - vtkm::RangeId3 range3(1, 8, 1, 8, 1, 8); - outCellSet = worklet.Run(cellSet, range3, sample, includeBoundary, includeOffset); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 64), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27), - "Wrong result for ExtractStructured worklet"); - - // RangeId3 intersects dataset without corner - vtkm::RangeId3 range4(2, 8, 1, 4, 1, 4); - outCellSet = worklet.Run(cellSet, range4, sample, includeBoundary, includeOffset); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), - "Wrong result for ExtractStructured worklet"); - - // RangeId3 intersects dataset with plane - vtkm::RangeId3 range5(2, 8, 1, 2, 1, 4); - outCellSet = worklet.Run(cellSet, range5, sample, includeBoundary, includeOffset); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 9), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4), - "Wrong result for ExtractStructured worklet"); - } - - void TestUniform3D1() const - { - std::cout << "Testing extract structured uniform with sampling" << std::endl; - using CellSetType = vtkm::cont::CellSetStructured<3>; - - // Create the input uniform cell set - vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet1(); - CellSetType cellSet; - dataSet.GetCellSet().AsCellSet(cellSet); - - vtkm::worklet::ExtractStructured worklet; - vtkm::worklet::ExtractStructured::UncertainCellSetStructured outCellSet; - - // RangeId3 within data set with sampling - vtkm::RangeId3 range0(0, 5, 0, 5, 1, 4); - vtkm::Id3 sample0(2, 2, 1); - bool includeBoundary0 = false; - bool includeOffset = false; - - outCellSet = worklet.Run(cellSet, range0, sample0, includeBoundary0, includeOffset); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), - "Wrong result for ExtractStructured worklet"); - - // RangeId3 and subsample - vtkm::RangeId3 range1(0, 5, 0, 5, 1, 4); - vtkm::Id3 sample1(3, 3, 2); - bool includeBoundary1 = false; - - outCellSet = worklet.Run(cellSet, range1, sample1, includeBoundary1, includeOffset); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 8), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1), - "Wrong result for ExtractStructured worklet"); - - // RangeId3 and subsample - vtkm::RangeId3 range2(0, 5, 0, 5, 1, 4); - vtkm::Id3 sample2(3, 3, 2); - bool includeBoundary2 = true; - - outCellSet = worklet.Run(cellSet, range2, sample2, includeBoundary2, includeOffset); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 18), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4), - "Wrong result for ExtractStructured worklet"); - } - - void TestRectilinear2D() const - { - std::cout << "Testing extract structured rectilinear" << std::endl; - using CellSetType = vtkm::cont::CellSetStructured<2>; - - // Create the input uniform cell set - vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DRectilinearDataSet0(); - CellSetType cellSet; - dataSet.GetCellSet().AsCellSet(cellSet); - - // RangeId3 and subsample - vtkm::RangeId3 range(0, 2, 0, 2, 0, 1); - vtkm::Id3 sample(1, 1, 1); - bool includeBoundary = false; - bool includeOffset = false; - - // Extract subset - vtkm::worklet::ExtractStructured worklet; - auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 4), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1), - "Wrong result for ExtractStructured worklet"); - } - - void TestRectilinear3D() const - { - std::cout << "Testing extract structured rectilinear" << std::endl; - using CellSetType = vtkm::cont::CellSetStructured<3>; - - // Create the input uniform cell set - vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DRectilinearDataSet0(); - CellSetType cellSet; - dataSet.GetCellSet().AsCellSet(cellSet); - - // RangeId3 and subsample - vtkm::RangeId3 range(0, 2, 0, 2, 0, 2); - vtkm::Id3 sample(1, 1, 1); - bool includeBoundary = false; - bool includeOffset = false; - - // Extract subset - vtkm::worklet::ExtractStructured worklet; - auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 8), - "Wrong result for ExtractStructured worklet"); - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1), - "Wrong result for ExtractStructured worklet"); - } - - void TestOffset3D1() const - { - std::cout << "Testing offset 3D-1" << std::endl; - using CellSetType = vtkm::cont::CellSetStructured<3>; - - CellSetType cellSet; - - // RangeID3 and subsample - vtkm::RangeId3 range(5, 15, 0, 10, 0, 10); - vtkm::Id3 sample(1, 1, 1); - vtkm::Id3 test_offset(10, 0, 0); - vtkm::Id3 no_offset(0, 0, 0); - vtkm::Id3 new_dims(5, 10, 10); - bool includeBoundary = false; - bool includeOffset = false; - cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10)); - - vtkm::worklet::ExtractStructured worklet; - auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset); - - VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), no_offset)); - vtkm::Id3 cellDims = - outCellSet.AsCellSet().GetSchedulingRange(vtkm::TopologyElementTagCell()); - - includeOffset = true; - cellSet.SetGlobalPointIndexStart(test_offset); - outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset); - cellDims = - outCellSet.AsCellSet().GetSchedulingRange(vtkm::TopologyElementTagCell()); - CellSetType cs = outCellSet.AsCellSet(); - cellDims = cs.GetPointDimensions(); - VTKM_TEST_ASSERT(test_equal(cellDims, new_dims)); - VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), test_offset)); - } - - void TestOffset3D2() const - { - std::cout << "Testing Offset 3D-2" << std::endl; - using CellSetType = vtkm::cont::CellSetStructured<3>; - CellSetType cellSet; - vtkm::RangeId3 range(15, 20, 0, 10, 0, 10); - vtkm::Id3 sample(1, 1, 1); - vtkm::Id3 test_dims(5, 10, 10); - vtkm::Id3 gpis(10, 0, 0); - vtkm::Id3 test_offset(15, 0, 0); - bool includeBoundary = false; - bool includeOffset = true; - cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10)); - cellSet.SetGlobalPointIndexStart(gpis); - vtkm::worklet::ExtractStructured worklet; - - auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset); - CellSetType cs = outCellSet.AsCellSet(); - vtkm::Id3 cellDims = cs.GetPointDimensions(); - VTKM_TEST_ASSERT(test_equal(cellDims, test_dims)); - VTKM_TEST_ASSERT(test_equal(cs.GetGlobalPointIndexStart(), test_offset)); - } - - void TestOffset3D3() const - { - std::cout << "Testing Offset 3D-3" << std::endl; - using CellSetType = vtkm::cont::CellSetStructured<3>; - CellSetType cellSet; - vtkm::RangeId3 range(100, 110, 0, 10, 0, 10); - vtkm::Id3 sample(1, 1, 1); - vtkm::Id3 test_dims(0, 0, 0); - bool includeBoundary = false; - bool includeOffset = true; - cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10)); - vtkm::worklet::ExtractStructured worklet; - - auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset); - CellSetType cs = outCellSet.AsCellSet(); - VTKM_TEST_ASSERT(test_equal(cs.GetPointDimensions(), test_dims)); - } - void TestOffset2D() const - { - std::cout << "Testing offset 2D" << std::endl; - using CellSetType = vtkm::cont::CellSetStructured<2>; - CellSetType cellSet; - // RangeID3 and subsample - vtkm::RangeId3 range(5, 15, 0, 10, 0, 1); - vtkm::Id3 sample(1, 1, 1); - vtkm::Id2 test_offset(10, 0); - vtkm::Id2 no_offset(0, 0); - vtkm::Id2 new_dims(5, 10); - bool includeBoundary = false; - bool includeOffset = false; - cellSet.SetPointDimensions(vtkm::make_Vec(10, 10)); - vtkm::worklet::ExtractStructured worklet; - auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset); - VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), no_offset)); - vtkm::Id2 cellDims = - outCellSet.AsCellSet().GetSchedulingRange(vtkm::TopologyElementTagCell()); - // Test with offset now - includeOffset = true; - cellSet.SetGlobalPointIndexStart(test_offset); - outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset); - cellDims = - outCellSet.AsCellSet().GetSchedulingRange(vtkm::TopologyElementTagCell()); - CellSetType cs = outCellSet.AsCellSet(); - cellDims = cs.GetPointDimensions(); - VTKM_TEST_ASSERT(test_equal(cellDims, new_dims)); - VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), test_offset)); - } - - void operator()() const - { - TestUniform2D(); - TestUniform3D(); - TestUniform3D1(); - TestRectilinear2D(); - TestRectilinear3D(); - TestOffset3D1(); - TestOffset3D2(); - TestOffset3D3(); - TestOffset2D(); - } -}; - -int UnitTestExtractStructured(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestingExtractStructured(), argc, argv); -} From 679f1b00e97360717d4d8288ceab35949ddcfed8 Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Mon, 10 Jan 2022 09:15:30 -0700 Subject: [PATCH 4/7] 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); -} From e8278094f9822c0c8d4cdefc18be1a13fbde68af Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Mon, 10 Jan 2022 11:11:12 -0700 Subject: [PATCH 5/7] migrate Mask tidy up language and library usage update benchmark --- benchmarking/BenchmarkFilters.cxx | 2 +- vtkm/filter/CMakeLists.txt | 1 - vtkm/filter/Mask.h | 55 +++----- vtkm/filter/entity_extraction/CMakeLists.txt | 2 + .../entity_extraction/ExternalFaces.cxx | 3 +- vtkm/filter/entity_extraction/ExternalFaces.h | 2 +- .../entity_extraction/ExtractGeometry.cxx | 2 +- .../entity_extraction/ExtractGeometry.h | 6 +- .../entity_extraction/ExtractPoints.cxx | 13 +- vtkm/filter/entity_extraction/ExtractPoints.h | 2 +- .../entity_extraction/ExtractStructured.cxx | 3 +- .../entity_extraction/ExtractStructured.h | 2 +- .../entity_extraction/GhostCellRemove.cxx | 6 +- .../entity_extraction/GhostCellRemove.h | 2 +- .../{Mask.hxx => entity_extraction/Mask.cxx} | 79 ++++++------ vtkm/filter/entity_extraction/Mask.h | 53 ++++++++ vtkm/filter/entity_extraction/MaskPoints.cxx | 2 +- vtkm/filter/entity_extraction/Threshold.cxx | 2 +- .../entity_extraction/ThresholdPoints.cxx | 6 +- .../entity_extraction/ThresholdPoints.h | 6 +- .../entity_extraction/testing/CMakeLists.txt | 1 + .../testing/UnitTestGhostCellRemove.cxx | 49 ++++---- .../testing/UnitTestMaskFilter.cxx | 8 +- .../entity_extraction/worklet/CMakeLists.txt | 1 + .../worklet/ExtractGeometry.h | 7 +- .../entity_extraction/worklet/ExtractPoints.h | 13 +- .../worklet/ExtractStructured.h | 15 +-- .../entity_extraction}/worklet/Mask.h | 2 - .../entity_extraction/worklet/MaskPoints.h | 1 - .../entity_extraction/worklet/Threshold.h | 2 - .../worklet/ThresholdPoints.h | 11 +- vtkm/filter/testing/CMakeLists.txt | 1 - vtkm/worklet/CMakeLists.txt | 1 - vtkm/worklet/testing/CMakeLists.txt | 1 - vtkm/worklet/testing/UnitTestMask.cxx | 119 ------------------ 35 files changed, 188 insertions(+), 293 deletions(-) rename vtkm/filter/{Mask.hxx => entity_extraction/Mask.cxx} (59%) create mode 100644 vtkm/filter/entity_extraction/Mask.h rename vtkm/filter/{ => entity_extraction}/testing/UnitTestMaskFilter.cxx (94%) rename vtkm/{ => filter/entity_extraction}/worklet/Mask.h (96%) delete mode 100644 vtkm/worklet/testing/UnitTestMask.cxx diff --git a/benchmarking/BenchmarkFilters.cxx b/benchmarking/BenchmarkFilters.cxx index 076bb2c9a..3dd748713 100644 --- a/benchmarking/BenchmarkFilters.cxx +++ b/benchmarking/BenchmarkFilters.cxx @@ -193,7 +193,7 @@ void BenchThreshold(::benchmark::State& state) vtkm::Float64 quarter = range.Length() / 4.; vtkm::Float64 mid = range.Center(); - vtkm::filter::Threshold filter; + vtkm::filter::entity_extraction::Threshold filter; filter.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::POINTS); filter.SetLowerThreshold(mid - quarter); filter.SetUpperThreshold(mid + quarter); diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index e16f9ab77..c774ef855 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -139,7 +139,6 @@ set(extra_header_template_sources ImageMedian.hxx Lagrangian.hxx LagrangianStructures.hxx - Mask.hxx MeshQuality.hxx MIRFilter.hxx NDEntropy.hxx diff --git a/vtkm/filter/Mask.h b/vtkm/filter/Mask.h index 2eb870495..4eabdb99f 100644 --- a/vtkm/filter/Mask.h +++ b/vtkm/filter/Mask.h @@ -7,57 +7,32 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_Mask_h #define vtk_m_filter_Mask_h -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Subselect cells using a stride -/// -/// Extract only every Nth cell where N is equal to a stride value -class Mask : public vtkm::filter::FilterDataSet + +VTKM_DEPRECATED(1.8, "Use vtkm/filter/entity_extraction/Mask.h instead of vtkm/filter/Mask.h.") +inline void Mask_deprecated() {} + +inline void Mask_deprecated_warning() { -public: - VTKM_CONT - Mask(); + Mask_deprecated(); +} - // When CompactPoints is set, instead of copying the points and point fields - // from the input, the filter will create new compact fields without the unused elements - VTKM_CONT - bool GetCompactPoints() const { return this->CompactPoints; } - VTKM_CONT - void SetCompactPoints(bool value) { this->CompactPoints = value; } - - // Set the stride of the subsample - VTKM_CONT - vtkm::Id GetStride() const { return this->Stride; } - VTKM_CONT - void SetStride(vtkm::Id& stride) { this->Stride = stride; } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy); - - //Map a new field onto the resulting dataset after running the filter - template - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase policy); - -private: - vtkm::Id Stride; - bool CompactPoints; - vtkm::worklet::Mask Worklet; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::Mask.") Mask + : public vtkm::filter::entity_extraction::Mask +{ + using entity_extraction::Mask::Mask; }; + } } // namespace vtkm::filter -#include - -#endif // vtk_m_filter_Mask_h +#endif //vtk_m_filter_Mask_h diff --git a/vtkm/filter/entity_extraction/CMakeLists.txt b/vtkm/filter/entity_extraction/CMakeLists.txt index c538c04ef..cd350b19f 100644 --- a/vtkm/filter/entity_extraction/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/CMakeLists.txt @@ -13,6 +13,7 @@ set(entity_extraction_headers ExtractPoints.h ExtractStructured.h GhostCellRemove.h + Mask.h MaskPoints.h Threshold.h ThresholdPoints.h @@ -23,6 +24,7 @@ set(entity_extraction_sources_device ExtractPoints.cxx ExtractStructured.cxx GhostCellRemove.cxx + Mask.cxx MaskPoints.cxx Threshold.cxx ThresholdPoints.cxx diff --git a/vtkm/filter/entity_extraction/ExternalFaces.cxx b/vtkm/filter/entity_extraction/ExternalFaces.cxx index 40beff9fc..1fb314fdc 100644 --- a/vtkm/filter/entity_extraction/ExternalFaces.cxx +++ b/vtkm/filter/entity_extraction/ExternalFaces.cxx @@ -46,7 +46,8 @@ vtkm::cont::DataSet ExternalFaces::GenerateOutput(const vtkm::cont::DataSet& inp bool hasCellFields = false; for (vtkm::Id fieldIdx = 0; fieldIdx < numFields && !hasCellFields; ++fieldIdx) { - hasCellFields = input.GetField(fieldIdx).IsFieldCell(); + const auto& f = input.GetField(fieldIdx); + hasCellFields = f.IsFieldCell(); } if (!hasCellFields) diff --git a/vtkm/filter/entity_extraction/ExternalFaces.h b/vtkm/filter/entity_extraction/ExternalFaces.h index 677429c48..f15dd276c 100644 --- a/vtkm/filter/entity_extraction/ExternalFaces.h +++ b/vtkm/filter/entity_extraction/ExternalFaces.h @@ -36,7 +36,7 @@ class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT ExternalFaces : public vtkm::filter:: { public: ExternalFaces(); - ~ExternalFaces(); + ~ExternalFaces() override; // New Design: I am too lazy to make this filter thread-safe. Let's use it as an example of // thread un-safe filter. diff --git a/vtkm/filter/entity_extraction/ExtractGeometry.cxx b/vtkm/filter/entity_extraction/ExtractGeometry.cxx index 9737ffdd2..faed88cc8 100644 --- a/vtkm/filter/entity_extraction/ExtractGeometry.cxx +++ b/vtkm/filter/entity_extraction/ExtractGeometry.cxx @@ -117,7 +117,7 @@ vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input) output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.SetCellSet(outCells); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; MapFieldsOntoOutput(input, output, mapper); return output; diff --git a/vtkm/filter/entity_extraction/ExtractGeometry.h b/vtkm/filter/entity_extraction/ExtractGeometry.h index 46850b8f8..b4f0c37c6 100644 --- a/vtkm/filter/entity_extraction/ExtractGeometry.h +++ b/vtkm/filter/entity_extraction/ExtractGeometry.h @@ -51,7 +51,7 @@ public: const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; } VTKM_CONT - bool GetExtractInside() { return this->ExtractInside; } + bool GetExtractInside() const { return this->ExtractInside; } VTKM_CONT void SetExtractInside(bool value) { this->ExtractInside = value; } VTKM_CONT @@ -60,7 +60,7 @@ public: void ExtractInsideOff() { this->ExtractInside = false; } VTKM_CONT - bool GetExtractBoundaryCells() { return this->ExtractBoundaryCells; } + bool GetExtractBoundaryCells() const { return this->ExtractBoundaryCells; } VTKM_CONT void SetExtractBoundaryCells(bool value) { this->ExtractBoundaryCells = value; } VTKM_CONT @@ -69,7 +69,7 @@ public: void ExtractBoundaryCellsOff() { this->ExtractBoundaryCells = false; } VTKM_CONT - bool GetExtractOnlyBoundaryCells() { return this->ExtractOnlyBoundaryCells; } + bool GetExtractOnlyBoundaryCells() const { return this->ExtractOnlyBoundaryCells; } VTKM_CONT void SetExtractOnlyBoundaryCells(bool value) { this->ExtractOnlyBoundaryCells = value; } VTKM_CONT diff --git a/vtkm/filter/entity_extraction/ExtractPoints.cxx b/vtkm/filter/entity_extraction/ExtractPoints.cxx index 344f4946b..fd53ede8e 100644 --- a/vtkm/filter/entity_extraction/ExtractPoints.cxx +++ b/vtkm/filter/entity_extraction/ExtractPoints.cxx @@ -13,10 +13,6 @@ #include #include -namespace vtkm -{ -namespace filter -{ namespace { bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field) @@ -38,7 +34,12 @@ bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field) return false; } } -} +} // anonymous namespace + +namespace vtkm +{ +namespace filter +{ namespace entity_extraction { //----------------------------------------------------------------------------- @@ -62,7 +63,7 @@ vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& input) output.SetCellSet(outCellSet); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); }; this->MapFieldsOntoOutput(input, output, mapper); // compact the unused points in the output dataset diff --git a/vtkm/filter/entity_extraction/ExtractPoints.h b/vtkm/filter/entity_extraction/ExtractPoints.h index fe850c7cd..98942c1d0 100644 --- a/vtkm/filter/entity_extraction/ExtractPoints.h +++ b/vtkm/filter/entity_extraction/ExtractPoints.h @@ -51,7 +51,7 @@ public: const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; } VTKM_CONT - bool GetExtractInside() { return this->ExtractInside; } + bool GetExtractInside() const { return this->ExtractInside; } VTKM_CONT void SetExtractInside(bool value) { this->ExtractInside = value; } VTKM_CONT diff --git a/vtkm/filter/entity_extraction/ExtractStructured.cxx b/vtkm/filter/entity_extraction/ExtractStructured.cxx index c69c8dab5..79b1408da 100644 --- a/vtkm/filter/entity_extraction/ExtractStructured.cxx +++ b/vtkm/filter/entity_extraction/ExtractStructured.cxx @@ -11,7 +11,6 @@ #include #include - #include namespace vtkm @@ -75,7 +74,7 @@ vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& inpu auto PointFieldMap = Worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints())); - auto mapper = [&, this](auto& result, const auto& f) { + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, CellFieldMap, PointFieldMap); }; MapFieldsOntoOutput(input, output, mapper); diff --git a/vtkm/filter/entity_extraction/ExtractStructured.h b/vtkm/filter/entity_extraction/ExtractStructured.h index 081db8747..5218a0a00 100644 --- a/vtkm/filter/entity_extraction/ExtractStructured.h +++ b/vtkm/filter/entity_extraction/ExtractStructured.h @@ -73,7 +73,7 @@ public: /// Get if we should include the outer boundary on a subsample VTKM_CONT - bool GetIncludeBoundary() { return this->IncludeBoundary; } + bool GetIncludeBoundary() const { return this->IncludeBoundary; } /// Set if we should include the outer boundary on a subsample VTKM_CONT void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; } diff --git a/vtkm/filter/entity_extraction/GhostCellRemove.cxx b/vtkm/filter/entity_extraction/GhostCellRemove.cxx index 8c2b454a4..654fce6dd 100644 --- a/vtkm/filter/entity_extraction/GhostCellRemove.cxx +++ b/vtkm/filter/entity_extraction/GhostCellRemove.cxx @@ -24,7 +24,7 @@ class RemoveAllGhosts { public: VTKM_CONT - RemoveAllGhosts() {} + RemoveAllGhosts() = default; VTKM_EXEC bool operator()(const vtkm::UInt8& value) const { return (value == 0); } }; @@ -39,7 +39,7 @@ public: } VTKM_CONT - RemoveGhostByType(const vtkm::UInt8& val) + explicit RemoveGhostByType(const vtkm::UInt8& val) : RemoveType(static_cast(~val)) { } @@ -378,7 +378,7 @@ VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(const vtkm::cont::DataS output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.SetCellSet(cellOut); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; MapFieldsOntoOutput(input, output, mapper); return output; diff --git a/vtkm/filter/entity_extraction/GhostCellRemove.h b/vtkm/filter/entity_extraction/GhostCellRemove.h index ddb744433..41c17328f 100644 --- a/vtkm/filter/entity_extraction/GhostCellRemove.h +++ b/vtkm/filter/entity_extraction/GhostCellRemove.h @@ -40,7 +40,7 @@ public: this->RemoveVals = vals; } VTKM_CONT - bool GetRemoveGhostField() { return this->RemoveField; } + bool GetRemoveGhostField() const { return this->RemoveField; } VTKM_CONT bool GetRemoveAllGhost() const { return this->RemoveAll; } diff --git a/vtkm/filter/Mask.hxx b/vtkm/filter/entity_extraction/Mask.cxx similarity index 59% rename from vtkm/filter/Mask.hxx rename to vtkm/filter/entity_extraction/Mask.cxx index 569f8fc3c..ceb6c2810 100644 --- a/vtkm/filter/Mask.hxx +++ b/vtkm/filter/entity_extraction/Mask.cxx @@ -7,11 +7,14 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_filter_Mask_hxx -#define vtk_m_filter_Mask_hxx - #include +#include +#include +namespace vtkm +{ +namespace filter +{ namespace { @@ -35,43 +38,9 @@ struct CallWorklet } }; -} // end anon namespace - -namespace vtkm -{ -namespace filter -{ - -//----------------------------------------------------------------------------- -inline VTKM_CONT Mask::Mask() - : vtkm::filter::FilterDataSet() - , Stride(1) - , CompactPoints(false) -{ -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy) -{ - const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); - vtkm::cont::UnknownCellSet cellOut; - CallWorklet workletCaller(this->Stride, cellOut, this->Worklet); - vtkm::filter::ApplyPolicyCellSet(cells, policy, *this).CastAndCall(workletCaller); - - // create the output dataset - vtkm::cont::DataSet output; - output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - output.SetCellSet(cellOut); - return output; -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT bool Mask::MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase) +VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::worklet::Mask& Worklet) { if (field.IsFieldPoint() || field.IsFieldGlobal()) { @@ -80,13 +49,37 @@ inline VTKM_CONT bool Mask::MapFieldOntoOutput(vtkm::cont::DataSet& result, } else if (field.IsFieldCell()) { - return vtkm::filter::MapFieldPermutation(field, this->Worklet.GetValidCellIds(), result); + return vtkm::filter::MapFieldPermutation(field, Worklet.GetValidCellIds(), result); } else { return false; } } +} // end anon namespace + +namespace entity_extraction +{ +//----------------------------------------------------------------------------- +VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(const vtkm::cont::DataSet& input) +{ + const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); + vtkm::cont::UnknownCellSet cellOut; + vtkm::worklet::Mask Worklet; + + CallWorklet workletCaller(this->Stride, cellOut, Worklet); + cells.CastAndCallForTypes(workletCaller); + + // create the output dataset + vtkm::cont::DataSet output; + output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); + output.SetCellSet(cellOut); + + auto mapper = [&](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/Mask.h b/vtkm/filter/entity_extraction/Mask.h new file mode 100644 index 000000000..4611b0341 --- /dev/null +++ b/vtkm/filter/entity_extraction/Mask.h @@ -0,0 +1,53 @@ +//============================================================================ +// 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_Mask_h +#define vtk_m_filter_Mask_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace entity_extraction +{ +/// \brief Subselect cells using a stride +/// +/// Extract only every Nth cell where N is equal to a stride value +class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT Mask : public vtkm::filter::NewFilterField +{ +public: + // When CompactPoints is set, instead of copying the points and point fields + // from the input, the filter will create new compact fields without the unused elements + VTKM_CONT + bool GetCompactPoints() const { return this->CompactPoints; } + VTKM_CONT + void SetCompactPoints(bool value) { this->CompactPoints = value; } + + // Set the stride of the subsample + VTKM_CONT + vtkm::Id GetStride() const { return this->Stride; } + VTKM_CONT + void SetStride(vtkm::Id& stride) { this->Stride = stride; } + +private: + VTKM_CONT + vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + vtkm::Id Stride = 1; + bool CompactPoints = false; +}; +} // namespace entity_extraction +} // namespace filter +} // namespace vtk + +#endif // vtk_m_filter_Mask_h diff --git a/vtkm/filter/entity_extraction/MaskPoints.cxx b/vtkm/filter/entity_extraction/MaskPoints.cxx index 7693d0f60..20064efa3 100644 --- a/vtkm/filter/entity_extraction/MaskPoints.cxx +++ b/vtkm/filter/entity_extraction/MaskPoints.cxx @@ -59,7 +59,7 @@ VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute(const vtkm::cont::DataSet& i output.SetCellSet(outCellSet); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); }; this->MapFieldsOntoOutput(input, output, mapper); // compact the unused points in the output dataset diff --git a/vtkm/filter/entity_extraction/Threshold.cxx b/vtkm/filter/entity_extraction/Threshold.cxx index 4dac3158b..8cd46df3c 100644 --- a/vtkm/filter/entity_extraction/Threshold.cxx +++ b/vtkm/filter/entity_extraction/Threshold.cxx @@ -101,7 +101,7 @@ vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input) output.SetCellSet(cellOut); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; MapFieldsOntoOutput(input, output, mapper); return output; diff --git a/vtkm/filter/entity_extraction/ThresholdPoints.cxx b/vtkm/filter/entity_extraction/ThresholdPoints.cxx index d5435816b..a1c69d239 100644 --- a/vtkm/filter/entity_extraction/ThresholdPoints.cxx +++ b/vtkm/filter/entity_extraction/ThresholdPoints.cxx @@ -19,7 +19,7 @@ class ValuesBelow { public: VTKM_CONT - ValuesBelow(const vtkm::Float64& value) + explicit ValuesBelow(const vtkm::Float64& value) : Value(value) { } @@ -39,7 +39,7 @@ class ValuesAbove { public: VTKM_CONT - ValuesAbove(const vtkm::Float64& value) + explicit ValuesAbove(const vtkm::Float64& value) : Value(value) { } @@ -178,7 +178,7 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS output.SetCellSet(outCellSet); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&, this](auto& result, const auto& f) { DoMapField(result, f); }; + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); }; this->MapFieldsOntoOutput(input, output, mapper); // compact the unused points in the output dataset diff --git a/vtkm/filter/entity_extraction/ThresholdPoints.h b/vtkm/filter/entity_extraction/ThresholdPoints.h index a2cda39ee..58ce00b47 100644 --- a/vtkm/filter/entity_extraction/ThresholdPoints.h +++ b/vtkm/filter/entity_extraction/ThresholdPoints.h @@ -41,11 +41,11 @@ public: void SetUpperThreshold(vtkm::Float64 value) { this->UpperValue = value; } VTKM_CONT - void SetThresholdBelow(const vtkm::Float64 value); + void SetThresholdBelow(vtkm::Float64 value); VTKM_CONT - void SetThresholdAbove(const vtkm::Float64 value); + void SetThresholdAbove(vtkm::Float64 value); VTKM_CONT - void SetThresholdBetween(const vtkm::Float64 value1, const vtkm::Float64 value2); + void SetThresholdBetween(vtkm::Float64 value1, vtkm::Float64 value2); private: VTKM_CONT diff --git a/vtkm/filter/entity_extraction/testing/CMakeLists.txt b/vtkm/filter/entity_extraction/testing/CMakeLists.txt index b737cb1c0..5f295de87 100644 --- a/vtkm/filter/entity_extraction/testing/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/testing/CMakeLists.txt @@ -14,6 +14,7 @@ set(unit_tests UnitTestExtractPointsFilter.cxx UnitTestExtractStructuredFilter.cxx UnitTestGhostCellRemove.cxx + UnitTestMaskFilter.cxx UnitTestMaskPointsFilter.cxx UnitTestThresholdFilter.cxx UnitTestThresholdPointsFilter.cxx diff --git a/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx b/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx index 3e7168f53..f78cf073b 100644 --- a/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx @@ -19,11 +19,11 @@ namespace { -static vtkm::cont::ArrayHandle StructuredGhostCellArray(vtkm::Id nx, - vtkm::Id ny, - vtkm::Id nz, - int numLayers, - bool addMidGhost = false) +vtkm::cont::ArrayHandle StructuredGhostCellArray(vtkm::Id nx, + vtkm::Id ny, + vtkm::Id nz, + int numLayers, + bool addMidGhost = false) { vtkm::Id numCells = nx * ny; if (nz > 0) @@ -80,19 +80,18 @@ static vtkm::cont::ArrayHandle StructuredGhostCellArray(vtkm::Id nx return ghosts; } -static vtkm::cont::DataSet MakeUniform(vtkm::Id numI, - vtkm::Id numJ, - vtkm::Id numK, - int numLayers, - bool addMidGhost = false) +vtkm::cont::DataSet MakeUniform(vtkm::Id numI, + vtkm::Id numJ, + vtkm::Id numK, + int numLayers, + bool addMidGhost = false) { - vtkm::cont::DataSetBuilderUniform dsb; vtkm::cont::DataSet ds; if (numK == 0) - ds = dsb.Create(vtkm::Id2(numI + 1, numJ + 1)); + ds = vtkm::cont::DataSetBuilderUniform::Create(vtkm::Id2(numI + 1, numJ + 1)); else - ds = dsb.Create(vtkm::Id3(numI + 1, numJ + 1, numK + 1)); + ds = vtkm::cont::DataSetBuilderUniform::Create(vtkm::Id3(numI + 1, numJ + 1, numK + 1)); auto ghosts = StructuredGhostCellArray(numI, numJ, numK, numLayers, addMidGhost); ds.AddCellField("vtkmGhostCells", ghosts); @@ -100,13 +99,12 @@ static vtkm::cont::DataSet MakeUniform(vtkm::Id numI, return ds; } -static vtkm::cont::DataSet MakeRectilinear(vtkm::Id numI, - vtkm::Id numJ, - vtkm::Id numK, - int numLayers, - bool addMidGhost = false) +vtkm::cont::DataSet MakeRectilinear(vtkm::Id numI, + vtkm::Id numJ, + vtkm::Id numK, + int numLayers, + bool addMidGhost = false) { - vtkm::cont::DataSetBuilderRectilinear dsb; vtkm::cont::DataSet ds; std::size_t nx(static_cast(numI + 1)); std::size_t ny(static_cast(numJ + 1)); @@ -118,14 +116,14 @@ static vtkm::cont::DataSet MakeRectilinear(vtkm::Id numI, y[i] = static_cast(i); if (numK == 0) - ds = dsb.Create(x, y); + ds = vtkm::cont::DataSetBuilderRectilinear::Create(x, y); else { std::size_t nz(static_cast(numK + 1)); std::vector z(nz); for (std::size_t i = 0; i < nz; i++) z[i] = static_cast(i); - ds = dsb.Create(x, y, z); + ds = vtkm::cont::DataSetBuilderRectilinear::Create(x, y, z); } auto ghosts = StructuredGhostCellArray(numI, numJ, numK, numLayers, addMidGhost); @@ -166,7 +164,7 @@ static void MakeExplicitCells(const CellSetType& cellSet, } } -static vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, vtkm::Id numJ, vtkm::Id numK, int numLayers) +vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, vtkm::Id numJ, vtkm::Id numK, int numLayers) { using CoordType = vtkm::Vec3f_32; @@ -187,21 +185,22 @@ static vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, vtkm::Id numJ, vtkm::Id n vtkm::cont::ArrayHandle numIndices; vtkm::cont::ArrayHandle shapes; vtkm::cont::DataSet ds; - vtkm::cont::DataSetBuilderExplicit dsb; if (cellSet.IsType>()) { vtkm::Id2 dims(numI, numJ); MakeExplicitCells( cellSet.AsCellSet>(), dims, numIndices, shapes, conn); - ds = dsb.Create(explCoords, vtkm::CellShapeTagQuad(), 4, conn, "coordinates"); + ds = vtkm::cont::DataSetBuilderExplicit::Create( + explCoords, vtkm::CellShapeTagQuad(), 4, conn, "coordinates"); } else if (cellSet.IsType>()) { vtkm::Id3 dims(numI, numJ, numK); MakeExplicitCells( cellSet.AsCellSet>(), dims, numIndices, shapes, conn); - ds = dsb.Create(explCoords, vtkm::CellShapeTagHexahedron(), 8, conn, "coordinates"); + ds = vtkm::cont::DataSetBuilderExplicit::Create( + explCoords, vtkm::CellShapeTagHexahedron(), 8, conn, "coordinates"); } auto ghosts = StructuredGhostCellArray(numI, numJ, numK, numLayers); diff --git a/vtkm/filter/testing/UnitTestMaskFilter.cxx b/vtkm/filter/entity_extraction/testing/UnitTestMaskFilter.cxx similarity index 94% rename from vtkm/filter/testing/UnitTestMaskFilter.cxx rename to vtkm/filter/entity_extraction/testing/UnitTestMaskFilter.cxx index ac05c2850..ea4964e16 100644 --- a/vtkm/filter/testing/UnitTestMaskFilter.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestMaskFilter.cxx @@ -11,7 +11,7 @@ #include #include -#include +#include using vtkm::cont::testing::MakeTestDataSet; @@ -27,7 +27,7 @@ public: vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1(); // Setup and run filter to extract by stride - vtkm::filter::Mask mask; + vtkm::filter::entity_extraction::Mask mask; vtkm::Id stride = 2; mask.SetStride(stride); @@ -50,7 +50,7 @@ public: vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); // Setup and run filter to extract by stride - vtkm::filter::Mask mask; + vtkm::filter::entity_extraction::Mask mask; vtkm::Id stride = 9; mask.SetStride(stride); @@ -71,7 +71,7 @@ public: vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5(); // Setup and run filter to extract by stride - vtkm::filter::Mask mask; + vtkm::filter::entity_extraction::Mask mask; vtkm::Id stride = 2; mask.SetStride(stride); diff --git a/vtkm/filter/entity_extraction/worklet/CMakeLists.txt b/vtkm/filter/entity_extraction/worklet/CMakeLists.txt index 9292c3e9b..b53737f73 100644 --- a/vtkm/filter/entity_extraction/worklet/CMakeLists.txt +++ b/vtkm/filter/entity_extraction/worklet/CMakeLists.txt @@ -13,6 +13,7 @@ set(headers ExtractGeometry.h ExtractStructured.h ExtractPoints.h + Mask.h MaskPoints.h Threshold.h ThresholdPoints.h diff --git a/vtkm/filter/entity_extraction/worklet/ExtractGeometry.h b/vtkm/filter/entity_extraction/worklet/ExtractGeometry.h index 8b3ec2728..17679bdf9 100644 --- a/vtkm/filter/entity_extraction/worklet/ExtractGeometry.h +++ b/vtkm/filter/entity_extraction/worklet/ExtractGeometry.h @@ -10,7 +10,6 @@ #ifndef vtkm_m_worklet_ExtractGeometry_h #define vtkm_m_worklet_ExtractGeometry_h -#include #include #include @@ -18,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -144,8 +143,8 @@ public: vtkm::cont::ArrayHandle passFlags; ExtractCellsByVOI worklet(extractInside, extractBoundaryCells, extractOnlyBoundaryCells); - DispatcherMapTopology dispatcher(worklet); - dispatcher.Invoke(cellSet, coordinates, implicitFunction, passFlags); + vtkm::cont::Invoker invoke; + invoke(worklet, cellSet, coordinates, implicitFunction, passFlags); vtkm::cont::ArrayHandleCounting indices = vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues()); diff --git a/vtkm/filter/entity_extraction/worklet/ExtractPoints.h b/vtkm/filter/entity_extraction/worklet/ExtractPoints.h index 9fab54962..ea1ea85b1 100644 --- a/vtkm/filter/entity_extraction/worklet/ExtractPoints.h +++ b/vtkm/filter/entity_extraction/worklet/ExtractPoints.h @@ -10,17 +10,16 @@ #ifndef vtkm_m_worklet_ExtractPoints_h #define vtkm_m_worklet_ExtractPoints_h -#include -#include - #include #include #include #include -#include +#include #include +#include + namespace vtkm { namespace worklet @@ -41,7 +40,7 @@ public: using ExecutionSignature = _4(_2, _3); VTKM_CONT - ExtractPointsByVOI(bool extractInside) + explicit ExtractPointsByVOI(bool extractInside) : passValue(extractInside) , failValue(!extractInside) { @@ -93,8 +92,8 @@ public: vtkm::cont::ArrayHandle passFlags; ExtractPointsByVOI worklet(extractInside); - DispatcherMapTopology dispatcher(worklet); - dispatcher.Invoke(cellSet, coordinates, implicitFunction, passFlags); + vtkm::cont::Invoker invoke; + invoke(worklet, cellSet, coordinates, implicitFunction, passFlags); vtkm::cont::ArrayHandleCounting indices = vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues()); diff --git a/vtkm/filter/entity_extraction/worklet/ExtractStructured.h b/vtkm/filter/entity_extraction/worklet/ExtractStructured.h index 09b4051f4..f38e0d497 100644 --- a/vtkm/filter/entity_extraction/worklet/ExtractStructured.h +++ b/vtkm/filter/entity_extraction/worklet/ExtractStructured.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -73,7 +74,7 @@ struct ExtractCopy : public vtkm::worklet::WorkletMapField { using ControlSignature = void(FieldIn, FieldOut, WholeArrayIn); - ExtractCopy(const vtkm::Id3& dim) + explicit ExtractCopy(const vtkm::Id3& dim) : XDim(dim[0]) , XYDim(dim[0] * dim[1]) { @@ -178,7 +179,7 @@ private: return outCs; } default: - return UncertainCellSetStructured(); + return {}; } } @@ -438,7 +439,7 @@ private: inOrigin[2] + static_cast(this->VOI.Z.Min) * inSpacing[2]); CoordType outSpacing = inSpacing * static_cast(this->SampleRate); - return CoordsArray(this->OutputDimensions, outOrigin, outSpacing); + return { this->OutputDimensions, outOrigin, outSpacing }; } RectilinearCoordinatesArrayHandle MapCoordinatesRectilinear( @@ -522,8 +523,8 @@ public: result.Allocate(this->ValidPoints.GetNumberOfValues()); ExtractCopy worklet(this->InputDimensions); - DispatcherMapField dispatcher(worklet); - dispatcher.Invoke(this->ValidPoints, result, field); + vtkm::cont::Invoker invoke; + invoke(worklet, this->ValidPoints, result, field); return result; } @@ -538,8 +539,8 @@ public: auto inputCellDimensions = this->InputDimensions - vtkm::Id3(1); ExtractCopy worklet(inputCellDimensions); - DispatcherMapField dispatcher(worklet); - dispatcher.Invoke(this->ValidCells, result, field); + vtkm::cont::Invoker invoke; + invoke(worklet, this->ValidCells, result, field); return result; } diff --git a/vtkm/worklet/Mask.h b/vtkm/filter/entity_extraction/worklet/Mask.h similarity index 96% rename from vtkm/worklet/Mask.h rename to vtkm/filter/entity_extraction/worklet/Mask.h index a41b15563..b96efab9d 100644 --- a/vtkm/worklet/Mask.h +++ b/vtkm/filter/entity_extraction/worklet/Mask.h @@ -10,7 +10,6 @@ #ifndef vtkm_m_worklet_Mask_h #define vtkm_m_worklet_Mask_h -#include #include #include @@ -18,7 +17,6 @@ #include #include #include -#include namespace vtkm { diff --git a/vtkm/filter/entity_extraction/worklet/MaskPoints.h b/vtkm/filter/entity_extraction/worklet/MaskPoints.h index 5eb60d7c0..ed060c32a 100644 --- a/vtkm/filter/entity_extraction/worklet/MaskPoints.h +++ b/vtkm/filter/entity_extraction/worklet/MaskPoints.h @@ -13,7 +13,6 @@ #include #include #include -#include namespace vtkm { diff --git a/vtkm/filter/entity_extraction/worklet/Threshold.h b/vtkm/filter/entity_extraction/worklet/Threshold.h index dffb29e4a..d8ab6c3cd 100644 --- a/vtkm/filter/entity_extraction/worklet/Threshold.h +++ b/vtkm/filter/entity_extraction/worklet/Threshold.h @@ -15,10 +15,8 @@ #include #include -#include #include #include -#include #include #include #include diff --git a/vtkm/filter/entity_extraction/worklet/ThresholdPoints.h b/vtkm/filter/entity_extraction/worklet/ThresholdPoints.h index 4bc20eb9e..ece19b4cb 100644 --- a/vtkm/filter/entity_extraction/worklet/ThresholdPoints.h +++ b/vtkm/filter/entity_extraction/worklet/ThresholdPoints.h @@ -10,12 +10,11 @@ #ifndef vtkm_m_worklet_ThresholdPoints_h #define vtkm_m_worklet_ThresholdPoints_h -#include -#include - #include #include -#include +#include + +#include namespace vtkm { @@ -64,8 +63,8 @@ public: using ThresholdWorklet = ThresholdPointField; ThresholdWorklet worklet(predicate); - DispatcherMapTopology dispatcher(worklet); - dispatcher.Invoke(cellSet, scalars, passFlags); + vtkm::cont::Invoker invoker; + invoker(worklet, cellSet, scalars, passFlags); vtkm::cont::ArrayHandle pointIds; vtkm::cont::ArrayHandleCounting indices = diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index a96df9cad..d154d2a87 100644 --- a/vtkm/filter/testing/CMakeLists.txt +++ b/vtkm/filter/testing/CMakeLists.txt @@ -40,7 +40,6 @@ set(unit_tests UnitTestLagrangianStructuresFilter.cxx UnitTestMapFieldMergeAverage.cxx UnitTestMapFieldPermutation.cxx - UnitTestMaskFilter.cxx UnitTestMeshQualityFilter.cxx UnitTestMIRFilter.cxx UnitTestMultiBlockFilter.cxx diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index 2482a1592..521748a26 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -38,7 +38,6 @@ set(headers LagrangianStructures.h Magnitude.h Contour.h - Mask.h MaskIndices.h MaskNone.h MaskSelect.h diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index c3a185ec1..8084faeaa 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -39,7 +39,6 @@ set(unit_tests UnitTestImageConnectivity.cxx UnitTestKeys.cxx UnitTestMagnitude.cxx - UnitTestMask.cxx UnitTestMaskIndices.cxx UnitTestMaskSelect.cxx UnitTestNormalize.cxx diff --git a/vtkm/worklet/testing/UnitTestMask.cxx b/vtkm/worklet/testing/UnitTestMask.cxx deleted file mode 100644 index e943789b2..000000000 --- a/vtkm/worklet/testing/UnitTestMask.cxx +++ /dev/null @@ -1,119 +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 - -using vtkm::cont::testing::MakeTestDataSet; - -class TestingMask -{ -public: - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestUniform2D() const - { - std::cout << "Testing mask cells structured:" << std::endl; - - using CellSetType = vtkm::cont::CellSetStructured<2>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Output data set permutation - vtkm::worklet::Mask maskCells; - OutCellSetType outCellSet = maskCells.Run(cellSet, 2); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - vtkm::cont::ArrayHandle cellFieldArray = maskCells.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for Mask"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 && - cellFieldArray.ReadPortal().Get(7) == 14.f, - "Wrong cell field data"); - } - - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestUniform3D() const - { - std::cout << "Testing mask cells structured:" << std::endl; - - using CellSetType = vtkm::cont::CellSetStructured<3>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Output data set with cell set permuted - vtkm::worklet::Mask maskCells; - OutCellSetType outCellSet = maskCells.Run(cellSet, 9); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - vtkm::cont::ArrayHandle cellFieldArray = maskCells.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 7), "Wrong result for ExtractCells"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 7 && - cellFieldArray.ReadPortal().Get(2) == 18.f, - "Wrong cell field data"); - } - - ///////////////////////////////////////////////////////////////////////////////////////////////// - void TestExplicit() const - { - std::cout << "Testing mask cells explicit:" << std::endl; - - using CellSetType = vtkm::cont::CellSetExplicit<>; - using OutCellSetType = vtkm::cont::CellSetPermutation; - - // Input data set created - vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5(); - CellSetType cellSet; - dataset.GetCellSet().AsCellSet(cellSet); - - // Output data set with cell set permuted - vtkm::worklet::Mask maskCells; - OutCellSetType outCellSet = maskCells.Run(cellSet, 2); - - vtkm::cont::ArrayHandle cellvar; - dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar); - vtkm::cont::ArrayHandle cellFieldArray = maskCells.ProcessCellField(cellvar); - - VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 2), "Wrong result for ExtractCells"); - VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 && - cellFieldArray.ReadPortal().Get(1) == 120.2f, - "Wrong cell field data"); - } - - void operator()() const - { - this->TestUniform2D(); - this->TestUniform3D(); - this->TestExplicit(); - } -}; - -int UnitTestMask(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestingMask(), argc, argv); -} From ced89bb39674254de759ebf1c01edfe611872ed4 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 6 Jan 2022 07:15:38 -0700 Subject: [PATCH 6/7] Move internal functions into top level anonymous namespace --- vtkm/filter/clean_grid/CleanGrid.cxx | 119 ++++++++++-------- .../entity_extraction/ExtractGeometry.cxx | 26 ++-- .../entity_extraction/ExtractStructured.cxx | 21 ++-- .../entity_extraction/GhostCellRemove.cxx | 34 +++-- vtkm/filter/entity_extraction/Mask.cxx | 21 ++-- vtkm/filter/entity_extraction/Threshold.cxx | 26 ++-- 6 files changed, 120 insertions(+), 127 deletions(-) diff --git a/vtkm/filter/clean_grid/CleanGrid.cxx b/vtkm/filter/clean_grid/CleanGrid.cxx index fd9cc14b2..1dd3ebc07 100644 --- a/vtkm/filter/clean_grid/CleanGrid.cxx +++ b/vtkm/filter/clean_grid/CleanGrid.cxx @@ -26,7 +26,71 @@ struct SharedStates vtkm::worklet::RemoveDegenerateCells CellCompactor; vtkm::worklet::PointMerge PointMerger; }; +} +} +} +// New Filter Design: DoMapField is now a free function in an anonymous namespace. It should be +// considered as a convenience/extension to the lambda passed to the MapFieldsOntoOutput. +// Being a free function discourages the developer to "pass" mutable states from DoExecute phase +// to DoMapField phase via data member. However, there is nothing to prevent developer doing +// stupid thing to circumvent the protection. One example here is that the developer could +// always pass a mutable reference/pointer to the filter instance and thus pass mutable state +// across the DoExecute and DoMapField boundary. We need to explicitly discourage developer +// trying to do such a thing in the manual. +namespace +{ +bool DoMapField(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::filter::clean_grid::CleanGrid& self, + vtkm::filter::clean_grid::SharedStates& worklets) +{ + if (field.IsFieldPoint() && (self.GetCompactPointFields() || self.GetMergePoints())) + { + vtkm::cont::Field compactedField; + if (self.GetCompactPointFields()) + { + bool success = vtkm::filter::MapFieldPermutation( + field, worklets.PointCompactor.GetPointScatter().GetOutputToInputMap(), compactedField); + if (!success) + { + return false; + } + } + else + { + compactedField = field; + } + if (self.GetMergePoints()) + { + return vtkm::filter::MapFieldMergeAverage( + compactedField, worklets.PointMerger.GetMergeKeys(), result); + } + else + { + result.AddField(compactedField); + return true; + } + } + else if (field.IsFieldCell() && self.GetRemoveDegenerateCells()) + { + return vtkm::filter::MapFieldPermutation( + field, worklets.CellCompactor.GetValidCellIds(), result); + } + else + { + result.AddField(field); + return true; + } +} +} // anonymous namespace + +namespace vtkm +{ +namespace filter +{ +namespace clean_grid +{ //----------------------------------------------------------------------------- vtkm::cont::DataSet CleanGrid::GenerateOutput(const vtkm::cont::DataSet& inData, vtkm::cont::CellSetExplicit<>& outputCellSet, @@ -116,61 +180,6 @@ vtkm::cont::DataSet CleanGrid::GenerateOutput(const vtkm::cont::DataSet& inData, return outData; } -// New Filter Design: DoMapField is now a free function in an anonymous namespace. It should be -// considered as a convenience/extension to the lambda passed to the MapFieldsOntoOutput. -// Being a free function discourages the developer to "pass" mutable states from DoExecute phase -// to DoMapField phase via data member. However, there is nothing to prevent developer doing -// stupid thing to circumvent the protection. One example here is that the developer could -// always pass a mutable reference/pointer to the filter instance and thus pass mutable state -// across the DoExecute and DoMapField boundary. We need to explicitly discourage developer -// trying to do such a thing in the manual. -namespace -{ -bool DoMapField(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - const CleanGrid& self, - clean_grid::SharedStates& worklets) -{ - if (field.IsFieldPoint() && (self.GetCompactPointFields() || self.GetMergePoints())) - { - vtkm::cont::Field compactedField; - if (self.GetCompactPointFields()) - { - bool success = vtkm::filter::MapFieldPermutation( - field, worklets.PointCompactor.GetPointScatter().GetOutputToInputMap(), compactedField); - if (!success) - { - return false; - } - } - else - { - compactedField = field; - } - if (self.GetMergePoints()) - { - return vtkm::filter::MapFieldMergeAverage( - compactedField, worklets.PointMerger.GetMergeKeys(), result); - } - else - { - result.AddField(compactedField); - return true; - } - } - else if (field.IsFieldCell() && self.GetRemoveDegenerateCells()) - { - return vtkm::filter::MapFieldPermutation( - field, worklets.CellCompactor.GetValidCellIds(), result); - } - else - { - result.AddField(field); - return true; - } -} -} // anonymous namespace - vtkm::cont::DataSet CleanGrid::DoExecute(const vtkm::cont::DataSet& inData) { // New Filter Design: mutable states that was a data member of the filter is now a local diff --git a/vtkm/filter/entity_extraction/ExtractGeometry.cxx b/vtkm/filter/entity_extraction/ExtractGeometry.cxx index faed88cc8..187836a1e 100644 --- a/vtkm/filter/entity_extraction/ExtractGeometry.cxx +++ b/vtkm/filter/entity_extraction/ExtractGeometry.cxx @@ -1,5 +1,4 @@ //============================================================================ -//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. @@ -15,15 +14,6 @@ #include #include -namespace -{ - -} // end anon namespace - -namespace vtkm -{ -namespace filter -{ namespace { struct CallWorker @@ -67,7 +57,7 @@ struct CallWorker bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field, - const vtkm::worklet::ExtractGeometry& Worklet) + const vtkm::worklet::ExtractGeometry& worklet) { if (field.IsFieldPoint()) { @@ -76,7 +66,7 @@ bool DoMapField(vtkm::cont::DataSet& result, } else if (field.IsFieldCell()) { - vtkm::cont::ArrayHandle permutation = Worklet.GetValidCellIds(); + vtkm::cont::ArrayHandle permutation = worklet.GetValidCellIds(); return vtkm::filter::MapFieldPermutation(field, permutation, result); } else if (field.IsFieldGlobal()) @@ -91,6 +81,10 @@ bool DoMapField(vtkm::cont::DataSet& result, } } // anonymous namespace +namespace vtkm +{ +namespace filter +{ namespace entity_extraction { //----------------------------------------------------------------------------- @@ -101,10 +95,10 @@ vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input) const vtkm::cont::CoordinateSystem& coords = input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()); - vtkm::worklet::ExtractGeometry Worklet; + vtkm::worklet::ExtractGeometry worklet; vtkm::cont::UnknownCellSet outCells; CallWorker worker(outCells, - Worklet, + worklet, coords, this->Function, this->ExtractInside, @@ -117,8 +111,8 @@ vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input) output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.SetCellSet(outCells); - auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; - MapFieldsOntoOutput(input, output, mapper); + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); }; + this->MapFieldsOntoOutput(input, output, mapper); return output; } diff --git a/vtkm/filter/entity_extraction/ExtractStructured.cxx b/vtkm/filter/entity_extraction/ExtractStructured.cxx index 79b1408da..257da786a 100644 --- a/vtkm/filter/entity_extraction/ExtractStructured.cxx +++ b/vtkm/filter/entity_extraction/ExtractStructured.cxx @@ -13,10 +13,6 @@ #include #include -namespace vtkm -{ -namespace filter -{ namespace { VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, @@ -42,9 +38,12 @@ VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, return false; } } - } // anonymous namespace +namespace vtkm +{ +namespace filter +{ namespace entity_extraction { //----------------------------------------------------------------------------- @@ -53,14 +52,14 @@ vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& inpu const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); const vtkm::cont::CoordinateSystem& coordinates = input.GetCoordinateSystem(); - vtkm::worklet::ExtractStructured Worklet; - auto cellset = Worklet.Run(cells.ResetCellSetList(), + vtkm::worklet::ExtractStructured worklet; + auto cellset = worklet.Run(cells.ResetCellSetList(), this->VOI, this->SampleRate, this->IncludeBoundary, this->IncludeOffset); - auto coords = Worklet.MapCoordinates(coordinates); + auto coords = worklet.MapCoordinates(coordinates); vtkm::cont::CoordinateSystem outputCoordinates(coordinates.GetName(), coords); vtkm::cont::DataSet output; @@ -70,14 +69,14 @@ vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& inpu // Create map arrays for mapping fields. Could potentially save some time to first check to see // if these arrays would be used. auto CellFieldMap = - Worklet.ProcessCellField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfCells())); + worklet.ProcessCellField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfCells())); auto PointFieldMap = - Worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints())); + worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints())); auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, CellFieldMap, PointFieldMap); }; - MapFieldsOntoOutput(input, output, mapper); + this->MapFieldsOntoOutput(input, output, mapper); return output; } diff --git a/vtkm/filter/entity_extraction/GhostCellRemove.cxx b/vtkm/filter/entity_extraction/GhostCellRemove.cxx index 654fce6dd..31b48b02b 100644 --- a/vtkm/filter/entity_extraction/GhostCellRemove.cxx +++ b/vtkm/filter/entity_extraction/GhostCellRemove.cxx @@ -19,7 +19,6 @@ namespace { - class RemoveAllGhosts { public: @@ -274,17 +273,9 @@ bool CanDoStructuredStrip(const vtkm::cont::UnknownCellSet& cells, return canDo; } -} // end anon namespace - -namespace vtkm -{ -namespace filter -{ -namespace -{ bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field, - const vtkm::worklet::Threshold& Worklet) + const vtkm::worklet::Threshold& worklet) { if (field.IsFieldPoint()) { @@ -294,7 +285,7 @@ bool DoMapField(vtkm::cont::DataSet& result, } else if (field.IsFieldCell()) { - return vtkm::filter::MapFieldPermutation(field, Worklet.GetValidCellIds(), result); + return vtkm::filter::MapFieldPermutation(field, worklet.GetValidCellIds(), result); } else if (field.IsFieldGlobal()) { @@ -306,8 +297,12 @@ bool DoMapField(vtkm::cont::DataSet& result, return false; } } -} // anonymous namespace +} // end anon namespace +namespace vtkm +{ +namespace filter +{ namespace entity_extraction { //----------------------------------------------------------------------------- @@ -323,9 +318,8 @@ VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(const vtkm::cont::DataS const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); 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>(); + vtkm::cont::ArrayHandle fieldArray; + vtkm::cont::ArrayCopyShallowIfPossible(field.GetData(), fieldArray); //Preserve structured output where possible. if (cells.CanConvert>() || @@ -353,18 +347,18 @@ VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(const vtkm::cont::DataS } vtkm::cont::UnknownCellSet cellOut; - vtkm::worklet::Threshold Worklet; + vtkm::worklet::Threshold worklet; if (this->GetRemoveAllGhost()) { - cellOut = Worklet.Run(cells.ResetCellSetList(), + cellOut = worklet.Run(cells.ResetCellSetList(), fieldArray, field.GetAssociation(), RemoveAllGhosts()); } else if (this->GetRemoveByType()) { - cellOut = Worklet.Run(cells.ResetCellSetList(), + cellOut = worklet.Run(cells.ResetCellSetList(), fieldArray, field.GetAssociation(), RemoveGhostByType(this->GetRemoveType())); @@ -378,8 +372,8 @@ VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(const vtkm::cont::DataS output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.SetCellSet(cellOut); - auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; - MapFieldsOntoOutput(input, output, mapper); + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); }; + this->MapFieldsOntoOutput(input, output, mapper); return output; } diff --git a/vtkm/filter/entity_extraction/Mask.cxx b/vtkm/filter/entity_extraction/Mask.cxx index ceb6c2810..bbd74b27e 100644 --- a/vtkm/filter/entity_extraction/Mask.cxx +++ b/vtkm/filter/entity_extraction/Mask.cxx @@ -11,13 +11,8 @@ #include #include -namespace vtkm -{ -namespace filter -{ namespace { - struct CallWorklet { vtkm::Id Stride; @@ -40,7 +35,7 @@ struct CallWorklet VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field, - const vtkm::worklet::Mask& Worklet) + const vtkm::worklet::Mask& worklet) { if (field.IsFieldPoint() || field.IsFieldGlobal()) { @@ -49,7 +44,7 @@ VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, } else if (field.IsFieldCell()) { - return vtkm::filter::MapFieldPermutation(field, Worklet.GetValidCellIds(), result); + return vtkm::filter::MapFieldPermutation(field, worklet.GetValidCellIds(), result); } else { @@ -58,6 +53,10 @@ VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, } } // end anon namespace +namespace vtkm +{ +namespace filter +{ namespace entity_extraction { //----------------------------------------------------------------------------- @@ -65,9 +64,9 @@ VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(const vtkm::cont::DataSet& input) { const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); vtkm::cont::UnknownCellSet cellOut; - vtkm::worklet::Mask Worklet; + vtkm::worklet::Mask worklet; - CallWorklet workletCaller(this->Stride, cellOut, Worklet); + CallWorklet workletCaller(this->Stride, cellOut, worklet); cells.CastAndCallForTypes(workletCaller); // create the output dataset @@ -75,8 +74,8 @@ VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(const vtkm::cont::DataSet& input) output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.SetCellSet(cellOut); - auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; - MapFieldsOntoOutput(input, output, mapper); + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); }; + this->MapFieldsOntoOutput(input, output, mapper); return output; } diff --git a/vtkm/filter/entity_extraction/Threshold.cxx b/vtkm/filter/entity_extraction/Threshold.cxx index 8cd46df3c..34e22c6ec 100644 --- a/vtkm/filter/entity_extraction/Threshold.cxx +++ b/vtkm/filter/entity_extraction/Threshold.cxx @@ -11,15 +11,8 @@ #include #include -namespace vtkm -{ -namespace filter -{ -namespace entity_extraction -{ namespace { - class ThresholdRange { public: @@ -53,7 +46,7 @@ private: bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field, - const vtkm::worklet::Threshold& Worklet) + const vtkm::worklet::Threshold& worklet) { if (field.IsFieldPoint() || field.IsFieldGlobal()) { @@ -63,16 +56,21 @@ bool DoMapField(vtkm::cont::DataSet& result, } else if (field.IsFieldCell()) { - return vtkm::filter::MapFieldPermutation(field, Worklet.GetValidCellIds(), result); + return vtkm::filter::MapFieldPermutation(field, worklet.GetValidCellIds(), result); } else { return false; } } - } // end anon namespace +namespace vtkm +{ +namespace filter +{ +namespace entity_extraction +{ //----------------------------------------------------------------------------- vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input) { @@ -81,12 +79,12 @@ vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input) const auto& field = this->GetFieldFromDataSet(input); ThresholdRange predicate(this->GetLowerThreshold(), this->GetUpperThreshold()); - vtkm::worklet::Threshold Worklet; + 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(), + cellOut = worklet.Run(cells.ResetCellSetList(), concrete, field.GetAssociation(), predicate, @@ -101,8 +99,8 @@ vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input) output.SetCellSet(cellOut); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, Worklet); }; - MapFieldsOntoOutput(input, output, mapper); + auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); }; + this->MapFieldsOntoOutput(input, output, mapper); return output; } From 61e2a620a90a4ae95b60b6e7a4815bf074e769c1 Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Tue, 18 Jan 2022 08:47:14 -0700 Subject: [PATCH 7/7] document why a .ResetCellSetList is necessary --- vtkm/filter/entity_extraction/Threshold.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vtkm/filter/entity_extraction/Threshold.cxx b/vtkm/filter/entity_extraction/Threshold.cxx index 34e22c6ec..7dbd1b7cd 100644 --- a/vtkm/filter/entity_extraction/Threshold.cxx +++ b/vtkm/filter/entity_extraction/Threshold.cxx @@ -83,7 +83,10 @@ vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input) vtkm::cont::UnknownCellSet cellOut; auto ResolveArrayType = [&, this](const auto& concrete) { - // TODO: document the reason a .ResetCellSetList is needed here. + // Note: there are two overloads of .Run, the first one taking an UncertainCellSet, which is + // the desired entry point in the following call. The other is a function template on the input + // CellSet. Without the call to .ResetCellSetList to turn an UnknownCellSet to an UncertainCellSet, + // the compiler will pick the function template (i.e. wrong overload). cellOut = worklet.Run(cells.ResetCellSetList(), concrete, field.GetAssociation(),