From 455c20437354f63a88f69688bbf1c063dfb1cb1a Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Tue, 1 Feb 2022 11:51:01 -0700 Subject: [PATCH 1/5] Migrate field_transform --- benchmarking/BenchmarkFilters.cxx | 8 +- vtkm/filter/CMakeLists.txt | 18 +- vtkm/filter/CoordinateSystemTransform.h | 67 ++---- vtkm/filter/CoordinateSystemTransform.hxx | 75 ------- vtkm/filter/FieldToColors.h | 86 ++------ vtkm/filter/PointElevation.h | 53 ++--- vtkm/filter/PointElevation.hxx | 64 ------ vtkm/filter/PointTransform.h | 77 ++----- vtkm/filter/PointTransform.hxx | 142 ------------ vtkm/filter/WarpScalar.h | 101 ++------- vtkm/filter/WarpScalar.hxx | 55 ----- vtkm/filter/WarpVector.h | 73 ++----- vtkm/filter/WarpVector.hxx | 50 ----- vtkm/filter/field_transform/CMakeLists.txt | 23 +- .../CoordinateSystemTransform.cxx | 75 +++++++ .../CoordinateSystemTransform.h | 55 +++++ .../FieldToColors.cxx} | 167 +++++++------- vtkm/filter/field_transform/FieldToColors.h | 91 ++++++++ .../filter/field_transform/PointElevation.cxx | 46 ++++ vtkm/filter/field_transform/PointElevation.h | 60 ++++++ .../filter/field_transform/PointTransform.cxx | 67 ++++++ vtkm/filter/field_transform/PointTransform.h | 110 ++++++++++ vtkm/filter/field_transform/WarpScalar.cxx | 83 +++++++ vtkm/filter/field_transform/WarpScalar.h | 92 ++++++++ vtkm/filter/field_transform/WarpVector.cxx | 70 ++++++ vtkm/filter/field_transform/WarpVector.h | 67 ++++++ .../field_transform/testing/CMakeLists.txt | 20 +- .../testing/RenderTestPointTransform.cxx | 4 +- .../UnitTestCoordinateSystemTransform.cxx | 6 +- .../testing/UnitTestFieldToColors.cxx | 4 +- .../testing/UnitTestPointElevationFilter.cxx | 14 +- .../testing/UnitTestPointTransform.cxx | 8 +- .../testing/UnitTestWarpScalarFilter.cxx | 11 +- .../testing/UnitTestWarpVectorFilter.cxx | 9 +- .../field_transform/worklet/CMakeLists.txt | 19 ++ .../worklet/CoordinateSystemTransform.h | 20 +- .../field_transform}/worklet/PointElevation.h | 30 +-- .../field_transform/worklet/PointTransform.h | 49 +++++ .../field_transform}/worklet/WarpScalar.h | 0 .../field_transform}/worklet/WarpVector.h | 0 vtkm/filter/testing/CMakeLists.txt | 7 - vtkm/worklet/CMakeLists.txt | 5 - vtkm/worklet/PointTransform.h | 89 -------- vtkm/worklet/testing/CMakeLists.txt | 5 - .../UnitTestCoordinateSystemTransform.cxx | 203 ------------------ .../testing/UnitTestPointElevation.cxx | 94 -------- .../testing/UnitTestPointTransform.cxx | 187 ---------------- vtkm/worklet/testing/UnitTestWarpScalar.cxx | 95 -------- vtkm/worklet/testing/UnitTestWarpVector.cxx | 99 --------- 49 files changed, 1160 insertions(+), 1693 deletions(-) delete mode 100644 vtkm/filter/CoordinateSystemTransform.hxx delete mode 100644 vtkm/filter/PointElevation.hxx delete mode 100644 vtkm/filter/PointTransform.hxx delete mode 100644 vtkm/filter/WarpScalar.hxx delete mode 100644 vtkm/filter/WarpVector.hxx create mode 100644 vtkm/filter/field_transform/CoordinateSystemTransform.cxx create mode 100644 vtkm/filter/field_transform/CoordinateSystemTransform.h rename vtkm/filter/{FieldToColors.hxx => field_transform/FieldToColors.cxx} (60%) create mode 100644 vtkm/filter/field_transform/FieldToColors.h create mode 100644 vtkm/filter/field_transform/PointElevation.cxx create mode 100644 vtkm/filter/field_transform/PointElevation.h create mode 100644 vtkm/filter/field_transform/PointTransform.cxx create mode 100644 vtkm/filter/field_transform/PointTransform.h create mode 100644 vtkm/filter/field_transform/WarpScalar.cxx create mode 100644 vtkm/filter/field_transform/WarpScalar.h create mode 100644 vtkm/filter/field_transform/WarpVector.cxx create mode 100644 vtkm/filter/field_transform/WarpVector.h rename vtkm/filter/{ => field_transform}/testing/RenderTestPointTransform.cxx (94%) rename vtkm/filter/{ => field_transform}/testing/UnitTestCoordinateSystemTransform.cxx (96%) rename vtkm/filter/{ => field_transform}/testing/UnitTestFieldToColors.cxx (96%) rename vtkm/filter/{ => field_transform}/testing/UnitTestPointElevationFilter.cxx (92%) rename vtkm/filter/{ => field_transform}/testing/UnitTestPointTransform.cxx (96%) rename vtkm/filter/{ => field_transform}/testing/UnitTestWarpScalarFilter.cxx (93%) rename vtkm/filter/{ => field_transform}/testing/UnitTestWarpVectorFilter.cxx (92%) create mode 100644 vtkm/filter/field_transform/worklet/CMakeLists.txt rename vtkm/{ => filter/field_transform}/worklet/CoordinateSystemTransform.h (90%) rename vtkm/{ => filter/field_transform}/worklet/PointElevation.h (78%) create mode 100644 vtkm/filter/field_transform/worklet/PointTransform.h rename vtkm/{ => filter/field_transform}/worklet/WarpScalar.h (100%) rename vtkm/{ => filter/field_transform}/worklet/WarpVector.h (100%) delete mode 100644 vtkm/worklet/PointTransform.h delete mode 100644 vtkm/worklet/testing/UnitTestCoordinateSystemTransform.cxx delete mode 100644 vtkm/worklet/testing/UnitTestPointElevation.cxx delete mode 100644 vtkm/worklet/testing/UnitTestPointTransform.cxx delete mode 100644 vtkm/worklet/testing/UnitTestWarpScalar.cxx delete mode 100644 vtkm/worklet/testing/UnitTestWarpVector.cxx diff --git a/benchmarking/BenchmarkFilters.cxx b/benchmarking/BenchmarkFilters.cxx index 824de1e3a..28a567e0a 100644 --- a/benchmarking/BenchmarkFilters.cxx +++ b/benchmarking/BenchmarkFilters.cxx @@ -33,14 +33,14 @@ #include #include #include -#include -#include #include #include #include #include #include #include +#include +#include #include #include @@ -295,7 +295,7 @@ void BenchWarpScalar(::benchmark::State& state) { const vtkm::cont::DeviceAdapterId device = Config.Device; - vtkm::filter::WarpScalar filter{ 2. }; + vtkm::filter::field_transform::WarpScalar filter{ 2. }; filter.SetUseCoordinateSystemAsField(true); filter.SetNormalField(PointVectorsName, vtkm::cont::Field::Association::POINTS); filter.SetScalarFactorField(PointScalarsName, vtkm::cont::Field::Association::POINTS); @@ -318,7 +318,7 @@ void BenchWarpVector(::benchmark::State& state) { const vtkm::cont::DeviceAdapterId device = Config.Device; - vtkm::filter::WarpVector filter{ 2. }; + vtkm::filter::field_transform::WarpVector filter{ 2. }; filter.SetUseCoordinateSystemAsField(true); filter.SetVectorField(PointVectorsName, vtkm::cont::Field::Association::POINTS); diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index df68b5889..390910347 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -15,6 +15,7 @@ set(deprecated_headers ClipWithField.h ClipWithImplicitFunction.h Contour.h + CoordinateSystemTransform.h CrossProduct.h DotProduct.h Entropy.h @@ -22,6 +23,7 @@ set(deprecated_headers ExtractGeometry.h ExtractPoints.h ExtractStructured.h + FieldToColors.h GenerateIds.h GhostCellRemove.h Gradient.h @@ -34,11 +36,15 @@ set(deprecated_headers ParticleDensityCloudInCell.h ParticleDensityNearestGridPoint.h PointAverage.h + PointElevation.h + PointTransform.h Slice.h SurfaceNormal.h Threshold.h ThresholdPoints.h VectorMagnitude.h + WarpScalar.h + WarpVector.h ) vtkm_declare_headers(${deprecated_headers}) @@ -80,10 +86,8 @@ set(extra_headers ContourTreeUniformAugmented.h ContourTreeUniformDistributed.h ContourTreeUniform.h - CoordinateSystemTransform.h CreateResult.h FieldSelection.h - FieldToColors.h GhostCellClassify.h ImageDifference.h ImageMedian.h @@ -94,8 +98,6 @@ set(extra_headers ParticleAdvection.h Pathline.h PathParticle.h - PointElevation.h - PointTransform.h Probe.h SplitSharpEdges.h Streamline.h @@ -104,8 +106,6 @@ set(extra_headers Triangulate.h Tube.h VertexClustering.h - WarpScalar.h - WarpVector.h ZFPCompressor1D.h ZFPCompressor2D.h ZFPCompressor3D.h @@ -120,8 +120,6 @@ set(extra_header_template_sources ContourTreeUniformAugmented.hxx ContourTreeUniformDistributed.hxx ContourTreeUniform.hxx - CoordinateSystemTransform.hxx - FieldToColors.hxx GhostCellClassify.hxx ImageDifference.hxx ImageMedian.hxx @@ -132,8 +130,6 @@ set(extra_header_template_sources ParticleAdvection.hxx Pathline.hxx PathParticle.hxx - PointElevation.hxx - PointTransform.hxx Probe.hxx SplitSharpEdges.hxx Streamline.hxx @@ -142,8 +138,6 @@ set(extra_header_template_sources Triangulate.hxx Tube.hxx VertexClustering.hxx - WarpScalar.hxx - WarpVector.hxx ZFPCompressor1D.hxx ZFPCompressor2D.hxx ZFPCompressor3D.hxx diff --git a/vtkm/filter/CoordinateSystemTransform.h b/vtkm/filter/CoordinateSystemTransform.h index 2ad7730f9..aeb6de21c 100644 --- a/vtkm/filter/CoordinateSystemTransform.h +++ b/vtkm/filter/CoordinateSystemTransform.h @@ -7,65 +7,34 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ +#ifndef vtk_m_filter_CoordinateSystemTransform_h +#define vtk_m_filter_CoordinateSystemTransform_h -#ifndef vtk_m_filter_CoordianteSystemTransform_h -#define vtk_m_filter_CoordianteSystemTransform_h - -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief -/// -/// Generate a coordinate transformation on coordiantes from a dataset. -class CylindricalCoordinateTransform - : public vtkm::filter::FilterField + +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/field_transform/CoordinateSystemTransform.h instead of " + "vtkm/filter/CoordinateSystemTransform.h.") +inline void CoordinateSystemTransform_deprecated() {} + +inline void CoordinateSystemTransform_deprecated_warning() { -public: - using SupportedTypes = vtkm::TypeListFieldVec3; + CoordinateSystemTransform_deprecated(); +} - VTKM_CONT - CylindricalCoordinateTransform() = default; - - VTKM_CONT void SetCartesianToCylindrical() { Worklet.SetCartesianToCylindrical(); } - VTKM_CONT void SetCylindricalToCartesian() { Worklet.SetCylindricalToCartesian(); } - - 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); - -private: - vtkm::worklet::CylindricalCoordinateTransform Worklet; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::field_transform::CoordinateSystemTransform.") + CoordinateSystemTransform : public vtkm::filter::field_transform::CoordinateSystemTransform +{ + using field_transform::CoordinateSystemTransform::CoordinateSystemTransform; }; -class SphericalCoordinateTransform : public vtkm::filter::FilterField -{ -public: - using SupportedTypes = vtkm::TypeListFieldVec3; - - VTKM_CONT - SphericalCoordinateTransform() = default; - - VTKM_CONT void SetCartesianToSpherical() { Worklet.SetCartesianToSpherical(); } - VTKM_CONT void SetSphericalToCartesian() { Worklet.SetSphericalToCartesian(); } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, - const vtkm::filter::FieldMetadata&, - const vtkm::filter::PolicyBase& policy); - -private: - vtkm::worklet::SphericalCoordinateTransform Worklet; -}; } } // namespace vtkm::filter -#include - -#endif // vtk_m_filter_CoordianteSystemTransform_h +#endif //vtk_m_filter_CoordinateSystemTransform_h diff --git a/vtkm/filter/CoordinateSystemTransform.hxx b/vtkm/filter/CoordinateSystemTransform.hxx deleted file mode 100644 index 5f161369f..000000000 --- a/vtkm/filter/CoordinateSystemTransform.hxx +++ /dev/null @@ -1,75 +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_CoordianteSystemTransform_hxx -#define vtk_m_filter_CoordianteSystemTransform_hxx - -namespace vtkm -{ -namespace filter -{ - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet CylindricalCoordinateTransform::DoExecute( - const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& vtkmNotUsed(fieldMetadata), - const vtkm::filter::PolicyBase&) -{ - vtkm::cont::ArrayHandle outArray; - vtkm::cont::DataSet outDataSet; - - this->Worklet.Run(field, outArray); - - // We first add the result coords to keep them at the first position - // of the resulting dataset. - outDataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", outArray)); - - for (int i = 0; i < inDataSet.GetNumberOfCoordinateSystems(); i++) - { - outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(i)); - } - - outDataSet.SetCellSet(inDataSet.GetCellSet()); - - return outDataSet; -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet SphericalCoordinateTransform::DoExecute( - const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& vtkmNotUsed(fieldMetadata), - const vtkm::filter::PolicyBase&) -{ - vtkm::cont::ArrayHandle outArray; - vtkm::cont::DataSet outDataSet; - - this->Worklet.Run(field, outArray); - - // We first add the result coords to keep them at the first position - // of the resulting dataset. - outDataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", outArray)); - - for (int i = 0; i < inDataSet.GetNumberOfCoordinateSystems(); i++) - { - outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(i)); - } - - outDataSet.SetCellSet(inDataSet.GetCellSet()); - - return outDataSet; -} -} -} // namespace vtkm::filter - -#endif diff --git a/vtkm/filter/FieldToColors.h b/vtkm/filter/FieldToColors.h index d8bdc574e..7d8f7fd31 100644 --- a/vtkm/filter/FieldToColors.h +++ b/vtkm/filter/FieldToColors.h @@ -7,88 +7,34 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_FieldToColors_h #define vtk_m_filter_FieldToColors_h -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Convert an arbitrary field to an RGB or RGBA field -/// -class FieldToColors : public vtkm::filter::FilterField +VTKM_DEPRECATED( + 1.8, + "Use vtkm/filter/field_transform/FieldToColors.h instead of vtkm/filter/FieldToColors.h.") +inline void FieldToColors_deprecated() {} + +inline void FieldToColors_deprecated_warning() { -public: - VTKM_CONT - FieldToColors(const vtkm::cont::ColorTable& table = vtkm::cont::ColorTable()); + FieldToColors_deprecated(); +} - enum FieldToColorsInputMode - { - SCALAR, - MAGNITUDE, - COMPONENT - }; - - enum FieldToColorsOutputMode - { - RGB, - RGBA - }; - - void SetColorTable(const vtkm::cont::ColorTable& table) - { - this->Table = table; - this->ModifiedCount = -1; - } - const vtkm::cont::ColorTable& GetColorTable() const { return this->Table; } - - void SetMappingMode(FieldToColorsInputMode mode) { this->InputMode = mode; } - void SetMappingToScalar() { this->InputMode = FieldToColorsInputMode::SCALAR; } - void SetMappingToMagnitude() { this->InputMode = FieldToColorsInputMode::MAGNITUDE; } - void SetMappingToComponent() { this->InputMode = FieldToColorsInputMode::COMPONENT; } - FieldToColorsInputMode GetMappingMode() const { return this->InputMode; } - bool IsMappingScalar() const { return this->InputMode == FieldToColorsInputMode::SCALAR; } - bool IsMappingMagnitude() const { return this->InputMode == FieldToColorsInputMode::MAGNITUDE; } - bool IsMappingComponent() const { return this->InputMode == FieldToColorsInputMode::COMPONENT; } - - void SetMappingComponent(vtkm::IdComponent comp) { this->Component = comp; } - vtkm::IdComponent GetMappingComponent() const { return this->Component; } - - void SetOutputMode(FieldToColorsOutputMode mode) { this->OutputMode = mode; } - void SetOutputToRGB() { this->OutputMode = FieldToColorsOutputMode::RGB; } - void SetOutputToRGBA() { this->OutputMode = FieldToColorsOutputMode::RGBA; } - FieldToColorsOutputMode GetOutputMode() const { return this->OutputMode; } - bool IsOutputRGB() const { return this->OutputMode == FieldToColorsOutputMode::RGB; } - bool IsOutputRGBA() const { return this->OutputMode == FieldToColorsOutputMode::RGBA; } - - - void SetNumberOfSamplingPoints(vtkm::Int32 count); - vtkm::Int32 GetNumberOfSamplingPoints() const { return this->SampleCount; } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); - -private: - vtkm::cont::ColorTable Table; - FieldToColorsInputMode InputMode; - FieldToColorsOutputMode OutputMode; - vtkm::cont::ColorTableSamplesRGB SamplesRGB; - vtkm::cont::ColorTableSamplesRGBA SamplesRGBA; - vtkm::IdComponent Component; - vtkm::Int32 SampleCount; - vtkm::Id ModifiedCount; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::field_transform::FieldToColors.") FieldToColors + : public vtkm::filter::field_transform::FieldToColors +{ + using field_transform::FieldToColors::FieldToColors; }; + } } // namespace vtkm::filter -#include - -#endif // vtk_m_filter_FieldToColors_h +#endif //vtk_m_filter_FieldToColors_h diff --git a/vtkm/filter/PointElevation.h b/vtkm/filter/PointElevation.h index cc919ff2b..e0573d60f 100644 --- a/vtkm/filter/PointElevation.h +++ b/vtkm/filter/PointElevation.h @@ -7,53 +7,34 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_PointElevation_h #define vtk_m_filter_PointElevation_h -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief generate a scalar field along a specified direction -/// -/// Generate scalar field from a dataset. -/// The scalar field values lie within a user specified range, and -/// are generated by computing a projection of each dataset point onto -/// a line. The line can be oriented arbitrarily. A typical example is -/// to generate scalars based on elevation or height above a plane. -class PointElevation : public vtkm::filter::FilterField + +VTKM_DEPRECATED( + 1.8, + "Use vtkm/filter/field_transform/PointElevation.h instead of vtkm/filter/PointElevation.h.") +inline void PointElevation_deprecated() {} + +inline void PointElevation_deprecated_warning() { -public: - using SupportedTypes = vtkm::TypeListFieldVec3; + PointElevation_deprecated(); +} - VTKM_CONT - PointElevation(); - - VTKM_CONT - void SetLowPoint(vtkm::Float64 x, vtkm::Float64 y, vtkm::Float64 z); - - VTKM_CONT - void SetHighPoint(vtkm::Float64 x, vtkm::Float64 y, vtkm::Float64 z); - - VTKM_CONT - void SetRange(vtkm::Float64 low, vtkm::Float64 high); - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); - -private: - vtkm::worklet::PointElevation Worklet; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::field_transform::PointElevation.") PointElevation + : public vtkm::filter::field_transform::PointElevation +{ + using field_transform::PointElevation::PointElevation; }; + } } // namespace vtkm::filter -#include - -#endif // vtk_m_filter_PointElevation_h +#endif //vtk_m_filter_PointElevation_h diff --git a/vtkm/filter/PointElevation.hxx b/vtkm/filter/PointElevation.hxx deleted file mode 100644 index a0b76ac92..000000000 --- a/vtkm/filter/PointElevation.hxx +++ /dev/null @@ -1,64 +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_PointElevation_hxx -#define vtk_m_filter_PointElevation_hxx - -namespace vtkm -{ -namespace filter -{ - -//----------------------------------------------------------------------------- -inline VTKM_CONT PointElevation::PointElevation() - : Worklet() -{ - this->SetOutputFieldName("elevation"); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointElevation::SetLowPoint(vtkm::Float64 x, vtkm::Float64 y, vtkm::Float64 z) -{ - this->Worklet.SetLowPoint(vtkm::make_Vec(x, y, z)); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointElevation::SetHighPoint(vtkm::Float64 x, - vtkm::Float64 y, - vtkm::Float64 z) -{ - this->Worklet.SetHighPoint(vtkm::make_Vec(x, y, z)); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointElevation::SetRange(vtkm::Float64 low, vtkm::Float64 high) -{ - this->Worklet.SetRange(low, high); -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute( - const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMetadata, - vtkm::filter::PolicyBase) -{ - vtkm::cont::ArrayHandle outArray; - - //todo, we need to use the policy to determine the valid conversions - //that the dispatcher should do - this->Invoke(this->Worklet, field, outArray); - - return CreateResult(inDataSet, outArray, this->GetOutputFieldName(), fieldMetadata); -} -} -} // namespace vtkm::filter -#endif diff --git a/vtkm/filter/PointTransform.h b/vtkm/filter/PointTransform.h index 9c4940fae..e7c48eb4d 100644 --- a/vtkm/filter/PointTransform.h +++ b/vtkm/filter/PointTransform.h @@ -7,77 +7,34 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_PointTransform_h #define vtk_m_filter_PointTransform_h -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief -/// -/// Generate scalar field from a dataset. -class PointTransform : public vtkm::filter::FilterField + +VTKM_DEPRECATED( + 1.8, + "Use vtkm/filter/field_transform/PointTransform.h instead of vtkm/filter/PointTransform.h.") +inline void PointTransform_deprecated() {} + +inline void PointTransform_deprecated_warning() { -public: - using SupportedTypes = vtkm::TypeListFieldVec3; + PointTransform_deprecated(); +} - VTKM_CONT - PointTransform(); - - void SetTranslation(const vtkm::FloatDefault& tx, - const vtkm::FloatDefault& ty, - const vtkm::FloatDefault& tz); - - void SetTranslation(const vtkm::Vec3f& v); - - void SetRotation(const vtkm::FloatDefault& angleDegrees, const vtkm::Vec3f& axis); - - void SetRotation(const vtkm::FloatDefault& angleDegrees, - const vtkm::FloatDefault& rx, - const vtkm::FloatDefault& ry, - const vtkm::FloatDefault& rz); - - void SetRotationX(const vtkm::FloatDefault& angleDegrees); - - void SetRotationY(const vtkm::FloatDefault& angleDegrees); - - void SetRotationZ(const vtkm::FloatDefault& angleDegrees); - - void SetScale(const vtkm::FloatDefault& s); - - void SetScale(const vtkm::FloatDefault& sx, - const vtkm::FloatDefault& sy, - const vtkm::FloatDefault& sz); - - void SetScale(const vtkm::Vec3f& v); - - void SetTransform(const vtkm::Matrix& mtx); - - void SetChangeCoordinateSystem(bool flag); - bool GetChangeCoordinateSystem() const; - - - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); - -private: - vtkm::worklet::PointTransform Worklet; - bool ChangeCoordinateSystem; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::field_transform::PointTransform.") PointTransform + : public vtkm::filter::field_transform::PointTransform +{ + using field_transform::PointTransform::PointTransform; }; + } } // namespace vtkm::filter -#ifndef vtk_m_filter_PointTransform_hxx -#include -#endif - -#endif // vtk_m_filter_PointTransform_h +#endif //vtk_m_filter_PointTransform_h diff --git a/vtkm/filter/PointTransform.hxx b/vtkm/filter/PointTransform.hxx deleted file mode 100644 index cf36d2611..000000000 --- a/vtkm/filter/PointTransform.hxx +++ /dev/null @@ -1,142 +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_PointTransform_hxx -#define vtk_m_filter_PointTransform_hxx -#include - -namespace vtkm -{ -namespace filter -{ - -//----------------------------------------------------------------------------- -inline VTKM_CONT PointTransform::PointTransform() - : Worklet() - , ChangeCoordinateSystem(true) -{ - this->SetOutputFieldName("transform"); - this->SetUseCoordinateSystemAsField(true); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetTranslation(const vtkm::FloatDefault& tx, - const vtkm::FloatDefault& ty, - const vtkm::FloatDefault& tz) -{ - this->Worklet.SetTranslation(tx, ty, tz); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetTranslation(const vtkm::Vec3f& v) -{ - this->Worklet.SetTranslation(v); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetRotation(const vtkm::FloatDefault& angleDegrees, - const vtkm::Vec3f& axis) -{ - this->Worklet.SetRotation(angleDegrees, axis); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetRotation(const vtkm::FloatDefault& angleDegrees, - const vtkm::FloatDefault& rx, - const vtkm::FloatDefault& ry, - const vtkm::FloatDefault& rz) -{ - this->Worklet.SetRotation(angleDegrees, rx, ry, rz); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetRotationX(const vtkm::FloatDefault& angleDegrees) -{ - this->Worklet.SetRotationX(angleDegrees); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetRotationY(const vtkm::FloatDefault& angleDegrees) -{ - this->Worklet.SetRotationY(angleDegrees); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetRotationZ(const vtkm::FloatDefault& angleDegrees) -{ - this->Worklet.SetRotationZ(angleDegrees); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetScale(const vtkm::FloatDefault& s) -{ - this->Worklet.SetScale(s); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetScale(const vtkm::FloatDefault& sx, - const vtkm::FloatDefault& sy, - const vtkm::FloatDefault& sz) -{ - this->Worklet.SetScale(sx, sy, sz); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetScale(const vtkm::Vec3f& v) -{ - this->Worklet.SetScale(v); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetTransform( - const vtkm::Matrix& mtx) -{ - this->Worklet.SetTransform(mtx); -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT void PointTransform::SetChangeCoordinateSystem(bool flag) -{ - this->ChangeCoordinateSystem = flag; -} - -//----------------------------------------------------------------------------- -inline VTKM_CONT bool PointTransform::GetChangeCoordinateSystem() const -{ - return this->ChangeCoordinateSystem; -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet PointTransform::DoExecute( - const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMetadata, - vtkm::filter::PolicyBase) -{ - vtkm::cont::ArrayHandle outArray; - this->Invoke(this->Worklet, field, outArray); - - vtkm::cont::DataSet outData = - CreateResult(inDataSet, outArray, this->GetOutputFieldName(), fieldMetadata); - - if (this->GetChangeCoordinateSystem()) - { - vtkm::Id coordIndex = - this->GetUseCoordinateSystemAsField() ? this->GetActiveCoordinateSystemIndex() : 0; - outData.GetCoordinateSystem(coordIndex).SetData(outArray); - } - - return outData; -} -} -} // namespace vtkm::filter - -#endif //vtk_m_filter_PointTransform_hxx diff --git a/vtkm/filter/WarpScalar.h b/vtkm/filter/WarpScalar.h index fe8975e13..9e3939c9a 100644 --- a/vtkm/filter/WarpScalar.h +++ b/vtkm/filter/WarpScalar.h @@ -7,100 +7,33 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_WarpScalar_h #define vtk_m_filter_WarpScalar_h -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Modify points by moving points along point normals by the scalar -/// amount times the scalar factor. -/// -/// A filter that modifies point coordinates by moving points along point normals -/// by the scalar amount times the scalar factor. -/// It's a VTK-m version of the vtkWarpScalar in VTK. -/// Useful for creating carpet or x-y-z plots. -/// It doesn't modify the point coordinates, but creates a new point coordinates that have been warped. -class WarpScalar : public vtkm::filter::FilterField + +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/field_transform/WarpScalar.h instead of vtkm/filter/WarpScalar.h.") +inline void WarpScalar_deprecated() {} + +inline void WarpScalar_deprecated_warning() { -public: - // WarpScalar can only applies to Float and Double Vec3 arrays - using SupportedTypes = vtkm::TypeListFieldVec3; + WarpScalar_deprecated(); +} - // WarpScalar often operates on a constant normal value - using AdditionalFieldStorage = - vtkm::List::StorageTag, - vtkm::cont::ArrayHandleConstant::StorageTag>; - - VTKM_CONT - WarpScalar(vtkm::FloatDefault scaleAmount); - - //@{ - /// Choose the secondary field to operate on. In the warp op A + B * - /// scaleAmount * scalarFactor, B is the secondary field - VTKM_CONT - void SetNormalField( - const std::string& name, - vtkm::cont::Field::Association association = vtkm::cont::Field::Association::ANY) - { - this->NormalFieldName = name; - this->NormalFieldAssociation = association; - } - - VTKM_CONT const std::string& GetNormalFieldName() const { return this->NormalFieldName; } - - VTKM_CONT vtkm::cont::Field::Association GetNormalFieldAssociation() const - { - return this->NormalFieldAssociation; - } - //@} - - //@{ - /// Choose the scalar factor field to operate on. In the warp op A + B * - /// scaleAmount * scalarFactor, scalarFactor is the scalar factor field. - VTKM_CONT - void SetScalarFactorField( - const std::string& name, - vtkm::cont::Field::Association association = vtkm::cont::Field::Association::ANY) - { - this->ScalarFactorFieldName = name; - this->ScalarFactorFieldAssociation = association; - } - - VTKM_CONT const std::string& GetScalarFactorFieldName() const - { - return this->ScalarFactorFieldName; - } - - VTKM_CONT vtkm::cont::Field::Association GetScalarFactorFieldAssociation() const - { - return this->ScalarFactorFieldAssociation; - } - //@} - - template - VTKM_CONT vtkm::cont::DataSet DoExecute( - const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle, StorageType>& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); - -private: - vtkm::worklet::WarpScalar Worklet; - std::string NormalFieldName; - vtkm::cont::Field::Association NormalFieldAssociation; - std::string ScalarFactorFieldName; - vtkm::cont::Field::Association ScalarFactorFieldAssociation; - vtkm::FloatDefault ScaleAmount; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::field_transform::WarpScalar.") WarpScalar + : public vtkm::filter::field_transform::WarpScalar +{ + using field_transform::WarpScalar::WarpScalar; }; -} -} -#include +} +} // namespace vtkm::filter -#endif // vtk_m_filter_WarpScalar_h +#endif //vtk_m_filter_WarpScalar_h diff --git a/vtkm/filter/WarpScalar.hxx b/vtkm/filter/WarpScalar.hxx deleted file mode 100644 index 4993a0416..000000000 --- a/vtkm/filter/WarpScalar.hxx +++ /dev/null @@ -1,55 +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_WarpScalar_hxx -#define vtk_m_filter_WarpScalar_hxx - -namespace vtkm -{ -namespace filter -{ - -//----------------------------------------------------------------------------- -inline VTKM_CONT WarpScalar::WarpScalar(vtkm::FloatDefault scaleAmount) - : vtkm::filter::FilterField() - , Worklet() - , NormalFieldName("normal") - , NormalFieldAssociation(vtkm::cont::Field::Association::ANY) - , ScalarFactorFieldName("scalarfactor") - , ScalarFactorFieldAssociation(vtkm::cont::Field::Association::ANY) - , ScaleAmount(scaleAmount) -{ - this->SetOutputFieldName("warpscalar"); -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet WarpScalar::DoExecute( - const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle, StorageType>& field, - const vtkm::filter::FieldMetadata& fieldMetadata, - vtkm::filter::PolicyBase policy) -{ - using vecType = vtkm::Vec; - vtkm::cont::Field normalF = - inDataSet.GetField(this->NormalFieldName, this->NormalFieldAssociation); - vtkm::cont::Field sfF = - inDataSet.GetField(this->ScalarFactorFieldName, this->ScalarFactorFieldAssociation); - vtkm::cont::ArrayHandle result; - this->Worklet.Run(field, - vtkm::filter::ApplyPolicyFieldOfType(normalF, policy, *this), - vtkm::filter::ApplyPolicyFieldOfType(sfF, policy, *this), - this->ScaleAmount, - result); - - return CreateResult(inDataSet, result, this->GetOutputFieldName(), fieldMetadata); -} -} -} -#endif diff --git a/vtkm/filter/WarpVector.h b/vtkm/filter/WarpVector.h index dc49fae5c..f893a3c30 100644 --- a/vtkm/filter/WarpVector.h +++ b/vtkm/filter/WarpVector.h @@ -7,72 +7,33 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_WarpVector_h #define vtk_m_filter_WarpVector_h -#include -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Modify points by moving points along a vector multiplied by -/// the scale factor -/// -/// A filter that modifies point coordinates by moving points along a vector -/// multiplied by a scale factor. It's a VTK-m version of the vtkWarpVector in VTK. -/// Useful for showing flow profiles or mechanical deformation. -/// This worklet does not modify the input points but generate new point -/// coordinate instance that has been warped. -class WarpVector : public vtkm::filter::FilterField + +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/field_transform/WarpVector.h instead of vtkm/filter/WarpVector.h.") +inline void WarpVector_deprecated() {} + +inline void WarpVector_deprecated_warning() { -public: - using SupportedTypes = vtkm::TypeListFieldVec3; - using AdditionalFieldStorage = - vtkm::List::StorageTag, - vtkm::cont::ArrayHandleConstant::StorageTag>; + WarpVector_deprecated(); +} - VTKM_CONT - WarpVector(vtkm::FloatDefault scale); - - //@{ - /// Choose the vector field to operate on. In the warp op A + B *scale, B is - /// the vector field - VTKM_CONT - void SetVectorField( - const std::string& name, - vtkm::cont::Field::Association association = vtkm::cont::Field::Association::ANY) - { - this->VectorFieldName = name; - this->VectorFieldAssociation = association; - } - - VTKM_CONT const std::string& GetVectorFieldName() const { return this->VectorFieldName; } - - VTKM_CONT vtkm::cont::Field::Association GetVectorFieldAssociation() const - { - return this->VectorFieldAssociation; - } - //@} - - template - VTKM_CONT vtkm::cont::DataSet DoExecute( - const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle, StorageType>& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); - -private: - vtkm::worklet::WarpVector Worklet; - std::string VectorFieldName; - vtkm::cont::Field::Association VectorFieldAssociation; - vtkm::FloatDefault Scale; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::field_transform::WarpVector.") WarpVector + : public vtkm::filter::field_transform::WarpVector +{ + using field_transform::WarpVector::WarpVector; }; -} -} -#include +} +} // namespace vtkm::filter -#endif // vtk_m_filter_WarpVector_h +#endif //vtk_m_filter_WarpVector_h diff --git a/vtkm/filter/WarpVector.hxx b/vtkm/filter/WarpVector.hxx deleted file mode 100644 index 8d0ffb6df..000000000 --- a/vtkm/filter/WarpVector.hxx +++ /dev/null @@ -1,50 +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_WarpVector_hxx -#define vtk_m_filter_WarpVector_hxx - -namespace vtkm -{ -namespace filter -{ - -//----------------------------------------------------------------------------- -inline VTKM_CONT WarpVector::WarpVector(vtkm::FloatDefault scale) - : vtkm::filter::FilterField() - , Worklet() - , VectorFieldName("normal") - , VectorFieldAssociation(vtkm::cont::Field::Association::ANY) - , Scale(scale) -{ - this->SetOutputFieldName("warpvector"); -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet WarpVector::DoExecute( - const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle, StorageType>& field, - const vtkm::filter::FieldMetadata& fieldMetadata, - vtkm::filter::PolicyBase policy) -{ - using vecType = vtkm::Vec; - vtkm::cont::Field vectorF = - inDataSet.GetField(this->VectorFieldName, this->VectorFieldAssociation); - vtkm::cont::ArrayHandle result; - this->Worklet.Run(field, - vtkm::filter::ApplyPolicyFieldOfType(vectorF, policy, *this), - this->Scale, - result); - - return CreateResult(inDataSet, result, this->GetOutputFieldName(), fieldMetadata); -} -} -} -#endif diff --git a/vtkm/filter/field_transform/CMakeLists.txt b/vtkm/filter/field_transform/CMakeLists.txt index 58a39d054..ac28fd16c 100644 --- a/vtkm/filter/field_transform/CMakeLists.txt +++ b/vtkm/filter/field_transform/CMakeLists.txt @@ -8,20 +8,37 @@ ## PURPOSE. See the above copyright notice for more information. ##============================================================================ set(field_transform_headers - GenerateIds.h) + CoordinateSystemTransform.h + FieldToColors.h + GenerateIds.h + PointElevation.h + PointTransform.h + WarpScalar.h + WarpVector.h + ) + set(field_transform_sources - GenerateIds.cxx) + CoordinateSystemTransform.cxx + FieldToColors.cxx + GenerateIds.cxx + PointElevation.cxx + PointTransform.cxx + WarpScalar.cxx + WarpVector.cxx + ) vtkm_library( NAME vtkm_filter_field_transform HEADERS ${field_transform_headers} - SOURCES ${field_transform_sources} + DEVICE_SOURCES ${field_transform_sources} USE_VTKM_JOB_POOL ) target_link_libraries(vtkm_filter_field_transform PUBLIC vtkm_worklet vtkm_filter_core) target_link_libraries(vtkm_filter PUBLIC INTERFACE vtkm_filter_field_transform) +add_subdirectory(worklet) + #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - if (VTKm_ENABLE_TESTING) add_subdirectory(testing) diff --git a/vtkm/filter/field_transform/CoordinateSystemTransform.cxx b/vtkm/filter/field_transform/CoordinateSystemTransform.cxx new file mode 100644 index 000000000..294d6f3da --- /dev/null +++ b/vtkm/filter/field_transform/CoordinateSystemTransform.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. +//============================================================================ + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +//----------------------------------------------------------------------------- +vtkm::cont::DataSet CylindricalCoordinateTransform::DoExecute(const vtkm::cont::DataSet& inDataSet) +{ + auto field = this->GetFieldFromDataSet(inDataSet); + + vtkm::cont::UnknownArrayHandle outArray; + + auto resolveType = [&](const auto& concrete) { + // use std::decay to remove const ref from the decltype of concrete. + using T = typename std::decay_t::ValueType; + vtkm::cont::ArrayHandle result; + vtkm::worklet::CylindricalCoordinateTransform Worklet{ this->cartesianToCylindrical }; + Worklet.Run(concrete, result); + outArray = result; + }; + this->CastAndCallVecField<3>(field, resolveType); + + vtkm::cont::DataSet outDataSet = + this->CreateResult(inDataSet, + inDataSet.GetCellSet(), + vtkm::cont::CoordinateSystem("coordinates", outArray), + [](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) { + out.AddField(fieldToPass); + }); + return outDataSet; +} + +//----------------------------------------------------------------------------- +vtkm::cont::DataSet SphericalCoordinateTransform::DoExecute(const vtkm::cont::DataSet& inDataSet) +{ + auto field = this->GetFieldFromDataSet(inDataSet); + + vtkm::cont::UnknownArrayHandle outArray; + + auto resolveType = [&](const auto& concrete) { + // use std::decay to remove const ref from the decltype of concrete. + using T = typename std::decay_t::ValueType; + vtkm::cont::ArrayHandle result; + vtkm::worklet::SphericalCoordinateTransform Worklet{ this->cartesianToSpherical }; + Worklet.Run(concrete, result); + outArray = result; + }; + this->CastAndCallVecField<3>(field, resolveType); + + vtkm::cont::DataSet outDataSet = + this->CreateResult(inDataSet, + inDataSet.GetCellSet(), + vtkm::cont::CoordinateSystem("coordinates", outArray), + [](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) { + out.AddField(fieldToPass); + }); + return outDataSet; +} +} // namespace field_transform +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/field_transform/CoordinateSystemTransform.h b/vtkm/filter/field_transform/CoordinateSystemTransform.h new file mode 100644 index 000000000..cd800cc0f --- /dev/null +++ b/vtkm/filter/field_transform/CoordinateSystemTransform.h @@ -0,0 +1,55 @@ +//============================================================================ +// 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_field_transform_CoordinateSystemTransform_h +#define vtk_m_filter_field_transform_CoordinateSystemTransform_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +/// \brief +/// +/// Generate a coordinate transformation on coordinates from a dataset. +class VTKM_FILTER_FIELD_TRANSFORM_EXPORT CylindricalCoordinateTransform + : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT void SetCartesianToCylindrical() { cartesianToCylindrical = true; } + VTKM_CONT void SetCylindricalToCartesian() { cartesianToCylindrical = false; } + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + bool cartesianToCylindrical = true; +}; + +class VTKM_FILTER_FIELD_TRANSFORM_EXPORT SphericalCoordinateTransform + : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT void SetCartesianToSpherical() { cartesianToSpherical = true; } + VTKM_CONT void SetSphericalToCartesian() { cartesianToSpherical = false; } + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + bool cartesianToSpherical = true; +}; +} // namespace field_transform +} // namespace filter +} // namespace vtkm + +#endif // vtk_m_filter_field_transform_CoordinateSystemTransform_h diff --git a/vtkm/filter/FieldToColors.hxx b/vtkm/filter/field_transform/FieldToColors.cxx similarity index 60% rename from vtkm/filter/FieldToColors.hxx rename to vtkm/filter/field_transform/FieldToColors.cxx index e93ad765e..d202bff26 100644 --- a/vtkm/filter/FieldToColors.hxx +++ b/vtkm/filter/field_transform/FieldToColors.cxx @@ -7,19 +7,17 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - -#ifndef vtk_m_filter_FieldToColors_hxx -#define vtk_m_filter_FieldToColors_hxx - #include #include #include +#include namespace vtkm { namespace filter { - +namespace field_transform +{ namespace { struct ScalarInputMode @@ -100,16 +98,9 @@ inline bool execute(ComponentInputMode, //----------------------------------------------------------------------------- -inline VTKM_CONT FieldToColors::FieldToColors(const vtkm::cont::ColorTable& table) - : vtkm::filter::FilterField() - , Table(table) - , InputMode(SCALAR) - , OutputMode(RGBA) - , SamplesRGB() - , SamplesRGBA() - , Component(0) - , SampleCount(256) - , ModifiedCount(-1) +VTKM_CONT FieldToColors::FieldToColors(const vtkm::cont::ColorTable& table) + : Table(table) + { } @@ -124,13 +115,10 @@ inline VTKM_CONT void FieldToColors::SetNumberOfSamplingPoints(vtkm::Int32 count } //----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet FieldToColors::DoExecute( - const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& inField, - const vtkm::filter::FieldMetadata& fieldMetadata, - vtkm::filter::PolicyBase) +vtkm::cont::DataSet FieldToColors::DoExecute(const vtkm::cont::DataSet& input) { + auto field = this->GetFieldFromDataSet(input); + //If the table has been modified we need to rebuild our //sample tables if (this->Table.GetModifiedCount() > this->ModifiedCount) @@ -140,89 +128,94 @@ inline VTKM_CONT vtkm::cont::DataSet FieldToColors::DoExecute( this->ModifiedCount = this->Table.GetModifiedCount(); } - std::string outputName = this->GetOutputFieldName(); if (outputName.empty()) { // Default name is name of input_colors. - outputName = fieldMetadata.GetName() + "_colors"; + outputName = field.GetName() + "_colors"; } vtkm::cont::Field outField; //We need to verify if the array is a vtkm::Vec + vtkm::cont::UnknownArrayHandle outArray; + auto resolveType = [&, this](const auto& concrete) { + // use std::decay to remove const ref from the decltype of concrete. + using T = typename std::decay_t::ValueType; + using IsVec = typename vtkm::VecTraits::HasMultipleComponents; - using IsVec = typename vtkm::VecTraits::HasMultipleComponents; - if (this->OutputMode == RGBA) - { - vtkm::cont::ArrayHandle output; - - bool ran = false; - switch (this->InputMode) + if (this->OutputMode == RGBA) { - case SCALAR: - { - ran = - execute(ScalarInputMode{}, this->Component, inField, this->SamplesRGBA, output, IsVec{}); - break; - } - case MAGNITUDE: - { - ran = execute( - MagnitudeInputMode{}, this->Component, inField, this->SamplesRGBA, output, IsVec{}); - break; - } - case COMPONENT: - { - ran = execute( - ComponentInputMode{}, this->Component, inField, this->SamplesRGBA, output, IsVec{}); - break; - } - } + vtkm::cont::ArrayHandle result; - if (!ran) + bool ran = false; + switch (this->InputMode) + { + case SCALAR: + { + ran = execute( + ScalarInputMode{}, this->Component, concrete, this->SamplesRGBA, result, IsVec{}); + break; + } + case MAGNITUDE: + { + ran = execute( + MagnitudeInputMode{}, this->Component, concrete, this->SamplesRGBA, result, IsVec{}); + break; + } + case COMPONENT: + { + ran = execute( + ComponentInputMode{}, this->Component, concrete, this->SamplesRGBA, result, IsVec{}); + break; + } + } + + if (!ran) + { + throw vtkm::cont::ErrorFilterExecution("Unsupported input mode."); + } + outField = vtkm::cont::make_FieldPoint(outputName, result); + } + else { - throw vtkm::cont::ErrorFilterExecution("Unsupported input mode."); - } - outField = vtkm::cont::make_FieldPoint(outputName, output); - } - else - { - vtkm::cont::ArrayHandle output; + vtkm::cont::ArrayHandle result; - bool ran = false; - switch (this->InputMode) - { - case SCALAR: + bool ran = false; + switch (this->InputMode) { - ran = - execute(ScalarInputMode{}, this->Component, inField, this->SamplesRGB, output, IsVec{}); - break; + case SCALAR: + { + ran = execute( + ScalarInputMode{}, this->Component, concrete, this->SamplesRGB, result, IsVec{}); + break; + } + case MAGNITUDE: + { + ran = execute( + MagnitudeInputMode{}, this->Component, concrete, this->SamplesRGB, result, IsVec{}); + break; + } + case COMPONENT: + { + ran = execute( + ComponentInputMode{}, this->Component, concrete, this->SamplesRGB, result, IsVec{}); + break; + } } - case MAGNITUDE: + + if (!ran) { - ran = execute( - MagnitudeInputMode{}, this->Component, inField, this->SamplesRGB, output, IsVec{}); - break; - } - case COMPONENT: - { - ran = execute( - ComponentInputMode{}, this->Component, inField, this->SamplesRGB, output, IsVec{}); - break; + throw vtkm::cont::ErrorFilterExecution("Unsupported input mode."); } + outField = vtkm::cont::make_FieldPoint(outputName, result); } + }; + field.GetData() + .CastAndCallForTypesWithFloatFallback( + resolveType); - if (!ran) - { - throw vtkm::cont::ErrorFilterExecution("Unsupported input mode."); - } - outField = vtkm::cont::make_FieldPoint(outputName, output); - } - - - return CreateResult(input, outField); + return this->CreateResultField(input, outField); } -} -} // namespace vtkm::filter - -#endif +} // namespace field_transform +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/field_transform/FieldToColors.h b/vtkm/filter/field_transform/FieldToColors.h new file mode 100644 index 000000000..155edcb1c --- /dev/null +++ b/vtkm/filter/field_transform/FieldToColors.h @@ -0,0 +1,91 @@ +//============================================================================ +// 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_field_transform_FieldToColors_h +#define vtk_m_filter_field_transform_FieldToColors_h + +#include +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +/// \brief Convert an arbitrary field to an RGB or RGBA field +/// +class VTKM_FILTER_FIELD_TRANSFORM_EXPORT FieldToColors : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT + FieldToColors(const vtkm::cont::ColorTable& table = vtkm::cont::ColorTable()); + + enum FieldToColorsInputMode + { + SCALAR, + MAGNITUDE, + COMPONENT + }; + + enum FieldToColorsOutputMode + { + RGB, + RGBA + }; + + void SetColorTable(const vtkm::cont::ColorTable& table) + { + this->Table = table; + this->ModifiedCount = -1; + } + const vtkm::cont::ColorTable& GetColorTable() const { return this->Table; } + + void SetMappingMode(FieldToColorsInputMode mode) { this->InputMode = mode; } + void SetMappingToScalar() { this->InputMode = FieldToColorsInputMode::SCALAR; } + void SetMappingToMagnitude() { this->InputMode = FieldToColorsInputMode::MAGNITUDE; } + void SetMappingToComponent() { this->InputMode = FieldToColorsInputMode::COMPONENT; } + FieldToColorsInputMode GetMappingMode() const { return this->InputMode; } + bool IsMappingScalar() const { return this->InputMode == FieldToColorsInputMode::SCALAR; } + bool IsMappingMagnitude() const { return this->InputMode == FieldToColorsInputMode::MAGNITUDE; } + bool IsMappingComponent() const { return this->InputMode == FieldToColorsInputMode::COMPONENT; } + + void SetMappingComponent(vtkm::IdComponent comp) { this->Component = comp; } + vtkm::IdComponent GetMappingComponent() const { return this->Component; } + + void SetOutputMode(FieldToColorsOutputMode mode) { this->OutputMode = mode; } + void SetOutputToRGB() { this->OutputMode = FieldToColorsOutputMode::RGB; } + void SetOutputToRGBA() { this->OutputMode = FieldToColorsOutputMode::RGBA; } + FieldToColorsOutputMode GetOutputMode() const { return this->OutputMode; } + bool IsOutputRGB() const { return this->OutputMode == FieldToColorsOutputMode::RGB; } + bool IsOutputRGBA() const { return this->OutputMode == FieldToColorsOutputMode::RGBA; } + + + void SetNumberOfSamplingPoints(vtkm::Int32 count); + vtkm::Int32 GetNumberOfSamplingPoints() const { return this->SampleCount; } + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + vtkm::cont::ColorTable Table; + FieldToColorsInputMode InputMode = SCALAR; + FieldToColorsOutputMode OutputMode = RGBA; + vtkm::cont::ColorTableSamplesRGB SamplesRGB; + vtkm::cont::ColorTableSamplesRGBA SamplesRGBA; + vtkm::IdComponent Component = 0; + vtkm::Int32 SampleCount = 256; + vtkm::Id ModifiedCount = -1; +}; +} // namespace field_transform +} // namespace filter +} // namespace vtkm + +#endif // vtk_m_filter_field_transform_FieldToColors_h diff --git a/vtkm/filter/field_transform/PointElevation.cxx b/vtkm/filter/field_transform/PointElevation.cxx new file mode 100644 index 000000000..363c1bca4 --- /dev/null +++ b/vtkm/filter/field_transform/PointElevation.cxx @@ -0,0 +1,46 @@ +//============================================================================ +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//============================================================================ + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +//----------------------------------------------------------------------------- +VTKM_CONT PointElevation::PointElevation() +{ + this->SetOutputFieldName("elevation"); +} + +//----------------------------------------------------------------------------- +VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute(const vtkm::cont::DataSet& inDataSet) +{ + auto field = this->GetFieldFromDataSet(inDataSet); + vtkm::cont::ArrayHandle outArray; + + auto resolveType = [&, this](const auto& concrete) { + this->Invoke( + vtkm::worklet::PointElevation{ + this->LowPoint, this->HighPoint, this->RangeLow, this->RangeHigh }, + concrete, + outArray); + }; + this->CastAndCallVecField<3>(field.GetData(), resolveType); + + return this->CreateResultField( + inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray); +} +} // namespace field_transform +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/field_transform/PointElevation.h b/vtkm/filter/field_transform/PointElevation.h new file mode 100644 index 000000000..587b76e25 --- /dev/null +++ b/vtkm/filter/field_transform/PointElevation.h @@ -0,0 +1,60 @@ +//============================================================================ +// 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_field_transform_PointElevation_h +#define vtk_m_filter_field_transform_PointElevation_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +/// \brief generate a scalar field along a specified direction +/// +/// Generate scalar field from a dataset. +/// The scalar field values lie within a user specified range, and +/// are generated by computing a projection of each dataset point onto +/// a line. The line can be oriented arbitrarily. A typical example is +/// to generate scalars based on elevation or height above a plane. +class VTKM_FILTER_FIELD_TRANSFORM_EXPORT PointElevation : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT + PointElevation(); + + VTKM_CONT + void SetLowPoint(const vtkm::Vec3f_64& point) { this->LowPoint = point; } + + VTKM_CONT + void SetHighPoint(const vtkm::Vec3f_64& point) { this->HighPoint = point; } + + VTKM_CONT + void SetRange(vtkm::Float64 low, vtkm::Float64 high) + { + this->RangeLow = low; + this->RangeHigh = high; + } + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + vtkm::Vec3f_64 LowPoint = { 0.0, 0.0, 0.0 }; + vtkm::Vec3f_64 HighPoint = { 0.0, 0.0, 1.0 }; + vtkm::Float64 RangeLow = 0.0, RangeHigh = 1.0; +}; +} // namespace field_transform +} // namespace filter +} // namespace vtkm + +#endif // vtk_m_filter_field_transform_PointElevation_h diff --git a/vtkm/filter/field_transform/PointTransform.cxx b/vtkm/filter/field_transform/PointTransform.cxx new file mode 100644 index 000000000..09f74b883 --- /dev/null +++ b/vtkm/filter/field_transform/PointTransform.cxx @@ -0,0 +1,67 @@ +//============================================================================ +// 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 + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +//----------------------------------------------------------------------------- +VTKM_CONT PointTransform::PointTransform() +{ + this->SetOutputFieldName("transform"); + this->SetUseCoordinateSystemAsField(true); +} + +//----------------------------------------------------------------------------- +inline VTKM_CONT void PointTransform::SetChangeCoordinateSystem(bool flag) +{ + this->ChangeCoordinateSystem = flag; +} + +//----------------------------------------------------------------------------- +inline VTKM_CONT bool PointTransform::GetChangeCoordinateSystem() const +{ + return this->ChangeCoordinateSystem; +} + +//----------------------------------------------------------------------------- +VTKM_CONT vtkm::cont::DataSet PointTransform::DoExecute(const vtkm::cont::DataSet& inDataSet) +{ + auto field = this->GetFieldFromDataSet(inDataSet); + vtkm::cont::UnknownArrayHandle outArray; + + auto resolveType = [&, this](const auto& concrete) { + using T = typename std::decay_t::ValueType; + vtkm::cont::ArrayHandle result; + this->Invoke(vtkm::worklet::PointTransform{ this->matrix }, field, result); + outArray = result; + }; + this->CastAndCallVecField<3>(field.GetData(), resolveType); + + vtkm::cont::DataSet outData = this->CreateResultField( + inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray); + + if (this->GetChangeCoordinateSystem()) + { + vtkm::Id coordIndex = + this->GetUseCoordinateSystemAsField() ? this->GetActiveCoordinateSystemIndex() : 0; + outData.GetCoordinateSystem(coordIndex).SetData(outArray); + } + + return outData; +} +} +} +} // namespace vtkm::filter diff --git a/vtkm/filter/field_transform/PointTransform.h b/vtkm/filter/field_transform/PointTransform.h new file mode 100644 index 000000000..dd37b5ff8 --- /dev/null +++ b/vtkm/filter/field_transform/PointTransform.h @@ -0,0 +1,110 @@ +//============================================================================ +// 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_field_transform_PointTransform_h +#define vtk_m_filter_field_transform_PointTransform_h + +#include +#include + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +/// \brief +/// +/// Generate scalar field from a dataset. +class VTKM_FILTER_FIELD_TRANSFORM_EXPORT PointTransform : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT + PointTransform(); + + //Translation + VTKM_CONT void SetTranslation(const vtkm::FloatDefault& tx, + const vtkm::FloatDefault& ty, + const vtkm::FloatDefault& tz) + { + matrix = vtkm::Transform3DTranslate(tx, ty, tz); + } + + VTKM_CONT void SetTranslation(const vtkm::Vec& v) + { + SetTranslation(v[0], v[1], v[2]); + } + + //Rotation + VTKM_CONT void SetRotation(const vtkm::FloatDefault& angleDegrees, + const vtkm::Vec& axis) + { + matrix = vtkm::Transform3DRotate(angleDegrees, axis); + } + + VTKM_CONT void SetRotation(const vtkm::FloatDefault& angleDegrees, + const vtkm::FloatDefault& rx, + const vtkm::FloatDefault& ry, + const vtkm::FloatDefault& rz) + { + SetRotation(angleDegrees, { rx, ry, rz }); + } + + VTKM_CONT void SetRotationX(const vtkm::FloatDefault& angleDegrees) + { + SetRotation(angleDegrees, 1, 0, 0); + } + + VTKM_CONT void SetRotationY(const vtkm::FloatDefault& angleDegrees) + { + SetRotation(angleDegrees, 0, 1, 0); + } + + VTKM_CONT void SetRotationZ(const vtkm::FloatDefault& angleDegrees) + { + SetRotation(angleDegrees, 0, 0, 1); + } + + //Scaling + VTKM_CONT void SetScale(const vtkm::FloatDefault& s) { matrix = vtkm::Transform3DScale(s, s, s); } + + VTKM_CONT void SetScale(const vtkm::FloatDefault& sx, + const vtkm::FloatDefault& sy, + const vtkm::FloatDefault& sz) + { + matrix = vtkm::Transform3DScale(sx, sy, sz); + } + + VTKM_CONT void SetScale(const vtkm::Vec& v) + { + matrix = vtkm::Transform3DScale(v[0], v[1], v[2]); + } + + //General transformation + VTKM_CONT + void SetTransform(const vtkm::Matrix& mtx) { matrix = mtx; } + + void SetChangeCoordinateSystem(bool flag); + bool GetChangeCoordinateSystem() const; + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + vtkm::Matrix matrix; + bool ChangeCoordinateSystem = true; +}; +} +} +} // namespace vtkm::filter + +#endif // vtk_m_filter_field_transform_PointTransform_h diff --git a/vtkm/filter/field_transform/WarpScalar.cxx b/vtkm/filter/field_transform/WarpScalar.cxx new file mode 100644 index 000000000..fd39c6bce --- /dev/null +++ b/vtkm/filter/field_transform/WarpScalar.cxx @@ -0,0 +1,83 @@ +//============================================================================ +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//============================================================================ + +#include +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +//----------------------------------------------------------------------------- +VTKM_CONT WarpScalar::WarpScalar(vtkm::FloatDefault scaleAmount) + : ScaleAmount(scaleAmount) +{ + this->SetOutputFieldName("warpscalar"); +} + +//----------------------------------------------------------------------------- +VTKM_CONT vtkm::cont::DataSet WarpScalar::DoExecute(const vtkm::cont::DataSet& inDataSet) +{ + // TODO: do we still need to deal with this? + // WarpScalar often operates on a constant normal value + // using AdditionalFieldStorage = + // vtkm::List::StorageTag, + // vtkm::cont::ArrayHandleConstant::StorageTag>; + // TODO: + // Ken suggested to provide additional public interface for user to supply a single + // value for const normal (and scale factor?). + auto field = this->GetFieldFromDataSet(inDataSet); + vtkm::cont::Field normalF = + inDataSet.GetField(this->NormalFieldName, this->NormalFieldAssociation); + vtkm::cont::ArrayHandle normalArray; + if (normalF.GetData().CanConvert>()) + { + vtkm::Vec3f_32 norm = + normalF.GetData().AsArrayHandle>().GetValue(); + normalArray.AllocateAndFill(normalF.GetData().GetNumberOfValues(), vtkm::Vec3f(norm)); + } + else if (normalF.GetData().CanConvert>()) + { + vtkm::Vec3f_64 norm = + normalF.GetData().AsArrayHandle>().GetValue(); + normalArray.AllocateAndFill(normalF.GetData().GetNumberOfValues(), vtkm::Vec3f(norm)); + } + else + { + vtkm::cont::ArrayCopyShallowIfPossible(normalF.GetData(), normalArray); + } + + vtkm::cont::Field sfF = + inDataSet.GetField(this->ScalarFactorFieldName, this->ScalarFactorFieldAssociation); + vtkm::cont::ArrayHandle scaleFactorArray; + vtkm::cont::ArrayCopyShallowIfPossible(sfF.GetData(), scaleFactorArray); + + vtkm::cont::UnknownArrayHandle outArray; + + auto resolveType = [&, this](const auto& concrete) { + // We know ValueType is some form of Vec3 due to CastAndCallVecField + using VecType = typename std::decay_t::ValueType; + + vtkm::cont::ArrayHandle result; + vtkm::worklet::WarpScalar worklet; + worklet.Run(concrete, normalArray, scaleFactorArray, this->ScaleAmount, result); + outArray = result; + }; + this->CastAndCallVecField<3>(field.GetData(), resolveType); + + return this->CreateResultField( + inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray); +} +} // namespace field_transform +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/field_transform/WarpScalar.h b/vtkm/filter/field_transform/WarpScalar.h new file mode 100644 index 000000000..e4a5f2586 --- /dev/null +++ b/vtkm/filter/field_transform/WarpScalar.h @@ -0,0 +1,92 @@ +//============================================================================ +// 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_field_transform_WarpScalar_h +#define vtk_m_filter_field_transform_WarpScalar_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +/// \brief Modify points by moving points along point normals by the scalar +/// amount times the scalar factor. +/// +/// A filter that modifies point coordinates by moving points along point normals +/// by the scalar amount times the scalar factor. +/// It's a VTK-m version of the vtkWarpScalar in VTK. +/// Useful for creating carpet or x-y-z plots. +/// It doesn't modify the point coordinates, but creates a new point coordinates that have been warped. +class VTKM_FILTER_FIELD_TRANSFORM_EXPORT WarpScalar : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT + WarpScalar(vtkm::FloatDefault scaleAmount); + + //@{ + /// Choose the secondary field to operate on. In the warp op A + B * + /// scaleAmount * scalarFactor, B is the secondary field + VTKM_CONT + void SetNormalField( + const std::string& name, + vtkm::cont::Field::Association association = vtkm::cont::Field::Association::ANY) + { + this->NormalFieldName = name; + this->NormalFieldAssociation = association; + } + + VTKM_CONT const std::string& GetNormalFieldName() const { return this->NormalFieldName; } + + VTKM_CONT vtkm::cont::Field::Association GetNormalFieldAssociation() const + { + return this->NormalFieldAssociation; + } + //@} + + //@{ + /// Choose the scalar factor field to operate on. In the warp op A + B * + /// scaleAmount * scalarFactor, scalarFactor is the scalar factor field. + VTKM_CONT + void SetScalarFactorField( + const std::string& name, + vtkm::cont::Field::Association association = vtkm::cont::Field::Association::ANY) + { + this->ScalarFactorFieldName = name; + this->ScalarFactorFieldAssociation = association; + } + + VTKM_CONT const std::string& GetScalarFactorFieldName() const + { + return this->ScalarFactorFieldName; + } + + VTKM_CONT vtkm::cont::Field::Association GetScalarFactorFieldAssociation() const + { + return this->ScalarFactorFieldAssociation; + } + //@} + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + std::string NormalFieldName = "normal"; + vtkm::cont::Field::Association NormalFieldAssociation = vtkm::cont::Field::Association::ANY; + std::string ScalarFactorFieldName = "scalarfactor"; + vtkm::cont::Field::Association ScalarFactorFieldAssociation = vtkm::cont::Field::Association::ANY; + vtkm::FloatDefault ScaleAmount; +}; +} // namespace field_transform +} // namespace filter +} // namespace vtkm +#endif // vtk_m_filter_field_transform_WarpScalar_h diff --git a/vtkm/filter/field_transform/WarpVector.cxx b/vtkm/filter/field_transform/WarpVector.cxx new file mode 100644 index 000000000..5a2699f69 --- /dev/null +++ b/vtkm/filter/field_transform/WarpVector.cxx @@ -0,0 +1,70 @@ +//============================================================================ +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//============================================================================ + +#include +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +//----------------------------------------------------------------------------- +VTKM_CONT WarpVector::WarpVector(vtkm::FloatDefault scale) + : Scale(scale) +{ + this->SetOutputFieldName("warpvector"); +} + +//----------------------------------------------------------------------------- +VTKM_CONT vtkm::cont::DataSet WarpVector::DoExecute(const vtkm::cont::DataSet& inDataSet) +{ + auto field = this->GetFieldFromDataSet(inDataSet); + vtkm::cont::Field vectorF = + inDataSet.GetField(this->VectorFieldName, this->VectorFieldAssociation); + vtkm::cont::ArrayHandle vectorArray; + if (vectorF.GetData().CanConvert>()) + { + vtkm::Vec3f_32 norm = + vectorF.GetData().AsArrayHandle>().GetValue(); + vectorArray.AllocateAndFill(vectorF.GetData().GetNumberOfValues(), vtkm::Vec3f(norm)); + } + else if (vectorF.GetData().CanConvert>()) + { + vtkm::Vec3f_64 norm = + vectorF.GetData().AsArrayHandle>().GetValue(); + vectorArray.AllocateAndFill(vectorF.GetData().GetNumberOfValues(), vtkm::Vec3f(norm)); + } + else + { + vtkm::cont::ArrayCopyShallowIfPossible(vectorF.GetData(), vectorArray); + } + + vtkm::cont::UnknownArrayHandle outArray; + + auto resolveType = [&, this](const auto& concrete) { + // We know ValueType is some form of Vec3 due to CastAndCallVecField + using VecType = typename std::decay_t::ValueType; + + vtkm::cont::ArrayHandle result; + vtkm::worklet::WarpVector worklet; + worklet.Run(concrete, vectorArray, this->Scale, result); + outArray = result; + }; + this->CastAndCallVecField<3>(field, resolveType); + + return this->CreateResultField( + inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray); +} +} // namespace field_transform +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/field_transform/WarpVector.h b/vtkm/filter/field_transform/WarpVector.h new file mode 100644 index 000000000..40901a3ad --- /dev/null +++ b/vtkm/filter/field_transform/WarpVector.h @@ -0,0 +1,67 @@ +//============================================================================ +// 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_field_transform_WarpVector_h +#define vtk_m_filter_field_transform_WarpVector_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace field_transform +{ +/// \brief Modify points by moving points along a vector multiplied by +/// the scale factor +/// +/// A filter that modifies point coordinates by moving points along a vector +/// multiplied by a scale factor. It's a VTK-m version of the vtkWarpVector in VTK. +/// Useful for showing flow profiles or mechanical deformation. +/// This worklet does not modify the input points but generate new point +/// coordinate instance that has been warped. +class VTKM_FILTER_FIELD_TRANSFORM_EXPORT WarpVector : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT + WarpVector(vtkm::FloatDefault scale); + + //@{ + /// Choose the vector field to operate on. In the warp op A + B *scale, B is + /// the vector field + VTKM_CONT + void SetVectorField( + const std::string& name, + vtkm::cont::Field::Association association = vtkm::cont::Field::Association::ANY) + { + this->VectorFieldName = name; + this->VectorFieldAssociation = association; + } + + VTKM_CONT const std::string& GetVectorFieldName() const { return this->VectorFieldName; } + + VTKM_CONT vtkm::cont::Field::Association GetVectorFieldAssociation() const + { + return this->VectorFieldAssociation; + } + //@} + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + std::string VectorFieldName = "normal"; + vtkm::cont::Field::Association VectorFieldAssociation = vtkm::cont::Field::Association::ANY; + vtkm::FloatDefault Scale; +}; +} // namespace field_transform +} // namespace filter +} // namespace vtkm +#endif // vtk_m_filter_field_transform_WarpVector_h diff --git a/vtkm/filter/field_transform/testing/CMakeLists.txt b/vtkm/filter/field_transform/testing/CMakeLists.txt index 8b1d72d89..f4462db77 100644 --- a/vtkm/filter/field_transform/testing/CMakeLists.txt +++ b/vtkm/filter/field_transform/testing/CMakeLists.txt @@ -9,14 +9,32 @@ ##============================================================================ set(unit_tests - UnitTestGenerateIds.cxx) + UnitTestCoordinateSystemTransform.cxx + UnitTestFieldToColors.cxx + UnitTestGenerateIds.cxx + UnitTestPointElevationFilter.cxx + UnitTestPointTransform.cxx + UnitTestWarpScalarFilter.cxx + UnitTestWarpVectorFilter.cxx + ) set(libraries vtkm_filter_field_transform vtkm_source) +if (VTKm_ENABLE_RENDERING) + list(APPEND libraries + vtkm_rendering_testing + vtkm_rendering) + + list(APPEND unit_tests + RenderTestPointTransform.cxx + ) +endif() + vtkm_unit_tests( SOURCES ${unit_tests} LIBRARIES ${libraries} + ALL_BACKENDS # renderer requires device compiler USE_VTKM_JOB_POOL ) diff --git a/vtkm/filter/testing/RenderTestPointTransform.cxx b/vtkm/filter/field_transform/testing/RenderTestPointTransform.cxx similarity index 94% rename from vtkm/filter/testing/RenderTestPointTransform.cxx rename to vtkm/filter/field_transform/testing/RenderTestPointTransform.cxx index 6147e2189..184667e06 100644 --- a/vtkm/filter/testing/RenderTestPointTransform.cxx +++ b/vtkm/filter/field_transform/testing/RenderTestPointTransform.cxx @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include @@ -30,7 +30,7 @@ void TestPointTransform() vtkm::io::VTKDataSetReader reader(pathname); vtkm::cont::DataSet dataSet = reader.ReadDataSet(); - vtkm::filter::PointTransform pointTransform; + vtkm::filter::field_transform::PointTransform pointTransform; pointTransform.SetOutputFieldName("translation"); pointTransform.SetTranslation(vtkm::Vec3f(1, 1, 1)); diff --git a/vtkm/filter/testing/UnitTestCoordinateSystemTransform.cxx b/vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx similarity index 96% rename from vtkm/filter/testing/UnitTestCoordinateSystemTransform.cxx rename to vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx index 472558c5d..129fdc72f 100644 --- a/vtkm/filter/testing/UnitTestCoordinateSystemTransform.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx @@ -9,7 +9,7 @@ //============================================================================ #include -#include +#include #include #include @@ -134,7 +134,7 @@ void TestCoordinateSystemTransform() //Test cartesian to cyl vtkm::cont::DataSet dsCart = MakeTestDataSet(CART); - vtkm::filter::CylindricalCoordinateTransform cylTrn; + vtkm::filter::field_transform::CylindricalCoordinateTransform cylTrn; cylTrn.SetCartesianToCylindrical(); cylTrn.SetUseCoordinateSystemAsField(true); @@ -158,7 +158,7 @@ void TestCoordinateSystemTransform() std::cout << "Testing SphericalCoordinateTransform Filter" << std::endl; - vtkm::filter::SphericalCoordinateTransform sphTrn; + vtkm::filter::field_transform::SphericalCoordinateTransform sphTrn; sphTrn.SetUseCoordinateSystemAsField(true); sphTrn.SetCartesianToSpherical(); vtkm::cont::DataSet carToSphDataSet = sphTrn.Execute(dsCart); diff --git a/vtkm/filter/testing/UnitTestFieldToColors.cxx b/vtkm/filter/field_transform/testing/UnitTestFieldToColors.cxx similarity index 96% rename from vtkm/filter/testing/UnitTestFieldToColors.cxx rename to vtkm/filter/field_transform/testing/UnitTestFieldToColors.cxx index 8bcec5df8..cdc68b902 100644 --- a/vtkm/filter/testing/UnitTestFieldToColors.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestFieldToColors.cxx @@ -8,7 +8,7 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include +#include #include #include @@ -31,7 +31,7 @@ void TestFieldToColors() vtkm::cont::DataSet ds = vtkm::cont::testing::MakeTestDataSet().Make3DExplicitDataSetPolygonal(); ds.AddPointField("faux", data, nvals); - vtkm::filter::FieldToColors ftc(table); + vtkm::filter::field_transform::FieldToColors ftc(table); ftc.SetOutputToRGBA(); ftc.SetActiveField("faux"); ftc.SetOutputFieldName("colors"); diff --git a/vtkm/filter/testing/UnitTestPointElevationFilter.cxx b/vtkm/filter/field_transform/testing/UnitTestPointElevationFilter.cxx similarity index 92% rename from vtkm/filter/testing/UnitTestPointElevationFilter.cxx rename to vtkm/filter/field_transform/testing/UnitTestPointElevationFilter.cxx index 1c98e6cd5..351b50f04 100644 --- a/vtkm/filter/testing/UnitTestPointElevationFilter.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestPointElevationFilter.cxx @@ -9,7 +9,7 @@ //============================================================================ #include -#include +#include #include @@ -62,9 +62,9 @@ void TestPointElevationNoPolicy() vtkm::cont::DataSet inputData = MakePointElevationTestDataSet(); - vtkm::filter::PointElevation filter; - filter.SetLowPoint(0.0, 0.0, 0.0); - filter.SetHighPoint(0.0, 1.0, 0.0); + vtkm::filter::field_transform::PointElevation filter; + filter.SetLowPoint({ 0.0, 0.0, 0.0 }); + filter.SetHighPoint({ 0.0, 1.0, 0.0 }); filter.SetRange(0.0, 2.0); filter.SetOutputFieldName("height"); @@ -94,9 +94,9 @@ void TestPointElevationWithPolicy() vtkm::cont::DataSet inputData = MakePointElevationTestDataSet(); - vtkm::filter::PointElevation filter; - filter.SetLowPoint(0.0, 0.0, 0.0); - filter.SetHighPoint(0.0, 1.0, 0.0); + vtkm::filter::field_transform::PointElevation filter; + filter.SetLowPoint({ 0.0, 0.0, 0.0 }); + filter.SetHighPoint({ 0.0, 1.0, 0.0 }); filter.SetRange(0.0, 2.0); filter.SetUseCoordinateSystemAsField(true); diff --git a/vtkm/filter/testing/UnitTestPointTransform.cxx b/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx similarity index 96% rename from vtkm/filter/testing/UnitTestPointTransform.cxx rename to vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx index 727dd7d8b..10da342df 100644 --- a/vtkm/filter/testing/UnitTestPointTransform.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx @@ -9,7 +9,7 @@ //============================================================================ #include -#include +#include #include #include @@ -98,7 +98,7 @@ void ValidatePointTransform(const vtkm::cont::CoordinateSystem& coords, void TestPointTransformTranslation(const vtkm::cont::DataSet& ds, const vtkm::Vec3f& trans) { - vtkm::filter::PointTransform filter; + vtkm::filter::field_transform::PointTransform filter; filter.SetOutputFieldName("translation"); filter.SetTranslation(trans); @@ -110,7 +110,7 @@ void TestPointTransformTranslation(const vtkm::cont::DataSet& ds, const vtkm::Ve void TestPointTransformScale(const vtkm::cont::DataSet& ds, const vtkm::Vec3f& scale) { - vtkm::filter::PointTransform filter; + vtkm::filter::field_transform::PointTransform filter; filter.SetOutputFieldName("scale"); filter.SetScale(scale); @@ -123,7 +123,7 @@ void TestPointTransformRotation(const vtkm::cont::DataSet& ds, const vtkm::FloatDefault& angle, const vtkm::Vec3f& axis) { - vtkm::filter::PointTransform filter; + vtkm::filter::field_transform::PointTransform filter; filter.SetOutputFieldName("rotation"); filter.SetRotation(angle, axis); diff --git a/vtkm/filter/testing/UnitTestWarpScalarFilter.cxx b/vtkm/filter/field_transform/testing/UnitTestWarpScalarFilter.cxx similarity index 93% rename from vtkm/filter/testing/UnitTestWarpScalarFilter.cxx rename to vtkm/filter/field_transform/testing/UnitTestWarpScalarFilter.cxx index 09e1fd69a..1590626df 100644 --- a/vtkm/filter/testing/UnitTestWarpScalarFilter.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestWarpScalarFilter.cxx @@ -8,11 +8,9 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include #include -#include +#include -#include #include namespace @@ -54,7 +52,8 @@ vtkm::cont::DataSet MakeWarpScalarTestDataSet() return dataSet; } -void CheckResult(const vtkm::filter::WarpScalar& filter, const vtkm::cont::DataSet& result) +void CheckResult(const vtkm::filter::field_transform::WarpScalar& filter, + const vtkm::cont::DataSet& result) { VTKM_TEST_ASSERT(result.HasPointField("warpscalar"), "Output filed warpscalar is missing"); using vecType = vtkm::Vec3f; @@ -94,7 +93,7 @@ void TestWarpScalarFilter() { std::cout << " First field as coordinates" << std::endl; - vtkm::filter::WarpScalar filter(scale); + vtkm::filter::field_transform::WarpScalar filter(scale); filter.SetUseCoordinateSystemAsField(true); filter.SetNormalField("normal"); filter.SetScalarFactorField("scalarfactor"); @@ -104,7 +103,7 @@ void TestWarpScalarFilter() { std::cout << " First field as a vector" << std::endl; - vtkm::filter::WarpScalar filter(scale); + vtkm::filter::field_transform::WarpScalar filter(scale); filter.SetActiveField("vec1"); filter.SetNormalField("normal"); filter.SetScalarFactorField("scalarfactor"); diff --git a/vtkm/filter/testing/UnitTestWarpVectorFilter.cxx b/vtkm/filter/field_transform/testing/UnitTestWarpVectorFilter.cxx similarity index 92% rename from vtkm/filter/testing/UnitTestWarpVectorFilter.cxx rename to vtkm/filter/field_transform/testing/UnitTestWarpVectorFilter.cxx index 1e3a1ded3..89f3c724d 100644 --- a/vtkm/filter/testing/UnitTestWarpVectorFilter.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestWarpVectorFilter.cxx @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -51,7 +51,8 @@ vtkm::cont::DataSet MakeWarpVectorTestDataSet() return dataSet; } -void CheckResult(const vtkm::filter::WarpVector& filter, const vtkm::cont::DataSet& result) +void CheckResult(const vtkm::filter::field_transform::WarpVector& filter, + const vtkm::cont::DataSet& result) { VTKM_TEST_ASSERT(result.HasPointField("warpvector"), "Output filed WarpVector is missing"); using vecType = vtkm::Vec3f; @@ -88,7 +89,7 @@ void TestWarpVectorFilter() { std::cout << " First field as coordinates" << std::endl; - vtkm::filter::WarpVector filter(scale); + vtkm::filter::field_transform::WarpVector filter(scale); filter.SetUseCoordinateSystemAsField(true); filter.SetVectorField("vec2"); vtkm::cont::DataSet result = filter.Execute(ds); @@ -97,7 +98,7 @@ void TestWarpVectorFilter() { std::cout << " First field as a vector" << std::endl; - vtkm::filter::WarpVector filter(scale); + vtkm::filter::field_transform::WarpVector filter(scale); filter.SetActiveField("vec1"); filter.SetVectorField("vec2"); vtkm::cont::DataSet result = filter.Execute(ds); diff --git a/vtkm/filter/field_transform/worklet/CMakeLists.txt b/vtkm/filter/field_transform/worklet/CMakeLists.txt new file mode 100644 index 000000000..6b1dc89bc --- /dev/null +++ b/vtkm/filter/field_transform/worklet/CMakeLists.txt @@ -0,0 +1,19 @@ +##============================================================================ +## 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 + CoordinateSystemTransform.h + PointElevation.h + PointTransform.h + WarpScalar.h + WarpVector.h + ) + +vtkm_declare_headers(${headers}) diff --git a/vtkm/worklet/CoordinateSystemTransform.h b/vtkm/filter/field_transform/worklet/CoordinateSystemTransform.h similarity index 90% rename from vtkm/worklet/CoordinateSystemTransform.h rename to vtkm/filter/field_transform/worklet/CoordinateSystemTransform.h index 145d923c9..c6a44960f 100644 --- a/vtkm/worklet/CoordinateSystemTransform.h +++ b/vtkm/filter/field_transform/worklet/CoordinateSystemTransform.h @@ -117,14 +117,11 @@ class CylindricalCoordinateTransform { public: VTKM_CONT - CylindricalCoordinateTransform() - : cartesianToCylindrical(true) + CylindricalCoordinateTransform(bool car2cyl) + : cartesianToCylindrical(car2cyl) { } - VTKM_CONT void SetCartesianToCylindrical() { cartesianToCylindrical = true; } - VTKM_CONT void SetCylindricalToCartesian() { cartesianToCylindrical = false; } - template void Run(const vtkm::cont::ArrayHandle, InStorageType>& inPoints, vtkm::cont::ArrayHandle, OutStorageType>& outPoints) const @@ -165,19 +162,16 @@ class SphericalCoordinateTransform { public: VTKM_CONT - SphericalCoordinateTransform() - : CartesianToSpherical(true) + SphericalCoordinateTransform(bool car2sph) + : cartesianToSpherical(car2sph) { } - VTKM_CONT void SetCartesianToSpherical() { CartesianToSpherical = true; } - VTKM_CONT void SetSphericalToCartesian() { CartesianToSpherical = false; } - template void Run(const vtkm::cont::ArrayHandle, InStorageType>& inPoints, vtkm::cont::ArrayHandle, OutStorageType>& outPoints) const { - if (CartesianToSpherical) + if (cartesianToSpherical) { vtkm::worklet::DispatcherMapField> dispatcher; dispatcher.Invoke(inPoints, outPoints); @@ -193,7 +187,7 @@ public: void Run(const vtkm::cont::CoordinateSystem& inPoints, vtkm::cont::ArrayHandle, CoordsStorageType>& outPoints) const { - if (CartesianToSpherical) + if (cartesianToSpherical) { vtkm::worklet::DispatcherMapField> dispatcher; dispatcher.Invoke(inPoints, outPoints); @@ -206,7 +200,7 @@ public: } private: - bool CartesianToSpherical; + bool cartesianToSpherical; }; } } // namespace vtkm::worklet diff --git a/vtkm/worklet/PointElevation.h b/vtkm/filter/field_transform/worklet/PointElevation.h similarity index 78% rename from vtkm/worklet/PointElevation.h rename to vtkm/filter/field_transform/worklet/PointElevation.h index f44f6fa42..cba957be7 100644 --- a/vtkm/worklet/PointElevation.h +++ b/vtkm/filter/field_transform/worklet/PointElevation.h @@ -37,27 +37,17 @@ public: using ExecutionSignature = _2(_1); VTKM_CONT - PointElevation() - : LowPoint(0.0, 0.0, 0.0) - , HighPoint(0.0, 0.0, 1.0) - , RangeLow(0.0) - , RangeHigh(1.0) + PointElevation(const vtkm::Vec3f_64& lp, + const vtkm::Vec3f_64& hp, + vtkm::Float64 low, + vtkm::Float64 hi) + : LowPoint(lp) + , HighPoint(hp) + , RangeLow(low) + , RangeHigh(hi) { } - VTKM_CONT - void SetLowPoint(const vtkm::Vec3f_64& point) { this->LowPoint = point; } - - VTKM_CONT - void SetHighPoint(const vtkm::Vec3f_64& point) { this->HighPoint = point; } - - VTKM_CONT - void SetRange(vtkm::Float64 low, vtkm::Float64 high) - { - this->RangeLow = low; - this->RangeHigh = high; - } - VTKM_EXEC vtkm::Float64 operator()(const vtkm::Vec3f_64& vec) const { @@ -78,8 +68,8 @@ public: } private: - vtkm::Vec3f_64 LowPoint, HighPoint; - vtkm::Float64 RangeLow, RangeHigh; + const vtkm::Vec3f_64 LowPoint, HighPoint; + const vtkm::Float64 RangeLow, RangeHigh; }; } } // namespace vtkm::worklet diff --git a/vtkm/filter/field_transform/worklet/PointTransform.h b/vtkm/filter/field_transform/worklet/PointTransform.h new file mode 100644 index 000000000..e852160c4 --- /dev/null +++ b/vtkm/filter/field_transform/worklet/PointTransform.h @@ -0,0 +1,49 @@ +//============================================================================ +// 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_worklet_PointTransform_h +#define vtk_m_worklet_PointTransform_h + +#include +#include +#include +#include + +namespace vtkm +{ +namespace worklet +{ + +class PointTransform : public vtkm::worklet::WorkletMapField +{ +public: + using ControlSignature = void(FieldIn, FieldOut); + using ExecutionSignature = _2(_1); + + VTKM_CONT + PointTransform(const vtkm::Matrix& m) + : matrix(m) + { + } + + //Functor + VTKM_EXEC + vtkm::Vec operator()(const vtkm::Vec& vec) const + { + return vtkm::Transform3DPoint(matrix, vec); + } + +private: + const vtkm::Matrix matrix; +}; +} +} // namespace vtkm::worklet + +#endif // vtk_m_worklet_PointTransform_h diff --git a/vtkm/worklet/WarpScalar.h b/vtkm/filter/field_transform/worklet/WarpScalar.h similarity index 100% rename from vtkm/worklet/WarpScalar.h rename to vtkm/filter/field_transform/worklet/WarpScalar.h diff --git a/vtkm/worklet/WarpVector.h b/vtkm/filter/field_transform/worklet/WarpVector.h similarity index 100% rename from vtkm/worklet/WarpVector.h rename to vtkm/filter/field_transform/worklet/WarpVector.h diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index 1c654c692..27b4407ae 100644 --- a/vtkm/filter/testing/CMakeLists.txt +++ b/vtkm/filter/testing/CMakeLists.txt @@ -17,10 +17,8 @@ set(unit_tests UnitTestContourTreeUniformFilter.cxx UnitTestContourTreeUniformAugmentedFilter.cxx UnitTestContourTreeUniformDistributedFilter.cxx - UnitTestCoordinateSystemTransform.cxx UnitTestFieldMetadata.cxx UnitTestFieldSelection.cxx - UnitTestFieldToColors.cxx UnitTestGhostCellClassify.cxx UnitTestImageDifferenceFilter.cxx UnitTestImageMedianFilter.cxx @@ -32,8 +30,6 @@ set(unit_tests UnitTestMIRFilter.cxx UnitTestMultiBlockFilter.cxx UnitTestPartitionedDataSetFilters.cxx - UnitTestPointElevationFilter.cxx - UnitTestPointTransform.cxx UnitTestProbe.cxx UnitTestSplitSharpEdgesFilter.cxx UnitTestStreamlineFilter.cxx @@ -42,8 +38,6 @@ set(unit_tests UnitTestTriangulateFilter.cxx UnitTestTubeFilter.cxx UnitTestVertexClusteringFilter.cxx - UnitTestWarpScalarFilter.cxx - UnitTestWarpVectorFilter.cxx UnitTestZFP.cxx ) @@ -68,7 +62,6 @@ if (VTKm_ENABLE_RENDERING) list(APPEND unit_tests RenderTestAmrArrays.cxx - RenderTestPointTransform.cxx RenderTestSplitSharpEdges.cxx RenderTestStreamline.cxx ) diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index 4ba587f70..3d3cd5b4e 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -16,7 +16,6 @@ set(headers CellMeasure.h ContourTreeUniform.h ContourTreeUniformAugmented.h - CoordinateSystemTransform.h CosmoTools.h DispatcherMapField.h DispatcherMapTopology.h @@ -37,8 +36,6 @@ set(headers NDimsHistMarginalization.h Normalize.h ParticleAdvection.h - PointElevation.h - PointTransform.h Probe.h ScalarsToColors.h ScatterCounting.h @@ -55,8 +52,6 @@ set(headers Triangulate.h Tube.h VertexClustering.h - WarpScalar.h - WarpVector.h WaveletCompressor.h WorkletMapField.h WorkletMapTopology.h diff --git a/vtkm/worklet/PointTransform.h b/vtkm/worklet/PointTransform.h deleted file mode 100644 index 48fe2d765..000000000 --- a/vtkm/worklet/PointTransform.h +++ /dev/null @@ -1,89 +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_worklet_PointTransform_h -#define vtk_m_worklet_PointTransform_h - -#include -#include -#include -#include - -namespace vtkm -{ -namespace worklet -{ - -template -class PointTransform : public vtkm::worklet::WorkletMapField -{ -public: - using ControlSignature = void(FieldIn, FieldOut); - using ExecutionSignature = _2(_1); - - VTKM_CONT - PointTransform() {} - - //Translation - VTKM_CONT void SetTranslation(const T& tx, const T& ty, const T& tz) - { - matrix = vtkm::Transform3DTranslate(tx, ty, tz); - } - - VTKM_CONT void SetTranslation(const vtkm::Vec& v) { SetTranslation(v[0], v[1], v[2]); } - - //Rotation - VTKM_CONT void SetRotation(const T& angleDegrees, const vtkm::Vec& axis) - { - matrix = vtkm::Transform3DRotate(angleDegrees, axis); - } - - VTKM_CONT void SetRotation(const T& angleDegrees, const T& rx, const T& ry, const T& rz) - { - SetRotation(angleDegrees, { rx, ry, rz }); - } - - VTKM_CONT void SetRotationX(const T& angleDegrees) { SetRotation(angleDegrees, 1, 0, 0); } - - VTKM_CONT void SetRotationY(const T& angleDegrees) { SetRotation(angleDegrees, 0, 1, 0); } - - VTKM_CONT void SetRotationZ(const T& angleDegrees) { SetRotation(angleDegrees, 0, 0, 1); } - - //Scaling - VTKM_CONT void SetScale(const T& s) { matrix = vtkm::Transform3DScale(s, s, s); } - - VTKM_CONT void SetScale(const T& sx, const T& sy, const T& sz) - { - matrix = vtkm::Transform3DScale(sx, sy, sz); - } - - VTKM_CONT void SetScale(const vtkm::Vec& v) - { - matrix = vtkm::Transform3DScale(v[0], v[1], v[2]); - } - - //General transformation - VTKM_CONT - void SetTransform(const vtkm::Matrix& mtx) { matrix = mtx; } - - //Functor - VTKM_EXEC - vtkm::Vec operator()(const vtkm::Vec& vec) const - { - return vtkm::Transform3DPoint(matrix, vec); - } - -private: - vtkm::Matrix matrix; -}; -} -} // namespace vtkm::worklet - -#endif // vtk_m_worklet_PointTransform_h diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index b5fd4b555..d6b91eb3d 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -21,7 +21,6 @@ set(unit_tests UnitTestContourTreeUniform.cxx UnitTestContourTreeUniformAugmented.cxx UnitTestContourTreeUniformDistributed.cxx - UnitTestCoordinateSystemTransform.cxx UnitTestCosmoTools.cxx UnitTestDescriptiveStatistics.cxx UnitTestFieldStatistics.cxx @@ -31,8 +30,6 @@ set(unit_tests UnitTestNormalize.cxx UnitTestNDimsHistMarginalization.cxx UnitTestParticleAdvection.cxx - UnitTestPointElevation.cxx - UnitTestPointTransform.cxx UnitTestProbe.cxx UnitTestScalarsToColors.cxx UnitTestScatterAndMask.cxx @@ -59,8 +56,6 @@ set(unit_tests UnitTestWorkletMapTopologyUniform.cxx UnitTestWorkletReduceByKey.cxx UnitTestVertexClustering.cxx - UnitTestWarpScalar.cxx - UnitTestWarpVector.cxx UnitTestWaveletCompressor.cxx UnitTestZFPCompressor.cxx ) diff --git a/vtkm/worklet/testing/UnitTestCoordinateSystemTransform.cxx b/vtkm/worklet/testing/UnitTestCoordinateSystemTransform.cxx deleted file mode 100644 index 1274363c1..000000000 --- a/vtkm/worklet/testing/UnitTestCoordinateSystemTransform.cxx +++ /dev/null @@ -1,203 +0,0 @@ -//============================================================================ -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//============================================================================ - -#include -#include -#include -#include -#include - -#include -#include - -namespace -{ -std::mt19937 randGenerator; - -enum CoordinateType -{ - CART = 0, - CYL, - SPH -}; - -vtkm::cont::DataSet MakeTestDataSet(const CoordinateType& cType) -{ - vtkm::cont::DataSet dataSet; - - std::vector coordinates; - const vtkm::Id dim = 5; - if (cType == CART) - { - for (vtkm::Id j = 0; j < dim; ++j) - { - vtkm::FloatDefault z = - static_cast(j) / static_cast(dim - 1); - for (vtkm::Id i = 0; i < dim; ++i) - { - vtkm::FloatDefault x = - static_cast(i) / static_cast(dim - 1); - vtkm::FloatDefault y = (x * x + z * z) / 2.0f; - coordinates.push_back(vtkm::make_Vec(x + 0, y + 0, z + 0)); - } - } - } - else if (cType == CYL) - { - vtkm::FloatDefault R = 1.0f; - for (vtkm::Id j = 0; j < dim; j++) - { - vtkm::FloatDefault Z = - static_cast(j) / static_cast(dim - 1); - for (vtkm::Id i = 0; i < dim; i++) - { - vtkm::FloatDefault Theta = vtkm::TwoPif() * - (static_cast(i) / static_cast(dim - 1)); - coordinates.push_back(vtkm::make_Vec(R, Theta, Z)); - } - } - } - else if (cType == SPH) - { - //Spherical coordinates have some degenerate cases, so provide some good cases. - vtkm::FloatDefault R = 1.0f; - vtkm::FloatDefault eps = vtkm::Epsilon(); - std::vector Thetas = { - eps, vtkm::Pif() / 4, vtkm::Pif() / 3, vtkm::Pif() / 2, vtkm::Pif() - eps - }; - std::vector Phis = { - eps, vtkm::TwoPif() / 4, vtkm::TwoPif() / 3, vtkm::TwoPif() / 2, vtkm::TwoPif() - eps - }; - for (std::size_t i = 0; i < Thetas.size(); i++) - for (std::size_t j = 0; j < Phis.size(); j++) - coordinates.push_back(vtkm::make_Vec(R, Thetas[i], Phis[j])); - } - - vtkm::Id numCells = (dim - 1) * (dim - 1); - dataSet.AddCoordinateSystem( - vtkm::cont::make_CoordinateSystem("coordinates", coordinates, vtkm::CopyFlag::On)); - - vtkm::cont::CellSetExplicit<> cellSet; - cellSet.PrepareToAddCells(numCells, numCells * 4); - for (vtkm::Id j = 0; j < dim - 1; ++j) - { - for (vtkm::Id i = 0; i < dim - 1; ++i) - { - cellSet.AddCell(vtkm::CELL_SHAPE_QUAD, - 4, - vtkm::make_Vec( - j * dim + i, j * dim + i + 1, (j + 1) * dim + i + 1, (j + 1) * dim + i)); - } - } - cellSet.CompleteAddingCells(vtkm::Id(coordinates.size())); - - dataSet.SetCellSet(cellSet); - return dataSet; -} - -void ValidateCoordTransform(const vtkm::cont::CoordinateSystem& coords, - const vtkm::cont::ArrayHandle& transform, - const vtkm::cont::ArrayHandle& doubleTransform, - const std::vector& isAngle) -{ - auto points = coords.GetDataAsMultiplexer(); - VTKM_TEST_ASSERT(points.GetNumberOfValues() == transform.GetNumberOfValues() && - points.GetNumberOfValues() == doubleTransform.GetNumberOfValues(), - "Incorrect number of points in point transform"); - - //The double transform should produce the same result. - auto pointsPortal = points.ReadPortal(); - auto resultsPortal = doubleTransform.ReadPortal(); - - for (vtkm::Id i = 0; i < points.GetNumberOfValues(); i++) - { - vtkm::Vec3f p = pointsPortal.Get(i); - vtkm::Vec3f r = resultsPortal.Get(i); - bool isEqual = true; - for (vtkm::IdComponent j = 0; j < 3; j++) - { - if (isAngle[static_cast(j)]) - isEqual &= (test_equal(p[j], r[j]) || test_equal(p[j] + vtkm::TwoPif(), r[j]) || - test_equal(p[j], r[j] + vtkm::TwoPif())); - else - isEqual &= test_equal(p[j], r[j]); - } - VTKM_TEST_ASSERT(isEqual, "Wrong result for PointTransform worklet"); - } -} -} - -void TestCoordinateSystemTransform() -{ - std::cout << "Testing CylindricalCoordinateTransform Worklet" << std::endl; - - //Test cartesian to cyl - vtkm::cont::DataSet dsCart = MakeTestDataSet(CART); - vtkm::worklet::CylindricalCoordinateTransform cylTrn; - - vtkm::cont::ArrayHandle carToCylPts; - vtkm::cont::ArrayHandle revResult; - - cylTrn.SetCartesianToCylindrical(); - cylTrn.Run(dsCart.GetCoordinateSystem(), carToCylPts); - - cylTrn.SetCylindricalToCartesian(); - cylTrn.Run(carToCylPts, revResult); - ValidateCoordTransform( - dsCart.GetCoordinateSystem(), carToCylPts, revResult, { false, false, false }); - - //Test cylindrical to cartesian - vtkm::cont::DataSet dsCyl = MakeTestDataSet(CYL); - vtkm::cont::ArrayHandle cylToCarPts; - cylTrn.SetCylindricalToCartesian(); - cylTrn.Run(dsCyl.GetCoordinateSystem(), cylToCarPts); - - cylTrn.SetCartesianToCylindrical(); - cylTrn.Run(cylToCarPts, revResult); - ValidateCoordTransform( - dsCyl.GetCoordinateSystem(), cylToCarPts, revResult, { false, true, false }); - - //Spherical transform - //Test cartesian to sph - vtkm::worklet::SphericalCoordinateTransform sphTrn; - vtkm::cont::ArrayHandle carToSphPts; - - sphTrn.SetCartesianToSpherical(); - sphTrn.Run(dsCart.GetCoordinateSystem(), carToSphPts); - - sphTrn.SetSphericalToCartesian(); - sphTrn.Run(carToSphPts, revResult); - ValidateCoordTransform( - dsCart.GetCoordinateSystem(), carToSphPts, revResult, { false, true, true }); - - //Test spherical to cartesian - vtkm::cont::ArrayHandle sphToCarPts; - vtkm::cont::DataSet dsSph = MakeTestDataSet(SPH); - - sphTrn.SetSphericalToCartesian(); - sphTrn.Run(dsSph.GetCoordinateSystem(), sphToCarPts); - - sphTrn.SetCartesianToSpherical(); - sphTrn.Run(sphToCarPts, revResult); - - ValidateCoordTransform( - dsSph.GetCoordinateSystem(), sphToCarPts, revResult, { false, true, true }); - sphTrn.SetSphericalToCartesian(); - sphTrn.Run(dsSph.GetCoordinateSystem(), sphToCarPts); - sphTrn.SetCartesianToSpherical(); - sphTrn.Run(sphToCarPts, revResult); - ValidateCoordTransform( - dsSph.GetCoordinateSystem(), sphToCarPts, revResult, { false, true, true }); -} - -int UnitTestCoordinateSystemTransform(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestCoordinateSystemTransform, argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestPointElevation.cxx b/vtkm/worklet/testing/UnitTestPointElevation.cxx deleted file mode 100644 index bcf90b6b4..000000000 --- a/vtkm/worklet/testing/UnitTestPointElevation.cxx +++ /dev/null @@ -1,94 +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 MakePointElevationTestDataSet() -{ - vtkm::cont::DataSet dataSet; - - std::vector coordinates; - const vtkm::Id dim = 5; - for (vtkm::Id j = 0; j < dim; ++j) - { - vtkm::Float32 z = static_cast(j) / static_cast(dim - 1); - for (vtkm::Id i = 0; i < dim; ++i) - { - vtkm::Float32 x = static_cast(i) / static_cast(dim - 1); - vtkm::Float32 y = (x * x + z * z) / 2.0f; - coordinates.push_back(vtkm::make_Vec(x, y, z)); - } - } - - vtkm::Id numCells = (dim - 1) * (dim - 1); - dataSet.AddCoordinateSystem( - vtkm::cont::make_CoordinateSystem("coordinates", coordinates, vtkm::CopyFlag::On)); - - vtkm::cont::CellSetExplicit<> cellSet; - cellSet.PrepareToAddCells(numCells, numCells * 4); - for (vtkm::Id j = 0; j < dim - 1; ++j) - { - for (vtkm::Id i = 0; i < dim - 1; ++i) - { - cellSet.AddCell(vtkm::CELL_SHAPE_QUAD, - 4, - vtkm::make_Vec( - j * dim + i, j * dim + i + 1, (j + 1) * dim + i + 1, (j + 1) * dim + i)); - } - } - cellSet.CompleteAddingCells(vtkm::Id(coordinates.size())); - - dataSet.SetCellSet(cellSet); - return dataSet; -} -} - -void TestPointElevation() -{ - std::cout << "Testing PointElevation Worklet" << std::endl; - - vtkm::cont::DataSet dataSet = MakePointElevationTestDataSet(); - - vtkm::cont::ArrayHandle result; - - vtkm::worklet::PointElevation pointElevationWorklet; - pointElevationWorklet.SetLowPoint(vtkm::make_Vec(0.0, 0.0, 0.0)); - pointElevationWorklet.SetHighPoint(vtkm::make_Vec(0.0, 1.0, 0.0)); - pointElevationWorklet.SetRange(0.0, 2.0); - - vtkm::worklet::DispatcherMapField dispatcher( - pointElevationWorklet); - dispatcher.Invoke(dataSet.GetCoordinateSystem(), result); - - auto coordinates = dataSet.GetCoordinateSystem().GetDataAsMultiplexer(); - auto coordinatesPortal = coordinates.ReadPortal(); - auto resultPortal = result.ReadPortal(); - for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i) - { - VTKM_TEST_ASSERT(test_equal(coordinatesPortal.Get(i)[1] * 2.0, resultPortal.Get(i)), - "Wrong result for PointElevation worklet"); - } -} - -int UnitTestPointElevation(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestPointElevation, argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestPointTransform.cxx b/vtkm/worklet/testing/UnitTestPointTransform.cxx deleted file mode 100644 index 159d20389..000000000 --- a/vtkm/worklet/testing/UnitTestPointTransform.cxx +++ /dev/null @@ -1,187 +0,0 @@ -//============================================================================ -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//============================================================================ - -#include -#include -#include -#include -#include - -#include -#include - -namespace -{ -std::mt19937 randGenerator; - -vtkm::cont::DataSet MakePointTransformTestDataSet() -{ - vtkm::cont::DataSet dataSet; - - std::vector coordinates; - const vtkm::Id dim = 5; - for (vtkm::Id j = 0; j < dim; ++j) - { - vtkm::FloatDefault z = - static_cast(j) / static_cast(dim - 1); - for (vtkm::Id i = 0; i < dim; ++i) - { - vtkm::FloatDefault x = - static_cast(i) / static_cast(dim - 1); - vtkm::FloatDefault y = (x * x + z * z) / 2.0f; - coordinates.push_back(vtkm::make_Vec(x, y, z)); - } - } - - vtkm::Id numCells = (dim - 1) * (dim - 1); - dataSet.AddCoordinateSystem( - vtkm::cont::make_CoordinateSystem("coordinates", coordinates, vtkm::CopyFlag::On)); - - vtkm::cont::CellSetExplicit<> cellSet; - cellSet.PrepareToAddCells(numCells, numCells * 4); - for (vtkm::Id j = 0; j < dim - 1; ++j) - { - for (vtkm::Id i = 0; i < dim - 1; ++i) - { - cellSet.AddCell(vtkm::CELL_SHAPE_QUAD, - 4, - vtkm::make_Vec( - j * dim + i, j * dim + i + 1, (j + 1) * dim + i + 1, (j + 1) * dim + i)); - } - } - cellSet.CompleteAddingCells(vtkm::Id(coordinates.size())); - - dataSet.SetCellSet(cellSet); - return dataSet; -} - -void ValidatePointTransform(const vtkm::cont::CoordinateSystem& coords, - const vtkm::cont::ArrayHandle& result, - const vtkm::Matrix& matrix) -{ - auto points = coords.GetDataAsMultiplexer(); - VTKM_TEST_ASSERT(points.GetNumberOfValues() == result.GetNumberOfValues(), - "Incorrect number of points in point transform"); - - auto pointsPortal = points.ReadPortal(); - auto resultsPortal = result.ReadPortal(); - - for (vtkm::Id i = 0; i < points.GetNumberOfValues(); i++) - VTKM_TEST_ASSERT( - test_equal(resultsPortal.Get(i), vtkm::Transform3DPoint(matrix, pointsPortal.Get(i))), - "Wrong result for PointTransform worklet"); -} - - -void TestPointTransformTranslation(const vtkm::cont::DataSet& ds, const vtkm::Vec3f& trans) -{ - vtkm::cont::ArrayHandle result; - vtkm::worklet::PointTransform worklet; - - worklet.SetTranslation(trans); - vtkm::worklet::DispatcherMapField> dispatcher( - worklet); - dispatcher.Invoke(ds.GetCoordinateSystem(), result); - - ValidatePointTransform(ds.GetCoordinateSystem(), result, Transform3DTranslate(trans)); -} - -void TestPointTransformScale(const vtkm::cont::DataSet& ds, const vtkm::Vec3f& scale) -{ - vtkm::cont::ArrayHandle result; - vtkm::worklet::PointTransform worklet; - - worklet.SetScale(scale); - vtkm::worklet::DispatcherMapField> dispatcher( - worklet); - dispatcher.Invoke(ds.GetCoordinateSystem(), result); - - ValidatePointTransform(ds.GetCoordinateSystem(), result, Transform3DScale(scale)); -} - -void TestPointTransformRotation(const vtkm::cont::DataSet& ds, - const vtkm::FloatDefault& angle, - const vtkm::Vec3f& axis) -{ - vtkm::cont::ArrayHandle result; - vtkm::worklet::PointTransform worklet; - - worklet.SetRotation(angle, axis); - vtkm::worklet::DispatcherMapField> dispatcher( - worklet); - dispatcher.Invoke(ds.GetCoordinateSystem(), result); - - ValidatePointTransform(ds.GetCoordinateSystem(), result, Transform3DRotate(angle, axis)); -} -} - -void TestPointTransform() -{ - std::cout << "Testing PointTransform Worklet" << std::endl; - - vtkm::cont::DataSet ds = MakePointTransformTestDataSet(); - int N = 41; - - //Test translation - TestPointTransformTranslation(ds, vtkm::Vec3f(0, 0, 0)); - TestPointTransformTranslation(ds, vtkm::Vec3f(1, 1, 1)); - TestPointTransformTranslation(ds, vtkm::Vec3f(-1, -1, -1)); - - std::uniform_real_distribution transDist(-100, 100); - for (int i = 0; i < N; i++) - TestPointTransformTranslation( - ds, - vtkm::Vec3f(transDist(randGenerator), transDist(randGenerator), transDist(randGenerator))); - - //Test scaling - TestPointTransformScale(ds, vtkm::Vec3f(1, 1, 1)); - TestPointTransformScale(ds, vtkm::Vec3f(.23f, .23f, .23f)); - TestPointTransformScale(ds, vtkm::Vec3f(1, 2, 3)); - TestPointTransformScale(ds, vtkm::Vec3f(3.23f, 9.23f, 4.23f)); - - std::uniform_real_distribution scaleDist(0.0001f, 100); - for (int i = 0; i < N; i++) - { - TestPointTransformScale(ds, vtkm::Vec3f(scaleDist(randGenerator))); - TestPointTransformScale( - ds, - vtkm::Vec3f(scaleDist(randGenerator), scaleDist(randGenerator), scaleDist(randGenerator))); - } - - //Test rotation - std::vector angles; - std::uniform_real_distribution angleDist(0, 360); - for (int i = 0; i < N; i++) - angles.push_back(angleDist(randGenerator)); - - std::vector axes; - axes.push_back(vtkm::Vec3f(1, 0, 0)); - axes.push_back(vtkm::Vec3f(0, 1, 0)); - axes.push_back(vtkm::Vec3f(0, 0, 1)); - axes.push_back(vtkm::Vec3f(1, 1, 1)); - axes.push_back(-axes[0]); - axes.push_back(-axes[1]); - axes.push_back(-axes[2]); - axes.push_back(-axes[3]); - - std::uniform_real_distribution axisDist(-1, 1); - for (int i = 0; i < N; i++) - axes.push_back( - vtkm::Vec3f(axisDist(randGenerator), axisDist(randGenerator), axisDist(randGenerator))); - - for (std::size_t i = 0; i < angles.size(); i++) - for (std::size_t j = 0; j < axes.size(); j++) - TestPointTransformRotation(ds, angles[i], axes[j]); -} - -int UnitTestPointTransform(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestPointTransform, argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestWarpScalar.cxx b/vtkm/worklet/testing/UnitTestWarpScalar.cxx deleted file mode 100644 index 7d61c4d12..000000000 --- a/vtkm/worklet/testing/UnitTestWarpScalar.cxx +++ /dev/null @@ -1,95 +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 -{ -template -vtkm::cont::DataSet MakeWarpScalarTestDataSet() -{ - vtkm::cont::DataSet dataSet; - - std::vector> coordinates; - std::vector scaleFactor; - const vtkm::Id dim = 5; - for (vtkm::Id i = 0; i < dim; ++i) - { - T z = static_cast(i); - for (vtkm::Id j = 0; j < dim; ++j) - { - T x = static_cast(j); - T y = static_cast(j + 1); - coordinates.push_back(vtkm::make_Vec(x, y, z)); - scaleFactor.push_back(static_cast(i * dim + j)); - } - } - - dataSet.AddCoordinateSystem( - vtkm::cont::make_CoordinateSystem("coordinates", coordinates, vtkm::CopyFlag::On)); - dataSet.AddPointField("scalefactor", scaleFactor); - return dataSet; -} -} - -void TestWarpScalar() -{ - std::cout << "Testing WarpScalar Worklet" << std::endl; - using vecType = vtkm::Vec3f; - - vtkm::cont::DataSet ds = MakeWarpScalarTestDataSet(); - - vtkm::FloatDefault scaleAmount = 2; - vtkm::cont::ArrayHandle result; - - vecType normal = vtkm::make_Vec(static_cast(0.0), - static_cast(0.0), - static_cast(1.0)); - auto coordinate = ds.GetCoordinateSystem().GetDataAsMultiplexer(); - vtkm::Id nov = coordinate.GetNumberOfValues(); - vtkm::cont::ArrayHandleConstant normalAH = - vtkm::cont::make_ArrayHandleConstant(normal, nov); - - vtkm::cont::ArrayHandle scaleFactorArray; - auto scaleFactor = ds.GetField("scalefactor") - .GetData() - .ResetTypes(); - scaleFactor.AsArrayHandle(scaleFactorArray); - - vtkm::worklet::WarpScalar warpWorklet; - warpWorklet.Run( - ds.GetCoordinateSystem().GetDataAsMultiplexer(), normalAH, scaleFactor, scaleAmount, result); - - auto sFAPortal = scaleFactorArray.ReadPortal(); - auto resultPortal = result.ReadPortal(); - for (vtkm::Id i = 0; i < nov; i++) - { - for (vtkm::Id j = 0; j < 3; j++) - { - vtkm::FloatDefault ans = coordinate.ReadPortal().Get(i)[static_cast(j)] + - scaleAmount * normal[static_cast(j)] * sFAPortal.Get(i); - VTKM_TEST_ASSERT(test_equal(ans, resultPortal.Get(i)[static_cast(j)]), - " Wrong result for WarpVector worklet"); - } - } -} - -int UnitTestWarpScalar(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestWarpScalar, argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestWarpVector.cxx b/vtkm/worklet/testing/UnitTestWarpVector.cxx deleted file mode 100644 index fa10aa4c6..000000000 --- a/vtkm/worklet/testing/UnitTestWarpVector.cxx +++ /dev/null @@ -1,99 +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 -{ -template -vtkm::cont::DataSet MakeWarpVectorTestDataSet() -{ - vtkm::cont::DataSet dataSet; - - std::vector> coordinates; - const vtkm::Id dim = 5; - for (vtkm::Id j = 0; j < dim; ++j) - { - T z = static_cast(j) / static_cast(dim - 1); - for (vtkm::Id i = 0; i < dim; ++i) - { - T x = static_cast(i) / static_cast(dim - 1); - T y = (x * x + z * z) / 2.0f; - coordinates.push_back(vtkm::make_Vec(x, y, z)); - } - } - - vtkm::Id numCells = (dim - 1) * (dim - 1); - dataSet.AddCoordinateSystem( - vtkm::cont::make_CoordinateSystem("coordinates", coordinates, vtkm::CopyFlag::On)); - - vtkm::cont::CellSetExplicit<> cellSet; - cellSet.PrepareToAddCells(numCells, numCells * 4); - for (vtkm::Id j = 0; j < dim - 1; ++j) - { - for (vtkm::Id i = 0; i < dim - 1; ++i) - { - cellSet.AddCell(vtkm::CELL_SHAPE_QUAD, - 4, - vtkm::make_Vec( - j * dim + i, j * dim + i + 1, (j + 1) * dim + i + 1, (j + 1) * dim + i)); - } - } - cellSet.CompleteAddingCells(vtkm::Id(coordinates.size())); - dataSet.SetCellSet(cellSet); - return dataSet; -} -} - -void TestWarpVector() -{ - std::cout << "Testing WarpVector Worklet" << std::endl; - using vecType = vtkm::Vec3f; - - vtkm::cont::DataSet ds = MakeWarpVectorTestDataSet(); - vtkm::cont::ArrayHandle result; - - vtkm::FloatDefault scale = 2; - - vecType vector = vtkm::make_Vec(static_cast(0.0), - static_cast(0.0), - static_cast(2.0)); - auto coordinate = ds.GetCoordinateSystem().GetDataAsMultiplexer(); - vtkm::Id nov = coordinate.GetNumberOfValues(); - vtkm::cont::ArrayHandleConstant vectorAH = - vtkm::cont::make_ArrayHandleConstant(vector, nov); - - vtkm::worklet::WarpVector warpWorklet; - warpWorklet.Run(ds.GetCoordinateSystem(), vectorAH, scale, result); - auto resultPortal = result.ReadPortal(); - for (vtkm::Id i = 0; i < nov; i++) - { - for (vtkm::Id j = 0; j < 3; j++) - { - vtkm::FloatDefault ans = coordinate.ReadPortal().Get(i)[static_cast(j)] + - scale * vector[static_cast(j)]; - VTKM_TEST_ASSERT(test_equal(ans, resultPortal.Get(i)[static_cast(j)]), - " Wrong result for WarpVector worklet"); - } - } -} - -int UnitTestWarpVector(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestWarpVector, argc, argv); -} From b3327e544a76ef308cbe91317bb9456a8c823cff Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Wed, 2 Feb 2022 05:45:24 -0700 Subject: [PATCH 2/5] move auto field = ... around to minimize accidential capture --- .../field_transform/CoordinateSystemTransform.cxx | 10 ++++------ vtkm/filter/field_transform/PointElevation.cxx | 4 ++-- vtkm/filter/field_transform/PointTransform.cxx | 4 ++-- vtkm/filter/field_transform/WarpScalar.cxx | 4 ++-- vtkm/filter/field_transform/WarpVector.cxx | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/vtkm/filter/field_transform/CoordinateSystemTransform.cxx b/vtkm/filter/field_transform/CoordinateSystemTransform.cxx index 294d6f3da..c72d64ad5 100644 --- a/vtkm/filter/field_transform/CoordinateSystemTransform.cxx +++ b/vtkm/filter/field_transform/CoordinateSystemTransform.cxx @@ -47,19 +47,17 @@ vtkm::cont::DataSet CylindricalCoordinateTransform::DoExecute(const vtkm::cont:: //----------------------------------------------------------------------------- vtkm::cont::DataSet SphericalCoordinateTransform::DoExecute(const vtkm::cont::DataSet& inDataSet) { - auto field = this->GetFieldFromDataSet(inDataSet); - vtkm::cont::UnknownArrayHandle outArray; - auto resolveType = [&](const auto& concrete) { + auto resolveType = [&, this](const auto& concrete) { // use std::decay to remove const ref from the decltype of concrete. using T = typename std::decay_t::ValueType; vtkm::cont::ArrayHandle result; - vtkm::worklet::SphericalCoordinateTransform Worklet{ this->cartesianToSpherical }; - Worklet.Run(concrete, result); + vtkm::worklet::SphericalCoordinateTransform worklet{ this->cartesianToSpherical }; + worklet.Run(concrete, result); outArray = result; }; - this->CastAndCallVecField<3>(field, resolveType); + this->CastAndCallVecField<3>(this->GetFieldFromDataSet(inDataSet), resolveType); vtkm::cont::DataSet outDataSet = this->CreateResult(inDataSet, diff --git a/vtkm/filter/field_transform/PointElevation.cxx b/vtkm/filter/field_transform/PointElevation.cxx index 363c1bca4..b523890bd 100644 --- a/vtkm/filter/field_transform/PointElevation.cxx +++ b/vtkm/filter/field_transform/PointElevation.cxx @@ -26,7 +26,6 @@ VTKM_CONT PointElevation::PointElevation() //----------------------------------------------------------------------------- VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute(const vtkm::cont::DataSet& inDataSet) { - auto field = this->GetFieldFromDataSet(inDataSet); vtkm::cont::ArrayHandle outArray; auto resolveType = [&, this](const auto& concrete) { @@ -36,7 +35,8 @@ VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute(const vtkm::cont::DataSe concrete, outArray); }; - this->CastAndCallVecField<3>(field.GetData(), resolveType); + auto field = this->GetFieldFromDataSet(inDataSet); + this->CastAndCallVecField<3>(field, resolveType); return this->CreateResultField( inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray); diff --git a/vtkm/filter/field_transform/PointTransform.cxx b/vtkm/filter/field_transform/PointTransform.cxx index 09f74b883..d10785f14 100644 --- a/vtkm/filter/field_transform/PointTransform.cxx +++ b/vtkm/filter/field_transform/PointTransform.cxx @@ -39,15 +39,15 @@ inline VTKM_CONT bool PointTransform::GetChangeCoordinateSystem() const //----------------------------------------------------------------------------- VTKM_CONT vtkm::cont::DataSet PointTransform::DoExecute(const vtkm::cont::DataSet& inDataSet) { - auto field = this->GetFieldFromDataSet(inDataSet); vtkm::cont::UnknownArrayHandle outArray; auto resolveType = [&, this](const auto& concrete) { using T = typename std::decay_t::ValueType; vtkm::cont::ArrayHandle result; - this->Invoke(vtkm::worklet::PointTransform{ this->matrix }, field, result); + this->Invoke(vtkm::worklet::PointTransform{ this->matrix }, concrete, result); outArray = result; }; + auto field = this->GetFieldFromDataSet(inDataSet); this->CastAndCallVecField<3>(field.GetData(), resolveType); vtkm::cont::DataSet outData = this->CreateResultField( diff --git a/vtkm/filter/field_transform/WarpScalar.cxx b/vtkm/filter/field_transform/WarpScalar.cxx index fd39c6bce..bd0e5025c 100644 --- a/vtkm/filter/field_transform/WarpScalar.cxx +++ b/vtkm/filter/field_transform/WarpScalar.cxx @@ -36,7 +36,6 @@ VTKM_CONT vtkm::cont::DataSet WarpScalar::DoExecute(const vtkm::cont::DataSet& i // TODO: // Ken suggested to provide additional public interface for user to supply a single // value for const normal (and scale factor?). - auto field = this->GetFieldFromDataSet(inDataSet); vtkm::cont::Field normalF = inDataSet.GetField(this->NormalFieldName, this->NormalFieldAssociation); vtkm::cont::ArrayHandle normalArray; @@ -73,7 +72,8 @@ VTKM_CONT vtkm::cont::DataSet WarpScalar::DoExecute(const vtkm::cont::DataSet& i worklet.Run(concrete, normalArray, scaleFactorArray, this->ScaleAmount, result); outArray = result; }; - this->CastAndCallVecField<3>(field.GetData(), resolveType); + auto field = this->GetFieldFromDataSet(inDataSet); + this->CastAndCallVecField<3>(field, resolveType); return this->CreateResultField( inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray); diff --git a/vtkm/filter/field_transform/WarpVector.cxx b/vtkm/filter/field_transform/WarpVector.cxx index 5a2699f69..f0f315df4 100644 --- a/vtkm/filter/field_transform/WarpVector.cxx +++ b/vtkm/filter/field_transform/WarpVector.cxx @@ -28,7 +28,6 @@ VTKM_CONT WarpVector::WarpVector(vtkm::FloatDefault scale) //----------------------------------------------------------------------------- VTKM_CONT vtkm::cont::DataSet WarpVector::DoExecute(const vtkm::cont::DataSet& inDataSet) { - auto field = this->GetFieldFromDataSet(inDataSet); vtkm::cont::Field vectorF = inDataSet.GetField(this->VectorFieldName, this->VectorFieldAssociation); vtkm::cont::ArrayHandle vectorArray; @@ -60,6 +59,7 @@ VTKM_CONT vtkm::cont::DataSet WarpVector::DoExecute(const vtkm::cont::DataSet& i worklet.Run(concrete, vectorArray, this->Scale, result); outArray = result; }; + auto field = this->GetFieldFromDataSet(inDataSet); this->CastAndCallVecField<3>(field, resolveType); return this->CreateResultField( From 9958394fa6759c6fda66cfe617098cfbd35aefc0 Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Wed, 2 Feb 2022 09:52:51 -0700 Subject: [PATCH 3/5] tidy-up language usage and coding style conformation --- .../CoordinateSystemTransform.cxx | 12 +++++----- .../CoordinateSystemTransform.h | 12 +++++----- vtkm/filter/field_transform/FieldToColors.cxx | 4 ++-- vtkm/filter/field_transform/FieldToColors.h | 2 +- .../filter/field_transform/PointElevation.cxx | 4 ++-- .../filter/field_transform/PointTransform.cxx | 7 +++--- vtkm/filter/field_transform/WarpScalar.cxx | 4 ++-- vtkm/filter/field_transform/WarpScalar.h | 2 +- vtkm/filter/field_transform/WarpVector.cxx | 4 ++-- vtkm/filter/field_transform/WarpVector.h | 2 +- .../UnitTestCoordinateSystemTransform.cxx | 7 +++--- .../testing/UnitTestPointTransform.cxx | 19 ++++++++-------- .../testing/UnitTestWarpVectorFilter.cxx | 1 - .../worklet/CoordinateSystemTransform.h | 22 +++++++++---------- .../field_transform/worklet/PointTransform.h | 2 +- .../field_transform/worklet/WarpScalar.h | 2 +- .../field_transform/worklet/WarpVector.h | 2 +- 17 files changed, 52 insertions(+), 56 deletions(-) diff --git a/vtkm/filter/field_transform/CoordinateSystemTransform.cxx b/vtkm/filter/field_transform/CoordinateSystemTransform.cxx index c72d64ad5..41a2fdb6c 100644 --- a/vtkm/filter/field_transform/CoordinateSystemTransform.cxx +++ b/vtkm/filter/field_transform/CoordinateSystemTransform.cxx @@ -20,19 +20,17 @@ namespace field_transform //----------------------------------------------------------------------------- vtkm::cont::DataSet CylindricalCoordinateTransform::DoExecute(const vtkm::cont::DataSet& inDataSet) { - auto field = this->GetFieldFromDataSet(inDataSet); - vtkm::cont::UnknownArrayHandle outArray; auto resolveType = [&](const auto& concrete) { // use std::decay to remove const ref from the decltype of concrete. using T = typename std::decay_t::ValueType; vtkm::cont::ArrayHandle result; - vtkm::worklet::CylindricalCoordinateTransform Worklet{ this->cartesianToCylindrical }; - Worklet.Run(concrete, result); + vtkm::worklet::CylindricalCoordinateTransform worklet{ this->CartesianToCylindrical }; + worklet.Run(concrete, result); outArray = result; }; - this->CastAndCallVecField<3>(field, resolveType); + this->CastAndCallVecField<3>(this->GetFieldFromDataSet(inDataSet), resolveType); vtkm::cont::DataSet outDataSet = this->CreateResult(inDataSet, @@ -49,11 +47,11 @@ vtkm::cont::DataSet SphericalCoordinateTransform::DoExecute(const vtkm::cont::Da { vtkm::cont::UnknownArrayHandle outArray; - auto resolveType = [&, this](const auto& concrete) { + auto resolveType = [&](const auto& concrete) { // use std::decay to remove const ref from the decltype of concrete. using T = typename std::decay_t::ValueType; vtkm::cont::ArrayHandle result; - vtkm::worklet::SphericalCoordinateTransform worklet{ this->cartesianToSpherical }; + vtkm::worklet::SphericalCoordinateTransform worklet{ this->CartesianToSpherical }; worklet.Run(concrete, result); outArray = result; }; diff --git a/vtkm/filter/field_transform/CoordinateSystemTransform.h b/vtkm/filter/field_transform/CoordinateSystemTransform.h index cd800cc0f..2defa50f7 100644 --- a/vtkm/filter/field_transform/CoordinateSystemTransform.h +++ b/vtkm/filter/field_transform/CoordinateSystemTransform.h @@ -27,26 +27,26 @@ class VTKM_FILTER_FIELD_TRANSFORM_EXPORT CylindricalCoordinateTransform : public vtkm::filter::NewFilterField { public: - VTKM_CONT void SetCartesianToCylindrical() { cartesianToCylindrical = true; } - VTKM_CONT void SetCylindricalToCartesian() { cartesianToCylindrical = false; } + VTKM_CONT void SetCartesianToCylindrical() { CartesianToCylindrical = true; } + VTKM_CONT void SetCylindricalToCartesian() { CartesianToCylindrical = false; } private: VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; - bool cartesianToCylindrical = true; + bool CartesianToCylindrical = true; }; class VTKM_FILTER_FIELD_TRANSFORM_EXPORT SphericalCoordinateTransform : public vtkm::filter::NewFilterField { public: - VTKM_CONT void SetCartesianToSpherical() { cartesianToSpherical = true; } - VTKM_CONT void SetSphericalToCartesian() { cartesianToSpherical = false; } + VTKM_CONT void SetCartesianToSpherical() { CartesianToSpherical = true; } + VTKM_CONT void SetSphericalToCartesian() { CartesianToSpherical = false; } private: VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; - bool cartesianToSpherical = true; + bool CartesianToSpherical = true; }; } // namespace field_transform } // namespace filter diff --git a/vtkm/filter/field_transform/FieldToColors.cxx b/vtkm/filter/field_transform/FieldToColors.cxx index d202bff26..457ffad98 100644 --- a/vtkm/filter/field_transform/FieldToColors.cxx +++ b/vtkm/filter/field_transform/FieldToColors.cxx @@ -117,7 +117,7 @@ inline VTKM_CONT void FieldToColors::SetNumberOfSamplingPoints(vtkm::Int32 count //----------------------------------------------------------------------------- vtkm::cont::DataSet FieldToColors::DoExecute(const vtkm::cont::DataSet& input) { - auto field = this->GetFieldFromDataSet(input); + const auto& field = this->GetFieldFromDataSet(input); //If the table has been modified we need to rebuild our //sample tables @@ -138,7 +138,7 @@ vtkm::cont::DataSet FieldToColors::DoExecute(const vtkm::cont::DataSet& input) //We need to verify if the array is a vtkm::Vec vtkm::cont::UnknownArrayHandle outArray; - auto resolveType = [&, this](const auto& concrete) { + auto resolveType = [&](const auto& concrete) { // use std::decay to remove const ref from the decltype of concrete. using T = typename std::decay_t::ValueType; using IsVec = typename vtkm::VecTraits::HasMultipleComponents; diff --git a/vtkm/filter/field_transform/FieldToColors.h b/vtkm/filter/field_transform/FieldToColors.h index 155edcb1c..e68cc4a68 100644 --- a/vtkm/filter/field_transform/FieldToColors.h +++ b/vtkm/filter/field_transform/FieldToColors.h @@ -27,7 +27,7 @@ class VTKM_FILTER_FIELD_TRANSFORM_EXPORT FieldToColors : public vtkm::filter::Ne { public: VTKM_CONT - FieldToColors(const vtkm::cont::ColorTable& table = vtkm::cont::ColorTable()); + explicit FieldToColors(const vtkm::cont::ColorTable& table = vtkm::cont::ColorTable()); enum FieldToColorsInputMode { diff --git a/vtkm/filter/field_transform/PointElevation.cxx b/vtkm/filter/field_transform/PointElevation.cxx index b523890bd..dbdf16c07 100644 --- a/vtkm/filter/field_transform/PointElevation.cxx +++ b/vtkm/filter/field_transform/PointElevation.cxx @@ -28,14 +28,14 @@ VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute(const vtkm::cont::DataSe { vtkm::cont::ArrayHandle outArray; - auto resolveType = [&, this](const auto& concrete) { + auto resolveType = [&](const auto& concrete) { this->Invoke( vtkm::worklet::PointElevation{ this->LowPoint, this->HighPoint, this->RangeLow, this->RangeHigh }, concrete, outArray); }; - auto field = this->GetFieldFromDataSet(inDataSet); + const auto& field = this->GetFieldFromDataSet(inDataSet); this->CastAndCallVecField<3>(field, resolveType); return this->CreateResultField( diff --git a/vtkm/filter/field_transform/PointTransform.cxx b/vtkm/filter/field_transform/PointTransform.cxx index d10785f14..72ff99cc0 100644 --- a/vtkm/filter/field_transform/PointTransform.cxx +++ b/vtkm/filter/field_transform/PointTransform.cxx @@ -41,14 +41,15 @@ VTKM_CONT vtkm::cont::DataSet PointTransform::DoExecute(const vtkm::cont::DataSe { vtkm::cont::UnknownArrayHandle outArray; - auto resolveType = [&, this](const auto& concrete) { + auto resolveType = [&](const auto& concrete) { + // use std::decay to remove const ref from the decltype of concrete. using T = typename std::decay_t::ValueType; vtkm::cont::ArrayHandle result; this->Invoke(vtkm::worklet::PointTransform{ this->matrix }, concrete, result); outArray = result; }; - auto field = this->GetFieldFromDataSet(inDataSet); - this->CastAndCallVecField<3>(field.GetData(), resolveType); + const auto& field = this->GetFieldFromDataSet(inDataSet); + this->CastAndCallVecField<3>(field, resolveType); vtkm::cont::DataSet outData = this->CreateResultField( inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray); diff --git a/vtkm/filter/field_transform/WarpScalar.cxx b/vtkm/filter/field_transform/WarpScalar.cxx index bd0e5025c..0194ee71a 100644 --- a/vtkm/filter/field_transform/WarpScalar.cxx +++ b/vtkm/filter/field_transform/WarpScalar.cxx @@ -63,7 +63,7 @@ VTKM_CONT vtkm::cont::DataSet WarpScalar::DoExecute(const vtkm::cont::DataSet& i vtkm::cont::UnknownArrayHandle outArray; - auto resolveType = [&, this](const auto& concrete) { + auto resolveType = [&](const auto& concrete) { // We know ValueType is some form of Vec3 due to CastAndCallVecField using VecType = typename std::decay_t::ValueType; @@ -72,7 +72,7 @@ VTKM_CONT vtkm::cont::DataSet WarpScalar::DoExecute(const vtkm::cont::DataSet& i worklet.Run(concrete, normalArray, scaleFactorArray, this->ScaleAmount, result); outArray = result; }; - auto field = this->GetFieldFromDataSet(inDataSet); + const auto& field = this->GetFieldFromDataSet(inDataSet); this->CastAndCallVecField<3>(field, resolveType); return this->CreateResultField( diff --git a/vtkm/filter/field_transform/WarpScalar.h b/vtkm/filter/field_transform/WarpScalar.h index e4a5f2586..dae002f66 100644 --- a/vtkm/filter/field_transform/WarpScalar.h +++ b/vtkm/filter/field_transform/WarpScalar.h @@ -32,7 +32,7 @@ class VTKM_FILTER_FIELD_TRANSFORM_EXPORT WarpScalar : public vtkm::filter::NewFi { public: VTKM_CONT - WarpScalar(vtkm::FloatDefault scaleAmount); + explicit WarpScalar(vtkm::FloatDefault scaleAmount); //@{ /// Choose the secondary field to operate on. In the warp op A + B * diff --git a/vtkm/filter/field_transform/WarpVector.cxx b/vtkm/filter/field_transform/WarpVector.cxx index f0f315df4..cae7d9352 100644 --- a/vtkm/filter/field_transform/WarpVector.cxx +++ b/vtkm/filter/field_transform/WarpVector.cxx @@ -50,7 +50,7 @@ VTKM_CONT vtkm::cont::DataSet WarpVector::DoExecute(const vtkm::cont::DataSet& i vtkm::cont::UnknownArrayHandle outArray; - auto resolveType = [&, this](const auto& concrete) { + auto resolveType = [&](const auto& concrete) { // We know ValueType is some form of Vec3 due to CastAndCallVecField using VecType = typename std::decay_t::ValueType; @@ -59,7 +59,7 @@ VTKM_CONT vtkm::cont::DataSet WarpVector::DoExecute(const vtkm::cont::DataSet& i worklet.Run(concrete, vectorArray, this->Scale, result); outArray = result; }; - auto field = this->GetFieldFromDataSet(inDataSet); + const auto& field = this->GetFieldFromDataSet(inDataSet); this->CastAndCallVecField<3>(field, resolveType); return this->CreateResultField( diff --git a/vtkm/filter/field_transform/WarpVector.h b/vtkm/filter/field_transform/WarpVector.h index 40901a3ad..6650f4008 100644 --- a/vtkm/filter/field_transform/WarpVector.h +++ b/vtkm/filter/field_transform/WarpVector.h @@ -32,7 +32,7 @@ class VTKM_FILTER_FIELD_TRANSFORM_EXPORT WarpVector : public vtkm::filter::NewFi { public: VTKM_CONT - WarpVector(vtkm::FloatDefault scale); + explicit WarpVector(vtkm::FloatDefault scale); //@{ /// Choose the vector field to operate on. In the warp op A + B *scale, B is diff --git a/vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx b/vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx index 129fdc72f..65d24c8b8 100644 --- a/vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx @@ -11,7 +11,6 @@ #include #include -#include #include namespace @@ -71,9 +70,9 @@ vtkm::cont::DataSet MakeTestDataSet(const CoordinateType& cType) std::vector Phis = { eps, vtkm::TwoPif() / 4.0f, vtkm::TwoPif() / 3.0f, vtkm::TwoPif() / 2.0f, vtkm::TwoPif() - eps }; - for (std::size_t i = 0; i < Thetas.size(); i++) - for (std::size_t j = 0; j < Phis.size(); j++) - coordinates.push_back(vtkm::make_Vec(R, Thetas[i], Phis[j])); + for (float& Theta : Thetas) + for (float& Phi : Phis) + coordinates.push_back(vtkm::make_Vec(R, Theta, Phi)); } vtkm::Id numCells = (dim - 1) * (dim - 1); diff --git a/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx b/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx index 10da342df..151afa25c 100644 --- a/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx @@ -61,7 +61,7 @@ vtkm::cont::DataSet MakePointTransformTestDataSet() } void ValidatePointTransform(const vtkm::cont::CoordinateSystem& coords, - const std::string fieldName, + const std::string& fieldName, const vtkm::cont::DataSet& result, const vtkm::Matrix& matrix) { @@ -174,10 +174,10 @@ void TestPointTransform() angles.push_back(angleDist(randGenerator)); std::vector axes; - axes.push_back(vtkm::Vec3f(1, 0, 0)); - axes.push_back(vtkm::Vec3f(0, 1, 0)); - axes.push_back(vtkm::Vec3f(0, 0, 1)); - axes.push_back(vtkm::Vec3f(1, 1, 1)); + axes.emplace_back(1, 0, 0); + axes.emplace_back(0, 1, 0); + axes.emplace_back(0, 0, 1); + axes.emplace_back(1, 1, 1); axes.push_back(-axes[0]); axes.push_back(-axes[1]); axes.push_back(-axes[2]); @@ -185,12 +185,11 @@ void TestPointTransform() std::uniform_real_distribution axisDist(-1, 1); for (int i = 0; i < N; i++) - axes.push_back( - vtkm::Vec3f(axisDist(randGenerator), axisDist(randGenerator), axisDist(randGenerator))); + axes.emplace_back(axisDist(randGenerator), axisDist(randGenerator), axisDist(randGenerator)); - for (std::size_t i = 0; i < angles.size(); i++) - for (std::size_t j = 0; j < axes.size(); j++) - TestPointTransformRotation(ds, angles[i], axes[j]); + for (float& angle : angles) + for (auto& axe : axes) + TestPointTransformRotation(ds, angle, axe); } diff --git a/vtkm/filter/field_transform/testing/UnitTestWarpVectorFilter.cxx b/vtkm/filter/field_transform/testing/UnitTestWarpVectorFilter.cxx index 89f3c724d..f9649154d 100644 --- a/vtkm/filter/field_transform/testing/UnitTestWarpVectorFilter.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestWarpVectorFilter.cxx @@ -8,7 +8,6 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include #include #include diff --git a/vtkm/filter/field_transform/worklet/CoordinateSystemTransform.h b/vtkm/filter/field_transform/worklet/CoordinateSystemTransform.h index c6a44960f..3bb0a72cb 100644 --- a/vtkm/filter/field_transform/worklet/CoordinateSystemTransform.h +++ b/vtkm/filter/field_transform/worklet/CoordinateSystemTransform.h @@ -111,14 +111,14 @@ struct CarToSphere : public vtkm::worklet::WorkletMapField return vtkm::Vec(R, Theta, Phi); } }; -}; +} class CylindricalCoordinateTransform { public: VTKM_CONT - CylindricalCoordinateTransform(bool car2cyl) - : cartesianToCylindrical(car2cyl) + explicit CylindricalCoordinateTransform(bool car2cyl) + : CartesianToCylindrical(car2cyl) { } @@ -126,7 +126,7 @@ public: void Run(const vtkm::cont::ArrayHandle, InStorageType>& inPoints, vtkm::cont::ArrayHandle, OutStorageType>& outPoints) const { - if (cartesianToCylindrical) + if (CartesianToCylindrical) { vtkm::worklet::DispatcherMapField> dispatcher; dispatcher.Invoke(inPoints, outPoints); @@ -142,7 +142,7 @@ public: void Run(const vtkm::cont::CoordinateSystem& inPoints, vtkm::cont::ArrayHandle, CoordsStorageType>& outPoints) const { - if (cartesianToCylindrical) + if (CartesianToCylindrical) { vtkm::worklet::DispatcherMapField> dispatcher; dispatcher.Invoke(inPoints, outPoints); @@ -155,15 +155,15 @@ public: } private: - bool cartesianToCylindrical; + bool CartesianToCylindrical; }; class SphericalCoordinateTransform { public: VTKM_CONT - SphericalCoordinateTransform(bool car2sph) - : cartesianToSpherical(car2sph) + explicit SphericalCoordinateTransform(bool car2sph) + : CartesianToSpherical(car2sph) { } @@ -171,7 +171,7 @@ public: void Run(const vtkm::cont::ArrayHandle, InStorageType>& inPoints, vtkm::cont::ArrayHandle, OutStorageType>& outPoints) const { - if (cartesianToSpherical) + if (CartesianToSpherical) { vtkm::worklet::DispatcherMapField> dispatcher; dispatcher.Invoke(inPoints, outPoints); @@ -187,7 +187,7 @@ public: void Run(const vtkm::cont::CoordinateSystem& inPoints, vtkm::cont::ArrayHandle, CoordsStorageType>& outPoints) const { - if (cartesianToSpherical) + if (CartesianToSpherical) { vtkm::worklet::DispatcherMapField> dispatcher; dispatcher.Invoke(inPoints, outPoints); @@ -200,7 +200,7 @@ public: } private: - bool cartesianToSpherical; + bool CartesianToSpherical; }; } } // namespace vtkm::worklet diff --git a/vtkm/filter/field_transform/worklet/PointTransform.h b/vtkm/filter/field_transform/worklet/PointTransform.h index e852160c4..c956db6c8 100644 --- a/vtkm/filter/field_transform/worklet/PointTransform.h +++ b/vtkm/filter/field_transform/worklet/PointTransform.h @@ -28,7 +28,7 @@ public: using ExecutionSignature = _2(_1); VTKM_CONT - PointTransform(const vtkm::Matrix& m) + explicit PointTransform(const vtkm::Matrix& m) : matrix(m) { } diff --git a/vtkm/filter/field_transform/worklet/WarpScalar.h b/vtkm/filter/field_transform/worklet/WarpScalar.h index bae6e863b..8d3b03e5f 100644 --- a/vtkm/filter/field_transform/worklet/WarpScalar.h +++ b/vtkm/filter/field_transform/worklet/WarpScalar.h @@ -35,7 +35,7 @@ public: using ControlSignature = void(FieldIn, FieldIn, FieldIn, FieldOut); using ExecutionSignature = void(_1, _2, _3, _4); VTKM_CONT - WarpScalarImp(vtkm::FloatDefault scaleAmount) + explicit WarpScalarImp(vtkm::FloatDefault scaleAmount) : ScaleAmount(scaleAmount) { } diff --git a/vtkm/filter/field_transform/worklet/WarpVector.h b/vtkm/filter/field_transform/worklet/WarpVector.h index 06c7d60d4..559b3e42b 100644 --- a/vtkm/filter/field_transform/worklet/WarpVector.h +++ b/vtkm/filter/field_transform/worklet/WarpVector.h @@ -36,7 +36,7 @@ public: using ControlSignature = void(FieldIn, FieldIn, FieldOut); using ExecutionSignature = _3(_1, _2); VTKM_CONT - WarpVectorImp(vtkm::FloatDefault scale) + explicit WarpVectorImp(vtkm::FloatDefault scale) : Scale(scale) { } From 43dd4638ed477b13da5a79aa4ae941ea140014b2 Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Wed, 2 Feb 2022 13:20:04 -0700 Subject: [PATCH 4/5] use auto in range-based for loop --- .../testing/UnitTestCoordinateSystemTransform.cxx | 4 ++-- .../filter/field_transform/testing/UnitTestPointTransform.cxx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx b/vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx index 65d24c8b8..5270aa94c 100644 --- a/vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestCoordinateSystemTransform.cxx @@ -70,8 +70,8 @@ vtkm::cont::DataSet MakeTestDataSet(const CoordinateType& cType) std::vector Phis = { eps, vtkm::TwoPif() / 4.0f, vtkm::TwoPif() / 3.0f, vtkm::TwoPif() / 2.0f, vtkm::TwoPif() - eps }; - for (float& Theta : Thetas) - for (float& Phi : Phis) + for (auto& Theta : Thetas) + for (auto& Phi : Phis) coordinates.push_back(vtkm::make_Vec(R, Theta, Phi)); } diff --git a/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx b/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx index 151afa25c..dbd71e1a6 100644 --- a/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx @@ -187,7 +187,7 @@ void TestPointTransform() for (int i = 0; i < N; i++) axes.emplace_back(axisDist(randGenerator), axisDist(randGenerator), axisDist(randGenerator)); - for (float& angle : angles) + for (auto& angle : angles) for (auto& axe : axes) TestPointTransformRotation(ds, angle, axe); } From b8c1f5aac3b49bf3b31e59823b7f773b355eb7bd Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Wed, 2 Feb 2022 13:59:27 -0700 Subject: [PATCH 5/5] make calling to emplace_back type safe --- .../field_transform/testing/UnitTestPointTransform.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx b/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx index dbd71e1a6..5c53de261 100644 --- a/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx +++ b/vtkm/filter/field_transform/testing/UnitTestPointTransform.cxx @@ -174,10 +174,10 @@ void TestPointTransform() angles.push_back(angleDist(randGenerator)); std::vector axes; - axes.emplace_back(1, 0, 0); - axes.emplace_back(0, 1, 0); - axes.emplace_back(0, 0, 1); - axes.emplace_back(1, 1, 1); + axes.emplace_back(1.f, 0.f, 0.f); + axes.emplace_back(0.f, 1.f, 0.f); + axes.emplace_back(0.f, 0.f, 1.f); + axes.emplace_back(1.f, 1.f, 1.f); axes.push_back(-axes[0]); axes.push_back(-axes[1]); axes.push_back(-axes[2]);