2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2015-05-13 20:24:51 +00:00
|
|
|
// 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.
|
2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2015-05-13 20:24:51 +00:00
|
|
|
#ifndef vtk_m_cont_ArrayHandleConstant_h
|
|
|
|
#define vtk_m_cont_ArrayHandleConstant_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandleImplicit.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2015-05-13 20:24:51 +00:00
|
|
|
|
2020-01-04 06:46:43 +00:00
|
|
|
struct VTKM_ALWAYS_EXPORT StorageTagConstant
|
2019-12-30 21:04:55 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace internal
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2015-05-13 20:24:51 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ValueType>
|
2016-12-19 19:39:17 +00:00
|
|
|
struct VTKM_ALWAYS_EXPORT ConstantFunctor
|
2015-05-13 20:24:51 +00:00
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ConstantFunctor(const ValueType& value = ValueType())
|
|
|
|
: Value(value)
|
2015-05-13 20:24:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_EXEC_CONT
|
|
|
|
ValueType operator()(vtkm::Id vtkmNotUsed(index)) const { return this->Value; }
|
|
|
|
|
2015-05-13 20:24:51 +00:00
|
|
|
private:
|
|
|
|
ValueType Value;
|
|
|
|
};
|
|
|
|
|
2019-12-30 21:04:55 +00:00
|
|
|
template <typename T>
|
|
|
|
using StorageTagConstantSuperclass =
|
|
|
|
typename vtkm::cont::ArrayHandleImplicit<ConstantFunctor<T>>::StorageTag;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct Storage<T, vtkm::cont::StorageTagConstant> : Storage<T, StorageTagConstantSuperclass<T>>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
2015-05-13 20:24:51 +00:00
|
|
|
|
|
|
|
/// \brief An array handle with a constant value.
|
|
|
|
///
|
|
|
|
/// ArrayHandleConstant is an implicit array handle with a constant value. A
|
|
|
|
/// constant array handle is constructed by giving a value and an array length.
|
|
|
|
/// The resulting array is of the given size with each entry the same value
|
|
|
|
/// given in the constructor. The array is defined implicitly, so there it
|
|
|
|
/// takes (almost) no memory.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2019-12-30 21:04:55 +00:00
|
|
|
class ArrayHandleConstant : public vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConstant>
|
2015-05-13 20:24:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-05-26 17:53:28 +00:00
|
|
|
VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleConstant,
|
|
|
|
(ArrayHandleConstant<T>),
|
2019-12-30 21:04:55 +00:00
|
|
|
(vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConstant>));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-10-21 19:36:27 +00:00
|
|
|
ArrayHandleConstant(T value, vtkm::Id numberOfValues = 0)
|
2020-08-26 13:58:59 +00:00
|
|
|
: Superclass(internal::FunctorToArrayHandleImplicitBuffers(internal::ConstantFunctor<T>(value),
|
|
|
|
numberOfValues))
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
}
|
2020-10-21 14:17:35 +00:00
|
|
|
|
|
|
|
/// \brief Returns the constant value stored in this array.
|
|
|
|
///
|
|
|
|
/// The value set in the constructor of this array is returned even if the number of values is 0.
|
|
|
|
///
|
|
|
|
VTKM_CONT T GetValue() const { return this->ReadPortal().GetFunctor()(0); }
|
2015-05-13 20:24:51 +00:00
|
|
|
};
|
|
|
|
|
2016-04-07 22:48:49 +00:00
|
|
|
/// make_ArrayHandleConstant is convenience function to generate an
|
2015-05-13 20:24:51 +00:00
|
|
|
/// ArrayHandleImplicit. It takes a functor and the virtual length of the
|
2015-10-21 19:36:27 +00:00
|
|
|
/// array.
|
2015-05-13 20:24:51 +00:00
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
|
|
|
vtkm::cont::ArrayHandleConstant<T> make_ArrayHandleConstant(T value, vtkm::Id numberOfValues)
|
2015-05-13 20:24:51 +00:00
|
|
|
{
|
|
|
|
return vtkm::cont::ArrayHandleConstant<T>(value, numberOfValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // vtkm::cont
|
|
|
|
|
2018-06-08 15:56:40 +00:00
|
|
|
//=============================================================================
|
|
|
|
// Specializations of serialization related classes
|
2019-09-12 21:19:36 +00:00
|
|
|
/// @cond SERIALIZATION
|
2018-06-08 15:56:40 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename T>
|
2019-12-30 21:04:55 +00:00
|
|
|
struct SerializableTypeString<vtkm::cont::ArrayHandleConstant<T>>
|
2018-06-08 15:56:40 +00:00
|
|
|
{
|
|
|
|
static VTKM_CONT const std::string& Get()
|
|
|
|
{
|
2019-12-30 21:04:55 +00:00
|
|
|
static std::string name = "AH_Constant<" + SerializableTypeString<T>::Get() + ">";
|
2018-06-08 15:56:40 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
2019-12-30 21:04:55 +00:00
|
|
|
struct SerializableTypeString<vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConstant>>
|
|
|
|
: SerializableTypeString<vtkm::cont::ArrayHandleConstant<T>>
|
2018-06-08 15:56:40 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // vtkm::cont
|
|
|
|
|
2019-02-05 16:02:29 +00:00
|
|
|
namespace mangled_diy_namespace
|
2018-06-08 15:56:40 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct Serialization<vtkm::cont::ArrayHandleConstant<T>>
|
2019-12-30 21:04:55 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
using Type = vtkm::cont::ArrayHandleConstant<T>;
|
|
|
|
using BaseType = vtkm::cont::ArrayHandle<typename Type::ValueType, typename Type::StorageTag>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj)
|
|
|
|
{
|
|
|
|
vtkmdiy::save(bb, obj.GetNumberOfValues());
|
2020-01-28 19:14:32 +00:00
|
|
|
vtkmdiy::save(bb, obj.ReadPortal().Get(0));
|
2019-12-30 21:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VTKM_CONT void load(BinaryBuffer& bb, BaseType& obj)
|
|
|
|
{
|
|
|
|
vtkm::Id count = 0;
|
|
|
|
vtkmdiy::load(bb, count);
|
|
|
|
|
|
|
|
T value;
|
|
|
|
vtkmdiy::load(bb, value);
|
|
|
|
|
|
|
|
obj = vtkm::cont::make_ArrayHandleConstant(value, count);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct Serialization<vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConstant>>
|
|
|
|
: Serialization<vtkm::cont::ArrayHandleConstant<T>>
|
2018-06-08 15:56:40 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
} // diy
|
2019-09-12 21:19:36 +00:00
|
|
|
/// @endcond SERIALIZATION
|
2018-06-08 15:56:40 +00:00
|
|
|
|
2015-05-13 20:24:51 +00:00
|
|
|
#endif //vtk_m_cont_ArrayHandleConstant_h
|