Merge branch 'master' into field_conversion

# Conflicts:
#	benchmarking/BenchmarkFilters.cxx
#	vtkm/filter/CMakeLists.txt
#	vtkm/filter/testing/UnitTestSplitSharpEdgesFilter.cxx
This commit is contained in:
Li-Ta Lo 2022-01-31 14:08:02 -07:00
commit 8113d15ef7
75 changed files with 879 additions and 1724 deletions

@ -1,7 +1,7 @@
VTKm License Version 1.7
========================================================================
Copyright (c) 2014-2021
Copyright (c) 2014-2022
Kitware Inc.,
National Technology & Engineering Solutions of Sandia, LLC (NTESS),
UT-Battelle, LLC.,

@ -13,6 +13,7 @@
#include <vtkm/Math.h>
#include <vtkm/Range.h>
#include <vtkm/VecTraits.h>
#include <vtkm/VectorAnalysis.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
@ -28,11 +29,9 @@
#include <vtkm/cont/internal/OptionParser.h>
#include <vtkm/filter/FieldSelection.h>
#include <vtkm/filter/Gradient.h>
#include <vtkm/filter/PolicyBase.h>
#include <vtkm/filter/Tetrahedralize.h>
#include <vtkm/filter/Triangulate.h>
#include <vtkm/filter/VectorMagnitude.h>
#include <vtkm/filter/VertexClustering.h>
#include <vtkm/filter/WarpScalar.h>
#include <vtkm/filter/WarpVector.h>
@ -42,6 +41,8 @@
#include <vtkm/filter/entity_extraction/ThresholdPoints.h>
#include <vtkm/filter/field_conversion/CellAverage.h>
#include <vtkm/filter/field_conversion/PointAverage.h>
#include <vtkm/filter/vector_analysis/Gradient.h>
#include <vtkm/filter/vector_analysis/VectorMagnitude.h>
#include <vtkm/io/VTKDataSetReader.h>
@ -117,7 +118,7 @@ void BenchGradient(::benchmark::State& state, int options)
{
const vtkm::cont::DeviceAdapterId device = Config.Device;
vtkm::filter::Gradient filter;
vtkm::filter::vector_analysis::Gradient filter;
if (options & ScalarInput)
{
@ -706,7 +707,7 @@ void CreateMissingFields()
{
// Compute the magnitude of the vectors:
VTKM_ASSERT(!PointVectorsName.empty());
vtkm::filter::VectorMagnitude mag;
vtkm::filter::vector_analysis::VectorMagnitude mag;
mag.SetActiveField(PointVectorsName, vtkm::cont::Field::Association::POINTS);
mag.SetOutputFieldName("GeneratedPointScalars");
auto outds = mag.Execute(InputDataSet);

@ -25,12 +25,12 @@
#include <vtkm/cont/internal/OptionParser.h>
#include <vtkm/filter/Gradient.h>
#include <vtkm/filter/Streamline.h>
#include <vtkm/filter/Tetrahedralize.h>
#include <vtkm/filter/Tube.h>
#include <vtkm/filter/contour/Contour.h>
#include <vtkm/filter/contour/Slice.h>
#include <vtkm/filter/vector_analysis/Gradient.h>
#include <vtkm/rendering/Actor.h>
#include <vtkm/rendering/CanvasRayTracer.h>
@ -119,7 +119,7 @@ void BuildInputDataSet(uint32_t cycle, bool isStructured, bool isMultiBlock, vtk
}
// Generate Perln Noise Gradient point vector field
vtkm::filter::Gradient gradientFilter;
vtkm::filter::vector_analysis::Gradient gradientFilter;
gradientFilter.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::POINTS);
gradientFilter.SetComputePointGradient(true);
gradientFilter.SetOutputFieldName(PointVectorsName);

@ -0,0 +1,12 @@
VTK-m 1.7.1 Release Notes
=========================
| Merge request description | Merge request id |
| ------------------------------------------------------------------- | ---------------- |
| Update the link to register with the VTK-m dashboard | !2629 |
| Add instructions on how to commit Git-LFS files | !2651 |
| Missing changes for cell centered velocity fields | !2663 |
| CI: set GBench to latest tag | !2671 |
| HIP: remove bogus kokkoscore INTERFACE_COMPILE_DEFINITIONS property | !2679 |
| Fix out of bounds cell location searchs in VolumeRendererStructured | !2685 |
| CMAKE: CUDA ampere generate sm_80/86 | !2688 |

@ -0,0 +1,6 @@
# Add implementation of `VecTraits` for `Range` and `Bounds`
Added specializations of `vtkm::VecTraits` for the simple structures of
`vtkm::Range` and `vtkm::Bounds`. This expands the support for using these
structures in things like `ArrayHandle` and `UnknownArrayHandle`.

@ -15,7 +15,7 @@
#include <vtkm/cont/openmp/DeviceAdapterOpenMP.h>
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
#include <vtkm/filter/Gradient.h>
#include <vtkm/filter/vector_analysis/Gradient.h>
namespace
@ -206,7 +206,7 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet MultiDeviceGradient::PrepareForE
//Step 3. Construct the filter we want to run on each partition
vtkm::filter::Gradient gradient;
vtkm::filter::vector_analysis::Gradient gradient;
gradient.SetComputePointGradient(this->GetComputePointGradient());
gradient.SetActiveField(this->GetActiveFieldName());
@ -218,7 +218,7 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet MultiDeviceGradient::PrepareForE
vtkm::cont::DataSet input = *partition;
this->Queue.push( //build a lambda that is the work to do
[=]() {
vtkm::filter::Gradient perThreadGrad = gradient;
vtkm::filter::vector_analysis::Gradient perThreadGrad = gradient;
vtkm::cont::DataSet result = perThreadGrad.Execute(input);
outPtr->ReplacePartition(0, result);
@ -237,7 +237,7 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet MultiDeviceGradient::PrepareForE
//blocking manner
this->Queue.push( //build a lambda that is the work to do
[=]() {
vtkm::filter::Gradient perThreadGrad = gradient;
vtkm::filter::vector_analysis::Gradient perThreadGrad = gradient;
vtkm::cont::DataSet result = perThreadGrad.Execute(input);
outPtr->ReplacePartition(index, result);

@ -1 +1 @@
1.7.0
1.7.1

@ -218,11 +218,98 @@ struct Bounds
/// Helper function for printing bounds during testing
///
static inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::Bounds& bounds)
inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::Bounds& bounds)
{
return stream << "{ X:" << bounds.X << ", Y:" << bounds.Y << ", Z:" << bounds.Z << " }";
}
template <>
struct VTKM_NEVER_EXPORT VecTraits<vtkm::Bounds>
{
using ComponentType = vtkm::Range;
using BaseComponentType = vtkm::VecTraits<vtkm::Range>::BaseComponentType;
static constexpr vtkm::IdComponent NUM_COMPONENTS = 3;
static constexpr vtkm::IdComponent GetNumberOfComponents(const vtkm::Bounds&)
{
return NUM_COMPONENTS;
}
using HasMultipleComponents = vtkm::VecTraitsTagMultipleComponents;
using IsSizeStatic = vtkm::VecTraitsTagSizeStatic;
VTKM_EXEC_CONT
static const ComponentType& GetComponent(const vtkm::Bounds& bounds, vtkm::IdComponent component)
{
VTKM_ASSERT((component >= 0) || (component < 3));
switch (component)
{
case 0:
return bounds.X;
case 1:
return bounds.Y;
case 2:
return bounds.Z;
default:
// Should never reach here
return bounds.X;
}
}
VTKM_EXEC_CONT
static ComponentType& GetComponent(vtkm::Bounds& bounds, vtkm::IdComponent component)
{
VTKM_ASSERT((component >= 0) || (component < 3));
switch (component)
{
case 0:
return bounds.X;
case 1:
return bounds.Y;
case 2:
return bounds.Z;
default:
// Should never reach here
return bounds.X;
}
}
VTKM_EXEC_CONT
static void SetComponent(vtkm::Bounds& bounds,
vtkm::IdComponent component,
const ComponentType& value)
{
VTKM_ASSERT((component >= 0) || (component < 3));
switch (component)
{
case 0:
bounds.X = value;
break;
case 1:
bounds.Y = value;
break;
case 2:
bounds.Z = value;
break;
}
}
template <typename NewComponentType>
using ReplaceComponentType = vtkm::Vec<NewComponentType, NUM_COMPONENTS>;
template <typename NewComponentType>
using ReplaceBaseComponentType =
vtkm::Vec<NewComponentType, NUM_COMPONENTS * vtkm::VecTraits<vtkm::Range>::NUM_COMPONENTS>;
template <vtkm::IdComponent destSize>
VTKM_EXEC_CONT static void CopyInto(const vtkm::Bounds& src,
vtkm::Vec<ComponentType, destSize>& dest)
{
const vtkm::IdComponent maxComponent = (destSize < NUM_COMPONENTS) ? destSize : NUM_COMPONENTS;
for (vtkm::IdComponent component = 0; component < maxComponent; ++component)
{
dest[component] = GetComponent(src, component);
}
}
};
} // namespace vtkm
#endif //vtk_m_Bounds_h

@ -14,6 +14,7 @@
#include <vtkm/Assert.h>
#include <vtkm/Math.h>
#include <vtkm/Types.h>
#include <vtkm/VecTraits.h>
namespace vtkm
{
@ -185,6 +186,65 @@ inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::Rang
{
return stream << "[" << range.Min << ".." << range.Max << "]";
} // Declared inside of vtkm namespace so that the operator work with ADL lookup
template <>
struct VTKM_NEVER_EXPORT VecTraits<vtkm::Range>
{
using ComponentType = vtkm::Float64;
using BaseComponentType = vtkm::Float64;
static constexpr vtkm::IdComponent NUM_COMPONENTS = 2;
static constexpr vtkm::IdComponent GetNumberOfComponents(const vtkm::Range&)
{
return NUM_COMPONENTS;
}
using HasMultipleComponents = vtkm::VecTraitsTagMultipleComponents;
using IsSizeStatic = vtkm::VecTraitsTagSizeStatic;
VTKM_EXEC_CONT
static const ComponentType& GetComponent(const vtkm::Range& range, vtkm::IdComponent component)
{
VTKM_ASSERT((component == 0) || (component == 1));
return (component == 0) ? range.Min : range.Max;
}
VTKM_EXEC_CONT
static ComponentType& GetComponent(vtkm::Range& range, vtkm::IdComponent component)
{
VTKM_ASSERT((component == 0) || (component == 1));
return (component == 0) ? range.Min : range.Max;
}
VTKM_EXEC_CONT
static void SetComponent(vtkm::Range& range, vtkm::IdComponent component, ComponentType value)
{
VTKM_ASSERT((component == 0) || (component == 1));
if (component == 0)
{
range.Min = value;
}
else
{
range.Max = value;
}
}
template <typename NewComponentType>
using ReplaceComponentType = vtkm::Vec<NewComponentType, NUM_COMPONENTS>;
template <typename NewComponentType>
using ReplaceBaseComponentType = vtkm::Vec<NewComponentType, NUM_COMPONENTS>;
template <vtkm::IdComponent destSize>
VTKM_EXEC_CONT static void CopyInto(const vtkm::Range& src,
vtkm::Vec<ComponentType, destSize>& dest)
{
const vtkm::IdComponent maxComponent = (destSize < NUM_COMPONENTS) ? destSize : NUM_COMPONENTS;
for (vtkm::IdComponent component = 0; component < maxComponent; ++component)
{
dest[component] = GetComponent(src, component);
}
}
};
} // namespace vtkm

@ -93,23 +93,52 @@ template <>
struct ArrayExtractComponentImpl<vtkm::cont::StorageTagStride>
{
template <typename T>
vtkm::cont::ArrayHandleStride<T> operator()(
vtkm::cont::ArrayHandleStride<typename vtkm::VecTraits<T>::BaseComponentType> operator()(
const vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagStride>& src,
vtkm::IdComponent componentIndex,
vtkm::CopyFlag vtkmNotUsed(allowCopy)) const
vtkm::CopyFlag allowCopy) const
{
VTKM_ASSERT(componentIndex == 0);
return src;
return this->DoExtract(
src, componentIndex, allowCopy, typename vtkm::VecTraits<T>::HasMultipleComponents{});
}
template <typename T, vtkm::IdComponent N>
auto operator()(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, vtkm::cont::StorageTagStride>& src,
private:
template <typename T>
auto DoExtract(const vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagStride>& src,
vtkm::IdComponent componentIndex,
vtkm::CopyFlag allowCopy) const
-> decltype((*this)(vtkm::cont::ArrayHandleStride<T>{}, componentIndex, allowCopy))
vtkm::CopyFlag vtkmNotUsed(allowCopy),
vtkm::VecTraitsTagSingleComponent) const
{
VTKM_ASSERT(componentIndex == 0);
using VTraits = vtkm::VecTraits<T>;
using TBase = typename VTraits::BaseComponentType;
VTKM_STATIC_ASSERT(VTraits::NUM_COMPONENTS == 1);
vtkm::cont::ArrayHandleStride<T> array(src);
// Note, we are initializing the result in this strange way for cases where type
// T has a single component but does not equal its own BaseComponentType. A vtkm::Vec
// of size 1 fits into this category.
return vtkm::cont::ArrayHandleStride<TBase>(array.GetBuffers()[1],
array.GetNumberOfValues(),
array.GetStride(),
array.GetOffset(),
array.GetModulo(),
array.GetDivisor());
}
template <typename VecType>
auto DoExtract(const vtkm::cont::ArrayHandle<VecType, vtkm::cont::StorageTagStride>& src,
vtkm::IdComponent componentIndex,
vtkm::CopyFlag allowCopy,
vtkm::VecTraitsTagMultipleComponents) const
{
using VTraits = vtkm::VecTraits<VecType>;
using T = typename VTraits::ComponentType;
constexpr vtkm::IdComponent N = VTraits::NUM_COMPONENTS;
constexpr vtkm::IdComponent subStride = vtkm::internal::TotalNumComponents<T>::value;
vtkm::cont::ArrayHandleStride<vtkm::Vec<T, N>> array(src);
vtkm::cont::ArrayHandleStride<VecType> array(src);
vtkm::cont::ArrayHandleStride<T> tmpIn(array.GetBuffers()[1],
array.GetNumberOfValues(),
array.GetStride() * N,

@ -13,6 +13,9 @@
#include <vtkm/cont/ArrayHandleCast.h>
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/Bounds.h>
#include <vtkm/Range.h>
#include <vtkm/cont/testing/Testing.h>
namespace
@ -145,11 +148,35 @@ void TryCopy()
}
}
void TryRange()
{
std::cout << "Trying vtkm::Range" << std::endl;
vtkm::cont::ArrayHandle<vtkm::Range> values =
vtkm::cont::make_ArrayHandle<vtkm::Range>({ { 0.0, 1.0 }, { 1.0, 2.0 }, { 2.0, 4.0 } });
vtkm::Range range = vtkm::cont::ArrayGetValue(1, values);
VTKM_TEST_ASSERT(range == vtkm::Range{ 1.0, 2.0 });
}
void TryBounds()
{
std::cout << "Trying vtkm::Bounds" << std::endl;
vtkm::cont::ArrayHandle<vtkm::Bounds> values =
vtkm::cont::make_ArrayHandle<vtkm::Bounds>({ { { 0.0, 1.0 }, { 0.0, 1.0 }, { 0.0, 1.0 } },
{ { 1.0, 2.0 }, { 1.0, 2.0 }, { 1.0, 2.0 } },
{ { 2.0, 4.0 }, { 2.0, 4.0 }, { 2.0, 4.0 } } });
vtkm::Bounds bounds = vtkm::cont::ArrayGetValue(1, values);
VTKM_TEST_ASSERT(bounds == vtkm::Bounds{ { 1.0, 2.0 }, { 1.0, 2.0 }, { 1.0, 2.0 } });
}
void Test()
{
TryCopy<vtkm::Id>();
TryCopy<vtkm::IdComponent>();
TryCopy<vtkm::Float32>();
TryRange();
TryBounds();
}
} // anonymous namespace

@ -8,8 +8,6 @@
## PURPOSE. See the above copyright notice for more information.
##============================================================================
vtkm_add_instantiations(GradientInstantiations FILTER Gradient)
set(deprecated_headers
CellAverage.h
CellSetConnectivity.h
@ -26,6 +24,7 @@ set(deprecated_headers
ExtractStructured.h
GenerateIds.h
GhostCellRemove.h
Gradient.h
Histogram.h
ImageConnectivity.h
Mask.h
@ -36,8 +35,10 @@ set(deprecated_headers
ParticleDensityNearestGridPoint.h
PointAverage.h
Slice.h
SurfaceNormal.h
Threshold.h
ThresholdPoints.h
VectorMagnitude.h
)
vtkm_declare_headers(${deprecated_headers})
@ -99,11 +100,9 @@ set(extra_headers
SplitSharpEdges.h
Streamline.h
StreamSurface.h
SurfaceNormals.h
Tetrahedralize.h
Triangulate.h
Tube.h
VectorMagnitude.h
VertexClustering.h
WarpScalar.h
WarpVector.h
@ -139,11 +138,9 @@ set(extra_header_template_sources
SplitSharpEdges.hxx
Streamline.hxx
StreamSurface.hxx
SurfaceNormals.hxx
Tetrahedralize.hxx
Triangulate.hxx
Tube.hxx
VectorMagnitude.hxx
VertexClustering.hxx
WarpScalar.hxx
WarpVector.hxx
@ -156,24 +153,10 @@ set(extra_header_template_sources
)
set(extra_sources_device
VectorMagnitude.cxx
particleadvection/Messenger.cxx
particleadvection/ParticleMessenger.cxx
)
set(gradient_headers
Gradient.h
)
set(gradient_header_template_sources
Gradient.hxx
)
set(gradient_sources_device
${GradientInstantiations}
)
set(core_headers
NewFilter.h
NewFilterField.h
@ -216,33 +199,22 @@ vtkm_library(
USE_VTKM_JOB_POOL
)
vtkm_library(
NAME vtkm_filter_gradient
TEMPLATE_SOURCES ${gradient_header_template_sources}
HEADERS ${gradient_headers}
DEVICE_SOURCES ${gradient_sources_device}
USE_VTKM_JOB_POOL
)
set_target_properties(
vtkm_filter_core
vtkm_filter_extra
vtkm_filter_gradient
PROPERTIES
UNITY_BUILD ON
UNITY_BUILD_MODE BATCH
)
target_link_libraries(vtkm_filter_core PUBLIC vtkm_cont vtkm_worklet)
target_link_libraries(vtkm_filter_extra PUBLIC vtkm_cont vtkm_worklet)
target_link_libraries(vtkm_filter_gradient PUBLIC vtkm_cont vtkm_worklet)
target_link_libraries(vtkm_filter_extra PUBLIC vtkm_filter_common)
if (VTKm_ENABLE_MPI)
target_link_libraries(vtkm_filter_extra PUBLIC MPI::MPI_CXX)
target_link_libraries(vtkm_filter_gradient PUBLIC MPI::MPI_CXX)
endif()
target_link_libraries(vtkm_filter PUBLIC INTERFACE
vtkm_filter_extra
vtkm_filter_gradient
vtkm_filter_core
)
@ -257,7 +229,7 @@ add_subdirectory(internal)
add_subdirectory(particleadvection)
add_subdirectory(field_conversion)
add_subdirectory(field_transform)
add_subdirectory(vector_calculus)
add_subdirectory(vector_analysis)
#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
if (VTKm_ENABLE_TESTING)

@ -12,7 +12,7 @@
#define vtk_m_filter_CrossProduct_h
#include <vtkm/Deprecated.h>
#include <vtkm/filter/vector_calculus/CrossProduct.h>
#include <vtkm/filter/vector_analysis/CrossProduct.h>
namespace vtkm
{
@ -21,7 +21,7 @@ namespace filter
VTKM_DEPRECATED(
1.8,
"Use vtkm/filter/vector_calculus/CrossProduct.h instead of vtkm/filter/CrossProduct.h.")
"Use vtkm/filter/vector_analysis/CrossProduct.h instead of vtkm/filter/CrossProduct.h.")
inline void CrossProduct_deprecated() {}
inline void CrossProduct_deprecated_warning()
@ -29,10 +29,10 @@ inline void CrossProduct_deprecated_warning()
CrossProduct_deprecated();
}
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::vector_calculus::CrossProduct.") CrossProduct
: public vtkm::filter::vector_calculus::CrossProduct
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::vector_analysis::CrossProduct.") CrossProduct
: public vtkm::filter::vector_analysis::CrossProduct
{
using vector_calculus::CrossProduct::CrossProduct;
using vector_analysis::CrossProduct::CrossProduct;
};
}

@ -11,7 +11,7 @@
#define vtk_m_filter_DotProduct_h
#include <vtkm/Deprecated.h>
#include <vtkm/filter/vector_calculus/DotProduct.h>
#include <vtkm/filter/vector_analysis/DotProduct.h>
namespace vtkm
{
@ -19,7 +19,7 @@ namespace filter
{
VTKM_DEPRECATED(1.8,
"Use vtkm/filter/vector_calculus/DotProduct.h instead of vtkm/filter/DotProduct.h.")
"Use vtkm/filter/vector_analysis/DotProduct.h instead of vtkm/filter/DotProduct.h.")
inline void DotProduct_deprecated() {}
inline void DotProduct_deprecated_warning()
@ -27,10 +27,10 @@ inline void DotProduct_deprecated_warning()
DotProduct_deprecated();
}
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::vector_calculus::DotProduct.") DotProduct
: public vtkm::filter::vector_calculus::DotProduct
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::vector_analysis::DotProduct.") DotProduct
: public vtkm::filter::vector_analysis::DotProduct
{
using vector_calculus::DotProduct::DotProduct;
using vector_analysis::DotProduct::DotProduct;
};
}

@ -7,239 +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_Gradient_h
#define vtk_m_filter_Gradient_h
#include <vtkm/filter/vtkm_filter_gradient_export.h>
#include <vtkm/filter/FilterField.h>
#include <vtkm/filter/Instantiations.h>
#include <vtkm/cont/ArrayHandleSOA.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/vector_analysis/Gradient.h>
namespace vtkm
{
namespace filter
{
/// \brief A general filter for gradient estimation.
/// Estimates the gradient of a point field in a data set. The created gradient array
/// can be determined at either each point location or at the center of each cell.
///
/// The default for the filter is output as cell centered gradients.
/// To enable point based gradient computation enable \c SetComputePointGradient
///
/// Note: If no explicit name for the output field is provided the filter will
/// default to "Gradients"
class VTKM_FILTER_GRADIENT_EXPORT Gradient : public vtkm::filter::FilterField<Gradient>
VTKM_DEPRECATED(1.8,
"Use vtkm/filter/vector_analysis/Gradient.h instead of vtkm/filter/Gradient.h.")
inline void Gradient_deprecated() {}
inline void Gradient_deprecated_warning()
{
public:
using SupportedTypes = vtkm::List<vtkm::Float32, vtkm::Float64, vtkm::Vec3f_32, vtkm::Vec3f_64>;
Gradient_deprecated();
}
/// When this flag is on (default is off), the gradient filter will provide a
/// point based gradients, which are significantly more costly since for each
/// point we need to compute the gradient of each cell that uses it.
void SetComputePointGradient(bool enable) { ComputePointGradient = enable; }
bool GetComputePointGradient() const { return ComputePointGradient; }
/// Add divergence field to the output data. The name of the array
/// will be Divergence and will be a cell field unless \c ComputePointGradient
/// is enabled. The input array must have 3 components in order to
/// compute this. The default is off.
void SetComputeDivergence(bool enable) { ComputeDivergence = enable; }
bool GetComputeDivergence() const { return ComputeDivergence; }
/// Add voriticity/curl field to the output data. The name of the array
/// will be Vorticity and will be a cell field unless \c ComputePointGradient
/// is enabled. The input array must have 3 components in order to
/// compute this. The default is off.
void SetComputeVorticity(bool enable) { ComputeVorticity = enable; }
bool GetComputeVorticity() const { return ComputeVorticity; }
/// Add Q-criterion field to the output data. The name of the array
/// will be QCriterion and will be a cell field unless \c ComputePointGradient
/// is enabled. The input array must have 3 components in order to
/// compute this. The default is off.
void SetComputeQCriterion(bool enable) { ComputeQCriterion = enable; }
bool GetComputeQCriterion() const { return ComputeQCriterion; }
/// Add gradient field to the output data. The name of the array
/// will be Gradients and will be a cell field unless \c ComputePointGradient
/// is enabled. It is useful to turn this off when you are only interested
/// in the results of Divergence, Vorticity, or QCriterion. The default is on.
void SetComputeGradient(bool enable) { StoreGradient = enable; }
bool GetComputeGradient() const { return StoreGradient; }
/// Make the vector gradient output format be in FORTRAN Column-major order.
/// This is only used when the input field is a vector field ( 3 components ).
/// Enabling column-major is important if integrating with other projects
/// such as VTK.
/// Default: Row Order
void SetColumnMajorOrdering() { RowOrdering = false; }
/// Make the vector gradient output format be in C Row-major order.
/// This is only used when the input field is a vector field ( 3 components ).
/// Default: Row Order
void SetRowMajorOrdering() { RowOrdering = true; }
void SetDivergenceName(const std::string& name) { this->DivergenceName = name; }
const std::string& GetDivergenceName() const { return this->DivergenceName; }
void SetVorticityName(const std::string& name) { this->VorticityName = name; }
const std::string& GetVorticityName() const { return this->VorticityName; }
void SetQCriterionName(const std::string& name) { this->QCriterionName = name; }
const std::string& GetQCriterionName() const { return this->QCriterionName; }
template <typename T, typename StorageType, typename DerivedPolicy>
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);
VTKM_CONT
Filter* Clone() const override
{
Gradient* clone = new Gradient();
clone->CopyStateFrom(this);
return clone;
}
VTKM_CONT
bool CanThread() const override { return true; }
protected:
VTKM_CONT
void CopyStateFrom(const Gradient* gradient)
{
this->FilterField<Gradient>::CopyStateFrom(gradient);
this->ComputePointGradient = gradient->ComputePointGradient;
this->ComputeDivergence = gradient->ComputeDivergence;
this->ComputeVorticity = gradient->ComputeVorticity;
this->ComputeQCriterion = gradient->ComputeQCriterion;
this->StoreGradient = gradient->StoreGradient;
this->RowOrdering = gradient->RowOrdering;
}
private:
bool ComputePointGradient = false;
bool ComputeDivergence = false;
bool ComputeVorticity = false;
bool ComputeQCriterion = false;
bool StoreGradient = true;
bool RowOrdering = true;
std::string DivergenceName = "Divergence";
std::string GradientsName = "Gradients";
std::string QCriterionName = "QCriterion";
std::string VorticityName = "Vorticity";
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::vector_analysis::Gradient.") Gradient
: public vtkm::filter::vector_analysis::Gradient
{
using vector_analysis::Gradient::Gradient;
};
#ifndef vtkm_filter_Gradient_cxx
VTKM_INSTANTIATION_BEGIN
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<vtkm::Float32>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<vtkm::Float64>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<vtkm::Vec3f_32>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<vtkm::Vec3f_32, vtkm::cont::StorageTagSOA>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<vtkm::Vec3f_64>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<vtkm::Vec3f_64, vtkm::cont::StorageTagSOA>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<vtkm::Vec3f, vtkm::cont::StorageTagUniformPoints>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<
vtkm::Vec3f_32,
vtkm::cont::StorageTagCartesianProduct<vtkm::cont::StorageTagBasic,
vtkm::cont::StorageTagBasic,
vtkm::cont::StorageTagBasic>>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<
vtkm::Vec3f_64,
vtkm::cont::StorageTagCartesianProduct<vtkm::cont::StorageTagBasic,
vtkm::cont::StorageTagBasic,
vtkm::cont::StorageTagBasic>>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
#ifdef VTKM_ADD_XGC_DEFAULT_TYPES
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<vtkm::Vec<float, 3>, vtkm::cont::StorageTagXGCCoordinates>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
#endif
VTKM_INSTANTIATION_END
VTKM_INSTANTIATION_BEGIN
#ifdef VTKM_ADD_XGC_DEFAULT_TYPES
extern template VTKM_FILTER_GRADIENT_TEMPLATE_EXPORT vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet&,
const vtkm::cont::ArrayHandle<vtkm::Vec<double, 3>, vtkm::cont::StorageTagXGCCoordinates>&,
const vtkm::filter::FieldMetadata&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
#endif
VTKM_INSTANTIATION_END
#endif //vtkm_filter_Gradient_cxx
}
} // namespace vtkm::filter
#endif // vtk_m_filter_Gradient_h
#endif //vtk_m_filter_Gradient_h

@ -1,129 +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_Gradient_hxx
#define vtk_m_filter_Gradient_hxx
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/cont/UnknownCellSet.h>
#include <vtkm/worklet/Gradient.h>
namespace
{
//-----------------------------------------------------------------------------
template <typename T, typename S>
inline void transpose_3x3(vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Vec<T, 3>, 3>, S>& field)
{
vtkm::worklet::gradient::Transpose3x3<T> transpose;
transpose.Run(field);
}
//-----------------------------------------------------------------------------
template <typename T, typename S>
inline void transpose_3x3(vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, S>&)
{ //This is not a 3x3 matrix so no transpose needed
}
} //namespace
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline vtkm::cont::DataSet Gradient::DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& inField,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
if (!fieldMetadata.IsPointField())
{
throw vtkm::cont::ErrorFilterExecution("Point field expected.");
}
constexpr bool isVector = std::is_same<typename vtkm::VecTraits<T>::HasMultipleComponents,
vtkm::VecTraitsTagMultipleComponents>::value;
if (GetComputeQCriterion() && !isVector)
{
throw vtkm::cont::ErrorFilterExecution("scalar gradients can't generate qcriterion");
}
if (GetComputeVorticity() && !isVector)
{
throw vtkm::cont::ErrorFilterExecution("scalar gradients can't generate vorticity");
}
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
const vtkm::cont::CoordinateSystem& coords =
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
std::string outputName = this->GetOutputFieldName();
if (outputName.empty())
{
outputName = this->GradientsName;
}
//todo: we need to ask the policy what storage type we should be using
//If the input is implicit, we should know what to fall back to
vtkm::worklet::GradientOutputFields<T> gradientfields(this->GetComputeGradient(),
this->GetComputeDivergence(),
this->GetComputeVorticity(),
this->GetComputeQCriterion());
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> outArray;
if (this->ComputePointGradient)
{
vtkm::worklet::PointGradient gradient;
outArray = gradient.Run(
vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), coords, inField, gradientfields);
}
else
{
vtkm::worklet::CellGradient gradient;
outArray = gradient.Run(
vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), coords, inField, gradientfields);
}
if (!this->RowOrdering)
{
transpose_3x3(outArray);
}
vtkm::cont::Field::Association fieldAssociation(this->ComputePointGradient
? vtkm::cont::Field::Association::POINTS
: vtkm::cont::Field::Association::CELL_SET);
vtkm::cont::DataSet result;
result.CopyStructure(input);
result.AddField(vtkm::cont::Field{ outputName, fieldAssociation, outArray });
if (this->GetComputeDivergence() && isVector)
{
result.AddField(
vtkm::cont::Field{ this->GetDivergenceName(), fieldAssociation, gradientfields.Divergence });
}
if (this->GetComputeVorticity() && isVector)
{
result.AddField(
vtkm::cont::Field{ this->GetVorticityName(), fieldAssociation, gradientfields.Vorticity });
}
if (this->GetComputeQCriterion() && isVector)
{
result.AddField(
vtkm::cont::Field{ this->GetQCriterionName(), fieldAssociation, gradientfields.QCriterion });
}
return result;
}
}
} // namespace vtkm::filter
#endif

@ -0,0 +1,40 @@
//============================================================================
// 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_SurfaceNormal_h
#define vtk_m_filter_SurfaceNormal_h
#include <vtkm/Deprecated.h>
#include <vtkm/filter/vector_analysis/SurfaceNormal.h>
namespace vtkm
{
namespace filter
{
VTKM_DEPRECATED(
1.8,
"Use vtkm/filter/vector_analysis/SurfaceNormal.h instead of vtkm/filter/SurfaceNormal.h.")
inline void SurfaceNormal_deprecated() {}
inline void SurfaceNormal_deprecated_warning()
{
SurfaceNormal_deprecated();
}
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::vector_analysis::SurfaceNormal.") SurfaceNormal
: public vtkm::filter::vector_analysis::SurfaceNormal
{
using vector_analysis::SurfaceNormal::SurfaceNormal;
};
}
} // namespace vtkm::filter
#endif //vtk_m_filter_SurfaceNormal_h

@ -1,30 +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.
//============================================================================
#define vtkm_filter_VectorMagnitude_cxx
#include <vtkm/filter/VectorMagnitude.h>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
VectorMagnitude::VectorMagnitude()
: vtkm::filter::FilterField<VectorMagnitude>()
, Worklet()
{
this->SetOutputFieldName("magnitude");
}
//-----------------------------------------------------------------------------
VTKM_FILTER_EXTRA_INSTANTIATE_EXECUTE_METHOD(VectorMagnitude);
}
}

@ -7,43 +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_VectorMagnitude_h
#define vtk_m_filter_VectorMagnitude_h
#include <vtkm/filter/vtkm_filter_extra_export.h>
#include <vtkm/filter/FilterField.h>
#include <vtkm/worklet/Magnitude.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/vector_analysis/VectorMagnitude.h>
namespace vtkm
{
namespace filter
{
class VTKM_FILTER_EXTRA_EXPORT VectorMagnitude : public vtkm::filter::FilterField<VectorMagnitude>
VTKM_DEPRECATED(
1.8,
"Use vtkm/filter/vector_analysis/VectorMagnitude.h instead of vtkm/filter/VectorMagnitude.h.")
inline void VectorMagnitude_deprecated() {}
inline void VectorMagnitude_deprecated_warning()
{
public:
//currently the VectorMagnitude filter only works on vector data.
using SupportedTypes = vtkm::TypeListVecCommon;
VectorMagnitude_deprecated();
}
VectorMagnitude();
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::Magnitude Worklet;
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::vector_analysis::VectorMagnitude.") VectorMagnitude
: public vtkm::filter::vector_analysis::VectorMagnitude
{
using vector_analysis::VectorMagnitude::VectorMagnitude;
};
#ifndef vtkm_filter_VectorMagnitude_cxx
VTKM_FILTER_EXTRA_EXPORT_EXECUTE_METHOD(VectorMagnitude);
#endif
}
} // namespace vtkm::filter
#include <vtkm/filter/VectorMagnitude.hxx>
#endif // vtk_m_filter_VectorMagnitude_h
#endif //vtk_m_filter_VectorMagnitude_h

@ -1,37 +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_VectorMagnitude_hxx
#define vtk_m_filter_VectorMagnitude_hxx
#include <vtkm/Math.h>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet VectorMagnitude::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
using ReturnType = typename ::vtkm::detail::FloatingPointReturnType<T>::Type;
vtkm::cont::ArrayHandle<ReturnType> outArray;
this->Invoke(this->Worklet, field, outArray);
return CreateResult(inDataSet, outArray, this->GetOutputFieldName(), fieldMetadata);
}
}
} // namespace vtkm::filter
#endif

@ -17,7 +17,7 @@
#include <vtkm/filter/contour/Contour.h>
#include <vtkm/filter/contour/worklet/Contour.h>
#include <vtkm/worklet/SurfaceNormals.h>
#include <vtkm/filter/vector_analysis/worklet/SurfaceNormals.h>
namespace vtkm
{

@ -18,7 +18,7 @@
#include <vtkm/filter/contour/worklet/FlyingEdgesTables.h>
#include <vtkm/VectorAnalysis.h>
#include <vtkm/worklet/gradient/StructuredPointGradient.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/StructuredPointGradient.h>
namespace vtkm
{

@ -30,9 +30,9 @@
#include <vtkm/filter/contour/worklet/CommonState.h>
#include <vtkm/filter/contour/worklet/MarchingCellTables.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/PointGradient.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/StructuredPointGradient.h>
#include <vtkm/worklet/WorkletReduceByKey.h>
#include <vtkm/worklet/gradient/PointGradient.h>
#include <vtkm/worklet/gradient/StructuredPointGradient.h>
namespace vtkm
{

@ -21,8 +21,6 @@ set(unit_tests
UnitTestFieldMetadata.cxx
UnitTestFieldSelection.cxx
UnitTestFieldToColors.cxx
UnitTestGradientExplicit.cxx
UnitTestGradientUniform.cxx
UnitTestGhostCellClassify.cxx
UnitTestImageDifferenceFilter.cxx
UnitTestImageMedianFilter.cxx
@ -40,11 +38,9 @@ set(unit_tests
UnitTestSplitSharpEdgesFilter.cxx
UnitTestStreamlineFilter.cxx
UnitTestStreamSurfaceFilter.cxx
UnitTestSurfaceNormalsFilter.cxx
UnitTestTetrahedralizeFilter.cxx
UnitTestTriangulateFilter.cxx
UnitTestTubeFilter.cxx
UnitTestVectorMagnitudeFilter.cxx
UnitTestVertexClusteringFilter.cxx
UnitTestWarpScalarFilter.cxx
UnitTestWarpVectorFilter.cxx
@ -75,7 +71,6 @@ if (VTKm_ENABLE_RENDERING)
RenderTestPointTransform.cxx
RenderTestSplitSharpEdges.cxx
RenderTestStreamline.cxx
RenderTestSurfaceNormals.cxx
)
endif()

@ -14,7 +14,7 @@
#include <vtkm/io/VTKDataSetReader.h>
#include <vtkm/filter/PointTransform.h>
#include <vtkm/filter/VectorMagnitude.h>
#include <vtkm/filter/vector_analysis/VectorMagnitude.h>
#include <vtkm/rendering/testing/RenderTest.h>
#include <vtkm/rendering/testing/Testing.h>
@ -38,7 +38,7 @@ void TestPointTransform()
// Need to take the magnitude of the "translation" field.
// ColorMap only works with scalar fields (1 component)
vtkm::filter::VectorMagnitude vectorMagnitude;
vtkm::filter::vector_analysis::VectorMagnitude vectorMagnitude;
vectorMagnitude.SetActiveField("translation");
vectorMagnitude.SetOutputFieldName("pointvar");
result = vectorMagnitude.Execute(result);

@ -14,7 +14,7 @@
#include <vtkm/io/VTKDataSetReader.h>
#include <vtkm/filter/SplitSharpEdges.h>
#include <vtkm/filter/SurfaceNormals.h>
#include <vtkm/filter/vector_analysis/SurfaceNormals.h>
#include <vtkm/rendering/testing/RenderTest.h>
#include <vtkm/rendering/testing/Testing.h>

@ -13,10 +13,10 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/Gradient.h>
#include <vtkm/filter/clean_grid/CleanGrid.h>
#include <vtkm/filter/contour/ClipWithField.h>
#include <vtkm/filter/contour/Contour.h>
#include <vtkm/filter/vector_analysis/Gradient.h>
#include <vtkm/io/VTKDataSetReader.h>
#include <vtkm/source/Tangle.h>
@ -147,7 +147,7 @@ void TestMultiBlockFilter()
results.clear();
for (const auto doThreading : flags)
{
vtkm::filter::Gradient grad;
vtkm::filter::vector_analysis::Gradient grad;
grad.SetRunMultiThreadedFilter(doThreading);
grad.SetComputePointGradient(true);
grad.SetActiveField("tangle");

@ -8,9 +8,9 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/filter/SplitSharpEdges.h>
#include <vtkm/filter/SurfaceNormals.h>
#include <vtkm/filter/contour/Contour.h>
#include <vtkm/filter/field_conversion/CellAverage.h>
#include <vtkm/filter/vector_analysis/SurfaceNormals.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/testing/Testing.h>
@ -205,7 +205,7 @@ void TestWithExplicitData()
vtkm::cont::DataSet simpleCube = Make3DExplicitSimpleCube();
// Generate surface normal field
vtkm::filter::SurfaceNormals surfaceNormalsFilter;
vtkm::filter::vector_analysis::SurfaceNormals surfaceNormalsFilter;
surfaceNormalsFilter.SetGenerateCellNormals(true);
vtkm::cont::DataSet simpleCubeWithSN = surfaceNormalsFilter.Execute(simpleCube);
VTKM_TEST_ASSERT(simpleCubeWithSN.HasCellField("Normals"), "Cell normals missing.");

@ -7,25 +7,32 @@
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notice for more information.
##============================================================================
set(vector_calculus_headers
set(vector_analysis_headers
CrossProduct.h
DotProduct.h
Gradient.h
SurfaceNormals.h
VectorMagnitude.h
)
set(vector_calculus_sources_device
set(vector_analysis_sources_device
CrossProduct.cxx
DotProduct.cxx
Gradient.cxx
SurfaceNormals.cxx
VectorMagnitude.cxx
)
vtkm_library(
NAME vtkm_filter_vector_calculus
HEADERS ${vector_calculus_headers}
DEVICE_SOURCES ${vector_calculus_sources_device}
NAME vtkm_filter_vector_analysis
HEADERS ${vector_analysis_headers}
DEVICE_SOURCES ${vector_analysis_sources_device}
USE_VTKM_JOB_POOL
)
target_link_libraries(vtkm_filter_vector_calculus PUBLIC vtkm_worklet vtkm_filter_core)
target_link_libraries(vtkm_filter PUBLIC INTERFACE vtkm_filter_vector_calculus)
target_link_libraries(vtkm_filter_vector_analysis PUBLIC vtkm_worklet vtkm_filter_core)
target_link_libraries(vtkm_filter PUBLIC INTERFACE vtkm_filter_vector_analysis)
add_subdirectory(worklet)
#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
if (VTKm_ENABLE_TESTING)
add_subdirectory(testing)

@ -8,7 +8,7 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/filter/vector_calculus/CrossProduct.h>
#include <vtkm/filter/vector_analysis/CrossProduct.h>
#include <vtkm/worklet/WorkletMapField.h>
@ -39,7 +39,7 @@ namespace vtkm
{
namespace filter
{
namespace vector_calculus
namespace vector_analysis
{
//-----------------------------------------------------------------------------
@ -83,4 +83,4 @@ VTKM_CONT vtkm::cont::DataSet CrossProduct::DoExecute(const vtkm::cont::DataSet&
}
}
} // namespace vtkm::filter::vector_calculus
} // namespace vtkm::filter::vector_analysis

@ -8,21 +8,21 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_vector_calculus_CrossProduct_h
#define vtk_m_filter_vector_calculus_CrossProduct_h
#ifndef vtk_m_filter_vector_analysis_CrossProduct_h
#define vtk_m_filter_vector_analysis_CrossProduct_h
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/vector_calculus/vtkm_filter_vector_calculus_export.h>
#include <vtkm/filter/vector_analysis/vtkm_filter_vector_analysis_export.h>
namespace vtkm
{
namespace filter
{
namespace vector_calculus
namespace vector_analysis
{
class VTKM_FILTER_VECTOR_CALCULUS_EXPORT CrossProduct : public vtkm::filter::NewFilterField
class VTKM_FILTER_VECTOR_ANALYSIS_EXPORT CrossProduct : public vtkm::filter::NewFilterField
{
public:
VTKM_CONT
@ -124,6 +124,6 @@ private:
}
}
} // namespace vtkm::filter::vector_calculus
} // namespace vtkm::filter::vector_analysis
#endif // vtk_m_filter_vector_calculus_CrossProduct_h
#endif // vtk_m_filter_vector_analysis_CrossProduct_h

@ -9,7 +9,7 @@
//============================================================================
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/filter/vector_calculus/DotProduct.h>
#include <vtkm/filter/vector_analysis/DotProduct.h>
#include <vtkm/worklet/WorkletMapField.h>
namespace // anonymous namespace making worklet::DotProduct internal to this .cxx
@ -67,7 +67,7 @@ namespace vtkm
{
namespace filter
{
namespace vector_calculus
namespace vector_analysis
{
VTKM_CONT DotProduct::DotProduct()
@ -114,6 +114,6 @@ VTKM_CONT vtkm::cont::DataSet DotProduct::DoExecute(const vtkm::cont::DataSet& i
outArray);
}
} // namespace vector_calculus
} // namespace vector_analysis
} // namespace filter
} // namespace vtkm

@ -8,19 +8,19 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_vector_calculus_DotProduct_h
#define vtk_m_filter_vector_calculus_DotProduct_h
#ifndef vtk_m_filter_vector_analysis_DotProduct_h
#define vtk_m_filter_vector_analysis_DotProduct_h
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/vector_calculus/vtkm_filter_vector_calculus_export.h>
#include <vtkm/filter/vector_analysis/vtkm_filter_vector_analysis_export.h>
namespace vtkm
{
namespace filter
{
namespace vector_calculus
namespace vector_analysis
{
class VTKM_FILTER_VECTOR_CALCULUS_EXPORT DotProduct : public vtkm::filter::NewFilterField
class VTKM_FILTER_VECTOR_ANALYSIS_EXPORT DotProduct : public vtkm::filter::NewFilterField
{
public:
VTKM_CONT DotProduct();
@ -121,8 +121,8 @@ public:
private:
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
};
} // namespace vector_calculus
} // namespace vector_analysis
} // namespace filter
} // namespace vtkm
#endif // vtk_m_filter_vector_calculus_DotProduct_h
#endif // vtk_m_filter_vector_analysis_DotProduct_h

@ -0,0 +1,138 @@
//============================================================================
// 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/ErrorFilterExecution.h>
#include <vtkm/cont/UnknownCellSet.h>
#include <vtkm/filter/vector_analysis/Gradient.h>
#include <vtkm/filter/vector_analysis/worklet/Gradient.h>
namespace
{
//-----------------------------------------------------------------------------
template <typename T, typename S>
inline void transpose_3x3(vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Vec<T, 3>, 3>, S>& field)
{
vtkm::worklet::gradient::Transpose3x3<T> transpose;
transpose.Run(field);
}
//-----------------------------------------------------------------------------
template <typename T, typename S>
inline void transpose_3x3(vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, S>&)
{ //This is not a 3x3 matrix so no transpose needed
}
} //namespace
namespace vtkm
{
namespace filter
{
namespace vector_analysis
{
//-----------------------------------------------------------------------------
vtkm::cont::DataSet Gradient::DoExecute(const vtkm::cont::DataSet& inputDataSet)
{
auto field = this->GetFieldFromDataSet(inputDataSet);
if (!field.IsFieldPoint())
{
throw vtkm::cont::ErrorFilterExecution("Point field expected.");
}
const bool isVector = field.GetData().GetNumberOfComponents() == 3;
if (GetComputeQCriterion() && !isVector)
{
throw vtkm::cont::ErrorFilterExecution("scalar gradients can't generate qcriterion");
}
if (GetComputeVorticity() && !isVector)
{
throw vtkm::cont::ErrorFilterExecution("scalar gradients can't generate vorticity");
}
const vtkm::cont::UnknownCellSet& inputCellSet = inputDataSet.GetCellSet();
const vtkm::cont::CoordinateSystem& coords =
inputDataSet.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
vtkm::cont::UnknownArrayHandle gradientArray;
vtkm::cont::UnknownArrayHandle divergenceArray;
vtkm::cont::UnknownArrayHandle vorticityArray;
vtkm::cont::UnknownArrayHandle qcriterionArray;
// TODO: there are a humungous number of (weak) symbols in the .o file. Investigate if
// they are all legit.
auto resolveType = [&, this](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::worklet::GradientOutputFields<T> gradientfields(this->GetComputeGradient(),
this->GetComputeDivergence(),
this->GetComputeVorticity(),
this->GetComputeQCriterion());
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> result;
if (this->ComputePointGradient)
{
vtkm::worklet::PointGradient gradient;
result = gradient.Run(inputCellSet, coords, concrete, gradientfields);
}
else
{
vtkm::worklet::CellGradient gradient;
result = gradient.Run(inputCellSet, coords, concrete, gradientfields);
}
if (!this->RowOrdering)
{
transpose_3x3(result);
}
gradientArray = result;
divergenceArray = gradientfields.Divergence;
vorticityArray = gradientfields.Vorticity;
qcriterionArray = gradientfields.QCriterion;
};
using SupportedTypes = vtkm::List<vtkm::Float32, vtkm::Float64, vtkm::Vec3f_32, vtkm::Vec3f_64>;
field.GetData().CastAndCallForTypesWithFloatFallback<SupportedTypes, VTKM_DEFAULT_STORAGE_LIST>(
resolveType);
// This copies the CellSet and Fields to be passed from inputDataSet to outputDataSet
vtkm::cont::DataSet outputDataSet = this->CreateResult(inputDataSet);
std::string outputName = this->GetOutputFieldName();
if (outputName.empty())
{
outputName = this->GradientsName;
}
vtkm::cont::Field::Association fieldAssociation(this->ComputePointGradient
? vtkm::cont::Field::Association::POINTS
: vtkm::cont::Field::Association::CELL_SET);
outputDataSet.AddField(vtkm::cont::Field{ outputName, fieldAssociation, gradientArray });
if (this->GetComputeDivergence() && isVector)
{
outputDataSet.AddField(
vtkm::cont::Field{ this->GetDivergenceName(), fieldAssociation, divergenceArray });
}
if (this->GetComputeVorticity() && isVector)
{
outputDataSet.AddField(
vtkm::cont::Field{ this->GetVorticityName(), fieldAssociation, vorticityArray });
}
if (this->GetComputeQCriterion() && isVector)
{
outputDataSet.AddField(
vtkm::cont::Field{ this->GetQCriterionName(), fieldAssociation, qcriterionArray });
}
return outputDataSet;
}
} // namespace vector_analysis
} // namespace filter
} // namespace vtkm

@ -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_vector_analysis_Gradient_h
#define vtk_m_filter_vector_analysis_Gradient_h
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/vector_analysis/vtkm_filter_vector_analysis_export.h>
namespace vtkm
{
namespace filter
{
namespace vector_analysis
{
/// \brief A general filter for gradient estimation.
/// Estimates the gradient of a point field in a data set. The created gradient array
/// can be determined at either each point location or at the center of each cell.
///
/// The default for the filter is output as cell centered gradients.
/// To enable point based gradient computation enable \c SetComputePointGradient
///
/// Note: If no explicit name for the output field is provided the filter will
/// default to "Gradients"
class VTKM_FILTER_VECTOR_ANALYSIS_EXPORT Gradient : public vtkm::filter::NewFilterField
{
public:
/// When this flag is on (default is off), the gradient filter will provide a
/// point based gradients, which are significantly more costly since for each
/// point we need to compute the gradient of each cell that uses it.
void SetComputePointGradient(bool enable) { ComputePointGradient = enable; }
bool GetComputePointGradient() const { return ComputePointGradient; }
/// Add divergence field to the output data. The name of the array
/// will be Divergence and will be a cell field unless \c ComputePointGradient
/// is enabled. The input array must have 3 components in order to
/// compute this. The default is off.
void SetComputeDivergence(bool enable) { ComputeDivergence = enable; }
bool GetComputeDivergence() const { return ComputeDivergence; }
/// Add voriticity/curl field to the output data. The name of the array
/// will be Vorticity and will be a cell field unless \c ComputePointGradient
/// is enabled. The input array must have 3 components in order to
/// compute this. The default is off.
void SetComputeVorticity(bool enable) { ComputeVorticity = enable; }
bool GetComputeVorticity() const { return ComputeVorticity; }
/// Add Q-criterion field to the output data. The name of the array
/// will be QCriterion and will be a cell field unless \c ComputePointGradient
/// is enabled. The input array must have 3 components in order to
/// compute this. The default is off.
void SetComputeQCriterion(bool enable) { ComputeQCriterion = enable; }
bool GetComputeQCriterion() const { return ComputeQCriterion; }
/// Add gradient field to the output data. The name of the array
/// will be Gradients and will be a cell field unless \c ComputePointGradient
/// is enabled. It is useful to turn this off when you are only interested
/// in the results of Divergence, Vorticity, or QCriterion. The default is on.
void SetComputeGradient(bool enable) { StoreGradient = enable; }
bool GetComputeGradient() const { return StoreGradient; }
/// Make the vector gradient output format be in FORTRAN Column-major order.
/// This is only used when the input field is a vector field ( 3 components ).
/// Enabling column-major is important if integrating with other projects
/// such as VTK.
/// Default: Row Order
void SetColumnMajorOrdering() { RowOrdering = false; }
/// Make the vector gradient output format be in C Row-major order.
/// This is only used when the input field is a vector field ( 3 components ).
/// Default: Row Order
void SetRowMajorOrdering() { RowOrdering = true; }
void SetDivergenceName(const std::string& name) { this->DivergenceName = name; }
const std::string& GetDivergenceName() const { return this->DivergenceName; }
void SetVorticityName(const std::string& name) { this->VorticityName = name; }
const std::string& GetVorticityName() const { return this->VorticityName; }
void SetQCriterionName(const std::string& name) { this->QCriterionName = name; }
const std::string& GetQCriterionName() const { return this->QCriterionName; }
private:
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inputDataSet) override;
bool ComputePointGradient = false;
bool ComputeDivergence = false;
bool ComputeVorticity = false;
bool ComputeQCriterion = false;
bool StoreGradient = true;
bool RowOrdering = true;
std::string DivergenceName = "Divergence";
std::string GradientsName = "Gradients";
std::string QCriterionName = "QCriterion";
std::string VorticityName = "Vorticity";
};
} // namespace vector_analysis
} // namespace filter
} // namespace vtkm::filter
#endif // vtk_m_filter_vector_analysis_Gradient_h

@ -7,13 +7,11 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_SurfaceNormals_hxx
#define vtk_m_filter_SurfaceNormals_hxx
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/worklet/OrientNormals.h>
#include <vtkm/worklet/SurfaceNormals.h>
#include <vtkm/filter/vector_analysis/SurfaceNormals.h>
#include <vtkm/filter/vector_analysis/worklet/OrientNormals.h>
#include <vtkm/filter/vector_analysis/worklet/SurfaceNormals.h>
#include <vtkm/worklet/TriangleWinding.h>
namespace vtkm
@ -21,9 +19,10 @@ namespace vtkm
namespace filter
{
namespace internal
namespace vector_analysis
{
namespace
{
inline std::string ComputePointNormalsName(const SurfaceNormals* filter)
{
if (!filter->GetPointNormalsName().empty())
@ -58,59 +57,54 @@ inline std::string ComputeCellNormalsName(const SurfaceNormals* filter)
} // internal
inline SurfaceNormals::SurfaceNormals()
: GenerateCellNormals(false)
, NormalizeCellNormals(true)
, GeneratePointNormals(true)
, AutoOrientNormals(false)
, FlipNormals(false)
, Consistency(true)
SurfaceNormals::SurfaceNormals()
{
this->SetUseCoordinateSystemAsField(true);
}
template <typename T, typename StorageType, typename DerivedPolicy>
inline vtkm::cont::DataSet SurfaceNormals::DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& points,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
vtkm::cont::DataSet SurfaceNormals::DoExecute(const vtkm::cont::DataSet& inputDataSet)
{
VTKM_ASSERT(fieldMeta.IsPointField());
if (!this->GetUseCoordinateSystemAsField())
{
VTKM_LOG_S(vtkm::cont::LogLevel::Warn,
"Active scalars to SurfaceNormals filter must be a coordinate system. "
"Ignoring false UseCoordinateSystemAsField flag.");
}
if (!this->GenerateCellNormals && !this->GeneratePointNormals)
{
throw vtkm::cont::ErrorFilterExecution("No normals selected.");
}
const auto cellset =
vtkm::filter::ApplyPolicyCellSetUnstructured(input.GetCellSet(), policy, *this);
const auto coords =
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()).GetDataAsMultiplexer();
const auto& inputCellSet = inputDataSet.GetCellSet();
const auto& coords =
inputDataSet.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()).GetDataAsMultiplexer();
vtkm::cont::ArrayHandle<vtkm::Vec3f> faceNormals;
auto resolveType = [&](const auto& concrete) {
vtkm::worklet::FacetedSurfaceNormals faceted;
faceted.SetNormalize(this->NormalizeCellNormals);
faceted.Run(cellset, points, faceNormals);
faceted.Run(inputCellSet, concrete, faceNormals);
};
this->CastAndCallVecField<3>(coords, resolveType);
vtkm::cont::DataSet result;
vtkm::cont::DataSet outputDataSet;
vtkm::cont::ArrayHandle<vtkm::Vec3f> pointNormals;
if (this->GeneratePointNormals)
{
vtkm::worklet::SmoothSurfaceNormals smooth;
smooth.Run(cellset, faceNormals, pointNormals);
result = CreateResultFieldPoint(input, pointNormals, internal::ComputePointNormalsName(this));
smooth.Run(inputCellSet, faceNormals, pointNormals);
outputDataSet =
this->CreateResultFieldPoint(inputDataSet, ComputePointNormalsName(this), pointNormals);
if (this->GenerateCellNormals)
{
result.AddField(
vtkm::cont::make_FieldCell(internal::ComputeCellNormalsName(this), faceNormals));
outputDataSet.AddField(vtkm::cont::make_FieldCell(ComputeCellNormalsName(this), faceNormals));
}
}
else
{
result = CreateResultFieldCell(input, faceNormals, internal::ComputeCellNormalsName(this));
outputDataSet =
this->CreateResultFieldCell(inputDataSet, ComputeCellNormalsName(this), faceNormals);
}
if (this->AutoOrientNormals)
@ -119,15 +113,15 @@ inline vtkm::cont::DataSet SurfaceNormals::DoExecute(
if (this->GenerateCellNormals && this->GeneratePointNormals)
{
Orient::RunPointAndCellNormals(cellset, coords, pointNormals, faceNormals);
Orient::RunPointAndCellNormals(inputCellSet, coords, pointNormals, faceNormals);
}
else if (this->GenerateCellNormals)
{
Orient::RunCellNormals(cellset, coords, faceNormals);
Orient::RunCellNormals(inputCellSet, coords, faceNormals);
}
else if (this->GeneratePointNormals)
{
Orient::RunPointNormals(cellset, coords, pointNormals);
Orient::RunPointNormals(inputCellSet, coords, pointNormals);
}
if (this->FlipNormals)
@ -145,12 +139,12 @@ inline vtkm::cont::DataSet SurfaceNormals::DoExecute(
if (this->Consistency && this->GenerateCellNormals)
{
auto newCells = vtkm::worklet::TriangleWinding::Run(cellset, coords, faceNormals);
result.SetCellSet(newCells); // Overwrite the cellset in the result
auto newCells = vtkm::worklet::TriangleWinding::Run(inputCellSet, coords, faceNormals);
outputDataSet.SetCellSet(newCells); // Overwrite the inputCellSet in the outputDataSet
}
return result;
return outputDataSet;
}
}
} // vtkm::filter
#endif
} // namespace vector_analysis
} // namespace filter
} // namespace vtkm

@ -7,27 +7,27 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_SurfaceNormals_h
#define vtk_m_filter_SurfaceNormals_h
#ifndef vtk_m_filter_vector_analysis_SurfaceNormal_h
#define vtk_m_filter_vector_analysis_SurfaceNormal_h
#include <vtkm/filter/FilterField.h>
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/vector_analysis/vtkm_filter_vector_analysis_export.h>
namespace vtkm
{
namespace filter
{
namespace vector_analysis
{
/// \brief compute normals for polygonal mesh
///
/// Compute surface normals on points and/or cells of a polygonal dataset.
/// The cell normals are faceted and are computed based on the plane where a
/// face lies. The point normals are smooth normals, computed by averaging
/// the face normals of incident cells.
class SurfaceNormals : public vtkm::filter::FilterField<SurfaceNormals>
class VTKM_FILTER_VECTOR_ANALYSIS_EXPORT SurfaceNormals : public vtkm::filter::NewFilterField
{
public:
using SupportedTypes = vtkm::TypeListFieldVec3;
/// Create SurfaceNormals filter. This calls
/// this->SetUseCoordinateSystemAsField(true) since that is the most common
/// use-case for surface normals.
@ -94,26 +94,21 @@ public:
bool GetConsistency() const { return this->Consistency; }
/// @}
template <typename T, typename StorageType, typename DerivedPolicy>
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& points,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
private:
bool GenerateCellNormals;
bool NormalizeCellNormals;
bool GeneratePointNormals;
bool AutoOrientNormals;
bool FlipNormals;
bool Consistency;
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inputDataSet) override;
bool GenerateCellNormals = false;
bool NormalizeCellNormals = true;
bool GeneratePointNormals = true;
bool AutoOrientNormals = false;
bool FlipNormals = false;
bool Consistency = true;
std::string CellNormalsName;
std::string PointNormalsName;
};
}
}
} // vtkm::filter
#include <vtkm/filter/SurfaceNormals.hxx>
#endif // vtk_m_filter_SurfaceNormals_h
#endif // vtk_m_filter_vector_analysis_SurfaceNormal_h

@ -0,0 +1,48 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/filter/vector_analysis/VectorMagnitude.h>
#include <vtkm/filter/vector_analysis/worklet/Magnitude.h>
namespace vtkm
{
namespace filter
{
namespace vector_analysis
{
VectorMagnitude::VectorMagnitude()
{
this->SetOutputFieldName("magnitude");
}
VTKM_CONT vtkm::cont::DataSet VectorMagnitude::DoExecute(const vtkm::cont::DataSet& inDataSet)
{
auto field = this->GetFieldFromDataSet(inDataSet);
vtkm::cont::UnknownArrayHandle outArray;
auto resolveType = [&, this](const auto& concrete) {
// use std::decay to remove const ref from the decltype of concrete.
using T = typename std::decay_t<decltype(concrete)>::ValueType;
using ReturnType = typename ::vtkm::detail::FloatingPointReturnType<T>::Type;
vtkm::cont::ArrayHandle<ReturnType> result;
this->Invoke(vtkm::worklet::Magnitude{}, concrete, result);
outArray = result;
};
field.GetData()
.CastAndCallForTypesWithFloatFallback<vtkm::TypeListVecCommon, VTKM_DEFAULT_STORAGE_LIST>(
resolveType);
return this->CreateResultField(
inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray);
}
} // namespace vector_analysis
} // namespace filter
} // namespace vtkm

@ -0,0 +1,35 @@
//============================================================================
// 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_vector_analysis_VectorMagnitude_h
#define vtk_m_filter_vector_analysis_VectorMagnitude_h
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/vector_analysis/vtkm_filter_vector_analysis_export.h>
namespace vtkm
{
namespace filter
{
namespace vector_analysis
{
class VTKM_FILTER_VECTOR_ANALYSIS_EXPORT VectorMagnitude : public vtkm::filter::NewFilterField
{
public:
VectorMagnitude();
private:
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
};
} // namespace vector_analysis
} // namespace filter
} // namespace vtkm::filter
#endif // vtk_m_filter_vector_analysis_VectorMagnitude_h

@ -11,14 +11,29 @@
set(unit_tests
UnitTestCrossProductFilter.cxx
UnitTestDotProductFilter.cxx
UnitTestGradientExplicit.cxx
UnitTestGradientUniform.cxx
UnitTestSurfaceNormalsFilter.cxx
UnitTestVectorMagnitudeFilter.cxx
)
set(libraries
vtkm_filter_vector_calculus
vtkm_filter_vector_analysis
)
if (VTKm_ENABLE_RENDERING)
list(APPEND libraries
vtkm_rendering_testing
vtkm_rendering)
list(APPEND unit_tests
RenderTestSurfaceNormals.cxx
)
endif()
vtkm_unit_tests(
SOURCES ${unit_tests}
LIBRARIES ${libraries}
ALL_BACKENDS # RendererTest needs device compiler
USE_VTKM_JOB_POOL
)

@ -13,7 +13,7 @@
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/io/VTKDataSetReader.h>
#include <vtkm/filter/SurfaceNormals.h>
#include <vtkm/filter/vector_analysis/SurfaceNormals.h>
#include <vtkm/rendering/testing/RenderTest.h>
#include <vtkm/rendering/testing/Testing.h>
@ -32,7 +32,7 @@ void TestSurfaceNormals()
vtkm::io::VTKDataSetReader reader(pathname);
auto dataSet = reader.ReadDataSet();
vtkm::filter::SurfaceNormals surfaceNormals;
vtkm::filter::vector_analysis::SurfaceNormals surfaceNormals;
surfaceNormals.SetGeneratePointNormals(true);
surfaceNormals.SetAutoOrientNormals(true);

@ -10,7 +10,7 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/vector_calculus/CrossProduct.h>
#include <vtkm/filter/vector_analysis/CrossProduct.h>
#include <vtkm/VectorAnalysis.h>
@ -141,7 +141,7 @@ void TestCrossProduct()
{
std::cout << " Both vectors as normal fields" << std::endl;
vtkm::filter::vector_calculus::CrossProduct filter;
vtkm::filter::vector_analysis::CrossProduct filter;
filter.SetPrimaryField("vec1");
filter.SetSecondaryField("vec2", vtkm::cont::Field::Association::POINTS);
@ -165,7 +165,7 @@ void TestCrossProduct()
{
std::cout << " First field as coordinates" << std::endl;
vtkm::filter::vector_calculus::CrossProduct filter;
vtkm::filter::vector_analysis::CrossProduct filter;
filter.SetUseCoordinateSystemAsPrimaryField(true);
filter.SetPrimaryCoordinateSystem(1);
filter.SetSecondaryField("vec2");
@ -186,7 +186,7 @@ void TestCrossProduct()
{
std::cout << " Second field as coordinates" << std::endl;
vtkm::filter::vector_calculus::CrossProduct filter;
vtkm::filter::vector_analysis::CrossProduct filter;
filter.SetPrimaryField("vec1");
filter.SetUseCoordinateSystemAsSecondaryField(true);
filter.SetSecondaryCoordinateSystem(2);

@ -10,7 +10,7 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/vector_calculus/DotProduct.h>
#include <vtkm/filter/vector_analysis/DotProduct.h>
#include <random>
#include <vector>
@ -128,7 +128,7 @@ void TestDotProduct()
{
std::cout << " Both vectors as normal fields" << std::endl;
vtkm::filter::vector_calculus::DotProduct filter;
vtkm::filter::vector_analysis::DotProduct filter;
filter.SetPrimaryField("vec1");
filter.SetSecondaryField("vec2");
vtkm::cont::DataSet result = filter.Execute(dataSet);
@ -137,7 +137,7 @@ void TestDotProduct()
{
std::cout << " First field as coordinates" << std::endl;
vtkm::filter::vector_calculus::DotProduct filter;
vtkm::filter::vector_analysis::DotProduct filter;
filter.SetUseCoordinateSystemAsPrimaryField(true);
filter.SetPrimaryCoordinateSystem(1);
filter.SetSecondaryField("vec2");
@ -147,7 +147,7 @@ void TestDotProduct()
{
std::cout << " Second field as coordinates" << std::endl;
vtkm::filter::vector_calculus::DotProduct filter;
vtkm::filter::vector_analysis::DotProduct filter;
filter.SetPrimaryField("vec1");
filter.SetUseCoordinateSystemAsSecondaryField(true);
filter.SetSecondaryCoordinateSystem(2);

@ -8,7 +8,7 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/filter/Gradient.h>
#include <vtkm/filter/vector_analysis/Gradient.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
@ -23,7 +23,7 @@ void TestCellGradientExplicit()
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DExplicitDataSet0();
vtkm::filter::Gradient gradient;
vtkm::filter::vector_analysis::Gradient gradient;
gradient.SetOutputFieldName("gradient");
gradient.SetActiveField("pointvar");
@ -48,7 +48,7 @@ void TestPointGradientExplicit()
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DExplicitDataSet0();
vtkm::filter::Gradient gradient;
vtkm::filter::vector_analysis::Gradient gradient;
gradient.SetComputePointGradient(true);
gradient.SetOutputFieldName("gradient");
gradient.SetActiveField("pointvar");

@ -8,8 +8,9 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/filter/Gradient.h>
#include <vtkm/filter/vector_analysis/Gradient.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
@ -23,7 +24,7 @@ void TestCellGradientUniform3D()
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
vtkm::filter::Gradient gradient;
vtkm::filter::vector_analysis::Gradient gradient;
gradient.SetOutputFieldName("Gradient");
gradient.SetComputeVorticity(true); //this won't work as we have a scalar field
@ -65,7 +66,7 @@ void TestCellGradientUniform3DWithVectorField()
dataSet.AddPointField("vec_pointvar", input);
//we need to add Vec3 array to the dataset
vtkm::filter::Gradient gradient;
vtkm::filter::vector_analysis::Gradient gradient;
gradient.SetOutputFieldName("vec_gradient");
gradient.SetComputeVorticity(true);
gradient.SetComputeQCriterion(true);
@ -124,7 +125,7 @@ void TestPointGradientUniform3DWithVectorField()
dataSet.AddPointField("vec_pointvar", input);
//we need to add Vec3 array to the dataset
vtkm::filter::Gradient gradient;
vtkm::filter::vector_analysis::Gradient gradient;
gradient.SetComputePointGradient(true);
gradient.SetOutputFieldName("vec_gradient");
gradient.SetActiveField("vec_pointvar");

@ -7,7 +7,7 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/filter/SurfaceNormals.h>
#include <vtkm/filter/vector_analysis/SurfaceNormals.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
@ -57,7 +57,7 @@ void TestSurfaceNormals()
{
vtkm::cont::DataSet ds = vtkm::cont::testing::MakeTestDataSet().Make3DExplicitDataSetPolygonal();
vtkm::filter::SurfaceNormals filter;
vtkm::filter::vector_analysis::SurfaceNormals filter;
vtkm::cont::DataSet result;
std::cout << "testing default output (generate only point normals):\n";

@ -10,7 +10,7 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/VectorMagnitude.h>
#include <vtkm/filter/vector_analysis/VectorMagnitude.h>
#include <vector>
@ -38,7 +38,7 @@ void TestVectorMagnitude()
dataSet.AddPointField("double_vec_pointvar", finput);
vtkm::filter::VectorMagnitude vm;
vtkm::filter::vector_analysis::VectorMagnitude vm;
vm.SetActiveField("double_vec_pointvar");
auto result = vm.Execute(dataSet);

@ -0,0 +1,24 @@
##============================================================================
## 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
Gradient.h
Magnitude.h
OrientCellNormals.h
OrientNormals.h
OrientPointAndCellNormals.h
OrientPointNormals.h
SurfaceNormals.h
)
add_subdirectory(gradient)
#-----------------------------------------------------------------------------
vtkm_declare_headers(${headers})

@ -14,14 +14,14 @@
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/DispatcherPointNeighborhood.h>
#include <vtkm/worklet/gradient/CellGradient.h>
#include <vtkm/worklet/gradient/Divergence.h>
#include <vtkm/worklet/gradient/GradientOutput.h>
#include <vtkm/worklet/gradient/PointGradient.h>
#include <vtkm/worklet/gradient/QCriterion.h>
#include <vtkm/worklet/gradient/StructuredPointGradient.h>
#include <vtkm/worklet/gradient/Transpose.h>
#include <vtkm/worklet/gradient/Vorticity.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/CellGradient.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/Divergence.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/GradientOutput.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/PointGradient.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/QCriterion.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/StructuredPointGradient.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/Transpose.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/Vorticity.h>
namespace vtkm
{

@ -26,9 +26,9 @@
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleTransform.h>
#include <vtkm/worklet/OrientCellNormals.h>
#include <vtkm/worklet/OrientPointAndCellNormals.h>
#include <vtkm/worklet/OrientPointNormals.h>
#include <vtkm/filter/vector_analysis/worklet/OrientCellNormals.h>
#include <vtkm/filter/vector_analysis/worklet/OrientPointAndCellNormals.h>
#include <vtkm/filter/vector_analysis/worklet/OrientPointNormals.h>
namespace vtkm
{

@ -15,7 +15,7 @@
#include <vtkm/exec/ParametricCoordinates.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/worklet/gradient/GradientOutput.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/GradientOutput.h>
namespace vtkm
{

@ -19,9 +19,9 @@
#include <vtkm/cont/ExecutionObjectBase.h>
#include <vtkm/exec/arg/FetchTagArrayDirectOut.h>
#include <vtkm/worklet/gradient/Divergence.h>
#include <vtkm/worklet/gradient/QCriterion.h>
#include <vtkm/worklet/gradient/Vorticity.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/Divergence.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/QCriterion.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/Vorticity.h>
namespace vtkm
{

@ -16,7 +16,7 @@
#include <vtkm/worklet/WorkletMapTopology.h>
#include <utility>
#include <vtkm/worklet/gradient/GradientOutput.h>
#include <vtkm/filter/vector_analysis/worklet/gradient/GradientOutput.h>
namespace vtkm

@ -11,8 +11,8 @@
#ifndef vtk_m_worklet_gradient_StructuredPointGradient_h
#define vtk_m_worklet_gradient_StructuredPointGradient_h
#include <vtkm/filter/vector_analysis/worklet/gradient/GradientOutput.h>
#include <vtkm/worklet/WorkletPointNeighborhood.h>
#include <vtkm/worklet/gradient/GradientOutput.h>
namespace vtkm

@ -12,8 +12,8 @@
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/filter/vector_analysis/worklet/Magnitude.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/Magnitude.h>
#include <vtkm/interop/TransferToOpenGL.h>

@ -9,6 +9,7 @@
//============================================================================
#include <vtkm/Bounds.h>
#include <vtkm/VecTraits.h>
#include <vtkm/testing/Testing.h>
@ -130,6 +131,23 @@ void TestBounds()
VTKM_TEST_ASSERT(unionBounds.Contains(Vec3(4)), "Contains fail");
VTKM_TEST_ASSERT(unionBounds.Contains(Vec3(17, 3, 7)), "Contains fail");
VTKM_TEST_ASSERT(unionBounds.Contains(Vec3(25)), "Contains fail");
std::cout << "Try VecTraits." << std::endl;
using VTraits = vtkm::VecTraits<vtkm::Bounds>;
VTKM_TEST_ASSERT(VTraits::NUM_COMPONENTS == 3);
vtkm::Bounds simpleBounds{ { 0.0, 1.0 }, { 2.0, 4.0 }, { 8.0, 16.0 } };
VTKM_TEST_ASSERT(VTraits::GetNumberOfComponents(simpleBounds) == 3);
VTKM_TEST_ASSERT(VTraits::GetComponent(simpleBounds, 0) == vtkm::Range{ 0.0, 1.0 });
VTKM_TEST_ASSERT(VTraits::GetComponent(simpleBounds, 1) == vtkm::Range{ 2.0, 4.0 });
VTKM_TEST_ASSERT(VTraits::GetComponent(simpleBounds, 2) == vtkm::Range{ 8.0, 16.0 });
vtkm::Vec<vtkm::Range, 3> simpleBoundsCopy;
VTraits::CopyInto(simpleBounds, simpleBoundsCopy);
VTKM_TEST_ASSERT(simpleBoundsCopy == vtkm::Vec<vtkm::Range, 3>{ { 0, 1 }, { 2, 4 }, { 8, 16 } });
VTraits::SetComponent(simpleBounds, 0, { 8.0, 16.0 });
VTraits::SetComponent(simpleBounds, 2, { 2.0, 4.0 });
VTraits::SetComponent(simpleBounds, 1, { 0.0, 1.0 });
VTKM_TEST_ASSERT(!simpleBounds.Contains(vtkm::Vec3f_64{ 0.5, 3.0, 12.0 }));
VTKM_TEST_ASSERT(simpleBounds.Contains(vtkm::Vec3f_64{ 12.0, 0.5, 3.0 }));
}
} // anonymous namespace

@ -9,6 +9,7 @@
//============================================================================
#include <vtkm/Range.h>
#include <vtkm/VecTraits.h>
#include <vtkm/testing/Testing.h>
@ -132,6 +133,22 @@ void TestRange()
VTKM_TEST_ASSERT(unionRange.Contains(10), "Contains fail");
VTKM_TEST_ASSERT(unionRange.Contains(17), "Contains fail");
VTKM_TEST_ASSERT(unionRange.Contains(25), "Contains fail");
std::cout << "Try VecTraits." << std::endl;
using VTraits = vtkm::VecTraits<vtkm::Range>;
VTKM_TEST_ASSERT(VTraits::NUM_COMPONENTS == 2);
vtkm::Range simpleRange(2.0, 4.0);
VTKM_TEST_ASSERT(VTraits::GetNumberOfComponents(simpleRange) == 2);
VTKM_TEST_ASSERT(VTraits::GetComponent(simpleRange, 0) == 2.0);
VTKM_TEST_ASSERT(VTraits::GetComponent(simpleRange, 1) == 4.0);
vtkm::Vec2f_64 simpleRangeCopy;
VTraits::CopyInto(simpleRange, simpleRangeCopy);
VTKM_TEST_ASSERT(simpleRangeCopy == vtkm::Vec2f_64{ 2.0, 4.0 });
VTraits::SetComponent(simpleRange, 0, 1.0);
VTraits::SetComponent(simpleRange, 1, 2.0);
VTKM_TEST_ASSERT(!simpleRange.Contains(0.0));
VTKM_TEST_ASSERT(simpleRange.Contains(1.5));
VTKM_TEST_ASSERT(!simpleRange.Contains(3.0));
}
} // anonymous namespace

@ -24,13 +24,11 @@ set(headers
DispatcherPointNeighborhood.h
DispatcherReduceByKey.h
FieldStatistics.h
Gradient.h
ImageDifference.h
KdTree3D.h # Deprecated
KernelSplatter.h
Keys.h
LagrangianStructures.h
Magnitude.h
MaskIndices.h
MaskNone.h
MaskSelect.h
@ -38,10 +36,6 @@ set(headers
MIR.h
NDimsHistMarginalization.h
Normalize.h
OrientCellNormals.h
OrientNormals.h
OrientPointNormals.h
OrientPointAndCellNormals.h
ParticleAdvection.h
PointElevation.h
PointTransform.h
@ -56,7 +50,6 @@ set(headers
DescriptiveStatistics.h
StreamLineUniformGrid.h
StreamSurface.h
SurfaceNormals.h
Tetrahedralize.h
TriangleWinding.h
Triangulate.h
@ -109,7 +102,6 @@ add_subdirectory(contourtree)
add_subdirectory(contourtree_augmented)
add_subdirectory(contourtree_distributed)
add_subdirectory(cosmotools)
add_subdirectory(gradient)
add_subdirectory(histogram)
add_subdirectory(lcs)
add_subdirectory(mir)

@ -17,7 +17,6 @@ set(unit_tests
UnitTestAverageByKey.cxx
UnitTestBoundingIntervalHierarchy.cxx
UnitTestCellDeepCopy.cxx
UnitTestCellGradient.cxx
UnitTestCellMeasure.cxx
UnitTestContourTreeUniform.cxx
UnitTestContourTreeUniformAugmented.cxx
@ -27,15 +26,12 @@ set(unit_tests
UnitTestDescriptiveStatistics.cxx
UnitTestFieldStatistics.cxx
UnitTestKeys.cxx
UnitTestMagnitude.cxx
UnitTestMaskIndices.cxx
UnitTestMaskSelect.cxx
UnitTestNormalize.cxx
UnitTestNDimsHistMarginalization.cxx
UnitTestOrientNormals.cxx
UnitTestParticleAdvection.cxx
UnitTestPointElevation.cxx
UnitTestPointGradient.cxx
UnitTestPointTransform.cxx
UnitTestProbe.cxx
UnitTestScalarsToColors.cxx
@ -47,7 +43,6 @@ set(unit_tests
UnitTestScatterAndMaskWithTopology.cxx
UnitTestStreamLineUniformGrid.cxx
UnitTestStreamSurface.cxx
UnitTestSurfaceNormals.cxx
UnitTestTemporalAdvection.cxx
UnitTestTetrahedralize.cxx
UnitTestTriangleWinding.cxx

@ -1,248 +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/Gradient.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
namespace
{
void TestCellGradientUniform2D()
{
std::cout << "Testing CellGradient Worklet on 2D structured data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make2DUniformDataSet0();
vtkm::cont::ArrayHandle<vtkm::Float32> input;
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> result;
dataSet.GetField("pointvar").GetData().AsArrayHandle(input);
vtkm::worklet::CellGradient gradient;
result = gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), input);
vtkm::Vec3f_32 expected[2] = { { 10, 30, 0 }, { 10, 30, 0 } };
for (int i = 0; i < 2; ++i)
{
VTKM_TEST_ASSERT(test_equal(result.ReadPortal().Get(i), expected[i]),
"Wrong result for CellGradient worklet on 2D uniform data");
}
}
void TestCellGradientUniform3D()
{
std::cout << "Testing CellGradient Worklet on 3D structured data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
vtkm::cont::ArrayHandle<vtkm::Float32> input;
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> result;
dataSet.GetField("pointvar").GetData().AsArrayHandle(input);
vtkm::worklet::CellGradient gradient;
result = gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), input);
vtkm::Vec3f_32 expected[4] = {
{ 10.025f, 30.075f, 60.125f },
{ 10.025f, 30.075f, 60.125f },
{ 10.025f, 30.075f, 60.175f },
{ 10.025f, 30.075f, 60.175f },
};
for (int i = 0; i < 4; ++i)
{
VTKM_TEST_ASSERT(test_equal(result.ReadPortal().Get(i), expected[i]),
"Wrong result for CellGradient worklet on 3D uniform data");
}
}
void TestCellGradientUniform3DWithVectorField()
{
std::cout
<< "Testing CellGradient and QCriterion Worklet with a vector field on 3D structured data"
<< std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
//Verify that we can compute the gradient of a 3 component vector
const int nVerts = 18;
vtkm::Float64 vars[nVerts] = { 10.1, 20.1, 30.1, 40.1, 50.2, 60.2, 70.2, 80.2, 90.3,
100.3, 110.3, 120.3, 130.4, 140.4, 150.4, 160.4, 170.5, 180.5 };
std::vector<vtkm::Vec3f_64> vec(18);
for (std::size_t i = 0; i < vec.size(); ++i)
{
vec[i] = vtkm::make_Vec(vars[i], vars[i], vars[i]);
}
vtkm::cont::ArrayHandle<vtkm::Vec3f_64> input =
vtkm::cont::make_ArrayHandle(vec, vtkm::CopyFlag::Off);
//we need to add Vec3 array to the dataset
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Vec3f_64, 3>> result;
vtkm::worklet::GradientOutputFields<vtkm::Vec3f_64> extraOutput;
extraOutput.SetComputeDivergence(false);
extraOutput.SetComputeVorticity(false);
extraOutput.SetComputeQCriterion(true);
vtkm::worklet::CellGradient gradient;
result = gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), input, extraOutput);
VTKM_TEST_ASSERT((extraOutput.Gradient.GetNumberOfValues() == 4),
"Gradient field should be generated");
VTKM_TEST_ASSERT((extraOutput.Divergence.GetNumberOfValues() == 0),
"Divergence field shouldn't be generated");
VTKM_TEST_ASSERT((extraOutput.Vorticity.GetNumberOfValues() == 0),
"Vorticity field shouldn't be generated");
VTKM_TEST_ASSERT((extraOutput.QCriterion.GetNumberOfValues() == 4),
"QCriterion field should be generated");
vtkm::Vec<vtkm::Vec3f_64, 3> expected[4] = {
{ { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.125, 60.125, 60.125 } },
{ { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.125, 60.125, 60.125 } },
{ { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.175, 60.175, 60.175 } },
{ { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.175, 60.175, 60.175 } }
};
for (int i = 0; i < 4; ++i)
{
vtkm::Vec<vtkm::Vec3f_64, 3> e = expected[i];
vtkm::Vec<vtkm::Vec3f_64, 3> r = result.ReadPortal().Get(i);
VTKM_TEST_ASSERT(test_equal(e[0], r[0]),
"Wrong result for vec field CellGradient worklet on 3D uniform data");
VTKM_TEST_ASSERT(test_equal(e[1], r[1]),
"Wrong result for vec field CellGradient worklet on 3D uniform data");
VTKM_TEST_ASSERT(test_equal(e[2], r[2]),
"Wrong result for vec field CellGradient worklet on 3D uniform data");
const vtkm::Vec3f_64 v(e[1][2] - e[2][1], e[2][0] - e[0][2], e[0][1] - e[1][0]);
const vtkm::Vec3f_64 s(e[1][2] + e[2][1], e[2][0] + e[0][2], e[0][1] + e[1][0]);
const vtkm::Vec3f_64 d(e[0][0], e[1][1], e[2][2]);
//compute QCriterion
vtkm::Float64 qcriterion =
((vtkm::Dot(v, v) / 2.0f) - (vtkm::Dot(d, d) + (vtkm::Dot(s, s) / 2.0f))) / 2.0f;
vtkm::Float64 q = extraOutput.QCriterion.ReadPortal().Get(i);
std::cout << "qcriterion expected: " << qcriterion << std::endl;
std::cout << "qcriterion actual: " << q << std::endl;
VTKM_TEST_ASSERT(
test_equal(qcriterion, q),
"Wrong result for QCriterion field of CellGradient worklet on 3D uniform data");
}
}
void TestCellGradientUniform3DWithVectorField2()
{
std::cout << "Testing CellGradient Worklet with a vector field on 3D structured data" << std::endl
<< "Disabling Gradient computation and enabling Divergence, and Vorticity" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
//Verify that we can compute the gradient of a 3 component vector
const int nVerts = 18;
vtkm::Float64 vars[nVerts] = { 10.1, 20.1, 30.1, 40.1, 50.2, 60.2, 70.2, 80.2, 90.3,
100.3, 110.3, 120.3, 130.4, 140.4, 150.4, 160.4, 170.5, 180.5 };
std::vector<vtkm::Vec3f_64> vec(18);
for (std::size_t i = 0; i < vec.size(); ++i)
{
vec[i] = vtkm::make_Vec(vars[i], vars[i], vars[i]);
}
vtkm::cont::ArrayHandle<vtkm::Vec3f_64> input =
vtkm::cont::make_ArrayHandle(vec, vtkm::CopyFlag::Off);
vtkm::worklet::GradientOutputFields<vtkm::Vec3f_64> extraOutput;
extraOutput.SetComputeGradient(false);
extraOutput.SetComputeDivergence(true);
extraOutput.SetComputeVorticity(true);
extraOutput.SetComputeQCriterion(false);
vtkm::worklet::CellGradient gradient;
auto result =
gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), input, extraOutput);
//Verify that the result is 0 size
VTKM_TEST_ASSERT((result.GetNumberOfValues() == 0), "Gradient field shouldn't be generated");
//Verify that the extra arrays are the correct size
VTKM_TEST_ASSERT((extraOutput.Gradient.GetNumberOfValues() == 0),
"Gradient field shouldn't be generated");
VTKM_TEST_ASSERT((extraOutput.Divergence.GetNumberOfValues() == 4),
"Divergence field should be generated");
VTKM_TEST_ASSERT((extraOutput.Vorticity.GetNumberOfValues() == 4),
"Vorticity field should be generated");
VTKM_TEST_ASSERT((extraOutput.QCriterion.GetNumberOfValues() == 0),
"QCriterion field shouldn't be generated");
//Verify the contents of the other arrays
vtkm::Vec<vtkm::Vec3f_64, 3> expected_gradients[4] = {
{ { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.125, 60.125, 60.125 } },
{ { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.125, 60.125, 60.125 } },
{ { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.175, 60.175, 60.175 } },
{ { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.175, 60.175, 60.175 } }
};
auto vorticityPortal = extraOutput.Vorticity.ReadPortal();
auto divergencePortal = extraOutput.Divergence.ReadPortal();
for (int i = 0; i < 4; ++i)
{
vtkm::Vec<vtkm::Vec3f_64, 3> eg = expected_gradients[i];
vtkm::Float64 d = divergencePortal.Get(i);
VTKM_TEST_ASSERT(test_equal((eg[0][0] + eg[1][1] + eg[2][2]), d),
"Wrong result for Divergence on 3D uniform data");
vtkm::Vec3f_64 ev(eg[1][2] - eg[2][1], eg[2][0] - eg[0][2], eg[0][1] - eg[1][0]);
vtkm::Vec3f_64 v = vorticityPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(ev, v), "Wrong result for Vorticity on 3D uniform data");
}
}
void TestCellGradientExplicit()
{
std::cout << "Testing CellGradient Worklet on Explicit data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DExplicitDataSet0();
vtkm::cont::ArrayHandle<vtkm::Float32> input;
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> result;
dataSet.GetField("pointvar").GetData().AsArrayHandle(input);
vtkm::worklet::CellGradient gradient;
result = gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), input);
vtkm::Vec3f_32 expected[2] = { { 10.f, 10.1f, 0.0f }, { 10.f, 10.1f, -0.0f } };
auto resultPortal = result.ReadPortal();
for (int i = 0; i < 2; ++i)
{
VTKM_TEST_ASSERT(test_equal(resultPortal.Get(i), expected[i]),
"Wrong result for CellGradient worklet on 3D explicit data");
}
}
void TestCellGradient()
{
TestCellGradientUniform2D();
TestCellGradientUniform3D();
TestCellGradientUniform3DWithVectorField();
TestCellGradientUniform3DWithVectorField2();
TestCellGradientExplicit();
}
}
int UnitTestCellGradient(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestCellGradient, argc, argv);
}

@ -1,62 +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/Magnitude.h>
#include <vtkm/cont/testing/Testing.h>
namespace
{
void TestMagnitude()
{
std::cout << "Testing Magnitude Worklet" << std::endl;
vtkm::worklet::Magnitude magnitudeWorklet;
using ArrayReturnType = vtkm::cont::ArrayHandle<vtkm::Float64>;
using ArrayVectorType = vtkm::cont::ArrayHandle<vtkm::Vec4i_32>;
ArrayVectorType pythagoreanTriples;
pythagoreanTriples.Allocate(5);
{
auto inputPortal = pythagoreanTriples.WritePortal();
inputPortal.Set(0, vtkm::make_Vec(3, 4, 5, 0));
inputPortal.Set(1, vtkm::make_Vec(5, 12, 13, 0));
inputPortal.Set(2, vtkm::make_Vec(8, 15, 17, 0));
inputPortal.Set(3, vtkm::make_Vec(7, 24, 25, 0));
inputPortal.Set(4, vtkm::make_Vec(9, 40, 41, 0));
}
vtkm::worklet::DispatcherMapField<vtkm::worklet::Magnitude> dispatcher(magnitudeWorklet);
ArrayReturnType result;
dispatcher.Invoke(pythagoreanTriples, result);
auto inputPortal = pythagoreanTriples.ReadPortal();
auto resultPortal = result.ReadPortal();
for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i)
{
vtkm::Vec4i_32 inValue = inputPortal.Get(i);
vtkm::Float64 expectedValue =
std::sqrt((inValue[0] * inValue[0]) + (inValue[1] * inValue[1]) + (inValue[2] * inValue[2]));
vtkm::Float64 resultValue = resultPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(expectedValue, resultValue), expectedValue, " != ", resultValue);
}
}
}
int UnitTestMagnitude(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestMagnitude, argc, argv);
}

@ -1,383 +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.
//
// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2019 UT-Battelle, LLC.
// Copyright 2019 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//
//=============================================================================
#include <vtkm/worklet/OrientNormals.h>
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandleBitField.h>
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/cont/BitField.h>
#include <vtkm/cont/CellSet.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/filter/PolicyBase.h>
#include <vtkm/filter/SurfaceNormals.h>
#include <vtkm/filter/clean_grid/CleanGrid.h>
#include <vtkm/filter/contour/Contour.h>
#include <vtkm/source/Wavelet.h>
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/RuntimeDeviceTracker.h>
namespace
{
VTKM_CONT
vtkm::cont::DataSet CreateDataSet(bool pointNormals, bool cellNormals)
{
vtkm::source::Wavelet wavelet({ -25 }, { 25 });
wavelet.SetFrequency({ 20, 15, 25 });
wavelet.SetMagnitude({ 5 });
auto dataSet = wavelet.Execute();
vtkm::filter::clean_grid::CleanGrid toGrid;
// unstructured grid contour
vtkm::filter::contour::Contour contour;
contour.SetActiveField("RTData", vtkm::cont::Field::Association::POINTS);
contour.SetNumberOfIsoValues(1);
contour.SetIsoValue(192);
contour.SetMergeDuplicatePoints(true);
contour.SetGenerateNormals(false);
dataSet = contour.Execute(toGrid.Execute(dataSet));
vtkm::filter::SurfaceNormals normals;
normals.SetGeneratePointNormals(pointNormals);
normals.SetGenerateCellNormals(cellNormals);
normals.SetPointNormalsName("normals");
normals.SetCellNormalsName("normals");
normals.SetAutoOrientNormals(false);
dataSet = normals.Execute(dataSet);
return dataSet;
}
struct ValidateNormals
{
using CellSetType = vtkm::cont::CellSetSingleType<>;
using NormalType = vtkm::Vec3f;
using NormalsArrayType = vtkm::cont::ArrayHandle<NormalType>;
using NormalsPortalType = decltype(std::declval<NormalsArrayType>().ReadPortal());
using PointsType = decltype(std::declval<vtkm::cont::CoordinateSystem>().GetDataAsMultiplexer());
vtkm::cont::CoordinateSystem Coords;
CellSetType Cells;
PointsType Points;
NormalsArrayType PointNormalsArray;
NormalsPortalType PointNormals;
NormalsArrayType CellNormalsArray;
NormalsPortalType CellNormals;
vtkm::cont::BitField VisitedCellsField;
vtkm::cont::BitField VisitedPointsField;
bool CheckPoints;
bool CheckCells;
VTKM_CONT
static void Run(vtkm::cont::DataSet& dataset,
bool checkPoints,
bool checkCells,
const std::string& normalsName = "normals")
{
// Temporarily enable the serial device for workaround in ValidateNormals,
// which requires the serial device. This can be refactored once #377 is
// fixed.
vtkm::cont::ScopedRuntimeDeviceTracker tracker(vtkm::cont::DeviceAdapterTagSerial{},
vtkm::cont::RuntimeDeviceTrackerMode::Enable);
vtkm::cont::Field pointNormals;
vtkm::cont::Field cellNormals;
if (checkPoints)
{
pointNormals = dataset.GetPointField(normalsName);
}
if (checkCells)
{
cellNormals = dataset.GetCellField(normalsName);
}
ValidateNormals obj{ dataset, checkPoints, checkCells, pointNormals, cellNormals };
obj.Validate();
}
VTKM_CONT
ValidateNormals(const vtkm::cont::DataSet& dataset,
bool checkPoints,
bool checkCells,
const vtkm::cont::Field& pointNormalsField,
const vtkm::cont::Field& cellNormalsField)
: Coords{ dataset.GetCoordinateSystem() }
, Cells{ dataset.GetCellSet().AsCellSet<CellSetType>() }
, Points{ this->Coords.GetDataAsMultiplexer() }
, CheckPoints(checkPoints)
, CheckCells(checkCells)
{
// FIXME This would be much simplier if we had a GetPointCells() method on
// cell sets.... #377 will simplify this.
// Build the connectivity table on any device, then get a portal for serial
// so we can do lookups on the CPU.
this->Cells.GetConnectivityArray(vtkm::TopologyElementTagCell{},
vtkm::TopologyElementTagPoint{});
this->Cells.GetConnectivityArray(vtkm::TopologyElementTagCell{},
vtkm::TopologyElementTagPoint{});
if (this->CheckPoints)
{
pointNormalsField.GetData().AsArrayHandle(this->PointNormalsArray);
this->PointNormals = this->PointNormalsArray.ReadPortal();
}
if (this->CheckCells)
{
cellNormalsField.GetData().AsArrayHandle(this->CellNormalsArray);
this->CellNormals = this->CellNormalsArray.ReadPortal();
}
}
VTKM_CONT
void Validate()
{
// Locate a point with the minimum x coordinate:
const vtkm::Id startPoint = [&]() -> vtkm::Id {
const vtkm::Float64 xMin = this->Coords.GetBounds().X.Min;
const auto pointArray = this->Coords.GetDataAsMultiplexer();
const auto points = pointArray.ReadPortal();
const vtkm::Id numPoints = points.GetNumberOfValues();
vtkm::Id resultIdx = -1;
for (vtkm::Id pointIdx = 0; pointIdx < numPoints; ++pointIdx)
{
const auto point = points.Get(pointIdx);
if (static_cast<double>(point[0]) <= xMin)
{
resultIdx = pointIdx;
break;
}
}
if (resultIdx < 0)
{
throw vtkm::cont::ErrorBadValue("Minimum point not found!");
}
return resultIdx;
}();
// Start recursive validation.
this->Prepare();
this->ValidateImpl(startPoint, NormalType{ -1, 0, 0 });
vtkm::Id numPoints = this->Points.GetNumberOfValues();
vtkm::Id numCells = this->Cells.GetNumberOfCells();
vtkm::Id numVisitedPoints = vtkm::cont::Algorithm::CountSetBits(this->VisitedPointsField);
vtkm::Id numVisitedCells = vtkm::cont::Algorithm::CountSetBits(this->VisitedCellsField);
if (numPoints != numVisitedPoints)
{
std::cerr << __FILE__ << ":" << __LINE__ << ":" << __func__ << "\n";
std::cerr << "\tnumPoints is " << numPoints << ", but numVisitedPoints is only "
<< numVisitedPoints << "\n";
throw vtkm::cont::ErrorBadValue("Unvisited point!");
}
if (numCells != numVisitedCells)
{
std::cerr << __FILE__ << ":" << __LINE__ << ":" << __func__ << "\n";
std::cerr << "\tnumCells is " << numCells << ", but numVisitedCells is only "
<< numVisitedCells << "\n";
throw vtkm::cont::ErrorBadValue("Unvisited cell!");
}
}
private:
static bool SameHemisphere(const NormalType& a, const NormalType& b)
{
return vtkm::Dot(a, b) >= 0;
}
void Prepare()
{
this->VisitedPointsField.AllocateAndFill(this->Coords.GetNumberOfPoints(), false);
this->VisitedCellsField.AllocateAndFill(this->Cells.GetNumberOfCells(), false);
}
void ValidateImpl(vtkm::Id startPtIdx, const NormalType& startRefNormal)
{
vtkm::cont::BitField::WritePortalType visitedPoints = this->VisitedPointsField.WritePortal();
vtkm::cont::BitField::WritePortalType visitedCells = this->VisitedCellsField.WritePortal();
using Entry = vtkm::Pair<vtkm::Id, NormalType>;
std::vector<Entry> queue;
queue.emplace_back(startPtIdx, startRefNormal);
visitedPoints.SetBit(startPtIdx, true);
vtkm::cont::Token token;
auto connections = this->Cells.PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{},
vtkm::TopologyElementTagCell{},
vtkm::TopologyElementTagPoint{},
token);
auto reverseConnections = this->Cells.PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{},
vtkm::TopologyElementTagPoint{},
vtkm::TopologyElementTagCell{},
token);
auto points = this->Points.ReadPortal();
while (!queue.empty())
{
const vtkm::Id curPtIdx = queue.back().first;
NormalType refNormal = queue.back().second;
queue.pop_back();
if (this->CheckPoints)
{
const NormalType curNormal = this->PointNormals.Get(curPtIdx);
if (!this->SameHemisphere(curNormal, refNormal))
{
throw vtkm::cont::ErrorBadValue("Bad point normal found!");
}
refNormal = curNormal;
}
// Lookup and visit neighbor cells:
const auto neighborCells = reverseConnections.GetIndices(curPtIdx);
const auto numNeighborCells = neighborCells.GetNumberOfComponents();
for (vtkm::IdComponent nCellIdx = 0; nCellIdx < numNeighborCells; ++nCellIdx)
{
const vtkm::Id curCellIdx = neighborCells[nCellIdx];
// Skip this cell if already visited:
if (visitedCells.GetBit(curCellIdx))
{
continue;
}
visitedCells.SetBit(curCellIdx, true);
if (this->CheckCells)
{
const NormalType curNormal = this->CellNormals.Get(curCellIdx);
if (!this->SameHemisphere(curNormal, refNormal))
{
throw vtkm::cont::ErrorBadValue("Bad cell normal found!");
}
refNormal = curNormal;
}
// Lookup and visit points in this cell:
const auto neighborPoints = connections.GetIndices(curCellIdx);
const auto numNeighborPoints = neighborPoints.GetNumberOfComponents();
for (vtkm::IdComponent nPtIdx = 0; nPtIdx < numNeighborPoints; ++nPtIdx)
{
const vtkm::Id nextPtIdx = neighborPoints[nPtIdx];
// Skip if already visited:
if (visitedPoints.GetBit(nextPtIdx))
{
continue;
}
// Otherwise, queue next point using current normal as reference:
queue.emplace_back(nextPtIdx, refNormal);
visitedPoints.SetBit(nextPtIdx, true);
}
}
}
}
};
VTKM_CONT
void TestOrientNormals(bool testPoints, bool testCells)
{
using NormalArrayT = vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>>;
auto dataset = CreateDataSet(testPoints, testCells);
// Check that the input actually has bad normals:
const bool inputValid = [&]() -> bool {
try
{
ValidateNormals::Run(dataset, testPoints, testCells);
return true; // Dataset is already oriented
}
catch (vtkm::cont::ErrorBadValue&)
{
return false; // Dataset is unoriented
}
}();
if (inputValid)
{
throw vtkm::cont::ErrorBadValue("Error: Input doesn't have bad normals.");
}
// modify normals in place
const auto coords = dataset.GetCoordinateSystem().GetDataAsMultiplexer();
const auto cells = dataset.GetCellSet();
if (testPoints && testCells)
{
const auto pointNormalField = dataset.GetPointField("normals");
const auto cellNormalField = dataset.GetCellField("normals");
auto pointNormals = pointNormalField.GetData().AsArrayHandle<NormalArrayT>();
auto cellNormals = cellNormalField.GetData().AsArrayHandle<NormalArrayT>();
vtkm::worklet::OrientNormals::RunPointAndCellNormals(cells, coords, pointNormals, cellNormals);
}
else if (testPoints)
{
const auto pointNormalField = dataset.GetPointField("normals");
auto pointNormals = pointNormalField.GetData().AsArrayHandle<NormalArrayT>();
vtkm::worklet::OrientNormals::RunPointNormals(cells, coords, pointNormals);
}
else if (testCells)
{
const auto cellNormalField = dataset.GetCellField("normals");
auto cellNormals = cellNormalField.GetData().AsArrayHandle<NormalArrayT>();
vtkm::worklet::OrientNormals::RunCellNormals(cells, coords, cellNormals);
}
else
{
throw "Nothing tested...";
}
ValidateNormals::Run(dataset, testPoints, testCells);
}
void DoTest()
{
TestOrientNormals(true, false);
TestOrientNormals(false, true);
TestOrientNormals(true, true);
}
} // end anon namespace
int UnitTestOrientNormals(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(DoTest, argc, argv);
}

@ -1,280 +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/DispatcherMapTopology.h>
#include <vtkm/worklet/Gradient.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
namespace
{
void TestPointGradientUniform2D()
{
std::cout << "Testing PointGradient Worklet on 2D structured data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make2DUniformDataSet0();
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataSet.GetField("pointvar").GetData().AsArrayHandle(fieldArray);
vtkm::worklet::PointGradient gradient;
auto result = gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), fieldArray);
vtkm::Vec3f_32 expected[2] = { { 10, 30, 0 }, { 10, 30, 0 } };
for (int i = 0; i < 2; ++i)
{
VTKM_TEST_ASSERT(test_equal(result.ReadPortal().Get(i), expected[i]),
"Wrong result for PointGradient worklet on 2D uniform data",
"\nExpected ",
expected[i],
"\nGot ",
result.ReadPortal().Get(i),
"\n");
}
}
void TestPointGradientUniform3D()
{
std::cout << "Testing PointGradient Worklet on 3D structured data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataSet.GetField("pointvar").GetData().AsArrayHandle(fieldArray);
vtkm::worklet::PointGradient gradient;
auto result = gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), fieldArray);
vtkm::Vec3f_32 expected[4] = {
{ 10.0f, 30.f, 60.1f },
{ 10.0f, 30.1f, 60.1f },
{ 10.0f, 30.1f, 60.2f },
{ 10.1f, 30.f, 60.2f },
};
for (int i = 0; i < 4; ++i)
{
VTKM_TEST_ASSERT(test_equal(result.ReadPortal().Get(i), expected[i]),
"Wrong result for PointGradient worklet on 3D uniform data",
"\nExpected ",
expected[i],
"\nGot ",
result.ReadPortal().Get(i),
"\n");
}
}
void TestPointGradientUniform3DWithVectorField()
{
std::cout << "Testing PointGradient Worklet with a vector field on 3D structured data"
<< std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
//Verify that we can compute the gradient of a 3 component vector
const int nVerts = 18;
vtkm::Float64 vars[nVerts] = { 10.1, 20.1, 30.1, 40.1, 50.2, 60.2, 70.2, 80.2, 90.3,
100.3, 110.3, 120.3, 130.4, 140.4, 150.4, 160.4, 170.5, 180.5 };
std::vector<vtkm::Vec3f_64> vec(18);
for (std::size_t i = 0; i < vec.size(); ++i)
{
vec[i] = vtkm::make_Vec(vars[i], vars[i], vars[i]);
}
vtkm::cont::ArrayHandle<vtkm::Vec3f_64> input =
vtkm::cont::make_ArrayHandle(vec, vtkm::CopyFlag::On);
vtkm::worklet::PointGradient gradient;
auto result = gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), input);
vtkm::Vec<vtkm::Vec3f_64, 3> expected[4] = {
{ { 10.0, 10.0, 10.0 }, { 30.0, 30.0, 30.0 }, { 60.1, 60.1, 60.1 } },
{ { 10.0, 10.0, 10.0 }, { 30.1, 30.1, 30.1 }, { 60.1, 60.1, 60.1 } },
{ { 10.0, 10.0, 10.0 }, { 30.1, 30.1, 30.1 }, { 60.2, 60.2, 60.2 } },
{ { 10.1, 10.1, 10.1 }, { 30.0, 30.0, 30.0 }, { 60.2, 60.2, 60.2 } }
};
for (int i = 0; i < 4; ++i)
{
vtkm::Vec<vtkm::Vec3f_64, 3> e = expected[i];
vtkm::Vec<vtkm::Vec3f_64, 3> r = result.ReadPortal().Get(i);
VTKM_TEST_ASSERT(test_equal(e[0], r[0]),
"Wrong result for vec field PointGradient worklet on 3D uniform data");
VTKM_TEST_ASSERT(test_equal(e[1], r[1]),
"Wrong result for vec field PointGradient worklet on 3D uniform data");
VTKM_TEST_ASSERT(test_equal(e[2], r[2]),
"Wrong result for vec field PointGradient worklet on 3D uniform data");
}
}
void TestPointGradientUniform3DWithVectorField2()
{
std::cout << "Testing PointGradient Worklet with a vector field on 3D structured data"
<< std::endl
<< "Disabling Gradient computation and enabling Divergence, Vorticity, and QCriterion"
<< std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
//Verify that we can compute the gradient of a 3 component vector
const int nVerts = 18;
vtkm::Float64 vars[nVerts] = { 10.1, 20.1, 30.1, 40.1, 50.2, 60.2, 70.2, 80.2, 90.3,
100.3, 110.3, 120.3, 130.4, 140.4, 150.4, 160.4, 170.5, 180.5 };
std::vector<vtkm::Vec3f_64> vec(18);
for (std::size_t i = 0; i < vec.size(); ++i)
{
vec[i] = vtkm::make_Vec(vars[i], vars[i], vars[i]);
}
vtkm::cont::ArrayHandle<vtkm::Vec3f_64> input =
vtkm::cont::make_ArrayHandle(vec, vtkm::CopyFlag::On);
vtkm::worklet::GradientOutputFields<vtkm::Vec3f_64> extraOutput;
extraOutput.SetComputeGradient(false);
extraOutput.SetComputeDivergence(true);
extraOutput.SetComputeVorticity(true);
extraOutput.SetComputeQCriterion(true);
vtkm::worklet::PointGradient gradient;
auto result =
gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), input, extraOutput);
//Verify that the result is 0 size
VTKM_TEST_ASSERT((result.GetNumberOfValues() == 0), "Gradient field shouldn't be generated");
//Verify that the extra arrays are the correct size
VTKM_TEST_ASSERT((extraOutput.Gradient.GetNumberOfValues() == 0),
"Gradient field shouldn't be generated");
VTKM_TEST_ASSERT((extraOutput.Divergence.GetNumberOfValues() == nVerts),
"Divergence field should be generated");
VTKM_TEST_ASSERT((extraOutput.Vorticity.GetNumberOfValues() == nVerts),
"Vorticity field should be generated");
VTKM_TEST_ASSERT((extraOutput.QCriterion.GetNumberOfValues() == nVerts),
"QCriterion field should be generated");
vtkm::Vec<vtkm::Vec3f_64, 3> expected_gradients[4] = {
{ { 10.0, 10.0, 10.0 }, { 30.0, 30.0, 30.0 }, { 60.1, 60.1, 60.1 } },
{ { 10.0, 10.0, 10.0 }, { 30.1, 30.1, 30.1 }, { 60.1, 60.1, 60.1 } },
{ { 10.0, 10.0, 10.0 }, { 30.1, 30.1, 30.1 }, { 60.2, 60.2, 60.2 } },
{ { 10.1, 10.1, 10.1 }, { 30.0, 30.0, 30.0 }, { 60.2, 60.2, 60.2 } }
};
for (int i = 0; i < 4; ++i)
{
vtkm::Vec<vtkm::Vec3f_64, 3> eg = expected_gradients[i];
vtkm::Float64 d = extraOutput.Divergence.ReadPortal().Get(i);
VTKM_TEST_ASSERT(test_equal((eg[0][0] + eg[1][1] + eg[2][2]), d),
"Wrong result for Divergence on 3D uniform data");
vtkm::Vec3f_64 ev(eg[1][2] - eg[2][1], eg[2][0] - eg[0][2], eg[0][1] - eg[1][0]);
vtkm::Vec3f_64 v = extraOutput.Vorticity.ReadPortal().Get(i);
VTKM_TEST_ASSERT(test_equal(ev, v), "Wrong result for Vorticity on 3D uniform data");
const vtkm::Vec3f_64 es(eg[1][2] + eg[2][1], eg[2][0] + eg[0][2], eg[0][1] + eg[1][0]);
const vtkm::Vec3f_64 ed(eg[0][0], eg[1][1], eg[2][2]);
//compute QCriterion
vtkm::Float64 qcriterion =
((vtkm::Dot(ev, ev) / 2.0f) - (vtkm::Dot(ed, ed) + (vtkm::Dot(es, es) / 2.0f))) / 2.0f;
vtkm::Float64 q = extraOutput.QCriterion.ReadPortal().Get(i);
VTKM_TEST_ASSERT(
test_equal(qcriterion, q),
"Wrong result for QCriterion field of PointGradient worklet on 3D uniform data");
}
}
void TestPointGradientExplicit3D()
{
std::cout << "Testing PointGradient Worklet on Explicit 3D data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DExplicitDataSet5();
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataSet.GetField("pointvar").GetData().AsArrayHandle(fieldArray);
vtkm::worklet::PointGradient gradient;
auto result = gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), fieldArray);
//vtkm::cont::printSummary_ArrayHandle(result, std::cout, true);
const int nVerts = 11;
vtkm::Vec3f_32 expected[nVerts] = {
{ 10.0f, 40.2f, 30.1f }, { 27.4f, 40.1f, 10.1f }, { 17.425f, 40.0f, 10.1f },
{ -10.0f, 40.1f, 30.1f }, { 9.9f, -0.0500011f, 30.0f }, { 16.2125f, -4.55f, 10.0f },
{ 6.2f, -4.6f, 10.0f }, { -10.1f, -0.0999985f, 30.0f }, { 22.5125f, -4.575f, 10.025f },
{ 1.0f, -40.3f, 30.0f }, { 0.6f, -49.2f, 10.0f }
};
for (int i = 0; i < nVerts; ++i)
{
VTKM_TEST_ASSERT(test_equal(result.ReadPortal().Get(i), expected[i]),
"Wrong result for PointGradient worklet on 3D explicit data",
"\nExpected ",
expected[i],
"\nGot ",
result.ReadPortal().Get(i),
"\n");
}
}
void TestPointGradientExplicit2D()
{
std::cout << "Testing PointGradient Worklet on Explicit 2D data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make2DExplicitDataSet0();
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataSet.GetField("pointvar").GetData().AsArrayHandle(fieldArray);
vtkm::worklet::PointGradient gradient;
auto result = gradient.Run(dataSet.GetCellSet(), dataSet.GetCoordinateSystem(), fieldArray);
//vtkm::cont::printSummary_ArrayHandle(result, std::cout, true);
const int nVerts = 16;
vtkm::Vec3f_32 expected[nVerts] = {
{ -22.0f, -7.0f, 0.0f }, { -25.5f, -7.0f, 0.0f }, { -30.5f, 7.0f, 0.0f },
{ -32.0f, 16.0f, 0.0f }, { -23.0f, -42.0f, 0.0f }, { -23.25f, -17.0f, 0.0f },
{ -20.6667f, 1.33333f, 0.0f }, { -23.0f, 14.0f, 0.0f }, { -8.0f, -42.0f, 0.0f },
{ 2.91546f, -24.8357f, 0.0f }, { -0.140736f, -7.71853f, 0.0f }, { -5.0f, 12.0f, 0.0f },
{ 31.8803f, 1.0f, 0.0f }, { -44.8148f, 20.5f, 0.0f }, { 38.5653f, 5.86938f, 0.0f },
{ 26.3967f, 86.7934f, 0.0f }
};
for (int i = 0; i < nVerts; ++i)
{
VTKM_TEST_ASSERT(test_equal(result.ReadPortal().Get(i), expected[i]),
"Wrong result for PointGradient worklet on 2D explicit data",
"\nExpected ",
expected[i],
"\nGot ",
result.ReadPortal().Get(i),
"\n");
}
}
void TestPointGradient()
{
TestPointGradientUniform2D();
TestPointGradientUniform3D();
TestPointGradientUniform3DWithVectorField();
TestPointGradientUniform3DWithVectorField2();
TestPointGradientExplicit2D();
TestPointGradientExplicit3D();
}
}
int UnitTestPointGradient(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestPointGradient, argc, argv);
}

@ -7,8 +7,8 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/filter/vector_analysis/worklet/SurfaceNormals.h>
#include <vtkm/worklet/SplitSharpEdges.h>
#include <vtkm/worklet/SurfaceNormals.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/testing/Testing.h>

@ -1,79 +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/SurfaceNormals.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace
{
using NormalsArrayHandle = vtkm::cont::ArrayHandle<vtkm::Vec3f>;
void TestFacetedSurfaceNormals(const vtkm::cont::DataSet& dataset, NormalsArrayHandle& normals)
{
std::cout << "Testing FacetedSurfaceNormals:\n";
vtkm::worklet::FacetedSurfaceNormals faceted;
faceted.Run(dataset.GetCellSet(), dataset.GetCoordinateSystem().GetData(), normals);
vtkm::Vec3f expected[8] = { { -0.707f, -0.500f, 0.500f }, { -0.707f, -0.500f, 0.500f },
{ 0.707f, 0.500f, -0.500f }, { 0.000f, -0.707f, -0.707f },
{ 0.000f, -0.707f, -0.707f }, { 0.000f, 0.707f, 0.707f },
{ -0.707f, 0.500f, -0.500f }, { 0.707f, -0.500f, 0.500f } };
auto portal = normals.ReadPortal();
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == 8, "incorrect faceNormals array length");
for (vtkm::Id i = 0; i < 8; ++i)
{
VTKM_TEST_ASSERT(test_equal(portal.Get(i), expected[i], 0.001),
"result does not match expected value");
}
}
void TestSmoothSurfaceNormals(const vtkm::cont::DataSet& dataset,
const NormalsArrayHandle& faceNormals)
{
std::cout << "Testing SmoothSurfaceNormals:\n";
NormalsArrayHandle pointNormals;
vtkm::worklet::SmoothSurfaceNormals smooth;
smooth.Run(dataset.GetCellSet(), faceNormals, pointNormals);
vtkm::Vec3f expected[8] = { { -0.8165f, -0.4082f, -0.4082f }, { -0.2357f, -0.9714f, 0.0286f },
{ 0.0000f, -0.1691f, 0.9856f }, { -0.8660f, 0.0846f, 0.4928f },
{ 0.0000f, -0.1691f, -0.9856f }, { 0.0000f, 0.9856f, -0.1691f },
{ 0.8165f, 0.4082f, 0.4082f }, { 0.8165f, -0.4082f, -0.4082f } };
auto portal = pointNormals.ReadPortal();
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == 8, "incorrect pointNormals array length");
for (vtkm::Id i = 0; i < 8; ++i)
{
VTKM_TEST_ASSERT(test_equal(portal.Get(i), expected[i], 0.001),
"result does not match expected value");
}
}
void TestSurfaceNormals()
{
vtkm::cont::DataSet dataset =
vtkm::cont::testing::MakeTestDataSet().Make3DExplicitDataSetPolygonal();
NormalsArrayHandle faceNormals;
TestFacetedSurfaceNormals(dataset, faceNormals);
TestSmoothSurfaceNormals(dataset, faceNormals);
}
} // anonymous namespace
int UnitTestSurfaceNormals(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestSurfaceNormals, argc, argv);
}