Merge topic 'field_transform'

b8c1f5aac make calling to emplace_back type safe
43dd4638e use auto in range-based for loop
9958394fa tidy-up language usage and coding style conformation
b3327e544 move auto field = ... around to minimize accidential capture
455c20437 Migrate field_transform

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland <morelandkd@ornl.gov>
Merge-request: !2696
This commit is contained in:
Li-Ta Lo 2022-02-02 22:18:01 +00:00 committed by Kitware Robot
commit f3c65d3404
49 changed files with 1172 additions and 1711 deletions

@ -33,14 +33,14 @@
#include <vtkm/filter/Tetrahedralize.h>
#include <vtkm/filter/Triangulate.h>
#include <vtkm/filter/VertexClustering.h>
#include <vtkm/filter/WarpScalar.h>
#include <vtkm/filter/WarpVector.h>
#include <vtkm/filter/contour/Contour.h>
#include <vtkm/filter/entity_extraction/ExternalFaces.h>
#include <vtkm/filter/entity_extraction/Threshold.h>
#include <vtkm/filter/entity_extraction/ThresholdPoints.h>
#include <vtkm/filter/field_conversion/CellAverage.h>
#include <vtkm/filter/field_conversion/PointAverage.h>
#include <vtkm/filter/field_transform/WarpScalar.h>
#include <vtkm/filter/field_transform/WarpVector.h>
#include <vtkm/filter/vector_analysis/Gradient.h>
#include <vtkm/filter/vector_analysis/VectorMagnitude.h>
@ -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);

@ -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

@ -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 <vtkm/filter/FilterField.h>
#include <vtkm/worklet/CoordinateSystemTransform.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/field_transform/CoordinateSystemTransform.h>
namespace vtkm
{
namespace filter
{
/// \brief
///
/// Generate a coordinate transformation on coordiantes from a dataset.
class CylindricalCoordinateTransform
: public vtkm::filter::FilterField<CylindricalCoordinateTransform>
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 <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& 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<SphericalCoordinateTransform>
{
public:
using SupportedTypes = vtkm::TypeListFieldVec3;
VTKM_CONT
SphericalCoordinateTransform() = default;
VTKM_CONT void SetCartesianToSpherical() { Worklet.SetCartesianToSpherical(); }
VTKM_CONT void SetSphericalToCartesian() { Worklet.SetSphericalToCartesian(); }
template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<T, StorageType>&,
const vtkm::filter::FieldMetadata&,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy);
private:
vtkm::worklet::SphericalCoordinateTransform Worklet;
};
}
} // namespace vtkm::filter
#include <vtkm/filter/CoordinateSystemTransform.hxx>
#endif // vtk_m_filter_CoordianteSystemTransform_h
#endif //vtk_m_filter_CoordinateSystemTransform_h

@ -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 <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet CylindricalCoordinateTransform::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& vtkmNotUsed(fieldMetadata),
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
vtkm::cont::ArrayHandle<T> 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 <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet SphericalCoordinateTransform::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& vtkmNotUsed(fieldMetadata),
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
vtkm::cont::ArrayHandle<T> 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

@ -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 <vtkm/cont/ColorTable.h>
#include <vtkm/filter/FilterField.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/field_transform/FieldToColors.h>
namespace vtkm
{
namespace filter
{
/// \brief Convert an arbitrary field to an RGB or RGBA field
///
class FieldToColors : public vtkm::filter::FilterField<FieldToColors>
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 <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> 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 <vtkm/filter/FieldToColors.hxx>
#endif // vtk_m_filter_FieldToColors_h
#endif //vtk_m_filter_FieldToColors_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 <vtkm/filter/FilterField.h>
#include <vtkm/worklet/PointElevation.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/field_transform/PointElevation.h>
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<PointElevation>
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 <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> 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 <vtkm/filter/PointElevation.hxx>
#endif // vtk_m_filter_PointElevation_h
#endif //vtk_m_filter_PointElevation_h

@ -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 <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet PointElevation::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
vtkm::cont::ArrayHandle<vtkm::Float64> 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

@ -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 <vtkm/filter/FilterField.h>
#include <vtkm/worklet/PointTransform.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/field_transform/PointTransform.h>
namespace vtkm
{
namespace filter
{
/// \brief
///
/// Generate scalar field from a dataset.
class PointTransform : public vtkm::filter::FilterField<PointTransform>
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<vtkm::FloatDefault, 4, 4>& mtx);
void SetChangeCoordinateSystem(bool flag);
bool GetChangeCoordinateSystem() const;
template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
private:
vtkm::worklet::PointTransform<vtkm::FloatDefault> 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 <vtkm/filter/PointTransform.hxx>
#endif
#endif // vtk_m_filter_PointTransform_h
#endif //vtk_m_filter_PointTransform_h

@ -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 <vtkm/filter/PointTransform.h>
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<vtkm::FloatDefault, 4, 4>& 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 <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet PointTransform::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
vtkm::cont::ArrayHandle<T> 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

@ -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 <vtkm/filter/FilterField.h>
#include <vtkm/worklet/WarpScalar.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/field_transform/WarpScalar.h>
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<WarpScalar>
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<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_32>::StorageTag,
vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_64>::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 <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> 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 <vtkm/filter/WarpScalar.hxx>
}
} // namespace vtkm::filter
#endif // vtk_m_filter_WarpScalar_h
#endif //vtk_m_filter_WarpScalar_h

@ -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<WarpScalar>()
, Worklet()
, NormalFieldName("normal")
, NormalFieldAssociation(vtkm::cont::Field::Association::ANY)
, ScalarFactorFieldName("scalarfactor")
, ScalarFactorFieldAssociation(vtkm::cont::Field::Association::ANY)
, ScaleAmount(scaleAmount)
{
this->SetOutputFieldName("warpscalar");
}
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet WarpScalar::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
using vecType = vtkm::Vec<T, 3>;
vtkm::cont::Field normalF =
inDataSet.GetField(this->NormalFieldName, this->NormalFieldAssociation);
vtkm::cont::Field sfF =
inDataSet.GetField(this->ScalarFactorFieldName, this->ScalarFactorFieldAssociation);
vtkm::cont::ArrayHandle<vecType> result;
this->Worklet.Run(field,
vtkm::filter::ApplyPolicyFieldOfType<vecType>(normalF, policy, *this),
vtkm::filter::ApplyPolicyFieldOfType<T>(sfF, policy, *this),
this->ScaleAmount,
result);
return CreateResult(inDataSet, result, this->GetOutputFieldName(), fieldMetadata);
}
}
}
#endif

@ -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 <vtkm/filter/FilterField.h>
#include <vtkm/worklet/WarpVector.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/field_transform/WarpVector.h>
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<WarpVector>
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<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_32>::StorageTag,
vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_64>::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 <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> 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 <vtkm/filter/WarpVector.hxx>
}
} // namespace vtkm::filter
#endif // vtk_m_filter_WarpVector_h
#endif //vtk_m_filter_WarpVector_h

@ -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<WarpVector>()
, Worklet()
, VectorFieldName("normal")
, VectorFieldAssociation(vtkm::cont::Field::Association::ANY)
, Scale(scale)
{
this->SetOutputFieldName("warpvector");
}
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet WarpVector::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
using vecType = vtkm::Vec<T, 3>;
vtkm::cont::Field vectorF =
inDataSet.GetField(this->VectorFieldName, this->VectorFieldAssociation);
vtkm::cont::ArrayHandle<vecType> result;
this->Worklet.Run(field,
vtkm::filter::ApplyPolicyFieldOfType<vecType>(vectorF, policy, *this),
this->Scale,
result);
return CreateResult(inDataSet, result, this->GetOutputFieldName(), fieldMetadata);
}
}
}
#endif

@ -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)

@ -0,0 +1,71 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/filter/field_transform/CoordinateSystemTransform.h>
#include <vtkm/filter/field_transform/worklet/CoordinateSystemTransform.h>
namespace vtkm
{
namespace filter
{
namespace field_transform
{
//-----------------------------------------------------------------------------
vtkm::cont::DataSet CylindricalCoordinateTransform::DoExecute(const vtkm::cont::DataSet& 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<decltype(concrete)>::ValueType;
vtkm::cont::ArrayHandle<T> result;
vtkm::worklet::CylindricalCoordinateTransform worklet{ this->CartesianToCylindrical };
worklet.Run(concrete, result);
outArray = result;
};
this->CastAndCallVecField<3>(this->GetFieldFromDataSet(inDataSet), 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)
{
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<decltype(concrete)>::ValueType;
vtkm::cont::ArrayHandle<T> result;
vtkm::worklet::SphericalCoordinateTransform worklet{ this->CartesianToSpherical };
worklet.Run(concrete, result);
outArray = result;
};
this->CastAndCallVecField<3>(this->GetFieldFromDataSet(inDataSet), 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

@ -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 <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/field_transform/vtkm_filter_field_transform_export.h>
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

@ -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 <vtkm/VecTraits.h>
#include <vtkm/cont/ColorTableMap.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/filter/field_transform/FieldToColors.h>
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<FieldToColors>()
, 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 <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet FieldToColors::DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& inField,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy>)
vtkm::cont::DataSet FieldToColors::DoExecute(const vtkm::cont::DataSet& input)
{
const 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 = [&](const auto& concrete) {
// use std::decay to remove const ref from the decltype of concrete.
using T = typename std::decay_t<decltype(concrete)>::ValueType;
using IsVec = typename vtkm::VecTraits<T>::HasMultipleComponents;
using IsVec = typename vtkm::VecTraits<T>::HasMultipleComponents;
if (this->OutputMode == RGBA)
{
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> 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<vtkm::Vec4ui_8> 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<vtkm::Vec3ui_8> output;
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> 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<vtkm::TypeListField, VTKM_DEFAULT_STORAGE_LIST>(
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

@ -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 <vtkm/cont/ColorTable.h>
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/field_transform/vtkm_filter_field_transform_export.h>
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
explicit 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

@ -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 <vtkm/filter/field_transform/PointElevation.h>
#include <vtkm/filter/field_transform/worklet/PointElevation.h>
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)
{
vtkm::cont::ArrayHandle<vtkm::Float64> outArray;
auto resolveType = [&](const auto& concrete) {
this->Invoke(
vtkm::worklet::PointElevation{
this->LowPoint, this->HighPoint, this->RangeLow, this->RangeHigh },
concrete,
outArray);
};
const auto& field = this->GetFieldFromDataSet(inDataSet);
this->CastAndCallVecField<3>(field, resolveType);
return this->CreateResultField(
inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray);
}
} // namespace field_transform
} // namespace filter
} // namespace vtkm

@ -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 <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/field_transform/vtkm_filter_field_transform_export.h>
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

@ -0,0 +1,68 @@
//============================================================================
// 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 <vtkm/filter/field_transform/PointTransform.h>
#include <vtkm/filter/field_transform/worklet/PointTransform.h>
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)
{
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<decltype(concrete)>::ValueType;
vtkm::cont::ArrayHandle<T> result;
this->Invoke(vtkm::worklet::PointTransform{ this->matrix }, concrete, result);
outArray = result;
};
const auto& field = this->GetFieldFromDataSet(inDataSet);
this->CastAndCallVecField<3>(field, 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

@ -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 <vtkm/Matrix.h>
#include <vtkm/Transform3D.h>
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/field_transform/vtkm_filter_field_transform_export.h>
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<vtkm::FloatDefault, 3>& v)
{
SetTranslation(v[0], v[1], v[2]);
}
//Rotation
VTKM_CONT void SetRotation(const vtkm::FloatDefault& angleDegrees,
const vtkm::Vec<vtkm::FloatDefault, 3>& 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<vtkm::FloatDefault, 3>& v)
{
matrix = vtkm::Transform3DScale(v[0], v[1], v[2]);
}
//General transformation
VTKM_CONT
void SetTransform(const vtkm::Matrix<vtkm::FloatDefault, 4, 4>& 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<vtkm::FloatDefault, 4, 4> matrix;
bool ChangeCoordinateSystem = true;
};
}
}
} // namespace vtkm::filter
#endif // vtk_m_filter_field_transform_PointTransform_h

@ -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 <vtkm/cont/ArrayCopy.h>
#include <vtkm/filter/field_transform/WarpScalar.h>
#include <vtkm/filter/field_transform/worklet/WarpScalar.h>
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<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_32>::StorageTag,
// vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_64>::StorageTag>;
// TODO:
// Ken suggested to provide additional public interface for user to supply a single
// value for const normal (and scale factor?).
vtkm::cont::Field normalF =
inDataSet.GetField(this->NormalFieldName, this->NormalFieldAssociation);
vtkm::cont::ArrayHandle<vtkm::Vec3f> normalArray;
if (normalF.GetData().CanConvert<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_32>>())
{
vtkm::Vec3f_32 norm =
normalF.GetData().AsArrayHandle<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_32>>().GetValue();
normalArray.AllocateAndFill(normalF.GetData().GetNumberOfValues(), vtkm::Vec3f(norm));
}
else if (normalF.GetData().CanConvert<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_64>>())
{
vtkm::Vec3f_64 norm =
normalF.GetData().AsArrayHandle<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_64>>().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<vtkm::FloatDefault> scaleFactorArray;
vtkm::cont::ArrayCopyShallowIfPossible(sfF.GetData(), scaleFactorArray);
vtkm::cont::UnknownArrayHandle outArray;
auto resolveType = [&](const auto& concrete) {
// We know ValueType is some form of Vec3 due to CastAndCallVecField
using VecType = typename std::decay_t<decltype(concrete)>::ValueType;
vtkm::cont::ArrayHandle<VecType> result;
vtkm::worklet::WarpScalar worklet;
worklet.Run(concrete, normalArray, scaleFactorArray, this->ScaleAmount, result);
outArray = result;
};
const auto& field = this->GetFieldFromDataSet(inDataSet);
this->CastAndCallVecField<3>(field, resolveType);
return this->CreateResultField(
inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray);
}
} // namespace field_transform
} // namespace filter
} // namespace vtkm

@ -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 <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/field_transform/vtkm_filter_field_transform_export.h>
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
explicit 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

@ -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 <vtkm/cont/ArrayCopy.h>
#include <vtkm/filter/field_transform/WarpVector.h>
#include <vtkm/filter/field_transform/worklet/WarpVector.h>
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)
{
vtkm::cont::Field vectorF =
inDataSet.GetField(this->VectorFieldName, this->VectorFieldAssociation);
vtkm::cont::ArrayHandle<vtkm::Vec3f> vectorArray;
if (vectorF.GetData().CanConvert<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_32>>())
{
vtkm::Vec3f_32 norm =
vectorF.GetData().AsArrayHandle<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_32>>().GetValue();
vectorArray.AllocateAndFill(vectorF.GetData().GetNumberOfValues(), vtkm::Vec3f(norm));
}
else if (vectorF.GetData().CanConvert<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_64>>())
{
vtkm::Vec3f_64 norm =
vectorF.GetData().AsArrayHandle<vtkm::cont::ArrayHandleConstant<vtkm::Vec3f_64>>().GetValue();
vectorArray.AllocateAndFill(vectorF.GetData().GetNumberOfValues(), vtkm::Vec3f(norm));
}
else
{
vtkm::cont::ArrayCopyShallowIfPossible(vectorF.GetData(), vectorArray);
}
vtkm::cont::UnknownArrayHandle outArray;
auto resolveType = [&](const auto& concrete) {
// We know ValueType is some form of Vec3 due to CastAndCallVecField
using VecType = typename std::decay_t<decltype(concrete)>::ValueType;
vtkm::cont::ArrayHandle<VecType> result;
vtkm::worklet::WarpVector worklet;
worklet.Run(concrete, vectorArray, this->Scale, result);
outArray = result;
};
const auto& field = this->GetFieldFromDataSet(inDataSet);
this->CastAndCallVecField<3>(field, resolveType);
return this->CreateResultField(
inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray);
}
} // namespace field_transform
} // namespace filter
} // namespace vtkm

@ -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 <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/field_transform/vtkm_filter_field_transform_export.h>
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
explicit 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

@ -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
)

@ -13,7 +13,7 @@
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/io/VTKDataSetReader.h>
#include <vtkm/filter/PointTransform.h>
#include <vtkm/filter/field_transform/PointTransform.h>
#include <vtkm/filter/vector_analysis/VectorMagnitude.h>
#include <vtkm/rendering/testing/RenderTest.h>
@ -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));

@ -9,9 +9,8 @@
//============================================================================
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/CoordinateSystemTransform.h>
#include <vtkm/filter/field_transform/CoordinateSystemTransform.h>
#include <string>
#include <vector>
namespace
@ -71,9 +70,9 @@ vtkm::cont::DataSet MakeTestDataSet(const CoordinateType& cType)
std::vector<vtkm::FloatDefault> 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 (auto& Theta : Thetas)
for (auto& Phi : Phis)
coordinates.push_back(vtkm::make_Vec(R, Theta, Phi));
}
vtkm::Id numCells = (dim - 1) * (dim - 1);
@ -134,7 +133,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 +157,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);

@ -8,7 +8,7 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/filter/FieldToColors.h>
#include <vtkm/filter/field_transform/FieldToColors.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
@ -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");

@ -9,7 +9,7 @@
//============================================================================
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/PointElevation.h>
#include <vtkm/filter/field_transform/PointElevation.h>
#include <vector>
@ -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);

@ -9,7 +9,7 @@
//============================================================================
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/PointTransform.h>
#include <vtkm/filter/field_transform/PointTransform.h>
#include <random>
#include <string>
@ -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<vtkm::FloatDefault, 4, 4>& matrix)
{
@ -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);
@ -174,10 +174,10 @@ void TestPointTransform()
angles.push_back(angleDist(randGenerator));
std::vector<vtkm::Vec3f> 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.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]);
@ -185,12 +185,11 @@ void TestPointTransform()
std::uniform_real_distribution<vtkm::FloatDefault> 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 (auto& angle : angles)
for (auto& axe : axes)
TestPointTransformRotation(ds, angle, axe);
}

@ -8,11 +8,9 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/WarpScalar.h>
#include <vtkm/filter/field_transform/WarpScalar.h>
#include <random>
#include <vector>
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");

@ -8,9 +8,8 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/WarpVector.h>
#include <vtkm/filter/field_transform/WarpVector.h>
#include <random>
#include <vector>
@ -51,7 +50,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 +88,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 +97,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);

@ -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})

@ -111,25 +111,22 @@ struct CarToSphere : public vtkm::worklet::WorkletMapField
return vtkm::Vec<T, 3>(R, Theta, Phi);
}
};
};
}
class CylindricalCoordinateTransform
{
public:
VTKM_CONT
CylindricalCoordinateTransform()
: cartesianToCylindrical(true)
explicit CylindricalCoordinateTransform(bool car2cyl)
: CartesianToCylindrical(car2cyl)
{
}
VTKM_CONT void SetCartesianToCylindrical() { cartesianToCylindrical = true; }
VTKM_CONT void SetCylindricalToCartesian() { cartesianToCylindrical = false; }
template <typename T, typename InStorageType, typename OutStorageType>
void Run(const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, InStorageType>& inPoints,
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, OutStorageType>& outPoints) const
{
if (cartesianToCylindrical)
if (CartesianToCylindrical)
{
vtkm::worklet::DispatcherMapField<detail::CarToCyl<T>> dispatcher;
dispatcher.Invoke(inPoints, outPoints);
@ -145,7 +142,7 @@ public:
void Run(const vtkm::cont::CoordinateSystem& inPoints,
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, CoordsStorageType>& outPoints) const
{
if (cartesianToCylindrical)
if (CartesianToCylindrical)
{
vtkm::worklet::DispatcherMapField<detail::CarToCyl<T>> dispatcher;
dispatcher.Invoke(inPoints, outPoints);
@ -158,21 +155,18 @@ public:
}
private:
bool cartesianToCylindrical;
bool CartesianToCylindrical;
};
class SphericalCoordinateTransform
{
public:
VTKM_CONT
SphericalCoordinateTransform()
: CartesianToSpherical(true)
explicit SphericalCoordinateTransform(bool car2sph)
: CartesianToSpherical(car2sph)
{
}
VTKM_CONT void SetCartesianToSpherical() { CartesianToSpherical = true; }
VTKM_CONT void SetSphericalToCartesian() { CartesianToSpherical = false; }
template <typename T, typename InStorageType, typename OutStorageType>
void Run(const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, InStorageType>& inPoints,
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, OutStorageType>& outPoints) const

@ -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

@ -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 <vtkm/Math.h>
#include <vtkm/Matrix.h>
#include <vtkm/Transform3D.h>
#include <vtkm/worklet/WorkletMapField.h>
namespace vtkm
{
namespace worklet
{
class PointTransform : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = _2(_1);
VTKM_CONT
explicit PointTransform(const vtkm::Matrix<vtkm::FloatDefault, 4, 4>& m)
: matrix(m)
{
}
//Functor
VTKM_EXEC
vtkm::Vec<vtkm::FloatDefault, 3> operator()(const vtkm::Vec<vtkm::FloatDefault, 3>& vec) const
{
return vtkm::Transform3DPoint(matrix, vec);
}
private:
const vtkm::Matrix<vtkm::FloatDefault, 4, 4> matrix;
};
}
} // namespace vtkm::worklet
#endif // vtk_m_worklet_PointTransform_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)
{
}

@ -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)
{
}

@ -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
)

@ -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

@ -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 <vtkm/Math.h>
#include <vtkm/Matrix.h>
#include <vtkm/Transform3D.h>
#include <vtkm/worklet/WorkletMapField.h>
namespace vtkm
{
namespace worklet
{
template <typename T>
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<T, 3>& v) { SetTranslation(v[0], v[1], v[2]); }
//Rotation
VTKM_CONT void SetRotation(const T& angleDegrees, const vtkm::Vec<T, 3>& 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<T, 3>& v)
{
matrix = vtkm::Transform3DScale(v[0], v[1], v[2]);
}
//General transformation
VTKM_CONT
void SetTransform(const vtkm::Matrix<T, 4, 4>& mtx) { matrix = mtx; }
//Functor
VTKM_EXEC
vtkm::Vec<T, 3> operator()(const vtkm::Vec<T, 3>& vec) const
{
return vtkm::Transform3DPoint(matrix, vec);
}
private:
vtkm::Matrix<T, 4, 4> matrix;
};
}
} // namespace vtkm::worklet
#endif // vtk_m_worklet_PointTransform_h

@ -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
)

@ -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 <vtkm/cont/CellSetExplicit.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/worklet/CoordinateSystemTransform.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <random>
#include <vector>
namespace
{
std::mt19937 randGenerator;
enum CoordinateType
{
CART = 0,
CYL,
SPH
};
vtkm::cont::DataSet MakeTestDataSet(const CoordinateType& cType)
{
vtkm::cont::DataSet dataSet;
std::vector<vtkm::Vec3f> coordinates;
const vtkm::Id dim = 5;
if (cType == CART)
{
for (vtkm::Id j = 0; j < dim; ++j)
{
vtkm::FloatDefault z =
static_cast<vtkm::FloatDefault>(j) / static_cast<vtkm::FloatDefault>(dim - 1);
for (vtkm::Id i = 0; i < dim; ++i)
{
vtkm::FloatDefault x =
static_cast<vtkm::FloatDefault>(i) / static_cast<vtkm::FloatDefault>(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<vtkm::FloatDefault>(j) / static_cast<vtkm::FloatDefault>(dim - 1);
for (vtkm::Id i = 0; i < dim; i++)
{
vtkm::FloatDefault Theta = vtkm::TwoPif() *
(static_cast<vtkm::FloatDefault>(i) / static_cast<vtkm::FloatDefault>(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<float>();
std::vector<vtkm::FloatDefault> Thetas = {
eps, vtkm::Pif() / 4, vtkm::Pif() / 3, vtkm::Pif() / 2, vtkm::Pif() - eps
};
std::vector<vtkm::FloatDefault> 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<vtkm::Id>(
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<vtkm::Vec3f>& transform,
const vtkm::cont::ArrayHandle<vtkm::Vec3f>& doubleTransform,
const std::vector<bool>& 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<std::size_t>(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<vtkm::Vec3f> carToCylPts;
vtkm::cont::ArrayHandle<vtkm::Vec3f> 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<vtkm::Vec3f> 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<vtkm::Vec3f> 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<vtkm::Vec3f> 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);
}

@ -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 <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/PointElevation.h>
#include <vtkm/cont/CellSetExplicit.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vector>
namespace
{
vtkm::cont::DataSet MakePointElevationTestDataSet()
{
vtkm::cont::DataSet dataSet;
std::vector<vtkm::Vec3f_32> coordinates;
const vtkm::Id dim = 5;
for (vtkm::Id j = 0; j < dim; ++j)
{
vtkm::Float32 z = static_cast<vtkm::Float32>(j) / static_cast<vtkm::Float32>(dim - 1);
for (vtkm::Id i = 0; i < dim; ++i)
{
vtkm::Float32 x = static_cast<vtkm::Float32>(i) / static_cast<vtkm::Float32>(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<vtkm::Id>(
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<vtkm::Float32> result;
vtkm::worklet::PointElevation pointElevationWorklet;
pointElevationWorklet.SetLowPoint(vtkm::make_Vec<vtkm::Float64>(0.0, 0.0, 0.0));
pointElevationWorklet.SetHighPoint(vtkm::make_Vec<vtkm::Float64>(0.0, 1.0, 0.0));
pointElevationWorklet.SetRange(0.0, 2.0);
vtkm::worklet::DispatcherMapField<vtkm::worklet::PointElevation> 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);
}

@ -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 <vtkm/cont/CellSetExplicit.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/PointTransform.h>
#include <random>
#include <vector>
namespace
{
std::mt19937 randGenerator;
vtkm::cont::DataSet MakePointTransformTestDataSet()
{
vtkm::cont::DataSet dataSet;
std::vector<vtkm::Vec3f> coordinates;
const vtkm::Id dim = 5;
for (vtkm::Id j = 0; j < dim; ++j)
{
vtkm::FloatDefault z =
static_cast<vtkm::FloatDefault>(j) / static_cast<vtkm::FloatDefault>(dim - 1);
for (vtkm::Id i = 0; i < dim; ++i)
{
vtkm::FloatDefault x =
static_cast<vtkm::FloatDefault>(i) / static_cast<vtkm::FloatDefault>(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<vtkm::Id>(
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<vtkm::Vec3f>& result,
const vtkm::Matrix<vtkm::FloatDefault, 4, 4>& 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<vtkm::Vec3f> result;
vtkm::worklet::PointTransform<vtkm::FloatDefault> worklet;
worklet.SetTranslation(trans);
vtkm::worklet::DispatcherMapField<vtkm::worklet::PointTransform<vtkm::FloatDefault>> 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<vtkm::Vec3f> result;
vtkm::worklet::PointTransform<vtkm::FloatDefault> worklet;
worklet.SetScale(scale);
vtkm::worklet::DispatcherMapField<vtkm::worklet::PointTransform<vtkm::FloatDefault>> 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<vtkm::Vec3f> result;
vtkm::worklet::PointTransform<vtkm::FloatDefault> worklet;
worklet.SetRotation(angle, axis);
vtkm::worklet::DispatcherMapField<vtkm::worklet::PointTransform<vtkm::FloatDefault>> 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<vtkm::FloatDefault> 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<vtkm::FloatDefault> 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<vtkm::FloatDefault> angles;
std::uniform_real_distribution<vtkm::FloatDefault> angleDist(0, 360);
for (int i = 0; i < N; i++)
angles.push_back(angleDist(randGenerator));
std::vector<vtkm::Vec3f> 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<vtkm::FloatDefault> 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);
}

@ -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 <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WarpScalar.h>
#include <vtkm/cont/CellSetExplicit.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vector>
namespace
{
template <typename T>
vtkm::cont::DataSet MakeWarpScalarTestDataSet()
{
vtkm::cont::DataSet dataSet;
std::vector<vtkm::Vec<T, 3>> coordinates;
std::vector<T> scaleFactor;
const vtkm::Id dim = 5;
for (vtkm::Id i = 0; i < dim; ++i)
{
T z = static_cast<T>(i);
for (vtkm::Id j = 0; j < dim; ++j)
{
T x = static_cast<T>(j);
T y = static_cast<T>(j + 1);
coordinates.push_back(vtkm::make_Vec(x, y, z));
scaleFactor.push_back(static_cast<T>(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>();
vtkm::FloatDefault scaleAmount = 2;
vtkm::cont::ArrayHandle<vecType> result;
vecType normal = vtkm::make_Vec<vtkm::FloatDefault>(static_cast<vtkm::FloatDefault>(0.0),
static_cast<vtkm::FloatDefault>(0.0),
static_cast<vtkm::FloatDefault>(1.0));
auto coordinate = ds.GetCoordinateSystem().GetDataAsMultiplexer();
vtkm::Id nov = coordinate.GetNumberOfValues();
vtkm::cont::ArrayHandleConstant<vecType> normalAH =
vtkm::cont::make_ArrayHandleConstant(normal, nov);
vtkm::cont::ArrayHandle<vtkm::FloatDefault> scaleFactorArray;
auto scaleFactor = ds.GetField("scalefactor")
.GetData()
.ResetTypes<vtkm::TypeListFieldScalar, VTKM_DEFAULT_STORAGE_LIST>();
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<vtkm::IdComponent>(j)] +
scaleAmount * normal[static_cast<vtkm::IdComponent>(j)] * sFAPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(ans, resultPortal.Get(i)[static_cast<vtkm::IdComponent>(j)]),
" Wrong result for WarpVector worklet");
}
}
}
int UnitTestWarpScalar(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestWarpScalar, argc, argv);
}

@ -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 <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WarpVector.h>
#include <vtkm/cont/CellSetExplicit.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vector>
namespace
{
template <typename T>
vtkm::cont::DataSet MakeWarpVectorTestDataSet()
{
vtkm::cont::DataSet dataSet;
std::vector<vtkm::Vec<T, 3>> coordinates;
const vtkm::Id dim = 5;
for (vtkm::Id j = 0; j < dim; ++j)
{
T z = static_cast<T>(j) / static_cast<T>(dim - 1);
for (vtkm::Id i = 0; i < dim; ++i)
{
T x = static_cast<T>(i) / static_cast<T>(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<vtkm::Id>(
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::FloatDefault>();
vtkm::cont::ArrayHandle<vecType> result;
vtkm::FloatDefault scale = 2;
vecType vector = vtkm::make_Vec<vtkm::FloatDefault>(static_cast<vtkm::FloatDefault>(0.0),
static_cast<vtkm::FloatDefault>(0.0),
static_cast<vtkm::FloatDefault>(2.0));
auto coordinate = ds.GetCoordinateSystem().GetDataAsMultiplexer();
vtkm::Id nov = coordinate.GetNumberOfValues();
vtkm::cont::ArrayHandleConstant<vecType> 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<vtkm::IdComponent>(j)] +
scale * vector[static_cast<vtkm::IdComponent>(j)];
VTKM_TEST_ASSERT(test_equal(ans, resultPortal.Get(i)[static_cast<vtkm::IdComponent>(j)]),
" Wrong result for WarpVector worklet");
}
}
}
int UnitTestWarpVector(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestWarpVector, argc, argv);
}