6#ifndef vtkmlib_DataArrayConverters_h
7#define vtkmlib_DataArrayConverters_h
9#include "vtkAcceleratorsVTKmCoreModule.h"
10#include "vtkmConfigCore.h"
19#include <viskores/cont/ArrayExtractComponent.h>
20#include <viskores/cont/ArrayHandleBasic.h>
21#include <viskores/cont/ArrayHandleConstant.h>
22#include <viskores/cont/ArrayHandleCounting.h>
23#include <viskores/cont/ArrayHandleIndex.h>
24#include <viskores/cont/ArrayHandleRecombineVec.h>
25#include <viskores/cont/ArrayHandleRuntimeVec.h>
26#include <viskores/cont/ArrayHandleSOA.h>
27#include <viskores/cont/ArrayHandleStride.h>
28#include <viskores/cont/Field.h>
29#include <viskores/cont/UnknownArrayHandle.h>
38class CoordinateSystem;
42VTK_ABI_NAMESPACE_BEGIN
49VTK_ABI_NAMESPACE_BEGIN
56 static const char* name =
"NoNameVTKField";
69 auto deleter = [](
void* container)
74 auto reallocator = [](
void*& memory,
void*& container, viskores::BufferSizeType oldSize,
75 viskores::BufferSizeType newSize)
78 if ((
vtkArray->GetPointer(0) != memory) || (
vtkArray->GetNumberOfValues() != oldSize))
81 "Dangerous inconsistency found between pointers for VTK and Viskores. "
82 "Was the VTK array resized outside of Viskores?");
84 vtkArray->SetNumberOfValues(newSize);
88 return viskores::cont::ArrayHandleBasic<T>(
100 using ContainerPair = std::pair<vtkSOADataArrayTemplate<T>*,
int>;
101 ContainerPair* componentInput =
new ContainerPair(input, componentIndex);
103 auto deleter = [](
void* container)
105 ContainerPair* containerPair =
reinterpret_cast<ContainerPair*
>(container);
106 containerPair->first->UnRegister(
nullptr);
107 delete containerPair;
109 auto reallocator = [](
void*& memory,
void*& container,
110 viskores::BufferSizeType vtkNotUsed(oldSize),
111 viskores::BufferSizeType newSize)
113 ContainerPair* containerPair =
reinterpret_cast<ContainerPair*
>(container);
114 containerPair->first->SetNumberOfTuples(newSize);
115 memory = containerPair->first->GetComponentArrayPointer(containerPair->second);
137 viskores::cont::ArrayHandleRecombineVec<T> output;
142 output.AppendComponentArray(
143 viskores::cont::ArrayExtractComponent(componentArray, 0, viskores::CopyFlag::Off));
149template <
typename VecT>
153 return viskores::cont::ArrayHandleConstant<VecT>(
154 VecT{ input->GetBackend()->Value }, input->GetNumberOfTuples());
171 vtkGenericWarningMacro(<<
"Cannot convert constant array with "
173 return viskores::cont::UnknownArrayHandle{};
184 return viskores::cont::UnknownArrayHandle{};
190 if ((start == 0) && (step == 1))
195 return viskores::cont::ArrayHandleIndex(length);
199 return viskores::cont::ArrayHandleCounting<T>(start, step, length);
203template <
typename DataArrayType>
223VTK_ABI_NAMESPACE_BEGIN
225VTKACCELERATORSVTKMCORE_EXPORT
228VTKACCELERATORSVTKMCORE_EXPORT
231VTKACCELERATORSVTKMCORE_EXPORT
237VTK_ABI_NAMESPACE_BEGIN
240 using T = std::underlying_type<tovtkm::FieldsFlag>::type;
246 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.
A utility array for wrapping affine functions in implicit arrays.
Abstract interface for N-dimensional arrays.
A utility array for wrapping constant functions in implicit arrays.
std::shared_ptr< BackendT > GetBackend()
Setter/Getter for Backend.
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 viskores::cont::Field &input)
viskores::cont::ArrayHandleBasic< T > vtkAOSDataArrayToFlatArrayHandle(vtkAOSDataArrayTemplate< T > *input)
viskores::cont::ArrayHandleRuntimeVec< T > vtkDataArrayToArrayHandle(vtkAOSDataArrayTemplate< T > *input)
static const char * NoNameVTKFieldName()
Temporary name for arrays converted from VTK that do not have a name.
viskores::cont::ArrayHandleBasic< T > vtkSOADataArrayToComponentArrayHandle(vtkSOADataArrayTemplate< T > *input, int componentIndex)
viskores::cont::UnknownArrayHandle vtkDataArrayToUnknownArrayHandle(vtkConstantArray< T > *input)
#define vtkLog(verbosity_name, x)
Add to log given the verbosity level.