From 8520d70e0dc9cdfc7aa20ce8950f5adabccdf653 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 9 Sep 2019 09:39:23 -0400 Subject: [PATCH] Compile most frequently used VTK-m filters into a library VTK-m now provides the following filters with the default policy as part of the vtkm_filter library: - CellAverage - CleanGrid - ClipWithField - ClipWithImplicitFunction - Contour - ExternalFaces - ExtractStructured - PointAverage - Threshold - VectorMagnitude By building these as a library we hope to provide faster compile times for consumers of VTK-m when using common configurations. --- benchmarking/BenchmarkFilters.cxx | 19 ++- docs/changelog/provide-prebuilt-filters.md | 73 ++++++++++ examples/demo/CMakeLists.txt | 2 +- vtkm/cont/testing/UnitTestCellSetExtrude.cxx | 3 +- vtkm/filter/CMakeLists.txt | 28 ++-- vtkm/filter/CellAverage.cxx | 22 +++ vtkm/filter/CellAverage.h | 16 ++- vtkm/filter/CellAverage.hxx | 10 +- vtkm/filter/CleanGrid.cxx | 122 ++++++++++++++++ vtkm/filter/CleanGrid.h | 50 +++++-- vtkm/filter/CleanGrid.hxx | 130 +----------------- vtkm/filter/ClipWithField.cxx | 22 +++ vtkm/filter/ClipWithField.h | 39 ++++-- vtkm/filter/ClipWithField.hxx | 38 ----- vtkm/filter/ClipWithImplicitFunction.cxx | 22 +++ vtkm/filter/ClipWithImplicitFunction.h | 41 ++++-- vtkm/filter/ClipWithImplicitFunction.hxx | 37 +---- vtkm/filter/Contour.cxx | 75 ++++++++++ vtkm/filter/Contour.h | 54 ++++++-- vtkm/filter/Contour.hxx | 84 +---------- vtkm/filter/ExternalFaces.cxx | 71 ++++++++++ vtkm/filter/ExternalFaces.h | 42 +++++- vtkm/filter/ExternalFaces.hxx | 90 +----------- vtkm/filter/ExtractPoints.hxx | 20 +-- vtkm/filter/ExtractStructured.cxx | 34 +++++ vtkm/filter/ExtractStructured.h | 33 ++++- vtkm/filter/ExtractStructured.hxx | 40 ------ vtkm/filter/Filter.h | 13 ++ vtkm/filter/Filter.hxx | 4 +- vtkm/filter/FilterField.hxx | 6 +- vtkm/filter/GhostCellRemove.hxx | 2 +- vtkm/filter/Mask.h | 1 - vtkm/filter/MaskPoints.hxx | 20 +-- vtkm/filter/PointAverage.cxx | 22 +++ vtkm/filter/PointAverage.h | 16 ++- vtkm/filter/PointAverage.hxx | 9 +- vtkm/filter/Threshold.cxx | 21 +++ vtkm/filter/Threshold.h | 37 +++-- vtkm/filter/Threshold.hxx | 33 ----- vtkm/filter/ThresholdPoints.hxx | 17 +-- vtkm/filter/VectorMagnitude.cxx | 31 +++++ vtkm/filter/VectorMagnitude.h | 11 +- vtkm/filter/VectorMagnitude.hxx | 8 -- vtkm/filter/testing/UnitTestContourFilter.cxx | 1 + .../testing/UnitTestSplitSharpEdgesFilter.cxx | 4 +- vtkm/worklet/testing/CMakeLists.txt | 2 +- .../worklet/testing/UnitTestOrientNormals.cxx | 2 +- 47 files changed, 840 insertions(+), 637 deletions(-) create mode 100644 docs/changelog/provide-prebuilt-filters.md create mode 100644 vtkm/filter/CellAverage.cxx create mode 100644 vtkm/filter/CleanGrid.cxx create mode 100644 vtkm/filter/ClipWithField.cxx create mode 100644 vtkm/filter/ClipWithImplicitFunction.cxx create mode 100644 vtkm/filter/Contour.cxx create mode 100644 vtkm/filter/ExternalFaces.cxx create mode 100644 vtkm/filter/ExtractStructured.cxx create mode 100644 vtkm/filter/PointAverage.cxx create mode 100644 vtkm/filter/Threshold.cxx create mode 100644 vtkm/filter/VectorMagnitude.cxx diff --git a/benchmarking/BenchmarkFilters.cxx b/benchmarking/BenchmarkFilters.cxx index d0d37f8ee..dcf332bc8 100644 --- a/benchmarking/BenchmarkFilters.cxx +++ b/benchmarking/BenchmarkFilters.cxx @@ -142,7 +142,6 @@ using UnstructuredCellList = using AllCellList = vtkm::ListTagJoin; -using CoordinateList = vtkm::ListTagBase; class BenchmarkFilterPolicy : public vtkm::filter::PolicyBase { @@ -152,8 +151,6 @@ public: using StructuredCellSetList = StructuredCellList; using UnstructuredCellSetList = UnstructuredCellList; using AllCellSetList = AllCellList; - - using CoordinateTypeList = CoordinateList; }; // Class implementing all filter benchmarks: @@ -307,7 +304,7 @@ class BenchmarkFilters { Timer timer{ DeviceAdapter() }; timer.Start(); - auto result = this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); + auto result = this->Filter.Execute(InputDataSet); (void)result; return timer.GetElapsedTime(); } @@ -374,7 +371,7 @@ class BenchmarkFilters { Timer timer{ DeviceAdapter() }; timer.Start(); - auto result = this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); + auto result = this->Filter.Execute(InputDataSet); (void)result; return timer.GetElapsedTime(); } @@ -400,7 +397,7 @@ class BenchmarkFilters { Timer timer{ DeviceAdapter() }; timer.Start(); - auto result = this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); + auto result = this->Filter.Execute(InputDataSet); (void)result; return timer.GetElapsedTime(); } @@ -501,7 +498,7 @@ class BenchmarkFilters { Timer timer{ DeviceAdapter() }; timer.Start(); - auto result = this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); + auto result = this->Filter.Execute(InputDataSet); (void)result; return timer.GetElapsedTime(); } @@ -547,7 +544,7 @@ class BenchmarkFilters { Timer timer{ DeviceAdapter() }; timer.Start(); - auto result = this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); + auto result = this->Filter.Execute(InputDataSet); (void)result; return timer.GetElapsedTime(); } @@ -954,7 +951,7 @@ void CreateFields(bool needPointScalars, bool needCellScalars, bool needPointVec vtkm::filter::PointAverage avg; avg.SetActiveField(CellScalarsName, vtkm::cont::Field::Association::CELL_SET); avg.SetOutputFieldName("GeneratedPointScalars"); - auto outds = avg.Execute(InputDataSet, BenchmarkFilterPolicy()); + auto outds = avg.Execute(InputDataSet); InputDataSet.AddField( outds.GetField("GeneratedPointScalars", vtkm::cont::Field::Association::POINTS)); PointScalarsName = "GeneratedPointScalars"; @@ -977,7 +974,7 @@ void CreateFields(bool needPointScalars, bool needCellScalars, bool needPointVec vtkm::filter::VectorMagnitude mag; mag.SetActiveField(PointVectorsName, vtkm::cont::Field::Association::POINTS); mag.SetOutputFieldName("GeneratedPointScalars"); - auto outds = mag.Execute(InputDataSet, BenchmarkFilterPolicy()); + auto outds = mag.Execute(InputDataSet); InputDataSet.AddField( outds.GetField("GeneratedPointScalars", vtkm::cont::Field::Association::POINTS)); PointScalarsName = "GeneratedPointScalars"; @@ -999,7 +996,7 @@ void CreateFields(bool needPointScalars, bool needCellScalars, bool needPointVec vtkm::filter::CellAverage avg; avg.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::POINTS); avg.SetOutputFieldName("GeneratedCellScalars"); - auto outds = avg.Execute(InputDataSet, BenchmarkFilterPolicy()); + auto outds = avg.Execute(InputDataSet); InputDataSet.AddField( outds.GetField("GeneratedCellScalars", vtkm::cont::Field::Association::CELL_SET)); CellScalarsName = "GeneratedCellScalars"; diff --git a/docs/changelog/provide-prebuilt-filters.md b/docs/changelog/provide-prebuilt-filters.md new file mode 100644 index 000000000..648b40ae5 --- /dev/null +++ b/docs/changelog/provide-prebuilt-filters.md @@ -0,0 +1,73 @@ +# Provide pre-built filters in the vtkm_filter library. + +VTK-m now provides the following pre built versions of +the following filters as part of the vtkm_filter library, +when executed with the default types. + - CellAverage + - CleanGrid + - ClipWithField + - ClipWithImplicitFunction + - Contour + - ExternalFaces + - ExtractStuctured + - PointAverage + - Threshold + - VectorMagnitude + +The decision on providing a subset of filters as a library +was based on balancing the resulting library size and cross domain +applicibaility of the filter. So the initial set of algorithms +have been selected by looking at what is commonly used by +current VTK-m consuming applications. + +By default types we mean that no explicit user policy has been +passed to the `Execute` method on these filters. For example +the following will use the pre-build `Threshold` and `CleanGrid` +filters: + +```cpp + vtkm::cont::DataSet input = ...; + + //convert input to an unstructured grid + vtkm::filter::CleanGrid clean; + auto cleaned = clean.Execute(input); + + vtkm::filter::Threshold threshold; + threshold.SetLowerThreshold(60.1); + threshold.SetUpperThreshold(60.1); + threshold.SetActiveField("pointvar"); + threshold.SetFieldsToPass("cellvar"); + auto output = threshold.Execute(cleaned); + ... +``` + +While the following, even though it is a subset of the default +policy will need to be compiled by the consuming library by +including the relevant `.hxx` files + +```cpp + #include + #include + + ... + struct CustomPolicy : vtkm::filter::PolicyBase + { + // Defaults are the same as PolicyDefault expect for the field types + using FieldTypeList = vtkm::ListTagBase; + }; + ... + + vtkm::cont::DataSet input = ...; + + //convert input to an unstructured grid + vtkm::filter::CleanGrid clean; + auto cleaned = clean.Execute(input, CustomPolicy{}); + + vtkm::filter::Threshold threshold; + threshold.SetLowerThreshold(60.1); + threshold.SetUpperThreshold(60.1); + threshold.SetActiveField("pointvar"); + threshold.SetFieldsToPass("cellvar"); + auto output = threshold.Execute(cleaned, CustomPolicy{}); + ... +``` diff --git a/examples/demo/CMakeLists.txt b/examples/demo/CMakeLists.txt index fcbb25ba1..6e2da170b 100644 --- a/examples/demo/CMakeLists.txt +++ b/examples/demo/CMakeLists.txt @@ -15,7 +15,7 @@ find_package(VTKm REQUIRED QUIET) if(TARGET vtkm_rendering) add_executable(Demo Demo.cxx) - target_link_libraries(Demo PRIVATE vtkm_rendering) + target_link_libraries(Demo PRIVATE vtkm_filter vtkm_rendering) vtkm_add_target_information(Demo DROP_UNUSED_SYMBOLS MODIFY_CUDA_FLAGS DEVICE_SOURCES Demo.cxx) diff --git a/vtkm/cont/testing/UnitTestCellSetExtrude.cxx b/vtkm/cont/testing/UnitTestCellSetExtrude.cxx index f53ae36e3..ea8e4c496 100644 --- a/vtkm/cont/testing/UnitTestCellSetExtrude.cxx +++ b/vtkm/cont/testing/UnitTestCellSetExtrude.cxx @@ -13,8 +13,9 @@ #include #include #include -#include + #include +#include #include namespace diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index 815a10754..c1b6f6c5c 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -141,16 +141,26 @@ set(header_template_sources ZFPCompressor3D.hxx ZFPDecompressor3D.hxx ) +set(sources_device + CellAverage.cxx + CleanGrid.cxx + ClipWithField.cxx + ClipWithImplicitFunction.cxx + Contour.cxx + ExternalFaces.cxx + ExtractStructured.cxx + PointAverage.cxx + Threshold.cxx + VectorMagnitude.cxx +) -vtkm_declare_headers(${headers}) -vtkm_declare_headers(${header_template_sources}) - -# Create an interface library for vtkm_filter. At some point, this will be replaced with a real -# library that contains pre-built filters. That would be created with the vtkm_library CMake -# function (defined in VTKmWrappers.cmake). -add_library(vtkm_filter INTERFACE) -target_link_libraries(vtkm_filter INTERFACE vtkm_worklet) -install(TARGETS vtkm_filter EXPORT ${VTKm_EXPORT_NAME}) +vtkm_library( + NAME vtkm_filter + TEMPLATE_SOURCES ${header_template_sources} + HEADERS ${headers} + DEVICE_SOURCES ${sources_device} + ) +target_link_libraries(vtkm_filter PUBLIC vtkm_worklet) add_subdirectory(internal) diff --git a/vtkm/filter/CellAverage.cxx b/vtkm/filter/CellAverage.cxx new file mode 100644 index 000000000..8ccb4cc07 --- /dev/null +++ b/vtkm/filter/CellAverage.cxx @@ -0,0 +1,22 @@ +//============================================================================ +// 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_CellAverage_cxx + +#include +#include + +namespace vtkm +{ +namespace filter +{ +//----------------------------------------------------------------------------- +VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(CellAverage); +} +} diff --git a/vtkm/filter/CellAverage.h b/vtkm/filter/CellAverage.h index 4780d005d..1b6725c29 100644 --- a/vtkm/filter/CellAverage.h +++ b/vtkm/filter/CellAverage.h @@ -11,6 +11,9 @@ #ifndef vtk_m_filter_CellAverage_h #define vtk_m_filter_CellAverage_h +#include + +#include #include #include @@ -25,24 +28,23 @@ namespace filter /// The method of transformation is based on averaging the data /// values of all points used by particular cell. /// -class CellAverage : public vtkm::filter::FilterCell +class VTKM_ALWAYS_EXPORT CellAverage : public vtkm::filter::FilterCell { public: - VTKM_CONT - CellAverage(); - template VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, const vtkm::cont::ArrayHandle& field, const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase& policy); + vtkm::filter::PolicyBase policy); private: vtkm::worklet::CellAverage Worklet; }; + +#ifndef vtkm_filter_CellAverage_cxx +VTKM_FILTER_EXPORT_EXECUTE_METHOD(CellAverage); +#endif } } // namespace vtkm::filter -#include - #endif // vtk_m_filter_CellAverage_h diff --git a/vtkm/filter/CellAverage.hxx b/vtkm/filter/CellAverage.hxx index a3d0c4c7a..b02c8c6b1 100644 --- a/vtkm/filter/CellAverage.hxx +++ b/vtkm/filter/CellAverage.hxx @@ -15,21 +15,13 @@ namespace vtkm { namespace filter { - -//----------------------------------------------------------------------------- -inline VTKM_CONT CellAverage::CellAverage() - : vtkm::filter::FilterCell() - , Worklet() -{ -} - //----------------------------------------------------------------------------- template inline VTKM_CONT vtkm::cont::DataSet CellAverage::DoExecute( const vtkm::cont::DataSet& input, const vtkm::cont::ArrayHandle& inField, const vtkm::filter::FieldMetadata& fieldMetadata, - const vtkm::filter::PolicyBase& policy) + vtkm::filter::PolicyBase policy) { if (!fieldMetadata.IsPointField()) { diff --git a/vtkm/filter/CleanGrid.cxx b/vtkm/filter/CleanGrid.cxx new file mode 100644 index 000000000..19448cfa8 --- /dev/null +++ b/vtkm/filter/CleanGrid.cxx @@ -0,0 +1,122 @@ + +//============================================================================ +// 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_CleanGrid_cxx +#include +#include + +namespace vtkm +{ +namespace filter +{ + +//----------------------------------------------------------------------------- +CleanGrid::CleanGrid() + : CompactPointFields(true) + , MergePoints(true) + , Tolerance(1.0e-6) + , ToleranceIsAbsolute(false) + , RemoveDegenerateCells(true) + , FastMerge(true) +{ +} + +//----------------------------------------------------------------------------- +vtkm::cont::DataSet CleanGrid::GenerateOutput(const vtkm::cont::DataSet& inData, + vtkm::cont::CellSetExplicit<>& outputCellSet) +{ + using VecId = std::size_t; + const VecId activeCoordIndex = static_cast(this->GetActiveCoordinateSystemIndex()); + const VecId numCoordSystems = static_cast(inData.GetNumberOfCoordinateSystems()); + + std::vector outputCoordinateSystems(numCoordSystems); + + // Start with a shallow copy of the coordinate systems + for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex) + { + outputCoordinateSystems[coordSystemIndex] = + inData.GetCoordinateSystem(static_cast(coordSystemIndex)); + } + + // Optionally adjust the cell set indices to remove all unused points + if (this->GetCompactPointFields()) + { + this->PointCompactor.FindPointsStart(); + this->PointCompactor.FindPoints(outputCellSet); + this->PointCompactor.FindPointsEnd(); + + outputCellSet = this->PointCompactor.MapCellSet(outputCellSet); + + for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex) + { + outputCoordinateSystems[coordSystemIndex] = + vtkm::cont::CoordinateSystem(outputCoordinateSystems[coordSystemIndex].GetName(), + this->PointCompactor.MapPointFieldDeep( + outputCoordinateSystems[coordSystemIndex].GetData())); + } + } + + // Optionally find and merge coincident points + if (this->GetMergePoints()) + { + vtkm::cont::CoordinateSystem activeCoordSystem = outputCoordinateSystems[activeCoordIndex]; + vtkm::Bounds bounds = activeCoordSystem.GetBounds(); + + vtkm::Float64 delta = this->GetTolerance(); + if (!this->GetToleranceIsAbsolute()) + { + delta *= + vtkm::Magnitude(vtkm::make_Vec(bounds.X.Length(), bounds.Y.Length(), bounds.Z.Length())); + } + + auto coordArray = activeCoordSystem.GetData(); + this->PointMerger.Run(delta, this->GetFastMerge(), bounds, coordArray); + activeCoordSystem = vtkm::cont::CoordinateSystem(activeCoordSystem.GetName(), coordArray); + + for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex) + { + if (coordSystemIndex == activeCoordIndex) + { + outputCoordinateSystems[coordSystemIndex] = activeCoordSystem; + } + else + { + outputCoordinateSystems[coordSystemIndex] = vtkm::cont::CoordinateSystem( + outputCoordinateSystems[coordSystemIndex].GetName(), + this->PointMerger.MapPointField(outputCoordinateSystems[coordSystemIndex].GetData())); + } + } + + outputCellSet = this->PointMerger.MapCellSet(outputCellSet); + } + + // Optionally remove degenerate cells + if (this->GetRemoveDegenerateCells()) + { + outputCellSet = this->CellCompactor.Run(outputCellSet); + } + + // Construct resulting data set with new cell sets + vtkm::cont::DataSet outData; + outData.SetCellSet(outputCellSet); + + // Pass the coordinate systems + for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex) + { + outData.AddCoordinateSystem(outputCoordinateSystems[coordSystemIndex]); + } + + return outData; +} + +//----------------------------------------------------------------------------- +VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(CleanGrid); +} +} diff --git a/vtkm/filter/CleanGrid.h b/vtkm/filter/CleanGrid.h index f02ab61f8..52922b467 100644 --- a/vtkm/filter/CleanGrid.h +++ b/vtkm/filter/CleanGrid.h @@ -10,6 +10,8 @@ #ifndef vtk_m_filter_CleanGrid_h #define vtk_m_filter_CleanGrid_h +#include + #include #include @@ -35,10 +37,10 @@ namespace filter /// \todo Add a feature to merge points that are coincident or within a /// tolerance. /// -class CleanGrid : public vtkm::filter::FilterDataSet +class VTKM_ALWAYS_EXPORT CleanGrid : public vtkm::filter::FilterDataSet { public: - VTKM_CONT + VTKM_FILTER_EXPORT CleanGrid(); /// When the CompactPointFields flag is true, the filter will identify any @@ -85,15 +87,41 @@ public: VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData, vtkm::filter::PolicyBase policy); + template VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::ArrayHandle& input, const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase); + vtkm::filter::PolicyBase) + { + if (fieldMeta.IsPointField() && (this->GetCompactPointFields() || this->GetMergePoints())) + { + vtkm::cont::ArrayHandle compactedArray; + if (this->GetCompactPointFields()) + { + compactedArray = this->PointCompactor.MapPointFieldDeep(input); + if (this->GetMergePoints()) + { + compactedArray = this->PointMerger.MapPointField(compactedArray); + } + } + else if (this->GetMergePoints()) + { + compactedArray = this->PointMerger.MapPointField(input); + } + result.AddField(fieldMeta.AsField(compactedArray)); + } + else if (fieldMeta.IsCellField() && this->GetRemoveDegenerateCells()) + { + result.AddField(fieldMeta.AsField(this->CellCompactor.ProcessCellField(input))); + } + else + { + result.AddField(fieldMeta.AsField(input)); + } - template - VTKM_CONT vtkm::cont::ArrayHandle MapPointField( - const vtkm::cont::ArrayHandle& inArray) const; + return true; + } private: bool CompactPointFields; @@ -103,13 +131,19 @@ private: bool RemoveDegenerateCells; bool FastMerge; + VTKM_FILTER_EXPORT vtkm::cont::DataSet GenerateOutput( + const vtkm::cont::DataSet& inData, + vtkm::cont::CellSetExplicit<>& outputCellSet); + vtkm::worklet::RemoveUnusedPoints PointCompactor; vtkm::worklet::RemoveDegenerateCells CellCompactor; vtkm::worklet::PointMerge PointMerger; }; + +#ifndef vtkm_filter_CleanGrid_cxx +VTKM_FILTER_EXPORT_EXECUTE_METHOD(CleanGrid); +#endif } } // namespace vtkm::filter -#include - #endif //vtk_m_filter_CleanGrid_h diff --git a/vtkm/filter/CleanGrid.hxx b/vtkm/filter/CleanGrid.hxx index ebc5ef5f1..1912d0282 100644 --- a/vtkm/filter/CleanGrid.hxx +++ b/vtkm/filter/CleanGrid.hxx @@ -20,24 +20,11 @@ namespace vtkm namespace filter { -inline VTKM_CONT CleanGrid::CleanGrid() - : CompactPointFields(true) - , MergePoints(true) - , Tolerance(1.0e-6) - , ToleranceIsAbsolute(false) - , RemoveDegenerateCells(true) - , FastMerge(true) -{ -} - template inline VTKM_CONT vtkm::cont::DataSet CleanGrid::DoExecute(const vtkm::cont::DataSet& inData, vtkm::filter::PolicyBase policy) { using CellSetType = vtkm::cont::CellSetExplicit<>; - using VecId = std::size_t; - - VecId activeCoordIndex = static_cast(this->GetActiveCoordinateSystemIndex()); CellSetType outputCellSet; // Do a deep copy of the cells to new CellSetExplicit structures @@ -78,122 +65,7 @@ inline VTKM_CONT vtkm::cont::DataSet CleanGrid::DoExecute(const vtkm::cont::Data deducedCellSet.ReleaseResourcesExecution(); } - - VecId numCoordSystems = static_cast(inData.GetNumberOfCoordinateSystems()); - std::vector outputCoordinateSystems(numCoordSystems); - - // Start with a shallow copy of the coordinate systems - for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex) - { - outputCoordinateSystems[coordSystemIndex] = - inData.GetCoordinateSystem(static_cast(coordSystemIndex)); - } - - // Optionally adjust the cell set indices to remove all unused points - if (this->GetCompactPointFields()) - { - this->PointCompactor.FindPointsStart(); - this->PointCompactor.FindPoints(outputCellSet); - this->PointCompactor.FindPointsEnd(); - - outputCellSet = this->PointCompactor.MapCellSet(outputCellSet); - - for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex) - { - outputCoordinateSystems[coordSystemIndex] = - vtkm::cont::CoordinateSystem(outputCoordinateSystems[coordSystemIndex].GetName(), - this->PointCompactor.MapPointFieldDeep( - outputCoordinateSystems[coordSystemIndex].GetData())); - } - } - - // Optionally find and merge coincident points - if (this->GetMergePoints()) - { - vtkm::cont::CoordinateSystem activeCoordSystem = outputCoordinateSystems[activeCoordIndex]; - vtkm::Bounds bounds = activeCoordSystem.GetBounds(); - - vtkm::Float64 delta = this->GetTolerance(); - if (!this->GetToleranceIsAbsolute()) - { - delta *= - vtkm::Magnitude(vtkm::make_Vec(bounds.X.Length(), bounds.Y.Length(), bounds.Z.Length())); - } - - auto coordArray = activeCoordSystem.GetData(); - this->PointMerger.Run(delta, this->GetFastMerge(), bounds, coordArray); - activeCoordSystem = vtkm::cont::CoordinateSystem(activeCoordSystem.GetName(), coordArray); - - for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex) - { - if (coordSystemIndex == activeCoordIndex) - { - outputCoordinateSystems[coordSystemIndex] = activeCoordSystem; - } - else - { - outputCoordinateSystems[coordSystemIndex] = vtkm::cont::CoordinateSystem( - outputCoordinateSystems[coordSystemIndex].GetName(), - this->PointMerger.MapPointField(outputCoordinateSystems[coordSystemIndex].GetData())); - } - } - - outputCellSet = this->PointMerger.MapCellSet(outputCellSet); - } - - // Optionally remove degenerate cells - if (this->GetRemoveDegenerateCells()) - { - outputCellSet = this->CellCompactor.Run(outputCellSet); - } - - // Construct resulting data set with new cell sets - vtkm::cont::DataSet outData; - outData.SetCellSet(outputCellSet); - - // Pass the coordinate systems - for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex) - { - outData.AddCoordinateSystem(outputCoordinateSystems[coordSystemIndex]); - } - - return outData; -} - -template -inline VTKM_CONT bool CleanGrid::DoMapField( - vtkm::cont::DataSet& result, - const vtkm::cont::ArrayHandle& input, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase) -{ - if (fieldMeta.IsPointField() && (this->GetCompactPointFields() || this->GetMergePoints())) - { - vtkm::cont::ArrayHandle compactedArray; - if (this->GetCompactPointFields()) - { - compactedArray = this->PointCompactor.MapPointFieldDeep(input); - if (this->GetMergePoints()) - { - compactedArray = this->PointMerger.MapPointField(compactedArray); - } - } - else if (this->GetMergePoints()) - { - compactedArray = this->PointMerger.MapPointField(input); - } - result.AddField(fieldMeta.AsField(compactedArray)); - } - else if (fieldMeta.IsCellField() && this->GetRemoveDegenerateCells()) - { - result.AddField(fieldMeta.AsField(this->CellCompactor.ProcessCellField(input))); - } - else - { - result.AddField(fieldMeta.AsField(input)); - } - - return true; + return this->GenerateOutput(inData, outputCellSet); } } } diff --git a/vtkm/filter/ClipWithField.cxx b/vtkm/filter/ClipWithField.cxx new file mode 100644 index 000000000..8782beb2f --- /dev/null +++ b/vtkm/filter/ClipWithField.cxx @@ -0,0 +1,22 @@ +//============================================================================ +// 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_Clip_cxx + +#include +#include + +namespace vtkm +{ +namespace filter +{ +//----------------------------------------------------------------------------- +VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(ClipWithField); +} +} diff --git a/vtkm/filter/ClipWithField.h b/vtkm/filter/ClipWithField.h index a57880651..7c73fa6fe 100644 --- a/vtkm/filter/ClipWithField.h +++ b/vtkm/filter/ClipWithField.h @@ -11,6 +11,8 @@ #ifndef vtk_m_filter_ClipWithField_h #define vtk_m_filter_ClipWithField_h +#include + #include #include @@ -24,14 +26,11 @@ namespace filter /// value are considered outside, and will be discarded. All points that are greater /// are kept. /// The resulting geometry will not be water tight. -class ClipWithField : public vtkm::filter::FilterDataSetWithField +class VTKM_ALWAYS_EXPORT ClipWithField : public vtkm::filter::FilterDataSetWithField { public: using SupportedTypes = vtkm::TypeListTagScalarAll; - VTKM_CONT - ClipWithField(); - VTKM_CONT void SetClipValue(vtkm::Float64 value) { this->ClipValue = value; } @@ -53,16 +52,38 @@ public: VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::ArrayHandle& input, const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); + vtkm::filter::PolicyBase) + { + vtkm::cont::ArrayHandle output; + + if (fieldMeta.IsPointField()) + { + output = this->Worklet.ProcessPointField(input); + } + else if (fieldMeta.IsCellField()) + { + output = this->Worklet.ProcessCellField(input); + } + else + { + return false; + } + + //use the same meta data as the input so we get the same field name, etc. + result.AddField(fieldMeta.AsField(output)); + return true; + } private: - vtkm::Float64 ClipValue; + vtkm::Float64 ClipValue = 0; vtkm::worklet::Clip Worklet; - bool Invert; + bool Invert = false; }; + +#ifndef vtkm_filter_Clip_cxx +VTKM_FILTER_EXPORT_EXECUTE_METHOD(ClipWithField); +#endif } } // namespace vtkm::filter -#include - #endif // vtk_m_filter_ClipWithField_h diff --git a/vtkm/filter/ClipWithField.hxx b/vtkm/filter/ClipWithField.hxx index 861a22efa..6f67a4411 100644 --- a/vtkm/filter/ClipWithField.hxx +++ b/vtkm/filter/ClipWithField.hxx @@ -18,16 +18,6 @@ namespace vtkm { namespace filter { - -//----------------------------------------------------------------------------- -inline VTKM_CONT ClipWithField::ClipWithField() - : vtkm::filter::FilterDataSetWithField() - , ClipValue(0) - , Worklet() - , Invert(false) -{ -} - //----------------------------------------------------------------------------- template inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute( @@ -60,33 +50,5 @@ inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute( output.AddCoordinateSystem(outputCoords); return output; } - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT bool ClipWithField::DoMapField( - vtkm::cont::DataSet& result, - const vtkm::cont::ArrayHandle& input, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase) -{ - vtkm::cont::ArrayHandle output; - - if (fieldMeta.IsPointField()) - { - output = this->Worklet.ProcessPointField(input); - } - else if (fieldMeta.IsCellField()) - { - output = this->Worklet.ProcessCellField(input); - } - else - { - return false; - } - - //use the same meta data as the input so we get the same field name, etc. - result.AddField(fieldMeta.AsField(output)); - return true; -} } } // end namespace vtkm::filter diff --git a/vtkm/filter/ClipWithImplicitFunction.cxx b/vtkm/filter/ClipWithImplicitFunction.cxx new file mode 100644 index 000000000..8d8ad3e3e --- /dev/null +++ b/vtkm/filter/ClipWithImplicitFunction.cxx @@ -0,0 +1,22 @@ + +//============================================================================ +// 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_ClipWithImplicitFunction_cxx +#include +#include + +namespace vtkm +{ +namespace filter +{ +//----------------------------------------------------------------------------- +VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(ClipWithImplicitFunction); +} +} diff --git a/vtkm/filter/ClipWithImplicitFunction.h b/vtkm/filter/ClipWithImplicitFunction.h index 9d9114c04..359ccca7e 100644 --- a/vtkm/filter/ClipWithImplicitFunction.h +++ b/vtkm/filter/ClipWithImplicitFunction.h @@ -7,10 +7,11 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_ClipWithImplicitFunction_h #define vtk_m_filter_ClipWithImplicitFunction_h +#include + #include #include #include @@ -25,11 +26,10 @@ namespace filter /// Clip a dataset using a given implicit function value, such as vtkm::Sphere /// or vtkm::Frustum. /// The resulting geometry will not be water tight. -class ClipWithImplicitFunction : public vtkm::filter::FilterDataSet +class VTKM_ALWAYS_EXPORT ClipWithImplicitFunction + : public vtkm::filter::FilterDataSet { public: - ClipWithImplicitFunction(); - void SetImplicitFunction(const vtkm::cont::ImplicitFunctionHandle& func) { this->Function = func; @@ -41,7 +41,7 @@ public: template vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::filter::PolicyBase& policy); + vtkm::filter::PolicyBase policy); //Map a new field onto the resulting dataset after running the filter. //This call is only valid after Execute has been called. @@ -49,16 +49,39 @@ public: bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::ArrayHandle& input, const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase& policy); + vtkm::filter::PolicyBase) + { + vtkm::cont::ArrayHandle output; + + if (fieldMeta.IsPointField()) + { + output = this->Worklet.ProcessPointField(input); + } + else if (fieldMeta.IsCellField()) + { + output = this->Worklet.ProcessCellField(input); + } + else + { + return false; + } + + //use the same meta data as the input so we get the same field name, etc. + result.AddField(fieldMeta.AsField(output)); + + return true; + } private: vtkm::cont::ImplicitFunctionHandle Function; vtkm::worklet::Clip Worklet; - bool Invert; + bool Invert = false; }; + +#ifndef vtkm_filter_ClipWithImplicitFunction_cxx +VTKM_FILTER_EXPORT_EXECUTE_METHOD(ClipWithImplicitFunction); +#endif } } // namespace vtkm::filter -#include - #endif // vtk_m_filter_ClipWithImplicitFunction_h diff --git a/vtkm/filter/ClipWithImplicitFunction.hxx b/vtkm/filter/ClipWithImplicitFunction.hxx index 639b90ad6..a26e01bd8 100644 --- a/vtkm/filter/ClipWithImplicitFunction.hxx +++ b/vtkm/filter/ClipWithImplicitFunction.hxx @@ -17,16 +17,10 @@ namespace vtkm namespace filter { //----------------------------------------------------------------------------- - -ClipWithImplicitFunction::ClipWithImplicitFunction() - : Invert(false) -{ -} - template inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute( const vtkm::cont::DataSet& input, - const vtkm::filter::PolicyBase& policy) + vtkm::filter::PolicyBase policy) { //get the cells and coordinates of the dataset const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(); @@ -48,34 +42,5 @@ inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute( return output; } - -//----------------------------------------------------------------------------- -template -inline bool ClipWithImplicitFunction::DoMapField( - vtkm::cont::DataSet& result, - const vtkm::cont::ArrayHandle& input, - const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase&) -{ - vtkm::cont::ArrayHandle output; - - if (fieldMeta.IsPointField()) - { - output = this->Worklet.ProcessPointField(input); - } - else if (fieldMeta.IsCellField()) - { - output = this->Worklet.ProcessCellField(input); - } - else - { - return false; - } - - //use the same meta data as the input so we get the same field name, etc. - result.AddField(fieldMeta.AsField(output)); - - return true; -} } } // end namespace vtkm::filter diff --git a/vtkm/filter/Contour.cxx b/vtkm/filter/Contour.cxx new file mode 100644 index 000000000..d82fbf9a8 --- /dev/null +++ b/vtkm/filter/Contour.cxx @@ -0,0 +1,75 @@ +//============================================================================ +// 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_Contour_cxx +#include +#include + +namespace vtkm +{ +namespace filter +{ + +//----------------------------------------------------------------------------- +VTKM_FILTER_EXPORT Contour::Contour() + : vtkm::filter::FilterDataSetWithField() + , IsoValues() + , GenerateNormals(false) + , AddInterpolationEdgeIds(false) + , ComputeFastNormalsForStructured(false) + , ComputeFastNormalsForUnstructured(true) + , NormalArrayName("normals") + , InterpolationEdgeIdsArrayName("edgeIds") + , Worklet() +{ + // todo: keep an instance of marching cubes worklet as a member variable +} + +//----------------------------------------------------------------------------- +VTKM_FILTER_EXPORT void Contour::SetNumberOfIsoValues(vtkm::Id num) +{ + if (num >= 0) + { + this->IsoValues.resize(static_cast(num)); + } +} + +//----------------------------------------------------------------------------- +VTKM_FILTER_EXPORT vtkm::Id Contour::GetNumberOfIsoValues() const +{ + return static_cast(this->IsoValues.size()); +} + +//----------------------------------------------------------------------------- +VTKM_FILTER_EXPORT void Contour::SetIsoValue(vtkm::Id index, vtkm::Float64 v) +{ + std::size_t i = static_cast(index); + if (i >= this->IsoValues.size()) + { + this->IsoValues.resize(i + 1); + } + this->IsoValues[i] = v; +} + +//----------------------------------------------------------------------------- +VTKM_FILTER_EXPORT void Contour::SetIsoValues(const std::vector& values) +{ + this->IsoValues = values; +} + +//----------------------------------------------------------------------------- +VTKM_FILTER_EXPORT vtkm::Float64 Contour::GetIsoValue(vtkm::Id index) const +{ + return this->IsoValues[static_cast(index)]; +} + +//----------------------------------------------------------------------------- +VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(Contour); +} +} diff --git a/vtkm/filter/Contour.h b/vtkm/filter/Contour.h index 75c144925..0ff3f2bd3 100644 --- a/vtkm/filter/Contour.h +++ b/vtkm/filter/Contour.h @@ -11,6 +11,8 @@ #ifndef vtk_m_filter_Contour_h #define vtk_m_filter_Contour_h +#include + #include #include @@ -25,30 +27,30 @@ namespace filter /// Multiple contour values must be specified to generate the isosurfaces. /// @warning /// This filter is currently only supports 3D volumes. -class Contour : public vtkm::filter::FilterDataSetWithField +class VTKM_ALWAYS_EXPORT Contour : public vtkm::filter::FilterDataSetWithField { public: using SupportedTypes = vtkm::ListTagBase; - VTKM_CONT + VTKM_FILTER_EXPORT Contour(); - VTKM_CONT + VTKM_FILTER_EXPORT void SetNumberOfIsoValues(vtkm::Id num); - VTKM_CONT + VTKM_FILTER_EXPORT vtkm::Id GetNumberOfIsoValues() const; - VTKM_CONT + VTKM_FILTER_EXPORT void SetIsoValue(vtkm::Float64 v) { this->SetIsoValue(0, v); } - VTKM_CONT + VTKM_FILTER_EXPORT void SetIsoValue(vtkm::Id index, vtkm::Float64); - VTKM_CONT + VTKM_FILTER_EXPORT void SetIsoValues(const std::vector& values); - VTKM_CONT + VTKM_FILTER_EXPORT vtkm::Float64 GetIsoValue(vtkm::Id index) const; /// Set/Get whether the points generated should be unique for every triangle @@ -104,10 +106,10 @@ public: const std::string& GetNormalArrayName() const { return this->NormalArrayName; } template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase& policy); + 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 @@ -115,7 +117,27 @@ public: VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::ArrayHandle& input, const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase& policy); + vtkm::filter::PolicyBase) + { + vtkm::cont::ArrayHandle fieldArray; + + if (fieldMeta.IsPointField()) + { + fieldArray = this->Worklet.ProcessPointField(input); + } + else if (fieldMeta.IsCellField()) + { + fieldArray = this->Worklet.ProcessCellField(input); + } + else + { + return false; + } + + //use the same meta data as the input so we get the same field name, etc. + result.AddField(fieldMeta.AsField(fieldArray)); + return true; + } private: std::vector IsoValues; @@ -127,9 +149,11 @@ private: std::string InterpolationEdgeIdsArrayName; vtkm::worklet::Contour Worklet; }; + +#ifndef vtkm_filter_Contour_cxx +VTKM_FILTER_EXPORT_EXECUTE_METHOD(Contour); +#endif } } // namespace vtkm::filter -#include - #endif // vtk_m_filter_Contour_h diff --git a/vtkm/filter/Contour.hxx b/vtkm/filter/Contour.hxx index 177719fb6..19b082390 100644 --- a/vtkm/filter/Contour.hxx +++ b/vtkm/filter/Contour.hxx @@ -25,7 +25,7 @@ namespace { template -bool IsCellSetStructured(const vtkm::cont::DynamicCellSetBase& cellset) +inline bool IsCellSetStructured(const vtkm::cont::DynamicCellSetBase& cellset) { if (cellset.template IsType>() || cellset.template IsType>() || @@ -37,66 +37,13 @@ bool IsCellSetStructured(const vtkm::cont::DynamicCellSetBase& cell } } // anonymous namespace -//----------------------------------------------------------------------------- -inline VTKM_CONT Contour::Contour() - : vtkm::filter::FilterDataSetWithField() - , IsoValues() - , GenerateNormals(false) - , AddInterpolationEdgeIds(false) - , ComputeFastNormalsForStructured(false) - , ComputeFastNormalsForUnstructured(true) - , NormalArrayName("normals") - , InterpolationEdgeIdsArrayName("edgeIds") - , Worklet() -{ - // todo: keep an instance of marching cubes worklet as a member variable -} - -//----------------------------------------------------------------------------- -inline void Contour::SetNumberOfIsoValues(vtkm::Id num) -{ - if (num >= 0) - { - this->IsoValues.resize(static_cast(num)); - } -} - -//----------------------------------------------------------------------------- -inline vtkm::Id Contour::GetNumberOfIsoValues() const -{ - return static_cast(this->IsoValues.size()); -} - -//----------------------------------------------------------------------------- -inline void Contour::SetIsoValue(vtkm::Id index, vtkm::Float64 v) -{ - std::size_t i = static_cast(index); - if (i >= this->IsoValues.size()) - { - this->IsoValues.resize(i + 1); - } - this->IsoValues[i] = v; -} - -//----------------------------------------------------------------------------- -inline void Contour::SetIsoValues(const std::vector& values) -{ - this->IsoValues = values; -} - -//----------------------------------------------------------------------------- -inline vtkm::Float64 Contour::GetIsoValue(vtkm::Id index) const -{ - return this->IsoValues[static_cast(index)]; -} - //----------------------------------------------------------------------------- template inline VTKM_CONT vtkm::cont::DataSet Contour::DoExecute( const vtkm::cont::DataSet& input, const vtkm::cont::ArrayHandle& field, const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase& policy) + vtkm::filter::PolicyBase policy) { if (fieldMeta.IsPointField() == false) { @@ -203,32 +150,5 @@ inline VTKM_CONT vtkm::cont::DataSet Contour::DoExecute( return output; } - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT bool Contour::DoMapField(vtkm::cont::DataSet& result, - const vtkm::cont::ArrayHandle& input, - const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase&) -{ - vtkm::cont::ArrayHandle fieldArray; - - if (fieldMeta.IsPointField()) - { - fieldArray = this->Worklet.ProcessPointField(input); - } - else if (fieldMeta.IsCellField()) - { - fieldArray = this->Worklet.ProcessCellField(input); - } - else - { - return false; - } - - //use the same meta data as the input so we get the same field name, etc. - result.AddField(fieldMeta.AsField(fieldArray)); - return true; -} } } // namespace vtkm::filter diff --git a/vtkm/filter/ExternalFaces.cxx b/vtkm/filter/ExternalFaces.cxx new file mode 100644 index 000000000..23f2d4b45 --- /dev/null +++ b/vtkm/filter/ExternalFaces.cxx @@ -0,0 +1,71 @@ + +//============================================================================ +// 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_ExternalFaces_cxx +#include +#include + +namespace vtkm +{ +namespace filter +{ + +//----------------------------------------------------------------------------- +ExternalFaces::ExternalFaces() + : vtkm::filter::FilterDataSet() + , CompactPoints(false) + , Worklet() +{ + this->SetPassPolyData(true); +} + +//----------------------------------------------------------------------------- +vtkm::cont::DataSet ExternalFaces::GenerateOutput(const vtkm::cont::DataSet& input, + vtkm::cont::CellSetExplicit<>& outCellSet) +{ + //This section of ExternalFaces is independent of any input so we can build it + //into the vtkm_filter library + + //3. Check the fields of the dataset to see what kinds of fields are present so + // we can free the cell mapping array if it won't be needed. + const vtkm::Id numFields = input.GetNumberOfFields(); + bool hasCellFields = false; + for (vtkm::Id fieldIdx = 0; fieldIdx < numFields && !hasCellFields; ++fieldIdx) + { + auto f = input.GetField(fieldIdx); + hasCellFields = f.IsFieldCell(); + } + + if (!hasCellFields) + { + this->Worklet.ReleaseCellMapArrays(); + } + + //4. create the output dataset + vtkm::cont::DataSet output; + output.SetCellSet(outCellSet); + output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); + + if (this->CompactPoints) + { + this->Compactor.SetCompactPointFields(true); + this->Compactor.SetMergePoints(false); + return this->Compactor.Execute(output, PolicyDefault{}); + } + else + { + return output; + } +} + +//----------------------------------------------------------------------------- +VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(ExternalFaces); +} +} diff --git a/vtkm/filter/ExternalFaces.h b/vtkm/filter/ExternalFaces.h index 50a9b0925..9d0e0eb7f 100644 --- a/vtkm/filter/ExternalFaces.h +++ b/vtkm/filter/ExternalFaces.h @@ -11,6 +11,8 @@ #ifndef vtk_m_filter_ExternalFaces_h #define vtk_m_filter_ExternalFaces_h +#include + #include #include #include @@ -28,10 +30,10 @@ namespace filter /// @warning /// This filter is currently only supports propagation of point properties /// -class ExternalFaces : public vtkm::filter::FilterDataSet +class VTKM_ALWAYS_EXPORT ExternalFaces : public vtkm::filter::FilterDataSet { public: - VTKM_CONT + VTKM_FILTER_EXPORT ExternalFaces(); // When CompactPoints is set, instead of copying the points and point fields @@ -63,17 +65,45 @@ public: VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::ArrayHandle& input, const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); + vtkm::filter::PolicyBase policy) + { + if (fieldMeta.IsPointField()) + { + if (this->CompactPoints) + { + return this->Compactor.DoMapField(result, input, fieldMeta, policy); + } + else + { + result.AddField(fieldMeta.AsField(input)); + return true; + } + } + else if (fieldMeta.IsCellField()) + { + vtkm::cont::ArrayHandle fieldArray; + fieldArray = this->Worklet.ProcessCellField(input); + result.AddField(fieldMeta.AsField(fieldArray)); + return true; + } -public: + return false; + } + +private: bool CompactPoints; bool PassPolyData; + + VTKM_FILTER_EXPORT vtkm::cont::DataSet GenerateOutput(const vtkm::cont::DataSet& input, + vtkm::cont::CellSetExplicit<>& outCellSet); + vtkm::filter::CleanGrid Compactor; vtkm::worklet::ExternalFaces Worklet; }; +#ifndef vtkm_filter_ExternalFaces_cxx +VTKM_FILTER_EXPORT_EXECUTE_METHOD(ExternalFaces); +#endif } } // namespace vtkm::filter -#include - #endif // vtk_m_filter_ExternalFaces_h diff --git a/vtkm/filter/ExternalFaces.hxx b/vtkm/filter/ExternalFaces.hxx index c694e6501..2f2d4147f 100644 --- a/vtkm/filter/ExternalFaces.hxx +++ b/vtkm/filter/ExternalFaces.hxx @@ -13,33 +13,6 @@ namespace vtkm namespace filter { -//----------------------------------------------------------------------------- -inline VTKM_CONT ExternalFaces::ExternalFaces() - : vtkm::filter::FilterDataSet() - , CompactPoints(false) - , Worklet() -{ - this->SetPassPolyData(true); -} - -namespace -{ - -template -struct CellSetExplicitPolicy : public BasePolicy -{ - using AllCellSetList = vtkm::cont::CellSetListTagExplicitDefault; -}; - -template -inline vtkm::filter::PolicyBase> GetCellSetExplicitPolicy( - const vtkm::filter::PolicyBase&) -{ - return vtkm::filter::PolicyBase>(); -} - -} // anonymous namespace - //----------------------------------------------------------------------------- template inline VTKM_CONT vtkm::cont::DataSet ExternalFaces::DoExecute( @@ -64,68 +37,7 @@ inline VTKM_CONT vtkm::cont::DataSet ExternalFaces::DoExecute( this->Worklet.Run(vtkm::filter::ApplyPolicyCellSetUnstructured(cells, policy), outCellSet); } - //3. Check the fields of the dataset to see what kinds of fields are present so - // we can free the cell mapping array if it won't be needed. - const vtkm::Id numFields = input.GetNumberOfFields(); - bool hasCellFields = false; - for (vtkm::Id fieldIdx = 0; fieldIdx < numFields && !hasCellFields; ++fieldIdx) - { - auto f = input.GetField(fieldIdx); - hasCellFields = f.IsFieldCell(); - } - - if (!hasCellFields) - { - this->Worklet.ReleaseCellMapArrays(); - } - - //4. create the output dataset - vtkm::cont::DataSet output; - output.SetCellSet(outCellSet); - output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); - - if (this->CompactPoints) - { - this->Compactor.SetCompactPointFields(true); - this->Compactor.SetMergePoints(false); - return this->Compactor.DoExecute(output, GetCellSetExplicitPolicy(policy)); - } - else - { - return output; - } -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT bool ExternalFaces::DoMapField( - vtkm::cont::DataSet& result, - const vtkm::cont::ArrayHandle& input, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy) -{ - if (fieldMeta.IsPointField()) - { - if (this->CompactPoints) - { - return this->Compactor.DoMapField(result, input, fieldMeta, policy); - } - else - { - result.AddField(fieldMeta.AsField(input)); - return true; - } - } - else if (fieldMeta.IsCellField()) - { - vtkm::cont::ArrayHandle fieldArray; - fieldArray = this->Worklet.ProcessCellField(input); - result.AddField(fieldMeta.AsField(fieldArray)); - return true; - } - - - return false; + return this->GenerateOutput(input, outCellSet); } } } diff --git a/vtkm/filter/ExtractPoints.hxx b/vtkm/filter/ExtractPoints.hxx index ab2d18cbd..ac873a5af 100644 --- a/vtkm/filter/ExtractPoints.hxx +++ b/vtkm/filter/ExtractPoints.hxx @@ -11,24 +11,6 @@ #include #include -namespace -{ - -// Needed to CompactPoints -template -struct CellSetSingleTypePolicy : public BasePolicy -{ - using AllCellSetList = vtkm::cont::CellSetListTagUnstructured; -}; - -template -inline vtkm::filter::PolicyBase> GetCellSetSingleTypePolicy( - const vtkm::filter::PolicyBase&) -{ - return vtkm::filter::PolicyBase>(); -} -} - namespace vtkm { namespace filter @@ -71,7 +53,7 @@ inline vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& i { this->Compactor.SetCompactPointFields(true); this->Compactor.SetMergePoints(false); - return this->Compactor.DoExecute(output, GetCellSetSingleTypePolicy(policy)); + return this->Compactor.Execute(output, PolicyDefault{}); } else { diff --git a/vtkm/filter/ExtractStructured.cxx b/vtkm/filter/ExtractStructured.cxx new file mode 100644 index 000000000..e522e6338 --- /dev/null +++ b/vtkm/filter/ExtractStructured.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. +//============================================================================ +#define vtkm_filter_ExtractStructured_cxx +#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() +{ +} + + +//----------------------------------------------------------------------------- +VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(ExtractStructured); +} +} diff --git a/vtkm/filter/ExtractStructured.h b/vtkm/filter/ExtractStructured.h index 78a81d30a..4ab0beca1 100644 --- a/vtkm/filter/ExtractStructured.h +++ b/vtkm/filter/ExtractStructured.h @@ -11,6 +11,8 @@ #ifndef vtk_m_filter_ExtractStructured_h #define vtk_m_filter_ExtractStructured_h +#include + #include #include @@ -34,10 +36,10 @@ namespace filter /// for image processing, subsampling large volumes to reduce data size, or /// extracting regions of a volume with interesting data. /// -class ExtractStructured : public vtkm::filter::FilterDataSet +class VTKM_ALWAYS_EXPORT ExtractStructured : public vtkm::filter::FilterDataSet { public: - VTKM_CONT + VTKM_FILTER_EXPORT ExtractStructured(); // Set the bounding box for the volume of interest @@ -90,7 +92,27 @@ public: VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::ArrayHandle& input, const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); + vtkm::filter::PolicyBase) + { + if (fieldMeta.IsPointField()) + { + vtkm::cont::ArrayHandle output = this->Worklet.ProcessPointField(input); + + result.AddField(fieldMeta.AsField(output)); + return true; + } + + // cell data must be scattered to the cells created per input cell + if (fieldMeta.IsCellField()) + { + vtkm::cont::ArrayHandle output = this->Worklet.ProcessCellField(input); + + result.AddField(fieldMeta.AsField(output)); + return true; + } + + return false; + } private: vtkm::RangeId3 VOI; @@ -99,9 +121,12 @@ private: bool IncludeOffset; vtkm::worklet::ExtractStructured Worklet; }; + +#ifndef vtkm_filter_ExtractStructured_cxx +VTKM_FILTER_EXPORT_EXECUTE_METHOD(ExtractStructured); +#endif } } // namespace vtkm::filter -#include #endif // vtk_m_filter_ExtractStructured_h diff --git a/vtkm/filter/ExtractStructured.hxx b/vtkm/filter/ExtractStructured.hxx index caf006594..cef8c513d 100644 --- a/vtkm/filter/ExtractStructured.hxx +++ b/vtkm/filter/ExtractStructured.hxx @@ -12,18 +12,6 @@ namespace vtkm { namespace filter { - -//----------------------------------------------------------------------------- -inline VTKM_CONT 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() -{ -} - //----------------------------------------------------------------------------- template inline VTKM_CONT vtkm::cont::DataSet ExtractStructured::DoExecute( @@ -47,33 +35,5 @@ inline VTKM_CONT vtkm::cont::DataSet ExtractStructured::DoExecute( output.AddCoordinateSystem(outputCoordinates); return output; } - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT bool ExtractStructured::DoMapField( - vtkm::cont::DataSet& result, - const vtkm::cont::ArrayHandle& input, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase) -{ - if (fieldMeta.IsPointField()) - { - vtkm::cont::ArrayHandle output = this->Worklet.ProcessPointField(input); - - result.AddField(fieldMeta.AsField(output)); - return true; - } - - // cell data must be scattered to the cells created per input cell - if (fieldMeta.IsCellField()) - { - vtkm::cont::ArrayHandle output = this->Worklet.ProcessCellField(input); - - result.AddField(fieldMeta.AsField(output)); - return true; - } - - return false; -} } } diff --git a/vtkm/filter/Filter.h b/vtkm/filter/Filter.h index 53d34c3c7..639defd6d 100644 --- a/vtkm/filter/Filter.h +++ b/vtkm/filter/Filter.h @@ -279,5 +279,18 @@ private: } } // namespace vtkm::filter +#define VTKM_FILTER_EXPORT_EXECUTE_METHOD_WITH_POLICY(Name, Policy) \ + extern template VTKM_FILTER_TEMPLATE_EXPORT vtkm::cont::PartitionedDataSet \ + vtkm::filter::Filter::Execute(vtkm::cont::PartitionedDataSet const&, \ + vtkm::filter::PolicyBase) +#define VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD_WITH_POLICY(Name, Policy) \ + template VTKM_FILTER_EXPORT vtkm::cont::PartitionedDataSet Filter::Execute( \ + vtkm::cont::PartitionedDataSet const&, vtkm::filter::PolicyBase) + +#define VTKM_FILTER_EXPORT_EXECUTE_METHOD(Name) \ + VTKM_FILTER_EXPORT_EXECUTE_METHOD_WITH_POLICY(Name, vtkm::filter::PolicyDefault) +#define VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(Name) \ + VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD_WITH_POLICY(Name, vtkm::filter::PolicyDefault) + #include #endif diff --git a/vtkm/filter/Filter.hxx b/vtkm/filter/Filter.hxx index e39a56137..49256157e 100644 --- a/vtkm/filter/Filter.hxx +++ b/vtkm/filter/Filter.hxx @@ -264,7 +264,7 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet Filter::Execute( //---------------------------------------------------------------------------- template template -inline VTKM_CONT vtkm::cont::DataSet Filter::Execute( +VTKM_CONT vtkm::cont::DataSet Filter::Execute( const vtkm::cont::DataSet& input, vtkm::filter::PolicyBase policy) { @@ -284,7 +284,7 @@ inline VTKM_CONT vtkm::cont::DataSet Filter::Execute( //---------------------------------------------------------------------------- template template -inline VTKM_CONT vtkm::cont::PartitionedDataSet Filter::Execute( +VTKM_CONT vtkm::cont::PartitionedDataSet Filter::Execute( const vtkm::cont::PartitionedDataSet& input, vtkm::filter::PolicyBase policy) { diff --git a/vtkm/filter/FilterField.hxx b/vtkm/filter/FilterField.hxx index 7b546c4a3..233aaa528 100644 --- a/vtkm/filter/FilterField.hxx +++ b/vtkm/filter/FilterField.hxx @@ -46,7 +46,7 @@ inline VTKM_CONT FilterField::~FilterField() //----------------------------------------------------------------------------- template template -inline VTKM_CONT vtkm::cont::DataSet FilterField::PrepareForExecution( +VTKM_CONT vtkm::cont::DataSet FilterField::PrepareForExecution( const vtkm::cont::DataSet& input, vtkm::filter::PolicyBase policy) { @@ -67,7 +67,7 @@ inline VTKM_CONT vtkm::cont::DataSet FilterField::PrepareForExecution( //----------------------------------------------------------------------------- template template -inline VTKM_CONT vtkm::cont::DataSet FilterField::PrepareForExecution( +VTKM_CONT vtkm::cont::DataSet FilterField::PrepareForExecution( const vtkm::cont::DataSet& input, const vtkm::cont::Field& field, vtkm::filter::PolicyBase policy) @@ -89,7 +89,7 @@ inline VTKM_CONT vtkm::cont::DataSet FilterField::PrepareForExecution( //----------------------------------------------------------------------------- template template -inline VTKM_CONT vtkm::cont::DataSet FilterField::PrepareForExecution( +VTKM_CONT vtkm::cont::DataSet FilterField::PrepareForExecution( const vtkm::cont::DataSet& input, const vtkm::cont::CoordinateSystem& field, vtkm::filter::PolicyBase policy) diff --git a/vtkm/filter/GhostCellRemove.hxx b/vtkm/filter/GhostCellRemove.hxx index 9bdf144ca..aa47e088b 100644 --- a/vtkm/filter/GhostCellRemove.hxx +++ b/vtkm/filter/GhostCellRemove.hxx @@ -328,7 +328,7 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute( extract.SetFieldsToPass(this->GetActiveFieldName(), vtkm::filter::FieldSelection::MODE_EXCLUDE); - auto output = extract.Execute(input, vtkm::filter::GhostCellRemovePolicy()); + auto output = extract.Execute(input); return output; } } diff --git a/vtkm/filter/Mask.h b/vtkm/filter/Mask.h index 1b319e947..d3530edb8 100644 --- a/vtkm/filter/Mask.h +++ b/vtkm/filter/Mask.h @@ -11,7 +11,6 @@ #ifndef vtk_m_filter_Mask_h #define vtk_m_filter_Mask_h -#include #include #include diff --git a/vtkm/filter/MaskPoints.hxx b/vtkm/filter/MaskPoints.hxx index e355c5a3b..a47ef612d 100644 --- a/vtkm/filter/MaskPoints.hxx +++ b/vtkm/filter/MaskPoints.hxx @@ -8,24 +8,6 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -namespace -{ - -// Needed to CompactPoints -template -struct CellSetSingleTypePolicy : public BasePolicy -{ - using AllCellSetList = vtkm::cont::CellSetListTagUnstructured; -}; - -template -inline vtkm::filter::PolicyBase> GetCellSetSingleTypePolicy( - const vtkm::filter::PolicyBase&) -{ - return vtkm::filter::PolicyBase>(); -} -} - namespace vtkm { namespace filter @@ -64,7 +46,7 @@ inline VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute( { this->Compactor.SetCompactPointFields(true); this->Compactor.SetMergePoints(false); - return this->Compactor.DoExecute(output, GetCellSetSingleTypePolicy(policy)); + return this->Compactor.Execute(output, PolicyDefault{}); } else { diff --git a/vtkm/filter/PointAverage.cxx b/vtkm/filter/PointAverage.cxx new file mode 100644 index 000000000..32aab5f8b --- /dev/null +++ b/vtkm/filter/PointAverage.cxx @@ -0,0 +1,22 @@ +//============================================================================ +// 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_PointAverage_cxx + +#include +#include + +namespace vtkm +{ +namespace filter +{ +//----------------------------------------------------------------------------- +VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(PointAverage); +} +} diff --git a/vtkm/filter/PointAverage.h b/vtkm/filter/PointAverage.h index 5148b5fd2..1ca33773a 100644 --- a/vtkm/filter/PointAverage.h +++ b/vtkm/filter/PointAverage.h @@ -11,6 +11,9 @@ #ifndef vtk_m_filter_PointAverage_h #define vtk_m_filter_PointAverage_h +#include + +#include #include #include @@ -24,24 +27,23 @@ namespace filter /// specified per cell) into point data (i.e., data specified at cell /// points). The method of transformation is based on averaging the data /// values of all cells using a particular point. -class PointAverage : public vtkm::filter::FilterCell +class VTKM_ALWAYS_EXPORT PointAverage : public vtkm::filter::FilterCell { public: - VTKM_CONT - PointAverage(); - template VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, const vtkm::cont::ArrayHandle& field, const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase& policy); + vtkm::filter::PolicyBase policy); private: vtkm::worklet::PointAverage Worklet; }; + +#ifndef vtkm_filter_PointAverage_cxx +VTKM_FILTER_EXPORT_EXECUTE_METHOD(PointAverage); +#endif } } // namespace vtkm::filter -#include - #endif // vtk_m_filter_PointAverage_h diff --git a/vtkm/filter/PointAverage.hxx b/vtkm/filter/PointAverage.hxx index a4431aa7d..f61801293 100644 --- a/vtkm/filter/PointAverage.hxx +++ b/vtkm/filter/PointAverage.hxx @@ -16,20 +16,13 @@ namespace vtkm namespace filter { -//----------------------------------------------------------------------------- -inline VTKM_CONT PointAverage::PointAverage() - : vtkm::filter::FilterCell() - , Worklet() -{ -} - //----------------------------------------------------------------------------- template inline VTKM_CONT vtkm::cont::DataSet PointAverage::DoExecute( const vtkm::cont::DataSet& input, const vtkm::cont::ArrayHandle& inField, const vtkm::filter::FieldMetadata& fieldMetadata, - const vtkm::filter::PolicyBase& policy) + vtkm::filter::PolicyBase policy) { if (!fieldMetadata.IsCellField()) { diff --git a/vtkm/filter/Threshold.cxx b/vtkm/filter/Threshold.cxx new file mode 100644 index 000000000..ece40846a --- /dev/null +++ b/vtkm/filter/Threshold.cxx @@ -0,0 +1,21 @@ +//============================================================================ +// 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 +{ +//----------------------------------------------------------------------------- +VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(Threshold); +} +} diff --git a/vtkm/filter/Threshold.h b/vtkm/filter/Threshold.h index 73e46edfd..0b0d3573b 100644 --- a/vtkm/filter/Threshold.h +++ b/vtkm/filter/Threshold.h @@ -11,6 +11,8 @@ #ifndef vtk_m_filter_Threshold_h #define vtk_m_filter_Threshold_h +#include + #include #include @@ -28,14 +30,11 @@ namespace filter /// filter is an permutation of the input dataset. /// /// You can threshold either on point or cell fields -class Threshold : public vtkm::filter::FilterDataSetWithField +class VTKM_ALWAYS_EXPORT Threshold : public vtkm::filter::FilterDataSetWithField { public: using SupportedTypes = vtkm::TypeListTagScalarAll; - VTKM_CONT - Threshold(); - VTKM_CONT void SetLowerThreshold(vtkm::Float64 value) { this->LowerValue = value; } VTKM_CONT @@ -58,16 +57,36 @@ public: VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::ArrayHandle& input, const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); + vtkm::filter::PolicyBase) + { + if (fieldMeta.IsPointField()) + { + //we copy the input handle to the result dataset, reusing the metadata + result.AddField(fieldMeta.AsField(input)); + return true; + } + else if (fieldMeta.IsCellField()) + { + vtkm::cont::ArrayHandle out = this->Worklet.ProcessCellField(input); + result.AddField(fieldMeta.AsField(out)); + return true; + } + else + { + return false; + } + } private: - double LowerValue; - double UpperValue; + double LowerValue = 0; + double UpperValue = 0; vtkm::worklet::Threshold Worklet; }; + +#ifndef vtkm_filter_Threshold_cxx +VTKM_FILTER_EXPORT_EXECUTE_METHOD(Threshold); +#endif } } // namespace vtkm::filter -#include - #endif // vtk_m_filter_Threshold_h diff --git a/vtkm/filter/Threshold.hxx b/vtkm/filter/Threshold.hxx index 00b19d40e..e0ce26209 100644 --- a/vtkm/filter/Threshold.hxx +++ b/vtkm/filter/Threshold.hxx @@ -44,14 +44,6 @@ namespace vtkm namespace filter { -//----------------------------------------------------------------------------- -inline VTKM_CONT Threshold::Threshold() - : vtkm::filter::FilterDataSetWithField() - , LowerValue(0) - , UpperValue(0) -{ -} - //----------------------------------------------------------------------------- template inline VTKM_CONT vtkm::cont::DataSet Threshold::DoExecute( @@ -72,30 +64,5 @@ inline VTKM_CONT vtkm::cont::DataSet Threshold::DoExecute( output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); return output; } - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT bool Threshold::DoMapField(vtkm::cont::DataSet& result, - const vtkm::cont::ArrayHandle& input, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase) -{ - if (fieldMeta.IsPointField()) - { - //we copy the input handle to the result dataset, reusing the metadata - result.AddField(fieldMeta.AsField(input)); - return true; - } - else if (fieldMeta.IsCellField()) - { - vtkm::cont::ArrayHandle out = this->Worklet.ProcessCellField(input); - result.AddField(fieldMeta.AsField(out)); - return true; - } - else - { - return false; - } -} } } diff --git a/vtkm/filter/ThresholdPoints.hxx b/vtkm/filter/ThresholdPoints.hxx index 8a76b02ec..e7670420f 100644 --- a/vtkm/filter/ThresholdPoints.hxx +++ b/vtkm/filter/ThresholdPoints.hxx @@ -12,21 +12,6 @@ namespace { - -// Needed to CompactPoints -template -struct CellSetSingleTypePolicy : public BasePolicy -{ - using AllCellSetList = vtkm::cont::CellSetListTagUnstructured; -}; - -template -inline vtkm::filter::PolicyBase> GetCellSetSingleTypePolicy( - const vtkm::filter::PolicyBase&) -{ - return vtkm::filter::PolicyBase>(); -} - // Predicate for values less than minimum class ValuesBelow { @@ -191,7 +176,7 @@ inline VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute( { this->Compactor.SetCompactPointFields(true); this->Compactor.SetMergePoints(true); - return this->Compactor.DoExecute(output, GetCellSetSingleTypePolicy(policy)); + return this->Compactor.Execute(output, PolicyDefault{}); } else { diff --git a/vtkm/filter/VectorMagnitude.cxx b/vtkm/filter/VectorMagnitude.cxx new file mode 100644 index 000000000..2f3c083a5 --- /dev/null +++ b/vtkm/filter/VectorMagnitude.cxx @@ -0,0 +1,31 @@ +//============================================================================ +// 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_VectorMagnitude_cxx + +#include +#include + +namespace vtkm +{ +namespace filter +{ + +//----------------------------------------------------------------------------- +VectorMagnitude::VectorMagnitude() + : vtkm::filter::FilterField() + , Worklet() +{ + this->SetOutputFieldName("magnitude"); +} + +//----------------------------------------------------------------------------- +VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(VectorMagnitude); +} +} diff --git a/vtkm/filter/VectorMagnitude.h b/vtkm/filter/VectorMagnitude.h index 72d17fc7d..41dc3480b 100644 --- a/vtkm/filter/VectorMagnitude.h +++ b/vtkm/filter/VectorMagnitude.h @@ -11,6 +11,8 @@ #ifndef vtk_m_filter_VectorMagnitude_h #define vtk_m_filter_VectorMagnitude_h +#include + #include #include @@ -19,13 +21,13 @@ namespace vtkm namespace filter { -class VectorMagnitude : public vtkm::filter::FilterField +class VTKM_ALWAYS_EXPORT VectorMagnitude : public vtkm::filter::FilterField { public: //currently the VectorMagnitude filter only works on vector data. using SupportedTypes = vtkm::TypeListTagVecCommon; - VTKM_CONT + VTKM_FILTER_EXPORT VectorMagnitude(); template @@ -37,9 +39,10 @@ public: private: vtkm::worklet::Magnitude Worklet; }; +#ifndef vtkm_filter_VectorMagnitude_cxx +VTKM_FILTER_EXPORT_EXECUTE_METHOD(VectorMagnitude); +#endif } } // namespace vtkm::filter -#include - #endif // vtk_m_filter_VectorMagnitude_h diff --git a/vtkm/filter/VectorMagnitude.hxx b/vtkm/filter/VectorMagnitude.hxx index 43708e86a..996a1b0c1 100644 --- a/vtkm/filter/VectorMagnitude.hxx +++ b/vtkm/filter/VectorMagnitude.hxx @@ -15,14 +15,6 @@ namespace vtkm namespace filter { -//----------------------------------------------------------------------------- -inline VTKM_CONT VectorMagnitude::VectorMagnitude() - : vtkm::filter::FilterField() - , Worklet() -{ - this->SetOutputFieldName("magnitude"); -} - //----------------------------------------------------------------------------- template inline VTKM_CONT vtkm::cont::DataSet VectorMagnitude::DoExecute( diff --git a/vtkm/filter/testing/UnitTestContourFilter.cxx b/vtkm/filter/testing/UnitTestContourFilter.cxx index 5548a3f28..62ec66160 100644 --- a/vtkm/filter/testing/UnitTestContourFilter.cxx +++ b/vtkm/filter/testing/UnitTestContourFilter.cxx @@ -18,6 +18,7 @@ #include #include +#include #include namespace vtkm_ut_mc_filter diff --git a/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx b/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx index 1d842c2c6..8e17e2fb2 100644 --- a/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx +++ b/vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx @@ -244,12 +244,12 @@ void TestWithStructuredData() contour.SetGenerateNormals(true); contour.SetComputeFastNormalsForStructured(true); contour.SetNormalArrayName("normals"); - dataSet = contour.Execute(dataSet, SplitSharpTestPolicy{}); + dataSet = contour.Execute(dataSet); // Compute cell normals: vtkm::filter::CellAverage cellNormals; cellNormals.SetActiveField("normals", vtkm::cont::Field::Association::POINTS); - dataSet = cellNormals.Execute(dataSet, SplitSharpTestPolicy{}); + dataSet = cellNormals.Execute(dataSet); // Split sharp edges: std::cout << dataSet.GetNumberOfCells() << std::endl; diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index 1e6342d9e..3154df84c 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -89,7 +89,7 @@ set(unit_tests vtkm_unit_tests( SOURCES ${unit_tests} - LIBRARIES vtkm_worklet vtkm_source + LIBRARIES vtkm_source vtkm_worklet vtkm_filter ALL_BACKENDS ) if (TARGET vtkm::cuda) diff --git a/vtkm/worklet/testing/UnitTestOrientNormals.cxx b/vtkm/worklet/testing/UnitTestOrientNormals.cxx index 0ab38a96c..1e54f5da3 100644 --- a/vtkm/worklet/testing/UnitTestOrientNormals.cxx +++ b/vtkm/worklet/testing/UnitTestOrientNormals.cxx @@ -73,7 +73,7 @@ vtkm::cont::DataSet CreateDataSet(bool pointNormals, bool cellNormals) contour.SetIsoValue(192); contour.SetMergeDuplicatePoints(true); contour.SetGenerateNormals(false); - dataSet = contour.Execute(dataSet, TestPolicy{}); + dataSet = contour.Execute(dataSet); vtkm::filter::SurfaceNormals normals; normals.SetGeneratePointNormals(pointNormals);