Commit 0e6529eb authored by Kenneth Moreland's avatar Kenneth Moreland Committed by Kitware Robot

Merge topic 'unknownarray-variable-vec'

9b62c9ee Enable storing variable-sized Vecs in UnknownArrayHandle
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarRobert Maynard <robert.maynard@kitware.com>
Merge-request: !2260
parents fbb69b76 9b62c9ee
......@@ -51,10 +51,23 @@ static vtkm::Id UnknownAHNumberOfValues(void* mem)
return arrayHandle->GetNumberOfValues();
}
template <typename T, typename StaticSize = typename vtkm::VecTraits<T>::IsSizeStatic>
struct UnknownAHNumberOfComponentsImpl;
template <typename T>
struct UnknownAHNumberOfComponentsImpl<T, vtkm::VecTraitsTagSizeStatic>
{
static constexpr vtkm::IdComponent Value = vtkm::VecTraits<T>::NUM_COMPONENTS;
};
template <typename T>
struct UnknownAHNumberOfComponentsImpl<T, vtkm::VecTraitsTagSizeVariable>
{
static constexpr vtkm::IdComponent Value = 0;
};
template <typename T>
static vtkm::IdComponent UnknownAHNumberOfComponents()
{
return vtkm::VecTraits<T>::NUM_COMPONENTS;
return UnknownAHNumberOfComponentsImpl<T>::Value;
}
template <typename T, typename S>
......@@ -303,6 +316,8 @@ public:
///
/// If the array holds `vtkm::Vec` objects, this will return the number of components
/// in each value. If the array holds a basic C type (such as `float`), this will return 1.
/// If the array holds `Vec`-like objects that have the number of components that can vary
/// at runtime, this method will return 0 (because there is no consistent answer).
///
VTKM_CONT vtkm::IdComponent GetNumberOfComponents() const
{
......
......@@ -11,6 +11,12 @@
#include <vtkm/cont/UncertainArrayHandle.h>
#include <vtkm/cont/UnknownArrayHandle.h>
#include <vtkm/cont/ArrayHandleCast.h>
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandleGroupVecVariable.h>
#include <vtkm/cont/ArrayHandleMultiplexer.h>
#include <vtkm/TypeTraits.h>
#include <vtkm/cont/testing/Testing.h>
......@@ -237,6 +243,25 @@ void CheckAsArrayHandle(const ArrayHandleType& array)
ArrayHandleType retrievedArray = arrayUnknown2.AsArrayHandle<ArrayHandleType>();
VTKM_TEST_ASSERT(array == retrievedArray);
}
{
std::cout << " Try adding arrays with variable amounts of components" << std::endl;
// There might be some limited functionality, but you should still be able
// to get arrays in and out.
// Note, this is a bad way to implement this array. You should something like
// ArrayHandleGroupVec instead.
using VariableVecArrayType =
vtkm::cont::ArrayHandleGroupVecVariable<ArrayHandleType,
vtkm::cont::ArrayHandleCounting<vtkm::Id>>;
VariableVecArrayType inArray = vtkm::cont::make_ArrayHandleGroupVecVariable(
array, vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(0, 2, ARRAY_SIZE / 2 + 1));
VTKM_TEST_ASSERT(inArray.GetNumberOfValues() == ARRAY_SIZE / 2);
vtkm::cont::UnknownArrayHandle arrayUnknown2 = inArray;
VTKM_TEST_ASSERT(arrayUnknown2.IsType<VariableVecArrayType>());
VariableVecArrayType retrievedArray = arrayUnknown2.AsArrayHandle<VariableVecArrayType>();
VTKM_TEST_ASSERT(retrievedArray == inArray);
}
}
// A vtkm::Vec if NumComps > 1, otherwise a scalar
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment