From 77650a9ca05637a2e0c9081ac8dac96f9baed29e Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Sun, 16 Jan 2022 12:15:03 -0700 Subject: [PATCH] migrate connected components filters --- vtkm/filter/CMakeLists.txt | 12 +- vtkm/filter/CellSetConnectivity.h | 60 +++---- vtkm/filter/CellSetConnectivity.hxx | 42 ----- vtkm/filter/ImageConnectivity.h | 41 ++--- vtkm/filter/ImageConnectivity.hxx | 42 ----- .../connected_components/CMakeLists.txt | 34 ++++ .../CellSetConnectivity.cxx | 34 ++++ .../CellSetConnectivity.h | 46 ++++++ .../ImageConnectivity.cxx | 45 ++++++ .../connected_components/ImageConnectivity.h | 47 ++++++ .../testing/CMakeLists.txt | 26 +++ .../UnitTestCellSetConnectivityFilter.cxx | 8 +- .../UnitTestImageConnectivityFilter.cxx | 4 +- .../worklet}/CMakeLists.txt | 0 .../worklet}/CellSetConnectivity.h | 4 +- .../worklet}/CellSetDualGraph.h | 0 .../worklet}/GraphConnectivity.h | 6 +- .../worklet}/ImageConnectivity.h | 15 +- .../connected_components/worklet}/InnerJoin.h | 0 .../connected_components/worklet}/UnionFind.h | 0 vtkm/filter/testing/CMakeLists.txt | 2 - vtkm/worklet/CMakeLists.txt | 1 - vtkm/worklet/testing/CMakeLists.txt | 6 - .../testing/UnitTestCellSetConnectivity.cxx | 88 ----------- .../testing/UnitTestCellSetDualGraph.cxx | 112 ------------- .../testing/UnitTestGraphConnectivity.cxx | 141 ----------------- .../testing/UnitTestImageConnectivity.cxx | 148 ------------------ vtkm/worklet/testing/UnitTestInnerJoin.cxx | 96 ------------ .../testing/UnitTestPointerJumping.cxx | 40 ----- 29 files changed, 295 insertions(+), 805 deletions(-) delete mode 100644 vtkm/filter/CellSetConnectivity.hxx delete mode 100644 vtkm/filter/ImageConnectivity.hxx create mode 100644 vtkm/filter/connected_components/CMakeLists.txt create mode 100644 vtkm/filter/connected_components/CellSetConnectivity.cxx create mode 100644 vtkm/filter/connected_components/CellSetConnectivity.h create mode 100644 vtkm/filter/connected_components/ImageConnectivity.cxx create mode 100644 vtkm/filter/connected_components/ImageConnectivity.h create mode 100644 vtkm/filter/connected_components/testing/CMakeLists.txt rename vtkm/filter/{ => connected_components}/testing/UnitTestCellSetConnectivityFilter.cxx (91%) rename vtkm/filter/{ => connected_components}/testing/UnitTestImageConnectivityFilter.cxx (94%) rename vtkm/{worklet/connectivities => filter/connected_components/worklet}/CMakeLists.txt (100%) rename vtkm/{worklet/connectivities => filter/connected_components/worklet}/CellSetConnectivity.h (90%) rename vtkm/{worklet/connectivities => filter/connected_components/worklet}/CellSetDualGraph.h (100%) rename vtkm/{worklet/connectivities => filter/connected_components/worklet}/GraphConnectivity.h (94%) rename vtkm/{worklet/connectivities => filter/connected_components/worklet}/ImageConnectivity.h (94%) rename vtkm/{worklet/connectivities => filter/connected_components/worklet}/InnerJoin.h (100%) rename vtkm/{worklet/connectivities => filter/connected_components/worklet}/UnionFind.h (100%) delete mode 100644 vtkm/worklet/testing/UnitTestCellSetConnectivity.cxx delete mode 100644 vtkm/worklet/testing/UnitTestCellSetDualGraph.cxx delete mode 100644 vtkm/worklet/testing/UnitTestGraphConnectivity.cxx delete mode 100644 vtkm/worklet/testing/UnitTestImageConnectivity.cxx delete mode 100644 vtkm/worklet/testing/UnitTestInnerJoin.cxx delete mode 100644 vtkm/worklet/testing/UnitTestPointerJumping.cxx diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index d84216975..43dc8146e 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -21,6 +21,13 @@ vtkm_add_instantiations(ClipWithImplicitFunctionInstantiations INSTANTIATIONS_FILE ClipWithImplicitFunctionExternInstantiations.h ) +set(deprecated_headers + CellSetConnectivity.h + ImageConnectivity.h + ) + +vtkm_declare_headers(${deprecated_headers}) + set(common_headers CellAverage.h CellMeasures.h @@ -70,7 +77,6 @@ set(common_sources_device set(extra_headers AmrArrays.h - CellSetConnectivity.h ClipWithField.h ClipWithImplicitFunction.h ComputeMoments.h @@ -86,7 +92,6 @@ set(extra_headers GhostCellClassify.h GhostCellRemove.h Histogram.h - ImageConnectivity.h ImageDifference.h ImageMedian.h Lagrangian.h @@ -128,7 +133,6 @@ set(extra_headers set(extra_header_template_sources AmrArrays.hxx - CellSetConnectivity.hxx ClipWithField.hxx ClipWithImplicitFunction.hxx ClipWithFieldExternInstantiations.h @@ -141,7 +145,6 @@ set(extra_header_template_sources GhostCellClassify.hxx GhostCellRemove.hxx Histogram.hxx - ImageConnectivity.hxx ImageDifference.hxx ImageMedian.hxx Lagrangian.hxx @@ -313,6 +316,7 @@ target_link_libraries(vtkm_filter PUBLIC INTERFACE install(TARGETS vtkm_filter EXPORT ${VTKm_EXPORT_NAME}) add_subdirectory(clean_grid) +add_subdirectory(connected_components) add_subdirectory(entity_extraction) add_subdirectory(internal) add_subdirectory(particleadvection) diff --git a/vtkm/filter/CellSetConnectivity.h b/vtkm/filter/CellSetConnectivity.h index e3c073162..21f3ad13b 100644 --- a/vtkm/filter/CellSetConnectivity.h +++ b/vtkm/filter/CellSetConnectivity.h @@ -7,54 +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_CellSetConnectivity_h +#define vtk_m_filter_CellSetConnectivity_h -#ifndef vtkm_m_filter_CellSetConnectivity_h -#define vtkm_m_filter_CellSetConnectivity_h - -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Finds groups of cells that are connected together through their topology. -/// -/// Finds and labels groups of cells that are connected together through their topology. -/// Two cells are considered connected if they share an edge. CellSetConnectivity identifies some -/// number of components and assigns each component a unique integer. -/// The result of the filter is a cell field of type vtkm::Id with the default name of 'component'. -/// Each entry in the cell field will be a number that identifies to which component the cell belongs. -class CellSetConnectivity : public vtkm::filter::FilterDataSet + +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/connected_components/CellSetConnectivity.h instead of " + "vtkm/filter/CellSetConnectivity.h.") +inline void CellSetConnectivity_deprecated() {} + +inline void CellSetConnectivity_deprecated_warning() { -public: - using SupportedTypes = vtkm::TypeListScalarAll; - VTKM_CONT CellSetConnectivity(); + CellSetConnectivity_deprecated(); +} - void SetOutputFieldName(const std::string& name) { this->OutputFieldName = name; } - - VTKM_CONT - const std::string& GetOutputFieldName() const { return this->OutputFieldName; } - - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy); - - template - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - const vtkm::filter::PolicyBase&) - { - result.AddField(field); - return true; - } - -private: - std::string OutputFieldName; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::connected_components::CellSetConnectivity.") + CellSetConnectivity : public vtkm::filter::connected_components::CellSetConnectivity +{ + using connected_components::CellSetConnectivity::CellSetConnectivity; }; -} -} -#include +} +} // namespace vtkm::filter -#endif //vtkm_m_filter_CellSetConnectivity_h +#endif //vtk_m_filter_CellSetConnectivity_h diff --git a/vtkm/filter/CellSetConnectivity.hxx b/vtkm/filter/CellSetConnectivity.hxx deleted file mode 100644 index f5a7c0591..000000000 --- a/vtkm/filter/CellSetConnectivity.hxx +++ /dev/null @@ -1,42 +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 vtkm_m_filter_CellSetConnectivity_hxx -#define vtkm_m_filter_CellSetConnectivity_hxx - -#include -#include - -namespace vtkm -{ -namespace filter -{ - -VTKM_CONT CellSetConnectivity::CellSetConnectivity() - : OutputFieldName("component") -{ -} - -template -inline VTKM_CONT vtkm::cont::DataSet CellSetConnectivity::DoExecute( - const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy) -{ - vtkm::cont::ArrayHandle component; - - vtkm::worklet::connectivity::CellSetConnectivity().Run( - vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this), component); - - return CreateResultFieldCell(input, component, this->GetOutputFieldName()); -} -} -} - -#endif //vtkm_m_filter_CellSetConnectivity_hxx diff --git a/vtkm/filter/ImageConnectivity.h b/vtkm/filter/ImageConnectivity.h index c069c63b7..704f82dd5 100644 --- a/vtkm/filter/ImageConnectivity.h +++ b/vtkm/filter/ImageConnectivity.h @@ -7,43 +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_ImageConnectivity_h #define vtk_m_filter_ImageConnectivity_h -#include -#include +#include +#include -/// \brief Groups connected points that have the same field value -/// -/// -/// The ImageConnectivity filter finds groups of points that have the same field value and are -/// connected together through their topology. Any point is considered to be connected to its Moore neighborhood: -/// 8 neighboring points for 2D and 27 neighboring points for 3D. As the name implies, ImageConnectivity only -/// works on data with a structured cell set. You will get an error if you use any other type of cell set. -/// The active field passed to the filter must be associated with the points. -/// The result of the filter is a point field of type vtkm::Id. Each entry in the point field will be a number that -/// identifies to which region it belongs. By default, this output point field is named “component”. namespace vtkm { namespace filter { -class ImageConnectivity : public vtkm::filter::FilterField + +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/connected_components/ImageConnectivity.h instead of " + "vtkm/filter/ImageConnectivity.h.") +inline void ImageConnectivity_deprecated() {} + +inline void ImageConnectivity_deprecated_warning() { -public: - using SupportedTypes = vtkm::TypeListScalarAll; + ImageConnectivity_deprecated(); +} - VTKM_CONT inline ImageConnectivity() { this->SetOutputFieldName("component"); } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMetadata, - const vtkm::filter::PolicyBase&); +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::connected_components::ImageConnectivity.") + ImageConnectivity : public vtkm::filter::connected_components::ImageConnectivity +{ + using connected_components::ImageConnectivity::ImageConnectivity; }; + } } // namespace vtkm::filter -#include - #endif //vtk_m_filter_ImageConnectivity_h diff --git a/vtkm/filter/ImageConnectivity.hxx b/vtkm/filter/ImageConnectivity.hxx deleted file mode 100644 index 3bd094b69..000000000 --- a/vtkm/filter/ImageConnectivity.hxx +++ /dev/null @@ -1,42 +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_ImageConnectivity_hxx -#define vtk_m_filter_ImageConnectivity_hxx - -namespace vtkm -{ -namespace filter -{ - -template -inline VTKM_CONT vtkm::cont::DataSet ImageConnectivity::DoExecute( - const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMetadata, - const vtkm::filter::PolicyBase& policy) -{ - if (!fieldMetadata.IsPointField()) - { - throw vtkm::cont::ErrorBadValue("Active field for ImageConnectivity must be a point field."); - } - - vtkm::cont::ArrayHandle component; - - vtkm::worklet::connectivity::ImageConnectivity().Run( - vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this), field, component); - - auto result = CreateResult(input, component, this->GetOutputFieldName(), fieldMetadata); - return result; -} -} -} - -#endif diff --git a/vtkm/filter/connected_components/CMakeLists.txt b/vtkm/filter/connected_components/CMakeLists.txt new file mode 100644 index 000000000..0d56b1766 --- /dev/null +++ b/vtkm/filter/connected_components/CMakeLists.txt @@ -0,0 +1,34 @@ +##============================================================================ +## 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. +##============================================================================ +set(connected_components_headers + CellSetConnectivity.h + ImageConnectivity.h + ) +set(connected_components_sources_device + CellSetConnectivity.cxx + ImageConnectivity.cxx + ) + +vtkm_library( + NAME vtkm_filter_connected_components + HEADERS ${connected_components_headers} + DEVICE_SOURCES ${connected_components_sources_device} + USE_VTKM_JOB_POOL +) + +target_link_libraries(vtkm_filter_connected_components PRIVATE vtkm_worklet PUBLIC vtkm_filter_core) +target_link_libraries(vtkm_filter PUBLIC INTERFACE vtkm_filter_connected_components) + +add_subdirectory(worklet) + +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +if (VTKm_ENABLE_TESTING) + add_subdirectory(testing) +endif () diff --git a/vtkm/filter/connected_components/CellSetConnectivity.cxx b/vtkm/filter/connected_components/CellSetConnectivity.cxx new file mode 100644 index 000000000..0b7e02b14 --- /dev/null +++ b/vtkm/filter/connected_components/CellSetConnectivity.cxx @@ -0,0 +1,34 @@ +//============================================================================ +// 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 + +namespace vtkm +{ +namespace filter +{ +namespace connected_components +{ +VTKM_CONT vtkm::cont::DataSet CellSetConnectivity::DoExecute(const vtkm::cont::DataSet& input) +{ + vtkm::cont::ArrayHandle component; + + vtkm::worklet::connectivity::CellSetConnectivity().Run(input.GetCellSet(), component); + + auto output = CreateResultFieldCell(input, component, this->GetOutputFieldName()); + this->MapFieldsOntoOutput(input, output); + + return output; +} +} // namespace connected_components +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/connected_components/CellSetConnectivity.h b/vtkm/filter/connected_components/CellSetConnectivity.h new file mode 100644 index 000000000..a41c5d748 --- /dev/null +++ b/vtkm/filter/connected_components/CellSetConnectivity.h @@ -0,0 +1,46 @@ +//============================================================================ +// 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_connected_components_CellSetConnectivity_h +#define vtk_m_filter_connected_components_CellSetConnectivity_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace connected_components +{ +/// \brief Finds groups of cells that are connected together through their topology. +/// +/// Finds and labels groups of cells that are connected together through their topology. +/// Two cells are considered connected if they share an edge. CellSetConnectivity identifies some +/// number of components and assigns each component a unique integer. +/// The result of the filter is a cell field of type vtkm::Id with the default name of 'component'. +/// Each entry in the cell field will be a number that identifies to which component the cell belongs. +class VTKM_FILTER_CONNECTED_COMPONENTS_EXPORT CellSetConnectivity + : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT CellSetConnectivity() { this->SetOutputFieldName("component"); } + +private: + VTKM_CONT + vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + std::string OutputFieldName; +}; +} +} +} + +#endif //vtk_m_filter_connected_components_CellSetConnectivity_h diff --git a/vtkm/filter/connected_components/ImageConnectivity.cxx b/vtkm/filter/connected_components/ImageConnectivity.cxx new file mode 100644 index 000000000..e00a497be --- /dev/null +++ b/vtkm/filter/connected_components/ImageConnectivity.cxx @@ -0,0 +1,45 @@ +//============================================================================ +// 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 + +namespace vtkm +{ +namespace filter +{ +namespace connected_components +{ +VTKM_CONT vtkm::cont::DataSet ImageConnectivity::DoExecute(const vtkm::cont::DataSet& input) +{ + const auto& field = this->GetFieldFromDataSet(input); + + if (!field.IsFieldPoint()) + { + throw vtkm::cont::ErrorBadValue("Active field for ImageConnectivity must be a point field."); + } + + vtkm::cont::ArrayHandle component; + + auto resolveType = [&](const auto& concrete) { + vtkm::worklet::connectivity::ImageConnectivity().Run(input.GetCellSet(), concrete, component); + }; + const auto& fieldArray = field.GetData(); + fieldArray.CastAndCallForTypes(resolveType); + + auto output = CreateResultFieldPoint(input, component, this->GetOutputFieldName()); + this->MapFieldsOntoOutput(input, output); + + return output; +} +} // namespace connected_components +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/connected_components/ImageConnectivity.h b/vtkm/filter/connected_components/ImageConnectivity.h new file mode 100644 index 000000000..e66bc6b3e --- /dev/null +++ b/vtkm/filter/connected_components/ImageConnectivity.h @@ -0,0 +1,47 @@ +//============================================================================ +// 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_connected_components_ImageConnectivity_h +#define vtk_m_filter_connected_components_ImageConnectivity_h + +#include +#include + +/// \brief Groups connected points that have the same field value +/// +/// +/// The ImageConnectivity filter finds groups of points that have the same field value and are +/// connected together through their topology. Any point is considered to be connected to its Moore neighborhood: +/// 8 neighboring points for 2D and 27 neighboring points for 3D. As the name implies, ImageConnectivity only +/// works on data with a structured cell set. You will get an error if you use any other type of cell set. +/// The active field passed to the filter must be associated with the points. +/// The result of the filter is a point field of type vtkm::Id. Each entry in the point field will be a number that +/// identifies to which region it belongs. By default, this output point field is named “component”. +namespace vtkm +{ +namespace filter +{ +namespace connected_components +{ +class VTKM_FILTER_CONNECTED_COMPONENTS_EXPORT ImageConnectivity + : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT ImageConnectivity() { this->SetOutputFieldName("component"); } + +private: + VTKM_CONT + vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; +}; +} // namespace connected_components +} // namespace filter +} // namespace vtkm + +#endif //vtk_m_filter_connected_components_ImageConnectivity_h diff --git a/vtkm/filter/connected_components/testing/CMakeLists.txt b/vtkm/filter/connected_components/testing/CMakeLists.txt new file mode 100644 index 000000000..aed06407c --- /dev/null +++ b/vtkm/filter/connected_components/testing/CMakeLists.txt @@ -0,0 +1,26 @@ +##============================================================================ +## 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. +##============================================================================ + +set(unit_tests + UnitTestCellSetConnectivityFilter.cxx + UnitTestImageConnectivityFilter.cxx + ) + +set(libraries + vtkm_filter_contour + vtkm_filter_connected_components + vtkm_source + ) + +vtkm_unit_tests( + SOURCES ${unit_tests} + LIBRARIES ${libraries} + USE_VTKM_JOB_POOL +) diff --git a/vtkm/filter/testing/UnitTestCellSetConnectivityFilter.cxx b/vtkm/filter/connected_components/testing/UnitTestCellSetConnectivityFilter.cxx similarity index 91% rename from vtkm/filter/testing/UnitTestCellSetConnectivityFilter.cxx rename to vtkm/filter/connected_components/testing/UnitTestCellSetConnectivityFilter.cxx index b59d08348..88863d79d 100644 --- a/vtkm/filter/testing/UnitTestCellSetConnectivityFilter.cxx +++ b/vtkm/filter/connected_components/testing/UnitTestCellSetConnectivityFilter.cxx @@ -11,8 +11,8 @@ #include #include #include -#include #include +#include #include namespace @@ -34,7 +34,7 @@ public: filter.SetActiveField("tangle"); vtkm::cont::DataSet iso = filter.Execute(dataSet); - vtkm::filter::CellSetConnectivity connectivity; + vtkm::filter::connected_components::CellSetConnectivity connectivity; const vtkm::cont::DataSet output = connectivity.Execute(iso); vtkm::cont::ArrayHandle componentArray; @@ -52,7 +52,7 @@ public: { vtkm::cont::DataSet dataSet = vtkm::cont::testing::MakeTestDataSet().Make3DExplicitDataSet5(); - vtkm::filter::CellSetConnectivity connectivity; + vtkm::filter::connected_components::CellSetConnectivity connectivity; const vtkm::cont::DataSet output = connectivity.Execute(dataSet); vtkm::cont::ArrayHandle componentArray; @@ -69,7 +69,7 @@ public: void TestUniformDataSet() const { vtkm::cont::DataSet dataSet = vtkm::cont::testing::MakeTestDataSet().Make3DUniformDataSet1(); - vtkm::filter::CellSetConnectivity connectivity; + vtkm::filter::connected_components::CellSetConnectivity connectivity; const vtkm::cont::DataSet output = connectivity.Execute(dataSet); vtkm::cont::ArrayHandle componentArray; diff --git a/vtkm/filter/testing/UnitTestImageConnectivityFilter.cxx b/vtkm/filter/connected_components/testing/UnitTestImageConnectivityFilter.cxx similarity index 94% rename from vtkm/filter/testing/UnitTestImageConnectivityFilter.cxx rename to vtkm/filter/connected_components/testing/UnitTestImageConnectivityFilter.cxx index a2113b579..6c2cf4153 100644 --- a/vtkm/filter/testing/UnitTestImageConnectivityFilter.cxx +++ b/vtkm/filter/connected_components/testing/UnitTestImageConnectivityFilter.cxx @@ -8,7 +8,7 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include +#include #include @@ -39,7 +39,7 @@ void TestImageConnectivity() { vtkm::cont::DataSet dataSet = MakeTestDataSet(); - vtkm::filter::ImageConnectivity connectivity; + vtkm::filter::connected_components::ImageConnectivity connectivity; connectivity.SetActiveField("color"); const vtkm::cont::DataSet outputData = connectivity.Execute(dataSet); diff --git a/vtkm/worklet/connectivities/CMakeLists.txt b/vtkm/filter/connected_components/worklet/CMakeLists.txt similarity index 100% rename from vtkm/worklet/connectivities/CMakeLists.txt rename to vtkm/filter/connected_components/worklet/CMakeLists.txt diff --git a/vtkm/worklet/connectivities/CellSetConnectivity.h b/vtkm/filter/connected_components/worklet/CellSetConnectivity.h similarity index 90% rename from vtkm/worklet/connectivities/CellSetConnectivity.h rename to vtkm/filter/connected_components/worklet/CellSetConnectivity.h index 25fa10279..f97dc15b4 100644 --- a/vtkm/worklet/connectivities/CellSetConnectivity.h +++ b/vtkm/filter/connected_components/worklet/CellSetConnectivity.h @@ -10,8 +10,8 @@ #ifndef vtk_m_worklet_connectivity_CellSetConnectivity_h #define vtk_m_worklet_connectivity_CellSetConnectivity_h -#include -#include +#include +#include namespace vtkm { diff --git a/vtkm/worklet/connectivities/CellSetDualGraph.h b/vtkm/filter/connected_components/worklet/CellSetDualGraph.h similarity index 100% rename from vtkm/worklet/connectivities/CellSetDualGraph.h rename to vtkm/filter/connected_components/worklet/CellSetDualGraph.h diff --git a/vtkm/worklet/connectivities/GraphConnectivity.h b/vtkm/filter/connected_components/worklet/GraphConnectivity.h similarity index 94% rename from vtkm/worklet/connectivities/GraphConnectivity.h rename to vtkm/filter/connected_components/worklet/GraphConnectivity.h index cda31610d..0e676d154 100644 --- a/vtkm/worklet/connectivities/GraphConnectivity.h +++ b/vtkm/filter/connected_components/worklet/GraphConnectivity.h @@ -12,9 +12,9 @@ #define vtk_m_worklet_connectivity_graph_connectivity_h #include -#include -#include -#include +#include +#include +#include namespace vtkm { diff --git a/vtkm/worklet/connectivities/ImageConnectivity.h b/vtkm/filter/connected_components/worklet/ImageConnectivity.h similarity index 94% rename from vtkm/worklet/connectivities/ImageConnectivity.h rename to vtkm/filter/connected_components/worklet/ImageConnectivity.h index 455bbd00e..8d7a34660 100644 --- a/vtkm/worklet/connectivities/ImageConnectivity.h +++ b/vtkm/filter/connected_components/worklet/ImageConnectivity.h @@ -11,14 +11,15 @@ #ifndef vtk_m_worklet_connectivity_ImageConnectivity_h #define vtk_m_worklet_connectivity_ImageConnectivity_h +#include #include #include #include #include #include -#include -#include +#include +#include namespace vtkm @@ -41,7 +42,7 @@ public: using ExecutionSignature = void(Boundary, _2, _3, _4); - // compOut is a "linear" alias of neightborComp such that we can update component labels + // compOut is a "linear" alias of neighborComp such that we can update component labels template - -#include - -#include - -#include -#include -#include - -class TestCellSetConnectivity -{ -public: - void TestTangleIsosurface() const - { - vtkm::Id3 dims(4, 4, 4); - vtkm::source::Tangle tangle(dims); - vtkm::cont::DataSet dataSet = tangle.Execute(); - - vtkm::filter::Contour filter; - filter.SetGenerateNormals(true); - filter.SetMergeDuplicatePoints(true); - filter.SetIsoValue(0, 0.1); - filter.SetActiveField("tangle"); - vtkm::cont::DataSet outputData = filter.Execute(dataSet); - - auto cellSet = outputData.GetCellSet().AsCellSet>(); - vtkm::cont::ArrayHandle componentArray; - vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray); - - using Algorithm = vtkm::cont::Algorithm; - Algorithm::Sort(componentArray); - Algorithm::Unique(componentArray); - VTKM_TEST_ASSERT(componentArray.GetNumberOfValues() == 8, - "Wrong number of connected components"); - } - - void TestExplicitDataSet() const - { - vtkm::cont::DataSet dataSet = vtkm::cont::testing::MakeTestDataSet().Make3DExplicitDataSet5(); - - auto cellSet = dataSet.GetCellSet().AsCellSet>(); - vtkm::cont::ArrayHandle componentArray; - vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray); - - using Algorithm = vtkm::cont::Algorithm; - Algorithm::Sort(componentArray); - Algorithm::Unique(componentArray); - VTKM_TEST_ASSERT(componentArray.GetNumberOfValues() == 1, - "Wrong number of connected components"); - } - - void TestUniformDataSet() const - { - vtkm::cont::DataSet dataSet = vtkm::cont::testing::MakeTestDataSet().Make3DUniformDataSet1(); - - auto cellSet = dataSet.GetCellSet(); - vtkm::cont::ArrayHandle componentArray; - vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray); - - using Algorithm = vtkm::cont::Algorithm; - Algorithm::Sort(componentArray); - Algorithm::Unique(componentArray); - VTKM_TEST_ASSERT(componentArray.GetNumberOfValues() == 1, - "Wrong number of connected components"); - } - - void operator()() const - { - this->TestTangleIsosurface(); - this->TestExplicitDataSet(); - this->TestUniformDataSet(); - } -}; - -int UnitTestCellSetConnectivity(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestCellSetConnectivity(), argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestCellSetDualGraph.cxx b/vtkm/worklet/testing/UnitTestCellSetDualGraph.cxx deleted file mode 100644 index bf0560bab..000000000 --- a/vtkm/worklet/testing/UnitTestCellSetDualGraph.cxx +++ /dev/null @@ -1,112 +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 - -class TestCellSetDualGraph -{ -private: - using GroupedConnectivityArrayType = - vtkm::cont::ArrayHandleGroupVecVariable, - vtkm::cont::ArrayHandle>; - - static GroupedConnectivityArrayType MakeGroupedConnectivity( - vtkm::cont::ArrayHandle connectivity, - vtkm::cont::ArrayHandle counts) - { - return GroupedConnectivityArrayType(connectivity, - vtkm::cont::ConvertNumComponentsToOffsets(counts)); - } - - static bool TestConnectivity(GroupedConnectivityArrayType computedConnectivityArray, - GroupedConnectivityArrayType expectedConnectivityArray) - { - auto computedConnections = computedConnectivityArray.ReadPortal(); - auto expectedConnections = expectedConnectivityArray.ReadPortal(); - - vtkm::Id numItems = computedConnections.GetNumberOfValues(); - if (numItems != expectedConnections.GetNumberOfValues()) - { - return false; - } - - for (vtkm::Id itemIndex = 0; itemIndex < numItems; ++itemIndex) - { - auto computed = computedConnections.Get(itemIndex); - auto expected = expectedConnections.Get(itemIndex); - vtkm::IdComponent numConnections = computed.GetNumberOfComponents(); - if (numConnections != expected.GetNumberOfComponents()) - { - return false; - } - - // computed and expected are Vec-like objects that should represent the same thing. - // However, although both should have the same indices, they may be in different - // orders. - std::set computedSet; - std::set expectedSet; - for (vtkm::IdComponent componentIndex = 0; componentIndex < numConnections; ++componentIndex) - { - computedSet.insert(computed[componentIndex]); - expectedSet.insert(expected[componentIndex]); - } - if (computedSet != expectedSet) - { - return false; - } - } - - return true; - } - -public: - void TestTriangleMesh() const - { - auto connectivity = vtkm::cont::make_ArrayHandle( - { 0, 2, 4, 1, 3, 5, 2, 6, 4, 5, 3, 7, 2, 9, 6, 4, 6, 8 }); - - vtkm::cont::CellSetSingleType<> cellSet; - cellSet.Fill(10, vtkm::CELL_SHAPE_TRIANGLE, 3, connectivity); - - vtkm::cont::ArrayHandle numIndicesArray; - vtkm::cont::ArrayHandle indexOffsetArray; - vtkm::cont::ArrayHandle connectivityArray; - - vtkm::worklet::connectivity::CellSetDualGraph().Run( - cellSet, numIndicesArray, indexOffsetArray, connectivityArray); - - vtkm::cont::ArrayHandle expectedNumIndices = - vtkm::cont::make_ArrayHandle({ 1, 1, 3, 1, 1, 1 }); - VTKM_TEST_ASSERT( - test_equal_portals(numIndicesArray.ReadPortal(), expectedNumIndices.ReadPortal())); - - vtkm::cont::ArrayHandle expectedIndexOffset = - vtkm::cont::make_ArrayHandle({ 0, 1, 2, 5, 6, 7 }); - VTKM_TEST_ASSERT( - test_equal_portals(indexOffsetArray.ReadPortal(), expectedIndexOffset.ReadPortal())); - - vtkm::cont::ArrayHandle expectedConnectivity = - vtkm::cont::make_ArrayHandle({ 2, 3, 0, 4, 5, 1, 2, 2 }); - VTKM_TEST_ASSERT( - TestConnectivity(MakeGroupedConnectivity(connectivityArray, numIndicesArray), - MakeGroupedConnectivity(expectedConnectivity, numIndicesArray))); - } - - void operator()() const { this->TestTriangleMesh(); } -}; - -int UnitTestCellSetDualGraph(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestCellSetDualGraph(), argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestGraphConnectivity.cxx b/vtkm/worklet/testing/UnitTestGraphConnectivity.cxx deleted file mode 100644 index 7be3fc316..000000000 --- a/vtkm/worklet/testing/UnitTestGraphConnectivity.cxx +++ /dev/null @@ -1,141 +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 - -class AdjacentDifference : public vtkm::worklet::WorkletMapField -{ -public: - using ControlSignature = void(FieldIn index, WholeArrayIn counts, FieldOut outputCount); - using ExecutionSignature = void(_1, _2, _3); - using InputDomain = _1; - - template - VTKM_EXEC void operator()(const vtkm::Id& index, - const WholeArrayType& counts, - int& difference) const - { - difference = counts.Get(index + 1) - counts.Get(index); - } -}; - -class SameComponent : public vtkm::worklet::WorkletMapField -{ -public: - using ControlSignature = void(FieldIn start, - FieldIn degree, - WholeArrayIn conns, - WholeArrayIn comps, - AtomicArrayInOut same); - using ExecutionSignature = void(WorkIndex, _1, _2, _3, _4, _5); - - template - VTKM_EXEC void operator()(vtkm::Id index, - int start, - int degree, - const Conn& conns, - const Comp& comps, - AtomicSame& same) const - { - for (vtkm::Id offset = start; offset < start + degree; ++offset) - { - vtkm::Id neighbor = conns.Get(offset); - if (comps.Get(index) != comps.Get(neighbor)) - { - same.Set(0, 0); - } - } - } -}; - -class TestGraphConnectivity -{ -public: - void TestECL_CC(const std::string& filename, int ncomps) const - { - auto pathname = - vtkm::cont::testing::Testing::GetTestDataBasePath() + "/third_party/ecl_cc/" + filename; - std::ifstream stream(pathname, std::ios_base::in | std::ios_base::binary); - - int nnodes; - stream.read(reinterpret_cast(&nnodes), sizeof(nnodes)); - - int nedges; - stream.read(reinterpret_cast(&nedges), sizeof(nedges)); - - // CSR, there is one more element in offsets thant the actual number of nodes. - std::vector offsets(nnodes + 1); - std::vector conns(nedges); - - stream.read(reinterpret_cast(offsets.data()), (nnodes + 1) * sizeof(int)); - stream.read(reinterpret_cast(conns.data()), nedges * sizeof(int)); - - vtkm::cont::ArrayHandle counts_h; - vtkm::cont::Invoker invoke; - invoke(AdjacentDifference{}, - vtkm::cont::make_ArrayHandleCounting(0, 1, nnodes), - vtkm::cont::make_ArrayHandle(offsets, vtkm::CopyFlag::On), - counts_h); - - offsets.pop_back(); - vtkm::cont::ArrayHandle offsets_h = - vtkm::cont::make_ArrayHandle(offsets, vtkm::CopyFlag::On); - - vtkm::cont::ArrayHandle conns_h = vtkm::cont::make_ArrayHandle(conns, vtkm::CopyFlag::Off); - - vtkm::cont::ArrayHandle comps_h; - vtkm::worklet::connectivity::GraphConnectivity().Run(counts_h, offsets_h, conns_h, comps_h); - - VTKM_TEST_ASSERT(vtkm::cont::Algorithm::Reduce(comps_h, vtkm::Id(0), vtkm::Maximum{}) == - ncomps - 1, - "number of components mismatch"); - - vtkm::cont::ArrayHandle atomicSame; - atomicSame.Allocate(1); - atomicSame.WritePortal().Set(0, 1); - - invoke(SameComponent{}, offsets_h, counts_h, conns_h, comps_h, atomicSame); - VTKM_TEST_ASSERT(atomicSame.ReadPortal().Get(0) == 1, - "Neighboring nodes don't have the same component id"); - } - - void TestECL_CC_DataSets() const { TestECL_CC("internet.egr", 1); } - - void TestSimpleGraph() const - { - vtkm::cont::ArrayHandle counts_h = - vtkm::cont::make_ArrayHandle({ 1, 1, 2, 2, 2 }); - vtkm::cont::ArrayHandle offsets_h = - vtkm::cont::make_ArrayHandle({ 0, 1, 2, 4, 6 }); - vtkm::cont::ArrayHandle conn_h = - vtkm::cont::make_ArrayHandle({ 2, 4, 0, 3, 2, 4, 1, 3 }); - vtkm::cont::ArrayHandle comps; - - vtkm::worklet::connectivity::GraphConnectivity().Run(counts_h, offsets_h, conn_h, comps); - - for (int i = 0; i < comps.GetNumberOfValues(); i++) - { - VTKM_TEST_ASSERT(comps.ReadPortal().Get(i) == 0, "Components has unexpected value."); - } - } - - void operator()() const - { - TestSimpleGraph(); - TestECL_CC_DataSets(); - } -}; - -int UnitTestGraphConnectivity(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestGraphConnectivity(), argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestImageConnectivity.cxx b/vtkm/worklet/testing/UnitTestImageConnectivity.cxx deleted file mode 100644 index e42cb4b10..000000000 --- a/vtkm/worklet/testing/UnitTestImageConnectivity.cxx +++ /dev/null @@ -1,148 +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 - -class TestImageConnectivity -{ -public: - using Algorithm = vtkm::cont::Algorithm; - - void operator()() const - { - CCL_CUDA8x4(); - CCL_CUDA8x8(); - Valentine(); - } - - void CCL_CUDA8x4() const - { - // example image from Connected Component Labeling in CUDA by OndˇrejˇŚtava, - // Bedˇrich Beneˇ - std::vector pixels(8 * 4, 0); - pixels[3] = pixels[4] = pixels[10] = pixels[11] = 1; - pixels[1] = pixels[9] = pixels[16] = pixels[17] = pixels[24] = pixels[25] = 1; - pixels[7] = pixels[15] = pixels[21] = pixels[23] = pixels[28] = pixels[29] = pixels[30] = - pixels[31] = 1; - - vtkm::cont::DataSetBuilderUniform builder; - vtkm::cont::DataSet data = builder.Create(vtkm::Id3(8, 4, 1)); - - auto colorField = vtkm::cont::make_FieldPoint( - "color", vtkm::cont::make_ArrayHandle(pixels, vtkm::CopyFlag::On)); - data.AddField(colorField); - - vtkm::cont::ArrayHandle component; - vtkm::worklet::connectivity::ImageConnectivity().Run( - data.GetCellSet().AsCellSet>(), - colorField.GetData().AsArrayHandle>(), - component); - - std::vector componentExpected = { 0, 1, 2, 1, 1, 3, 3, 4, 0, 1, 1, 1, 3, 3, 3, 4, - 1, 1, 3, 3, 3, 4, 3, 4, 1, 1, 3, 3, 4, 4, 4, 4 }; - - - std::size_t i = 0; - for (vtkm::Id index = 0; index < component.GetNumberOfValues(); index++, i++) - { - VTKM_TEST_ASSERT(component.ReadPortal().Get(index) == componentExpected[i], - "Components has unexpected value."); - } - } - - void CCL_CUDA8x8() const - { - // example from Figure 35.7 of Connected Component Labeling in CUDA by OndˇrejˇŚtava, - // Bedˇrich Beneˇ - auto pixels = vtkm::cont::make_ArrayHandle({ - 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, - 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, - }); - - vtkm::cont::DataSetBuilderUniform builder; - vtkm::cont::DataSet data = builder.Create(vtkm::Id3(8, 8, 1)); - - auto colorField = vtkm::cont::make_FieldPoint("color", pixels); - data.AddField(colorField); - - vtkm::cont::ArrayHandle component; - vtkm::worklet::connectivity::ImageConnectivity().Run( - data.GetCellSet().AsCellSet>(), - colorField.GetData().AsArrayHandle>(), - component); - - std::vector componentExpected = { 0, 1, 1, 1, 0, 1, 1, 2, 0, 0, 0, 1, 0, 1, 1, 2, - 0, 1, 1, 0, 0, 1, 1, 2, 0, 1, 0, 0, 0, 1, 1, 2, - 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 0, 1, 0, 1, 1, 1, 3, 3, 0, 1, 1, 1, 1, 1, 3, 3 }; - - for (vtkm::Id i = 0; i < component.GetNumberOfValues(); ++i) - { - VTKM_TEST_ASSERT(component.ReadPortal().Get(i) == componentExpected[size_t(i)], - "Components has unexpected value."); - } - } - - void Valentine() const - { - // Sample image by VALENTINE PELTIER - - // clang-format off - auto pixels = vtkm::cont::make_ArrayHandle( { - 1, 1, 0, 1, 0, 0, - 0, 0, 0, 1, 1, 0, - 1, 1, 0, 1, 0, 1, - 1, 0, 1, 0, 0, 0, - 0, 1, 0, 1, 1, 1, - 1, 1, 0, 0, 1, 0, - }); - // clang-format on - - vtkm::cont::DataSetBuilderUniform builder; - vtkm::cont::DataSet data = builder.Create(vtkm::Id3(6, 6, 1)); - - auto colorField = vtkm::cont::make_FieldPoint("color", pixels); - data.AddField(colorField); - - vtkm::cont::ArrayHandle component; - vtkm::worklet::connectivity::ImageConnectivity().Run( - data.GetCellSet().AsCellSet>(), - colorField.GetData().AsArrayHandle>(), - component); - - // clang-format off - std::vector componentExpected = { - 0, 0, 1, 2, 1, 1, - 1, 1, 1, 2, 2, 1, - 2, 2, 1, 2, 1, 2, - 2, 1, 2, 1, 1, 1, - 1, 2, 1, 2, 2, 2, - 2, 2, 1, 1, 2, 3 - }; - // clang-format on - - for (vtkm::Id i = 0; i < component.GetNumberOfValues(); ++i) - { - VTKM_TEST_ASSERT(component.ReadPortal().Get(i) == componentExpected[size_t(i)], - "Components has unexpected value."); - } - } -}; - - -int UnitTestImageConnectivity(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestImageConnectivity(), argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestInnerJoin.cxx b/vtkm/worklet/testing/UnitTestInnerJoin.cxx deleted file mode 100644 index 59bb00453..000000000 --- a/vtkm/worklet/testing/UnitTestInnerJoin.cxx +++ /dev/null @@ -1,96 +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 - - -class TestInnerJoin -{ -public: - static bool TestJoinedValues(const vtkm::cont::ArrayHandle& computedValuesArray, - const vtkm::cont::ArrayHandle& expectedValuesArray, - const vtkm::cont::ArrayHandle& originalKeysArray) - { - auto computedValues = computedValuesArray.ReadPortal(); - auto expectedValues = expectedValuesArray.ReadPortal(); - auto originalKeys = originalKeysArray.ReadPortal(); - if (computedValues.GetNumberOfValues() != expectedValues.GetNumberOfValues()) - { - return false; - } - - for (vtkm::Id valueIndex = 0; valueIndex < computedValues.GetNumberOfValues(); ++valueIndex) - { - vtkm::Id computed = computedValues.Get(valueIndex); - vtkm::Id expected = expectedValues.Get(valueIndex); - - // The join algorithm uses some key/value sorts that are unstable. Thus, for keys - // that are repeated in the original input, the computed and expected values may be - // swapped in the results associated with those keys. To test correctly, the values - // we computed for are actually indices into the original keys array. Thus, if both - // computed and expected are different indices that point to the same original key, - // then the algorithm is still correct. - vtkm::Id computedKey = originalKeys.Get(computed); - vtkm::Id expectedKey = originalKeys.Get(expected); - if (computedKey != expectedKey) - { - return false; - } - } - - return true; - } - - void TestTwoArrays() const - { - vtkm::cont::ArrayHandle keysAOriginal = - vtkm::cont::make_ArrayHandle({ 8, 3, 6, 8, 9, 5, 12, 10, 14 }); - vtkm::cont::ArrayHandle keysBOriginal = - vtkm::cont::make_ArrayHandle({ 7, 11, 9, 8, 5, 1, 0, 5 }); - - vtkm::cont::ArrayHandle keysA; - vtkm::cont::ArrayHandle keysB; - vtkm::cont::ArrayHandle valuesA; - vtkm::cont::ArrayHandle valuesB; - - vtkm::cont::ArrayCopy(keysAOriginal, keysA); - vtkm::cont::ArrayCopy(keysBOriginal, keysB); - vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleIndex(keysA.GetNumberOfValues()), valuesA); - vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleIndex(keysB.GetNumberOfValues()), valuesB); - - vtkm::cont::ArrayHandle joinedIndex; - vtkm::cont::ArrayHandle outA; - vtkm::cont::ArrayHandle outB; - - vtkm::worklet::connectivity::InnerJoin().Run( - keysA, valuesA, keysB, valuesB, joinedIndex, outA, outB); - - vtkm::cont::ArrayHandle expectedIndex = - vtkm::cont::make_ArrayHandle({ 5, 5, 8, 8, 9 }); - VTKM_TEST_ASSERT(test_equal_portals(joinedIndex.ReadPortal(), expectedIndex.ReadPortal())); - - vtkm::cont::ArrayHandle expectedOutA = - vtkm::cont::make_ArrayHandle({ 5, 5, 0, 3, 4 }); - VTKM_TEST_ASSERT(TestJoinedValues(outA, expectedOutA, keysAOriginal)); - - vtkm::cont::ArrayHandle expectedOutB = - vtkm::cont::make_ArrayHandle({ 4, 7, 3, 3, 2 }); - VTKM_TEST_ASSERT(TestJoinedValues(outB, expectedOutB, keysBOriginal)); - } - - void operator()() const { this->TestTwoArrays(); } -}; - -int UnitTestInnerJoin(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestInnerJoin(), argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestPointerJumping.cxx b/vtkm/worklet/testing/UnitTestPointerJumping.cxx deleted file mode 100644 index 07d481055..000000000 --- a/vtkm/worklet/testing/UnitTestPointerJumping.cxx +++ /dev/null @@ -1,40 +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 - -void TestLinear() -{ - const vtkm::Id N = 100; - auto counting = vtkm::cont::make_ArrayHandleCounting(-1, 1, N - 1); - - vtkm::cont::ArrayHandle parents; - vtkm::cont::ArrayCopy(counting, parents); - parents.WritePortal().Set(0, 0); - - vtkm::cont::Invoker invoker; - invoker(vtkm::worklet::connectivity::PointerJumping{}, parents); - VTKM_TEST_ASSERT( - test_equal_ArrayHandles(vtkm::cont::ArrayHandleConstant(0, N - 1), parents)); -} - -void TestPointerJumping() -{ - TestLinear(); -} - -int UnitTestPointerJumping(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestPointerJumping, argc, argv); -}