From ab09f77b7c6dc4b6323a57aa12e0efff517a6978 Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Mon, 16 May 2022 14:55:14 -0600 Subject: [PATCH] migrate Probe filter --- .../multi_backend/MultiDeviceGradient.hxx | 1 + vtkm/filter/CMakeLists.txt | 4 +- vtkm/filter/NewFilter.h | 9 +- vtkm/filter/Probe.h | 50 +---- vtkm/filter/Probe.hxx | 111 --------- vtkm/filter/resampling/CMakeLists.txt | 32 +++ vtkm/filter/resampling/Probe.cxx | 85 +++++++ vtkm/filter/resampling/Probe.h | 66 ++++++ vtkm/filter/resampling/testing/CMakeLists.txt | 23 ++ .../testing/UnitTestProbe.cxx | 16 +- vtkm/filter/resampling/worklet/CMakeLists.txt | 15 ++ vtkm/{ => filter/resampling}/worklet/Probe.h | 0 vtkm/filter/testing/CMakeLists.txt | 1 - vtkm/worklet/CMakeLists.txt | 1 - vtkm/worklet/testing/CMakeLists.txt | 1 - vtkm/worklet/testing/UnitTestProbe.cxx | 211 ------------------ 16 files changed, 247 insertions(+), 379 deletions(-) delete mode 100644 vtkm/filter/Probe.hxx create mode 100644 vtkm/filter/resampling/CMakeLists.txt create mode 100644 vtkm/filter/resampling/Probe.cxx create mode 100644 vtkm/filter/resampling/Probe.h create mode 100644 vtkm/filter/resampling/testing/CMakeLists.txt rename vtkm/filter/{ => resampling}/testing/UnitTestProbe.cxx (96%) create mode 100644 vtkm/filter/resampling/worklet/CMakeLists.txt rename vtkm/{ => filter/resampling}/worklet/Probe.h (100%) delete mode 100644 vtkm/worklet/testing/UnitTestProbe.cxx diff --git a/examples/multi_backend/MultiDeviceGradient.hxx b/examples/multi_backend/MultiDeviceGradient.hxx index c7ceb9562..db3362f7f 100644 --- a/examples/multi_backend/MultiDeviceGradient.hxx +++ b/examples/multi_backend/MultiDeviceGradient.hxx @@ -17,6 +17,7 @@ #include +#include namespace { diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index 7452728e0..45b3cd7ab 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -45,6 +45,7 @@ set(deprecated_headers PointAverage.h PointElevation.h PointTransform.h + Probe.h Slice.h SplitSharpEdges.h SurfaceNormals.h @@ -106,7 +107,6 @@ set(extra_headers ParticleAdvection.h Pathline.h PathParticle.h - Probe.h Streamline.h StreamSurface.h ) @@ -122,7 +122,6 @@ set(extra_header_template_sources ParticleAdvection.hxx Pathline.hxx PathParticle.hxx - Probe.hxx Streamline.hxx StreamSurface.hxx ) @@ -200,6 +199,7 @@ add_subdirectory(field_conversion) add_subdirectory(field_transform) add_subdirectory(geometry_refinement) add_subdirectory(mesh_info) +add_subdirectory(resampling) add_subdirectory(vector_analysis) add_subdirectory(zfp) diff --git a/vtkm/filter/NewFilter.h b/vtkm/filter/NewFilter.h index df597cb7f..5fd801bf6 100644 --- a/vtkm/filter/NewFilter.h +++ b/vtkm/filter/NewFilter.h @@ -419,10 +419,6 @@ protected: VTKM_CONT virtual vtkm::cont::PartitionedDataSet DoExecutePartitions( const vtkm::cont::PartitionedDataSet& inData); -private: - VTKM_CONT - virtual vtkm::Id DetermineNumberOfThreads(const vtkm::cont::PartitionedDataSet& input); - template VTKM_CONT void MapFieldsOntoOutput(const vtkm::cont::DataSet& input, vtkm::cont::DataSet& output, @@ -438,6 +434,11 @@ private: } } +private: + VTKM_CONT + virtual vtkm::Id DetermineNumberOfThreads(const vtkm::cont::PartitionedDataSet& input); + + vtkm::filter::FieldSelection FieldsToPass = vtkm::filter::FieldSelection::Mode::All; bool RunFilterWithMultipleThreads = false; }; diff --git a/vtkm/filter/Probe.h b/vtkm/filter/Probe.h index 55ef54d80..561576a15 100644 --- a/vtkm/filter/Probe.h +++ b/vtkm/filter/Probe.h @@ -10,53 +10,23 @@ #ifndef vtk_m_filter_Probe_h #define vtk_m_filter_Probe_h -#include -#include +#include +#include namespace vtkm { namespace filter { -class Probe : public vtkm::filter::FilterDataSet +VTKM_DEPRECATED(1.8, "Use vtkm/filter/resampling/Probe.h instead of vtkm/filter/Probe.h.") +inline void Probe_deprecated() {} + +inline void Probe_deprecated_warning() { -public: - VTKM_CONT - void SetGeometry(const vtkm::cont::DataSet& geometry); - - VTKM_CONT - const vtkm::cont::DataSet& GetGeometry() const; - - VTKM_CONT void SetInvalidValue(vtkm::Float64 invalidValue) { this->InvalidValue = invalidValue; } - VTKM_CONT vtkm::Float64 GetInvalidValue() const { return this->InvalidValue; } - - 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 - //this call is only valid after calling DoExecute. - template - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase); - - template - VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, - const vtkm::cont::ArrayHandle& input, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); - -private: - vtkm::cont::DataSet Geometry; - vtkm::worklet::Probe Worklet; - vtkm::Float64 InvalidValue = vtkm::Nan64(); -}; + Probe_deprecated(); } -} // vtkm::filter -#ifndef vtk_m_filter_Probe_hxx -#include -#endif +} +} // namespace vtkm::filter -#endif // vtk_m_filter_Probe_h +#endif //vtk_m_filter_Probe_h diff --git a/vtkm/filter/Probe.hxx b/vtkm/filter/Probe.hxx deleted file mode 100644 index 3c2a99b1a..000000000 --- a/vtkm/filter/Probe.hxx +++ /dev/null @@ -1,111 +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_Probe_hxx -#define vtk_m_filter_Probe_hxx - -#include - -#include - -#include - -namespace vtkm -{ -namespace filter -{ - -VTKM_CONT -inline void Probe::SetGeometry(const vtkm::cont::DataSet& geometry) -{ - this->Geometry = vtkm::cont::DataSet(); - this->Geometry.SetCellSet(geometry.GetCellSet()); - this->Geometry.AddCoordinateSystem(geometry.GetCoordinateSystem()); -} - -VTKM_CONT -inline const vtkm::cont::DataSet& Probe::GetGeometry() const -{ - return this->Geometry; -} - -template -VTKM_CONT inline vtkm::cont::DataSet Probe::DoExecute( - const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy) -{ - this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this), - input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()), - this->Geometry.GetCoordinateSystem().GetData()); - - auto output = this->Geometry; - auto hpf = this->Worklet.GetHiddenPointsField(); - auto hcf = this->Worklet.GetHiddenCellsField( - vtkm::filter::ApplyPolicyCellSet(output.GetCellSet(), policy, *this)); - - output.AddField(vtkm::cont::make_FieldPoint("HIDDEN", hpf)); - output.AddField(vtkm::cont::make_FieldCell("HIDDEN", hcf)); - - return output; -} - -template -VTKM_CONT inline bool Probe::MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase policy) -{ - if (field.IsFieldPoint()) - { - // If the field is a point field, then we need to do a custom interpolation of the points. - // In this case, we need to call the superclass's MapFieldOntoOutput, which will in turn - // call our DoMapField. - return this->FilterDataSet::MapFieldOntoOutput(result, field, policy); - } - else if (field.IsFieldCell()) - { - vtkm::cont::Field outField; - if (vtkm::filter::MapFieldPermutation( - field, this->Worklet.GetCellIds(), outField, this->InvalidValue)) - { - // output field should be associated with points - outField = vtkm::cont::Field( - field.GetName(), vtkm::cont::Field::Association::Points, outField.GetData()); - result.AddField(outField); - return true; - } - return false; - } - else if (field.IsFieldGlobal()) - { - result.AddField(field); - return true; - } - else - { - return false; - } -} - -template -VTKM_CONT inline bool Probe::DoMapField(vtkm::cont::DataSet& result, - const vtkm::cont::ArrayHandle& input, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase) -{ - VTKM_ASSERT(fieldMeta.IsPointField()); - auto fieldArray = - this->Worklet.ProcessPointField(input, - vtkm::cont::internal::CastInvalidValue(this->InvalidValue), - typename DerivedPolicy::AllCellSetList()); - result.AddField(fieldMeta.AsField(fieldArray)); - return true; -} -} -} // vtkm::filter -#endif diff --git a/vtkm/filter/resampling/CMakeLists.txt b/vtkm/filter/resampling/CMakeLists.txt new file mode 100644 index 000000000..51f5c0074 --- /dev/null +++ b/vtkm/filter/resampling/CMakeLists.txt @@ -0,0 +1,32 @@ +##============================================================================ +## 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(resampling_headers + Probe.h + ) + +set(resampling_sources + Probe.cxx) + +vtkm_library( + NAME vtkm_filter_resampling + HEADERS ${resampling_headers} + DEVICE_SOURCES ${resampling_sources} + USE_VTKM_JOB_POOL +) + +target_link_libraries(vtkm_filter_resampling PUBLIC vtkm_worklet vtkm_filter_core) +target_link_libraries(vtkm_filter PUBLIC INTERFACE vtkm_filter_resampling) + +add_subdirectory(worklet) + +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +if (VTKm_ENABLE_TESTING) + add_subdirectory(testing) +endif () diff --git a/vtkm/filter/resampling/Probe.cxx b/vtkm/filter/resampling/Probe.cxx new file mode 100644 index 000000000..15c7b3900 --- /dev/null +++ b/vtkm/filter/resampling/Probe.cxx @@ -0,0 +1,85 @@ +//============================================================================ +// 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 resampling +{ +vtkm::cont::DataSet Probe::DoExecute(const vtkm::cont::DataSet& input) +{ + vtkm::worklet::Probe worklet; + worklet.Run(input.GetCellSet(), + input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()), + this->Geometry.GetCoordinateSystem().GetData()); + + auto output = this->Geometry; + auto hpf = worklet.GetHiddenPointsField(); + auto hcf = worklet.GetHiddenCellsField(output.GetCellSet()); + + output.AddField(vtkm::cont::make_FieldPoint("HIDDEN", hpf)); + output.AddField(vtkm::cont::make_FieldCell("HIDDEN", hcf)); + + auto mapper = [&](auto& outDataSet, const auto& f) { this->DoMapField(outDataSet, f, worklet); }; + this->MapFieldsOntoOutput(input, output, mapper); + + return output; +} + + +bool Probe::DoMapField(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::worklet::Probe& worklet) +{ + if (field.IsFieldPoint()) + { + auto resolve = [&](const auto& concrete) { + using T = typename std::decay_t::ValueType; + vtkm::cont::ArrayHandle outputArray = worklet.ProcessPointField( + concrete, vtkm::cont::internal::CastInvalidValue(this->InvalidValue)); + result.AddPointField(field.GetName(), outputArray); + }; + // FIXME: what kind of CastAndCall do we need? + CastAndCall(field.GetData(), resolve); + return true; + } + else if (field.IsFieldCell()) + { + vtkm::cont::Field outField; + if (vtkm::filter::MapFieldPermutation( + field, worklet.GetCellIds(), outField, this->InvalidValue)) + { + // output field should be associated with points + outField = vtkm::cont::Field( + field.GetName(), vtkm::cont::Field::Association::Points, outField.GetData()); + result.AddField(outField); + return true; + } + return false; + } + else if (field.IsFieldGlobal()) + { + result.AddField(field); + return true; + } + else + { + return false; + } +} +} // namespace resampling +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/resampling/Probe.h b/vtkm/filter/resampling/Probe.h new file mode 100644 index 000000000..133fd9341 --- /dev/null +++ b/vtkm/filter/resampling/Probe.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_Probe_h +#define vtk_m_filter_Probe_h + +#include +#include + +namespace vtkm +{ +namespace worklet +{ +class Probe; +} + +namespace filter +{ +namespace resampling +{ +class VTKM_FILTER_RESAMPLING_EXPORT Probe : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT + void SetGeometry(const vtkm::cont::DataSet& geometry) + { + this->Geometry = vtkm::cont::DataSet(); + this->Geometry.SetCellSet(geometry.GetCellSet()); + this->Geometry.AddCoordinateSystem(geometry.GetCoordinateSystem()); + } + + VTKM_CONT + const vtkm::cont::DataSet& GetGeometry() const { return this->Geometry; } + + VTKM_CONT void SetInvalidValue(vtkm::Float64 invalidValue) { this->InvalidValue = invalidValue; } + VTKM_CONT vtkm::Float64 GetInvalidValue() const { return this->InvalidValue; } + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + bool DoMapField(vtkm::cont::DataSet& result, + const vtkm::cont::Field& field, + const vtkm::worklet::Probe& worklet); + + vtkm::cont::DataSet Geometry; + + vtkm::Float64 InvalidValue = vtkm::Nan64(); +}; +} // namespace resampling + +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::resampling::Probe.") Probe + : public vtkm::filter::resampling::Probe +{ + using resampling::Probe::Probe; +}; + +} // namespace filter +} // namespace vtkm + +#endif // vtk_m_filter_Probe_h diff --git a/vtkm/filter/resampling/testing/CMakeLists.txt b/vtkm/filter/resampling/testing/CMakeLists.txt new file mode 100644 index 000000000..980a802a6 --- /dev/null +++ b/vtkm/filter/resampling/testing/CMakeLists.txt @@ -0,0 +1,23 @@ +##============================================================================ +## 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 + UnitTestProbe.cxx + ) + +set(libraries + vtkm_filter_resampling + ) + +vtkm_unit_tests( + SOURCES ${unit_tests} + LIBRARIES ${libraries} + USE_VTKM_JOB_POOL +) diff --git a/vtkm/filter/testing/UnitTestProbe.cxx b/vtkm/filter/resampling/testing/UnitTestProbe.cxx similarity index 96% rename from vtkm/filter/testing/UnitTestProbe.cxx rename to vtkm/filter/resampling/testing/UnitTestProbe.cxx index 2928b10ec..9f4cdc44c 100644 --- a/vtkm/filter/testing/UnitTestProbe.cxx +++ b/vtkm/filter/resampling/testing/UnitTestProbe.cxx @@ -7,13 +7,13 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include +#include "vtkm/filter/resampling/Probe.h" -#include -#include -#include +#include "vtkm/cont/ArrayCopy.h" +#include "vtkm/cont/DataSetBuilderUniform.h" +#include "vtkm/cont/testing/Testing.h" -#include +#include "vtkm/worklet/CellDeepCopy.h" namespace { @@ -153,7 +153,7 @@ private: auto input = ConvertDataSetUniformToExplicit(MakeInputDataSet()); auto geometry = MakeGeometryDataSet(); - vtkm::filter::Probe probe; + vtkm::filter::resampling::Probe probe; probe.SetGeometry(geometry); probe.SetFieldsToPass({ "pointdata", "celldata" }); auto output = probe.Execute(input); @@ -175,7 +175,7 @@ private: auto input = MakeInputDataSet(); auto geometry = ConvertDataSetUniformToExplicit(MakeGeometryDataSet()); - vtkm::filter::Probe probe; + vtkm::filter::resampling::Probe probe; probe.SetGeometry(geometry); probe.SetFieldsToPass({ "pointdata", "celldata" }); auto output = probe.Execute(input); @@ -197,7 +197,7 @@ private: auto input = ConvertDataSetUniformToExplicit(MakeInputDataSet()); auto geometry = ConvertDataSetUniformToExplicit(MakeGeometryDataSet()); - vtkm::filter::Probe probe; + vtkm::filter::resampling::Probe probe; probe.SetGeometry(geometry); probe.SetFieldsToPass({ "pointdata", "celldata" }); auto output = probe.Execute(input); diff --git a/vtkm/filter/resampling/worklet/CMakeLists.txt b/vtkm/filter/resampling/worklet/CMakeLists.txt new file mode 100644 index 000000000..3aa9b2d67 --- /dev/null +++ b/vtkm/filter/resampling/worklet/CMakeLists.txt @@ -0,0 +1,15 @@ +##============================================================================ +## 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(headers + Probe.h + ) + +vtkm_declare_headers(${headers}) diff --git a/vtkm/worklet/Probe.h b/vtkm/filter/resampling/worklet/Probe.h similarity index 100% rename from vtkm/worklet/Probe.h rename to vtkm/filter/resampling/worklet/Probe.h diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index 06efb1acf..a4d2f9afc 100644 --- a/vtkm/filter/testing/CMakeLists.txt +++ b/vtkm/filter/testing/CMakeLists.txt @@ -25,7 +25,6 @@ set(unit_tests UnitTestMIRFilter.cxx UnitTestMultiBlockFilter.cxx UnitTestPartitionedDataSetFilters.cxx - UnitTestProbe.cxx UnitTestStreamlineFilter.cxx UnitTestStreamSurfaceFilter.cxx ) diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index 5d617fbbe..0f7b6458c 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -33,7 +33,6 @@ set(headers NDimsHistMarginalization.h Normalize.h ParticleAdvection.h - Probe.h ScalarsToColors.h ScatterCounting.h ScatterIdentity.h diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index 40fdd504d..0f9a07c1c 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -29,7 +29,6 @@ set(unit_tests UnitTestNormalize.cxx UnitTestNDimsHistMarginalization.cxx UnitTestParticleAdvection.cxx - UnitTestProbe.cxx UnitTestScalarsToColors.cxx UnitTestScatterAndMask.cxx UnitTestScatterCounting.cxx diff --git a/vtkm/worklet/testing/UnitTestProbe.cxx b/vtkm/worklet/testing/UnitTestProbe.cxx deleted file mode 100644 index 928ede5c7..000000000 --- a/vtkm/worklet/testing/UnitTestProbe.cxx +++ /dev/null @@ -1,211 +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 - -namespace -{ - -vtkm::cont::DataSet MakeInputDataSet() -{ - auto input = vtkm::cont::DataSetBuilderUniform::Create( - vtkm::Id2(4, 4), vtkm::make_Vec(0.0f, 0.0f), vtkm::make_Vec(1.0f, 1.0f)); - input.AddPointField("pointdata", vtkm::cont::make_ArrayHandleCounting(0.0f, 0.3f, 16)); - input.AddCellField("celldata", vtkm::cont::make_ArrayHandleCounting(0.0f, 0.7f, 9)); - return input; -} - -vtkm::cont::DataSet MakeGeometryDataSet() -{ - auto geometry = vtkm::cont::DataSetBuilderUniform::Create( - vtkm::Id2(9, 9), vtkm::make_Vec(0.7f, 0.7f), vtkm::make_Vec(0.35f, 0.35f)); - return geometry; -} - -vtkm::cont::DataSet ConvertDataSetUniformToExplicit(const vtkm::cont::DataSet& uds) -{ - vtkm::cont::DataSet eds; - - vtkm::cont::CellSetExplicit<> cs; - vtkm::worklet::CellDeepCopy::Run(uds.GetCellSet(), cs); - eds.SetCellSet(cs); - - vtkm::cont::ArrayHandle points; - vtkm::cont::ArrayCopy(uds.GetCoordinateSystem().GetData(), points); - eds.AddCoordinateSystem( - vtkm::cont::CoordinateSystem(uds.GetCoordinateSystem().GetName(), points)); - - for (vtkm::IdComponent i = 0; i < uds.GetNumberOfFields(); ++i) - { - eds.AddField(uds.GetField(i)); - } - - return eds; -} - -const std::vector& GetExpectedPointData() -{ - static std::vector expected = { - 1.05f, 1.155f, 1.26f, 1.365f, 1.47f, 1.575f, 1.68f, 0.0f, 0.0f, 1.47f, 1.575f, 1.68f, - 1.785f, 1.89f, 1.995f, 2.1f, 0.0f, 0.0f, 1.89f, 1.995f, 2.1f, 2.205f, 2.31f, 2.415f, - 2.52f, 0.0f, 0.0f, 2.31f, 2.415f, 2.52f, 2.625f, 2.73f, 2.835f, 2.94f, 0.0f, 0.0f, - 2.73f, 2.835f, 2.94f, 3.045f, 3.15f, 3.255f, 3.36f, 0.0f, 0.0f, 3.15f, 3.255f, 3.36f, - 3.465f, 3.57f, 3.675f, 3.78f, 0.0f, 0.0f, 3.57f, 3.675f, 3.78f, 3.885f, 3.99f, 4.095f, - 4.2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f - }; - return expected; -} - -const std::vector& GetExpectedCellData() -{ - static std::vector expected = { - 0.0f, 0.7f, 0.7f, 0.7f, 1.4f, 1.4f, 1.4f, 0.0f, 0.0f, 2.1f, 2.8f, 2.8f, 2.8f, 3.5f, - 3.5f, 3.5f, 0.0f, 0.0f, 2.1f, 2.8f, 2.8f, 2.8f, 3.5f, 3.5f, 3.5f, 0.0f, 0.0f, 2.1f, - 2.8f, 2.8f, 2.8f, 3.5f, 3.5f, 3.5f, 0.0f, 0.0f, 4.2f, 4.9f, 4.9f, 4.9f, 5.6f, 5.6f, - 5.6f, 0.0f, 0.0f, 4.2f, 4.9f, 4.9f, 4.9f, 5.6f, 5.6f, 5.6f, 0.0f, 0.0f, 4.2f, 4.9f, - 4.9f, 4.9f, 5.6f, 5.6f, 5.6f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f - }; - return expected; -} - -const std::vector& GetExpectedHiddenPoints() -{ - static std::vector expected = { 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 2, - 2, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, - 2, 2, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, - 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; - return expected; -} - -const std::vector& GetExpectedHiddenCells() -{ - static std::vector expected = { 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 2, 2, - 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 2, 2, - 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; - return expected; -} - -template -void TestResultArray(const vtkm::cont::ArrayHandle& result, const std::vector& expected) -{ - vtkm::cont::printSummary_ArrayHandle(result, std::cout); - VTKM_TEST_ASSERT(result.GetNumberOfValues() == static_cast(expected.size()), - "Incorrect field size"); - - auto portal = result.ReadPortal(); - vtkm::Id size = portal.GetNumberOfValues(); - for (vtkm::Id i = 0; i < size; ++i) - { - VTKM_TEST_ASSERT(test_equal(portal.Get(i), expected[static_cast(i)]), - "Incorrect field value"); - } -} - -class TestProbe -{ -private: - using FieldArrayType = vtkm::cont::ArrayHandleCounting; - - static void ExplicitToUnifrom() - { - std::cout << "Testing Probe Explicit to Uniform:\n"; - - auto input = ConvertDataSetUniformToExplicit(MakeInputDataSet()); - auto geometry = MakeGeometryDataSet(); - - vtkm::worklet::Probe probe; - probe.Run(input.GetCellSet(), input.GetCoordinateSystem(), geometry.GetCoordinateSystem()); - - auto pf = probe.ProcessPointField( - input.GetField("pointdata").GetData().AsArrayHandle(), 0.0f); - auto cf = probe.ProcessCellField( - input.GetField("celldata").GetData().AsArrayHandle(), 0.0f); - auto hp = probe.GetHiddenPointsField(); - auto hc = probe.GetHiddenCellsField(geometry.GetCellSet()); - - TestResultArray(pf, GetExpectedPointData()); - TestResultArray(cf, GetExpectedCellData()); - TestResultArray(hp, GetExpectedHiddenPoints()); - TestResultArray(hc, GetExpectedHiddenCells()); - } - - static void UniformToExplict() - { - std::cout << "Testing Probe Uniform to Explicit:\n"; - - auto input = MakeInputDataSet(); - auto geometry = ConvertDataSetUniformToExplicit(MakeGeometryDataSet()); - - vtkm::worklet::Probe probe; - probe.Run(input.GetCellSet(), input.GetCoordinateSystem(), geometry.GetCoordinateSystem()); - - auto pf = probe.ProcessPointField( - input.GetField("pointdata").GetData().AsArrayHandle(), 0.0f); - auto cf = probe.ProcessCellField( - input.GetField("celldata").GetData().AsArrayHandle(), 0.0f); - - auto hp = probe.GetHiddenPointsField(); - auto hc = probe.GetHiddenCellsField(geometry.GetCellSet()); - - TestResultArray(pf, GetExpectedPointData()); - TestResultArray(cf, GetExpectedCellData()); - TestResultArray(hp, GetExpectedHiddenPoints()); - TestResultArray(hc, GetExpectedHiddenCells()); - } - - static void ExplicitToExplict() - { - std::cout << "Testing Probe Explicit to Explicit:\n"; - - auto input = ConvertDataSetUniformToExplicit(MakeInputDataSet()); - auto geometry = ConvertDataSetUniformToExplicit(MakeGeometryDataSet()); - - vtkm::worklet::Probe probe; - probe.Run(input.GetCellSet(), input.GetCoordinateSystem(), geometry.GetCoordinateSystem()); - - auto pf = probe.ProcessPointField( - input.GetField("pointdata").GetData().AsArrayHandle(), 0.0f); - auto cf = probe.ProcessCellField( - input.GetField("celldata").GetData().AsArrayHandle(), 0.0f); - - auto hp = probe.GetHiddenPointsField(); - auto hc = probe.GetHiddenCellsField(geometry.GetCellSet()); - - TestResultArray(pf, GetExpectedPointData()); - TestResultArray(cf, GetExpectedCellData()); - TestResultArray(hp, GetExpectedHiddenPoints()); - TestResultArray(hc, GetExpectedHiddenCells()); - } - -public: - static void Run() - { - ExplicitToUnifrom(); - UniformToExplict(); - ExplicitToExplict(); - } -}; - -} // anonymous namespace - -int UnitTestProbe(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestProbe::Run, argc, argv); -}