4 #ifndef vtkImplicitArray_h
5 #define vtkImplicitArray_h
7 #include "vtkCommonCoreModule.h"
12 #include <type_traits>
143 #define vtkImplicitArrayTypeMacro(thisClass, superclass) \
144 vtkAbstractTypeMacroWithNewInstanceType(thisClass, superclass, \
145 vtkAOSDataArrayTemplate<typename thisClass::ValueType>, typeid(thisClass).name()); \
148 vtkObjectBase* NewInstanceInternal() const override \
150 return vtkAOSDataArrayTemplate<typename thisClass::ValueType>::New(); \
156 VTK_ABI_NAMESPACE_BEGIN
157 template <
class BackendT,
int ArrayType = vtkArrayTypes::VTK_IMPLICIT_ARRAY>
160 typename vtk::detail::implicit_array_traits<BackendT>::rtype, ArrayType>
163 "Supplied backend type does not have mandatory read trait. Must implement either map() const "
164 "or operator() const.");
171 using typename Superclass::ArrayTypeTag;
172 using typename Superclass::DataTypeTag;
173 using typename Superclass::ValueType;
197 this->GetTypedTupleImpl<BackendT>(idx, tuple);
210 return this->GetTypedComponentImpl<BackendT>(idx, comp);
235 template <
typename... Params>
238 this->
SetBackend(std::make_shared<BackendT>(std::forward<Params>(params)...));
246 this->Initialize<BackendT>();
262 return this->GetActualMemorySizeImpl<BackendT>();
277 template <
typename OtherBackend,
int OtherArrayType>
280 static_assert(std::is_same_v<BackendT, OtherBackend>,
281 "Cannot copy implicit array with one type of backend to an implicit array with a different "
284 "Cannot copy implicit array with one array type to an implicit array with a different "
293 if (da ==
nullptr || da ==
this)
346 template <
typename U>
350 return this->Backend->map(idx);
358 template <
typename U>
362 return (*this->Backend)(idx);
370 template <
typename U>
371 typename std::enable_if<vtk::detail::implicit_array_traits<U>::default_constructible,
void>
::type
374 this->Backend = std::make_shared<BackendT>();
382 template <
typename U>
383 typename std::enable_if<!vtk::detail::implicit_array_traits<U>::default_constructible,
void>
::type
386 this->Backend =
nullptr;
394 template <
typename U>
395 typename std::enable_if<vtk::detail::implicit_array_traits<U>::can_direct_read_tuple,
void>
::type
400 "Tuple type should be the same as the return type of the mapTuple");
401 this->Backend->mapTuple(idx, tuple);
409 template <
typename U>
410 typename std::enable_if<!vtk::detail::implicit_array_traits<U>::can_direct_read_tuple &&
424 template <
typename U>
425 typename std::enable_if<!vtk::detail::implicit_array_traits<U>::can_direct_read_tuple &&
426 !vtk::detail::implicit_array_traits<U>::can_direct_read_component,
433 tuple[comp] = this->
GetValue(tupIdx + comp);
442 template <
typename U>
443 typename std::enable_if<vtk::detail::implicit_array_traits<U>::can_direct_read_component,
445 GetTypedComponentImpl(
vtkIdType idx,
int comp)
const
449 "Component return type should be the same as the return type of the mapComponent");
450 return this->Backend->mapComponent(idx, comp);
458 template <
typename U>
459 typename std::enable_if<!vtk::detail::implicit_array_traits<U>::can_direct_read_component,
461 GetTypedComponentImpl(
vtkIdType idx,
int comp)
const
463 return this->
GetValue(idx * this->NumberOfComponents + comp);
471 template <
typename U>
472 typename std::enable_if<vtk::detail::implicit_array_traits<U>::can_get_memory_size,
474 GetActualMemorySizeImpl()
const
476 return this->Backend->getMemorySize();
483 template <
typename U>
484 typename std::enable_if<!vtk::detail::implicit_array_traits<U>::can_get_memory_size,
486 GetActualMemorySizeImpl()
const
498 VTK_ABI_NAMESPACE_END
503 #define vtkCreateImplicitWrappedArrayInterface(T) \
504 vtkCreateWrappedArrayReadInterface(T); \
505 bool SetNumberOfValues(vtkIdType number) override;
507 #include "vtkImplicitArray.txx"
509 #endif // vtkImplicitArray_h
void SetNumberOfComponents(int num) override
A composite trait for handling all the different capabilities a "backend" to an implicit array can ha...
virtual void SetNumberOfTuples(vtkIdType numTuples)
Set the number of tuples (a component group) in the array.
unsigned long GetActualMemorySize() const override
Return the memory in kibibytes (1024 bytes) consumed by this implicit data array. ...
int GetNumberOfComponents() const
Set/Get the dimension (n) of the components.
Abstract superclass for all arrays.
virtual void Initialize()
Release storage and reset array to initial state.
vtkImplicitArrayTypeMacro(SelfType, GenericDataArrayType)
static vtkImplicitArray< BackendT, ArrayType > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Will not do anything for these read only arrays!
void SetValue(vtkIdType idx, ValueType value)
Will not do anything for these read only arrays!
bool AllocateTuples(vtkIdType numTuples)
No allocation necessary.
~vtkImplicitArray() override
Base interface for all typed vtkDataArray subclasses.
bool IsBackendConstructed() const
Setter/Getter for Backend.
typename trait::rtype rtype
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
std::shared_ptr< BackendT > GetBackend()
Setter/Getter for Backend.
void ImplicitDeepCopy(vtkImplicitArray< OtherBackend, OtherArrayType > *other)
Specific DeepCopy for implicit arrays.
ValueType GetValue(vtkIdType idx) const
Implementation of vtkGDAConceptMethods.
std::shared_ptr< BackendT > Backend
The backend object actually mapping the indexes.
abstract superclass for arrays of numeric data
void Initialize() override
Reset the array to default construction.
ValueType GetTypedComponent(vtkIdType idx, int comp) const
Get component comp of the tuple at idx.
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Will not do anything for these read only arrays!
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
A read only array class that wraps an implicit function from integers to any value type supported by ...
void SetBackend(std::shared_ptr< BackendT > newBackend)
Setter/Getter for Backend.
vtkArrayDownCast_Template2FastCastMacro(vtkImplicitArray)
void DeepCopy(vtkDataArray *da) override
Specific DeepCopy for implicit arrays.
void GetTypedTuple(vtkIdType idx, ValueType *tuple) const
Copy the tuple at idx into tuple.
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
bool ReallocateTuples(vtkIdType numTuples)
No allocation necessary.
static vtkImplicitArray * New()
#define VTK_DEPRECATED_IN_9_7_0(reason)
void Modified() override
Removes out-of-date L2_NORM_RANGE() and L2_NORM_FINITE_RANGE() values.
void ConstructBackend(Params &&...params)
Utility method for setting backend parameterization directly.
A utility structure serving as a backend for composite arrays: an array composed of multiple arrays c...