6#ifndef vtkmlib_DataArrayConverters_h
7#define vtkmlib_DataArrayConverters_h
9#include "vtkAcceleratorsVTKmCoreModule.h"
10#include "vtkmConfigCore.h"
17#include <vtkm/cont/ArrayExtractComponent.h>
18#include <vtkm/cont/ArrayHandleBasic.h>
19#include <vtkm/cont/ArrayHandleRecombineVec.h>
20#include <vtkm/cont/ArrayHandleRuntimeVec.h>
21#include <vtkm/cont/ArrayHandleSOA.h>
22#include <vtkm/cont/ArrayHandleStride.h>
23#include <vtkm/cont/Field.h>
24#include <vtkm/cont/UnknownArrayHandle.h>
33class CoordinateSystem;
37VTK_ABI_NAMESPACE_BEGIN
44VTK_ABI_NAMESPACE_BEGIN
51 static const char* name =
"NoNameVTKField";
63 auto deleter = [](
void* container)
69 [](
void*& memory,
void*& container, vtkm::BufferSizeType oldSize, vtkm::BufferSizeType newSize)
72 if ((
vtkArray->GetVoidPointer(0) != memory) || (
vtkArray->GetNumberOfValues() != oldSize))
75 "Dangerous inconsistency found between pointers for VTK and VTK-m. "
76 "Was the VTK array resized outside of VTK-m?");
78 vtkArray->SetNumberOfValues(newSize);
79 memory =
vtkArray->GetVoidPointer(0);
82 return vtkm::cont::ArrayHandleBasic<T>(
94 using ContainerPair = std::pair<vtkSOADataArrayTemplate<T>*,
int>;
95 ContainerPair* componentInput =
new ContainerPair(input, componentIndex);
97 auto deleter = [](
void* container)
99 ContainerPair* containerPair =
reinterpret_cast<ContainerPair*
>(container);
100 containerPair->first->UnRegister(
nullptr);
101 delete containerPair;
103 auto reallocator = [](
void*& memory,
void*& container, vtkm::BufferSizeType vtkNotUsed(oldSize),
104 vtkm::BufferSizeType newSize)
106 ContainerPair* containerPair =
reinterpret_cast<ContainerPair*
>(container);
107 containerPair->first->SetNumberOfTuples(newSize);
108 memory = containerPair->first->GetComponentArrayPointer(containerPair->second);
128 vtkm::cont::ArrayHandleRecombineVec<T> output;
133 output.AppendComponentArray(
134 vtkm::cont::ArrayExtractComponent(componentArray, 0, vtkm::CopyFlag::Off));
140template <
typename DataArrayType>
146template <
typename DataArrayType, vtkm::IdComponent NumComponents>
149template <
typename T, vtkm::IdComponent NumComponents>
153 typename std::conditional<NumComponents == 1, T, vtkm::Vec<T, NumComponents>>::type;
154 using StorageType = vtkm::cont::internal::Storage<ValueType, vtkm::cont::StorageTagBasic>;
155 using ArrayHandleType = vtkm::cont::ArrayHandle<ValueType, vtkm::cont::StorageTagBasic>;
160 return vtkm::cont::make_ArrayHandle(
reinterpret_cast<ValueType*
>(input->GetPointer(0)),
161 input->GetNumberOfTuples(), vtkm::CopyFlag::Off);
165template <
typename T, vtkm::IdComponent NumComponents>
169 using StorageType = vtkm::cont::internal::Storage<ValueType, vtkm::cont::StorageTagSOA>;
170 using ArrayHandleType = vtkm::cont::ArrayHandle<ValueType, vtkm::cont::StorageTagSOA>;
175 vtkm::Id numValues = input->GetNumberOfTuples();
176 vtkm::cont::ArrayHandleSOA<ValueType> handle;
177 for (vtkm::IdComponent i = 0; i < NumComponents; ++i)
180 vtkm::cont::make_ArrayHandle<T>(
reinterpret_cast<T*
>(input->GetComponentArrayPointer(i)),
181 numValues, vtkm::CopyFlag::Off));
184 return std::move(handle);
191 using StorageType = vtkm::cont::internal::Storage<T, vtkm::cont::StorageTagBasic>;
197 return vtkm::cont::make_ArrayHandle(
198 input->GetComponentArrayPointer(0), input->GetNumberOfTuples(), vtkm::CopyFlag::Off);
216VTK_ABI_NAMESPACE_BEGIN
218VTKACCELERATORSVTKMCORE_EXPORT
221VTKACCELERATORSVTKMCORE_EXPORT
224VTKACCELERATORSVTKMCORE_EXPORT
230VTK_ABI_NAMESPACE_BEGIN
233 using T = std::underlying_type<tovtkm::FieldsFlag>::type;
239 using T = std::underlying_type<tovtkm::FieldsFlag>::type;
tovtkm::FieldsFlag operator&(const tovtkm::FieldsFlag &a, const tovtkm::FieldsFlag &b)
tovtkm::FieldsFlag operator|(const tovtkm::FieldsFlag &a, const tovtkm::FieldsFlag &b)
Array-Of-Structs implementation of vtkGenericDataArray.
ValueType * GetPointer(vtkIdType valueIdx)
Get the address of a particular data index.
int GetNumberOfComponents() const
Set/Get the dimension (n) of the components.
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
Abstract interface for N-dimensional arrays.
abstract superclass for arrays of numeric data
virtual void UnRegister(vtkObjectBase *o)
Decrease the reference count (release by another object).
void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
represent and manipulate 3D points
Struct-Of-Arrays implementation of vtkGenericDataArray.
ValueType * GetComponentArrayPointer(int comp)
Return a pointer to a contiguous block of memory containing all values for a particular components (i...
VTKACCELERATORSVTKMCORE_EXPORT vtkDataArray * Convert(const vtkm::cont::Field &input)
vtkm::cont::ArrayHandleRuntimeVec< T > vtkDataArrayToArrayHandle(vtkAOSDataArrayTemplate< T > *input)
vtkm::cont::UnknownArrayHandle vtkDataArrayToUnknownArrayHandle(DataArrayType *input)
vtkm::cont::ArrayHandleBasic< T > vtkAOSDataArrayToFlatArrayHandle(vtkAOSDataArrayTemplate< T > *input)
vtkm::cont::ArrayHandleBasic< T > vtkSOADataArrayToComponentArrayHandle(vtkSOADataArrayTemplate< T > *input, int componentIndex)
static const char * NoNameVTKFieldName()
Temporary name for arrays converted from VTK that do not have a name.
typename std::conditional< NumComponents==1, T, vtkm::Vec< T, NumComponents > >::type ValueType
vtkm::cont::ArrayHandle< ValueType, vtkm::cont::StorageTagBasic > ArrayHandleType
vtkm::cont::internal::Storage< ValueType, vtkm::cont::StorageTagBasic > StorageType
vtkm::cont::ArrayHandle< T, vtkm::cont::StorageTagBasic > ArrayHandleType
vtkm::cont::internal::Storage< T, vtkm::cont::StorageTagBasic > StorageType
vtkm::Vec< T, NumComponents > ValueType
vtkm::cont::internal::Storage< ValueType, vtkm::cont::StorageTagSOA > StorageType
vtkm::cont::ArrayHandle< ValueType, vtkm::cont::StorageTagSOA > ArrayHandleType
#define VTK_DEPRECATED_IN_9_3_0(reason)
#define vtkLog(verbosity_name, x)
Add to log given the verbosity level.