vtk-m/vtkm/cont/ArrayHandleStride.cxx
Kenneth Moreland 723c9ed2f0 Support Fill for ArrayHandleStride
Previously, if you called `Fill` on an `ArrayHandleStride`, you would get
an exception that said the feature was not supported. It turns out that
filling values is very useful in situations where, for example, you need to
initialize an array when processing an unknown type (and thus dealing with
extracted components).

This implementation of `Fill` first attempts to call `Fill` on the
contained array. This only works if the stride is set to 1. If this does
not work, then the code leverages the precompiled `ArrayCopy`. It does this
by first creating a new `ArrayHandleStride` containing the fill value and a
modulo of 1 so that value is constantly repeated. It then reconstructs an
`ArrayHandleStride` for itself with a modified size and offset to match the
start and end indices.

Referencing the `ArrayCopy` was tricky because it kept creating circular
dependencies among `ArrayHandleStride`, `ArrayExtractComponent`, and
`UnknownArrayHandle`. These dependencies were broken by having
`ArrayHandleStride` directly use the internal `ArrayCopyUnknown` function
and to use a forward declaration of `UnknownArrayHandle` rather than
including its header.
2024-02-02 13:50:21 -05:00

52 lines
2.3 KiB
C++

//============================================================================
// 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 vtk_m_cont_ArrayHandleStride_cxx
#include <vtkm/cont/ArrayHandleStride.h>
#include <vtkm/cont/UnknownArrayHandle.h>
namespace vtkm
{
namespace cont
{
namespace internal
{
template class VTKM_CONT_EXPORT Storage<char, StorageTagStride>;
template class VTKM_CONT_EXPORT Storage<vtkm::Int8, StorageTagStride>;
template class VTKM_CONT_EXPORT Storage<vtkm::UInt8, StorageTagStride>;
template class VTKM_CONT_EXPORT Storage<vtkm::Int16, StorageTagStride>;
template class VTKM_CONT_EXPORT Storage<vtkm::UInt16, StorageTagStride>;
template class VTKM_CONT_EXPORT Storage<vtkm::Int32, StorageTagStride>;
template class VTKM_CONT_EXPORT Storage<vtkm::UInt32, StorageTagStride>;
template class VTKM_CONT_EXPORT Storage<vtkm::Int64, StorageTagStride>;
template class VTKM_CONT_EXPORT Storage<vtkm::UInt64, StorageTagStride>;
template class VTKM_CONT_EXPORT Storage<vtkm::Float32, StorageTagStride>;
template class VTKM_CONT_EXPORT Storage<vtkm::Float64, StorageTagStride>;
} // namespace internal
template class VTKM_CONT_EXPORT ArrayHandle<char, StorageTagStride>;
template class VTKM_CONT_EXPORT ArrayHandle<vtkm::Int8, StorageTagStride>;
template class VTKM_CONT_EXPORT ArrayHandle<vtkm::UInt8, StorageTagStride>;
template class VTKM_CONT_EXPORT ArrayHandle<vtkm::Int16, StorageTagStride>;
template class VTKM_CONT_EXPORT ArrayHandle<vtkm::UInt16, StorageTagStride>;
template class VTKM_CONT_EXPORT ArrayHandle<vtkm::Int32, StorageTagStride>;
template class VTKM_CONT_EXPORT ArrayHandle<vtkm::UInt32, StorageTagStride>;
template class VTKM_CONT_EXPORT ArrayHandle<vtkm::Int64, StorageTagStride>;
template class VTKM_CONT_EXPORT ArrayHandle<vtkm::UInt64, StorageTagStride>;
template class VTKM_CONT_EXPORT ArrayHandle<vtkm::Float32, StorageTagStride>;
template class VTKM_CONT_EXPORT ArrayHandle<vtkm::Float64, StorageTagStride>;
}
} // namespace vtkm::cont