From 6a934167c25ed2c022f421e0f438b8f4e1879f9f Mon Sep 17 00:00:00 2001 From: Dave Pugmire Date: Mon, 25 Jul 2022 09:09:59 -0400 Subject: [PATCH] Move streamsurface into flow --- vtkm/filter/StreamSurface.h | 70 ------------------- vtkm/filter/flow/CMakeLists.txt | 2 + .../StreamSurface.cxx} | 52 +++++--------- vtkm/filter/flow/StreamSurface.h | 48 +++++++++++++ vtkm/filter/flow/Streamline.h | 6 +- vtkm/filter/flow/testing/CMakeLists.txt | 2 + .../testing/UnitTestStreamSurfaceFilter.cxx | 4 +- .../testing/UnitTestStreamSurfaceWorklet.cxx} | 12 ++-- vtkm/filter/flow/worklet/CMakeLists.txt | 1 + .../{ => filter/flow}/worklet/StreamSurface.h | 14 ++-- vtkm/filter/testing/CMakeLists.txt | 3 - vtkm/worklet/CMakeLists.txt | 1 - vtkm/worklet/testing/CMakeLists.txt | 1 - 13 files changed, 91 insertions(+), 125 deletions(-) delete mode 100644 vtkm/filter/StreamSurface.h rename vtkm/filter/{StreamSurface.hxx => flow/StreamSurface.cxx} (56%) create mode 100644 vtkm/filter/flow/StreamSurface.h rename vtkm/filter/{ => flow}/testing/UnitTestStreamSurfaceFilter.cxx (96%) rename vtkm/{worklet/testing/UnitTestStreamSurface.cxx => filter/flow/testing/UnitTestStreamSurfaceWorklet.cxx} (92%) rename vtkm/{ => filter/flow}/worklet/StreamSurface.h (98%) diff --git a/vtkm/filter/StreamSurface.h b/vtkm/filter/StreamSurface.h deleted file mode 100644 index 1e3b1491f..000000000 --- a/vtkm/filter/StreamSurface.h +++ /dev/null @@ -1,70 +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_StreamSurface_h -#define vtk_m_filter_StreamSurface_h - -#include -#include -#include -#include -#include - -namespace vtkm -{ -namespace filter -{ -/// \brief generate streamlines from a vector field. - -/// Takes as input a vector field and seed locations and generates the -/// paths taken by the seeds through the vector field. -class StreamSurface : public vtkm::filter::FilterDataSetWithField -{ -public: - using SupportedTypes = vtkm::TypeListFieldVec3; - - VTKM_CONT - StreamSurface(); - - VTKM_CONT - void SetStepSize(vtkm::FloatDefault s) { this->StepSize = s; } - - VTKM_CONT - void SetNumberOfSteps(vtkm::Id n) { this->NumberOfSteps = n; } - - VTKM_CONT - void SetSeeds(vtkm::cont::ArrayHandle& seeds) { this->Seeds = seeds; } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute( - const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle, StorageType>& field, - const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase& policy); - - template - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase policy); - -private: - vtkm::Id NumberOfSteps; - vtkm::cont::ArrayHandle Seeds; - vtkm::FloatDefault StepSize; - vtkm::worklet::StreamSurface Worklet; -}; -} -} // namespace vtkm::filter - -#ifndef vtk_m_filter_StreamSurface_hxx -#include -#endif - -#endif // vtk_m_filter_StreamSurface_h diff --git a/vtkm/filter/flow/CMakeLists.txt b/vtkm/filter/flow/CMakeLists.txt index 153a346c5..c6c641a35 100644 --- a/vtkm/filter/flow/CMakeLists.txt +++ b/vtkm/filter/flow/CMakeLists.txt @@ -25,6 +25,7 @@ set(flow_headers Pathline.h PathParticle.h Streamline.h + StreamSurface.h ) set(flow_sources @@ -33,6 +34,7 @@ set(flow_sources Pathline.cxx PathParticle.cxx Streamline.cxx + StreamSurface.cxx ) vtkm_library( diff --git a/vtkm/filter/StreamSurface.hxx b/vtkm/filter/flow/StreamSurface.cxx similarity index 56% rename from vtkm/filter/StreamSurface.hxx rename to vtkm/filter/flow/StreamSurface.cxx index 05ba2ea6e..06b09849a 100644 --- a/vtkm/filter/StreamSurface.hxx +++ b/vtkm/filter/flow/StreamSurface.cxx @@ -8,13 +8,9 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_filter_StreamSurface_hxx -#define vtk_m_filter_StreamSurface_hxx - -#include +#include #include -#include #include #include #include @@ -22,57 +18,53 @@ #include #include #include +#include namespace vtkm { namespace filter { - -//----------------------------------------------------------------------------- -inline VTKM_CONT StreamSurface::StreamSurface() - : vtkm::filter::FilterDataSetWithField() - , Worklet() +namespace flow { -} -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet StreamSurface::DoExecute( - const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle, StorageType>& field, - const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase&) +VTKM_CONT vtkm::cont::DataSet StreamSurface::DoExecute(const vtkm::cont::DataSet& input) { - //Check for some basics. - if (this->Seeds.GetNumberOfValues() == 0) - throw vtkm::cont::ErrorFilterExecution("No seeds provided."); + this->ValidateOptions(); + + if (!this->Seeds.IsBaseComponentType()) + throw vtkm::cont::ErrorFilterExecution("Unsupported seed type in StreamSurface filter."); const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); const vtkm::cont::CoordinateSystem& coords = input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()); - using FieldHandle = vtkm::cont::ArrayHandle, StorageType>; + using FieldHandle = vtkm::cont::ArrayHandle; using FieldType = vtkm::worklet::flow::VelocityField; using GridEvalType = vtkm::worklet::flow::GridEvaluator; using RK4Type = vtkm::worklet::flow::RK4Integrator; using Stepper = vtkm::worklet::flow::Stepper; //compute streamlines - FieldType velocities(field, fieldMeta.GetAssociation()); + const auto& field = input.GetField(this->GetActiveFieldName()); + FieldHandle arr; + vtkm::cont::ArrayCopyShallowIfPossible(field.GetData(), arr); + FieldType velocities(arr, field.GetAssociation()); GridEvalType eval(coords, cells, velocities); Stepper rk4(eval, this->StepSize); vtkm::worklet::flow::Streamline streamline; + using ParticleArray = vtkm::cont::ArrayHandle; vtkm::cont::ArrayHandle seedArray; - vtkm::cont::ArrayCopy(this->Seeds, seedArray); + vtkm::cont::ArrayCopy(this->Seeds.AsArrayHandle(), seedArray); auto res = streamline.Run(rk4, seedArray, this->NumberOfSteps); //compute surface from streamlines + vtkm::worklet::flow::StreamSurface streamSurface; vtkm::cont::ArrayHandle srfPoints; vtkm::cont::CellSetSingleType<> srfCells; vtkm::cont::CoordinateSystem slCoords("coordinates", res.Positions); - this->Worklet.Run(slCoords, res.PolyLines, srfPoints, srfCells); + streamSurface.Run(slCoords, res.PolyLines, srfPoints, srfCells); vtkm::cont::DataSet outData; vtkm::cont::CoordinateSystem outputCoords("coordinates", srfPoints); @@ -82,14 +74,6 @@ inline VTKM_CONT vtkm::cont::DataSet StreamSurface::DoExecute( return outData; } -//----------------------------------------------------------------------------- -template -inline VTKM_CONT bool StreamSurface::MapFieldOntoOutput(vtkm::cont::DataSet&, - const vtkm::cont::Field&, - vtkm::filter::PolicyBase) -{ - return false; } } -} // namespace vtkm::filter -#endif +} // namespace vtkm::filter::flow diff --git a/vtkm/filter/flow/StreamSurface.h b/vtkm/filter/flow/StreamSurface.h new file mode 100644 index 000000000..c477c87e0 --- /dev/null +++ b/vtkm/filter/flow/StreamSurface.h @@ -0,0 +1,48 @@ +//============================================================================ +// 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_flow_StreamSurface_h +#define vtk_m_filter_flow_StreamSurface_h + +#include +#include +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace flow +{ + +/// \brief generate streamlines from a vector field. + +/// Takes as input a vector field and seed locations and generates the +/// paths taken by the seeds through the vector field. + +class VTKM_FILTER_FLOW_EXPORT StreamSurface + : public vtkm::filter::flow::NewFilterParticleAdvectionSteadyState +{ +public: + VTKM_CONT StreamSurface() + : NewFilterParticleAdvectionSteadyState(vtkm::filter::flow::FlowResultType::STREAMLINE_TYPE) + { + } + +protected: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData) override; +}; + +} +} +} // namespace vtkm::filter::flow + +#endif // vtk_m_filter_flow_StreamSurface_h diff --git a/vtkm/filter/flow/Streamline.h b/vtkm/filter/flow/Streamline.h index 628a326a9..84a2eef00 100644 --- a/vtkm/filter/flow/Streamline.h +++ b/vtkm/filter/flow/Streamline.h @@ -8,8 +8,8 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_filter_Streamline_h -#define vtk_m_filter_Streamline_h +#ifndef vtk_m_filter_flow_Streamline_h +#define vtk_m_filter_flow_Streamline_h #include #include @@ -46,4 +46,4 @@ protected: } } // namespace vtkm::filter::flow -#endif // vtk_m_filter_Streamline_h +#endif // vtk_m_filter_flow_Streamline_h diff --git a/vtkm/filter/flow/testing/CMakeLists.txt b/vtkm/filter/flow/testing/CMakeLists.txt index 80caed482..c9579b246 100644 --- a/vtkm/filter/flow/testing/CMakeLists.txt +++ b/vtkm/filter/flow/testing/CMakeLists.txt @@ -12,6 +12,8 @@ set(unit_tests UnitTestStreamlineFilter.cxx UnitTestWorkletParticleAdvection.cxx UnitTestWorkletTemporalAdvection.cxx +UnitTestStreamSurfaceFilter.cxx +UnitTestStreamSurfaceWorklet.cxx ) set(libraries diff --git a/vtkm/filter/testing/UnitTestStreamSurfaceFilter.cxx b/vtkm/filter/flow/testing/UnitTestStreamSurfaceFilter.cxx similarity index 96% rename from vtkm/filter/testing/UnitTestStreamSurfaceFilter.cxx rename to vtkm/filter/flow/testing/UnitTestStreamSurfaceFilter.cxx index ed085eb82..ca4ea34c1 100644 --- a/vtkm/filter/testing/UnitTestStreamSurfaceFilter.cxx +++ b/vtkm/filter/flow/testing/UnitTestStreamSurfaceFilter.cxx @@ -10,7 +10,7 @@ #include #include -#include +#include namespace { @@ -44,7 +44,7 @@ void TestStreamSurface() vtkm::Particle(vtkm::Vec3f(.1f, 3.0f, .3f), 2), vtkm::Particle(vtkm::Vec3f(.1f, 3.5f, .2f), 3) }); - vtkm::filter::StreamSurface streamSrf; + vtkm::filter::flow::StreamSurface streamSrf; streamSrf.SetStepSize(0.1f); streamSrf.SetNumberOfSteps(20); diff --git a/vtkm/worklet/testing/UnitTestStreamSurface.cxx b/vtkm/filter/flow/testing/UnitTestStreamSurfaceWorklet.cxx similarity index 92% rename from vtkm/worklet/testing/UnitTestStreamSurface.cxx rename to vtkm/filter/flow/testing/UnitTestStreamSurfaceWorklet.cxx index 23f611794..07848da0c 100644 --- a/vtkm/worklet/testing/UnitTestStreamSurface.cxx +++ b/vtkm/filter/flow/testing/UnitTestStreamSurfaceWorklet.cxx @@ -10,9 +10,9 @@ #include #include +#include #include #include -#include namespace { @@ -53,7 +53,7 @@ void TestSameNumPolylines() dsb.AddCell(vtkm::CELL_SHAPE_POLY_LINE, ids); vtkm::cont::DataSet ds = dsb.Create(); - vtkm::worklet::StreamSurface streamSurfaceWorklet; + vtkm::worklet::flow::StreamSurface streamSurfaceWorklet; vtkm::cont::ArrayHandle newPoints; vtkm::cont::CellSetSingleType<> newCells; streamSurfaceWorklet.Run(ds.GetCoordinateSystem(0), ds.GetCellSet(), newPoints, newCells); @@ -111,7 +111,7 @@ void TestUnequalNumPolylines(int unequalType) dsb.AddCell(vtkm::CELL_SHAPE_POLY_LINE, ids); vtkm::cont::DataSet ds = dsb.Create(); - vtkm::worklet::StreamSurface streamSurfaceWorklet; + vtkm::worklet::flow::StreamSurface streamSurfaceWorklet; vtkm::cont::ArrayHandle newPoints; vtkm::cont::CellSetSingleType<> newCells; streamSurfaceWorklet.Run(ds.GetCoordinateSystem(0), ds.GetCellSet(), newPoints, newCells); @@ -124,7 +124,7 @@ void TestUnequalNumPolylines(int unequalType) "Wrong number of cells in StreamSurface worklet"); } -void TestStreamSurface() +void TestStreamSurfaceWorklet() { std::cout << "Testing Stream Surface Worklet" << std::endl; TestSameNumPolylines(); @@ -134,7 +134,7 @@ void TestStreamSurface() } } -int UnitTestStreamSurface(int argc, char* argv[]) +int UnitTestStreamSurfaceWorklet(int argc, char* argv[]) { - return vtkm::cont::testing::Testing::Run(TestStreamSurface, argc, argv); + return vtkm::cont::testing::Testing::Run(TestStreamSurfaceWorklet, argc, argv); } diff --git a/vtkm/filter/flow/worklet/CMakeLists.txt b/vtkm/filter/flow/worklet/CMakeLists.txt index c52ad4eff..1d5116a6c 100644 --- a/vtkm/filter/flow/worklet/CMakeLists.txt +++ b/vtkm/filter/flow/worklet/CMakeLists.txt @@ -21,6 +21,7 @@ set(headers ParticleAdvectionWorklets.h RK4Integrator.h TemporalGridEvaluators.h + StreamSurface.h ) #----------------------------------------------------------------------------- diff --git a/vtkm/worklet/StreamSurface.h b/vtkm/filter/flow/worklet/StreamSurface.h similarity index 98% rename from vtkm/worklet/StreamSurface.h rename to vtkm/filter/flow/worklet/StreamSurface.h index a7fef872f..33389bba7 100644 --- a/vtkm/worklet/StreamSurface.h +++ b/vtkm/filter/flow/worklet/StreamSurface.h @@ -7,8 +7,8 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_worklet_streamsurface_h -#define vtk_m_worklet_streamsurface_h +#ifndef vtk_m_filter_flow_worklet_streamsurface_h +#define vtk_m_filter_flow_worklet_streamsurface_h #include #include @@ -24,6 +24,8 @@ namespace vtkm { namespace worklet { +namespace flow +{ class StreamSurface { @@ -276,7 +278,9 @@ public: private: }; -} -} -#endif // vtk_m_worklet_streamsurface_h +} +} +} //vtkm::worklet::flow + +#endif // vtk_m_filter_flow_worklet_streamsurface_h diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index 59014cec6..5580e99f7 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 - UnitTestStreamSurfaceFilter.cxx ) set(libraries @@ -54,8 +53,6 @@ if ((TARGET vtkm::cuda) OR (TARGET vtkm::kokkos_cuda)) set(large_kernel_sources RegressionTestStreamline.cxx UnitTestLagrangianFilter.cxx - UnitTestStreamlineFilter.cxx - UnitTestStreamSurfaceFilter.cxx ) set_source_files_properties(${large_kernel_sources} PROPERTIES COMPILE_OPTIONS "-Xptxas;--disable-optimizer-constants" diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index 1a1f16eaa..fd7d8c1ae 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -40,7 +40,6 @@ set(headers StableSortIndices.h DescriptiveStatistics.h StreamLineUniformGrid.h - StreamSurface.h TriangleWinding.h WaveletCompressor.h WorkletMapField.h diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index 051fc27fd..d4a94be33 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -35,7 +35,6 @@ set(unit_tests UnitTestSplatKernels.cxx UnitTestScatterAndMaskWithTopology.cxx UnitTestStreamLineUniformGrid.cxx - UnitTestStreamSurface.cxx UnitTestTriangleWinding.cxx UnitTestWholeCellSetIn.cxx UnitTestWorkletMapField.cxx