2014-02-10 18:57:46 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2014-02-10 18:57:46 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
2014-10-07 23:27:31 +00:00
|
|
|
#ifndef vtk_m_VecTraits_h
|
|
|
|
#define vtk_m_VecTraits_h
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
#include <vtkm/Deprecated.h>
|
|
|
|
#include <vtkm/StaticAssert.h>
|
2014-02-10 18:57:46 +00:00
|
|
|
#include <vtkm/Types.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
2014-02-10 18:57:46 +00:00
|
|
|
|
|
|
|
/// A tag for vectors that are "true" vectors (i.e. have more than one
|
|
|
|
/// component).
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
struct VecTraitsTagMultipleComponents
|
|
|
|
{
|
|
|
|
};
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2014-10-07 23:27:31 +00:00
|
|
|
/// A tag for vectors that are really just scalars (i.e. have only one
|
|
|
|
/// component)
|
2014-02-10 18:57:46 +00:00
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
struct VecTraitsTagSingleComponent
|
|
|
|
{
|
|
|
|
};
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2015-08-07 23:58:52 +00:00
|
|
|
/// A tag for vectors where the number of components are known at compile time.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
struct VecTraitsTagSizeStatic
|
|
|
|
{
|
|
|
|
};
|
2015-08-07 23:58:52 +00:00
|
|
|
|
|
|
|
/// A tag for vectors where the number of components are not determined until
|
|
|
|
/// run time.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
struct VecTraitsTagSizeVariable
|
|
|
|
{
|
|
|
|
};
|
2015-08-07 23:58:52 +00:00
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
/// \brief Traits that can be queried to treat any type as a `Vec`.
|
|
|
|
///
|
2014-10-07 23:27:31 +00:00
|
|
|
/// The VecTraits class gives several static members that define how
|
2023-03-16 17:00:47 +00:00
|
|
|
/// to use a given type as a vector. This is useful for templated
|
|
|
|
/// functions and methods that have a parameter that could be either
|
|
|
|
/// a standard scalar type or a `Vec` or some other `Vec`-like
|
|
|
|
/// object. When using this class, scalar objects are treated like
|
|
|
|
/// a `Vec` of size 1.
|
|
|
|
///
|
|
|
|
/// The default implementation of this template treats the type as
|
|
|
|
/// a scalar. Types that actually behave like vectors should
|
|
|
|
/// specialize this template to provide the proper information.
|
2014-02-10 18:57:46 +00:00
|
|
|
///
|
2023-03-16 17:00:47 +00:00
|
|
|
template <class T>
|
2019-06-06 21:28:47 +00:00
|
|
|
struct VTKM_NEVER_EXPORT VecTraits
|
2014-02-10 18:57:46 +00:00
|
|
|
{
|
2023-03-16 17:00:47 +00:00
|
|
|
// The base VecTraits should not be used with qualifiers.
|
|
|
|
VTKM_STATIC_ASSERT_MSG((std::is_same<std::remove_pointer_t<std::decay_t<T>>, T>::value),
|
|
|
|
"The base VecTraits should not be used with qualifiers.");
|
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Type of the components in the vector.
|
|
|
|
///
|
|
|
|
/// If the type is really a scalar, then the component type is the same as the scalar type.
|
2014-02-10 18:57:46 +00:00
|
|
|
///
|
2023-03-16 17:00:47 +00:00
|
|
|
using ComponentType = T;
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Base component type in the vector.
|
|
|
|
///
|
|
|
|
/// Similar to ComponentType except that for nested vectors (e.g. Vec<Vec<T, M>, N>), it
|
|
|
|
/// returns the base scalar type at the end of the composition (T in this example).
|
|
|
|
///
|
2023-03-16 17:00:47 +00:00
|
|
|
using BaseComponentType = T;
|
2019-09-03 03:52:56 +00:00
|
|
|
|
2015-08-20 12:50:19 +00:00
|
|
|
/// \brief Number of components in the vector.
|
|
|
|
///
|
2023-11-13 03:52:07 +00:00
|
|
|
/// This is only defined for vectors of a static size. That is, `NUM_COMPONENTS`
|
|
|
|
/// is not available when `IsSizeStatic` is set to `vtkm::VecTraitsTagSizeVariable`.
|
2014-02-10 18:57:46 +00:00
|
|
|
///
|
2023-03-16 17:00:47 +00:00
|
|
|
static constexpr vtkm::IdComponent NUM_COMPONENTS = 1;
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2023-11-13 03:52:07 +00:00
|
|
|
/// @brief Returns the number of components in the given vector.
|
|
|
|
///
|
|
|
|
/// The result of `GetNumberOfComponents()` is the same value of `NUM_COMPONENTS`
|
|
|
|
/// for vector types that have a static size (that is, `IsSizeStatic` is
|
|
|
|
/// `vtkm::VecTraitsTagSizeStatic`). But unlike `NUM_COMPONENTS`, `GetNumberOfComponents()`
|
|
|
|
/// works for vectors of any type.
|
2015-08-07 23:58:52 +00:00
|
|
|
///
|
2023-03-16 17:00:47 +00:00
|
|
|
static constexpr vtkm::IdComponent GetNumberOfComponents(const T&) { return NUM_COMPONENTS; }
|
2015-08-07 23:58:52 +00:00
|
|
|
|
2015-08-20 12:50:19 +00:00
|
|
|
/// \brief A tag specifying whether this vector has multiple components (i.e. is a "real" vector).
|
|
|
|
///
|
2023-11-13 03:52:07 +00:00
|
|
|
/// This type is set to either `vtkm::VecTraitsTagSingleComponent` if the vector length
|
|
|
|
/// is size 1 or `vtkm::VecTraitsTagMultipleComponents` otherwise.
|
|
|
|
/// This tag can be useful for creating specialized functions when a vector is really
|
|
|
|
/// just a scalar. If the vector type is of variable size (that is, `IsSizeStatic` is
|
|
|
|
/// `vtkm::VecTraitsTagSizeVariable`), then `HasMultipleComponents` might be
|
|
|
|
/// `vtkm::VecTraitsTagMultipleComponents` even when at run time there is only one component.
|
2014-02-10 18:57:46 +00:00
|
|
|
///
|
2023-03-16 17:00:47 +00:00
|
|
|
using HasMultipleComponents = vtkm::VecTraitsTagSingleComponent;
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2015-08-20 12:50:19 +00:00
|
|
|
/// \brief A tag specifying whether the size of this vector is known at compile time.
|
|
|
|
///
|
|
|
|
/// If set to \c VecTraitsTagSizeStatic, then \c NUM_COMPONENTS is set. If
|
|
|
|
/// set to \c VecTraitsTagSizeVariable, then the number of components is not
|
|
|
|
/// known at compile time and must be queried with \c GetNumberOfComponents.
|
2015-08-07 23:58:52 +00:00
|
|
|
///
|
2017-06-23 18:50:34 +00:00
|
|
|
using IsSizeStatic = vtkm::VecTraitsTagSizeStatic;
|
2015-08-07 23:58:52 +00:00
|
|
|
|
2014-02-10 18:57:46 +00:00
|
|
|
/// Returns the value in a given component of the vector.
|
|
|
|
///
|
2023-03-16 17:00:47 +00:00
|
|
|
VTKM_EXEC_CONT static const ComponentType& GetComponent(const T& vector,
|
|
|
|
vtkm::IdComponent vtkmNotUsed(component))
|
|
|
|
{
|
|
|
|
return vector;
|
|
|
|
}
|
2023-11-13 03:52:07 +00:00
|
|
|
/// @copydoc GetComponent
|
2023-03-16 17:00:47 +00:00
|
|
|
VTKM_EXEC_CONT static ComponentType& GetComponent(T& vector,
|
|
|
|
vtkm::IdComponent vtkmNotUsed(component))
|
|
|
|
{
|
|
|
|
return vector;
|
|
|
|
}
|
2014-02-10 18:57:46 +00:00
|
|
|
|
|
|
|
/// Changes the value in a given component of the vector.
|
|
|
|
///
|
2023-03-16 17:00:47 +00:00
|
|
|
VTKM_EXEC_CONT static void SetComponent(T& vector,
|
|
|
|
vtkm::IdComponent vtkmNotUsed(component),
|
|
|
|
ComponentType value)
|
|
|
|
{
|
|
|
|
vector = value;
|
|
|
|
}
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Get a vector of the same type but with a different component.
|
|
|
|
///
|
|
|
|
/// This type resolves to another vector with a different component type. For example,
|
2024-02-08 13:38:40 +00:00
|
|
|
/// `vtkm::VecTraits<vtkm::Vec<T, N>>::%ReplaceComponentType<T2>` is `vtkm::Vec<T2, N>`. This
|
|
|
|
/// replacement is not recursive. So `VecTraits<Vec<Vec<T, M>, N>::%ReplaceComponentType<T2>` is
|
|
|
|
/// `vtkm::Vec<T2, N>`.
|
2019-09-03 03:52:56 +00:00
|
|
|
///
|
2024-02-08 13:38:40 +00:00
|
|
|
// Note: the `%` in the code samples above is a hint to doxygen to avoid attempting
|
|
|
|
// to link to the object (i.e. `ReplaceBaseComponentType`), which results in a warning.
|
|
|
|
// The `%` is removed from the doxygen text.
|
2019-09-03 03:52:56 +00:00
|
|
|
template <typename NewComponentType>
|
2023-03-16 17:00:47 +00:00
|
|
|
using ReplaceComponentType = NewComponentType;
|
2019-09-03 03:52:56 +00:00
|
|
|
|
|
|
|
/// \brief Get a vector of the same type but with a different base component.
|
|
|
|
///
|
|
|
|
/// This type resolves to another vector with a different base component type. The replacement
|
|
|
|
/// is recursive for nested types. For example,
|
2024-02-08 13:38:40 +00:00
|
|
|
/// `VecTraits<Vec<Vec<T, M>, N>::%ReplaceBaseComponentType<T2>` is `Vec<Vec<T2, M>, N>`.
|
2019-09-03 03:52:56 +00:00
|
|
|
///
|
2024-02-08 13:38:40 +00:00
|
|
|
// Note: the `%` in the code samples above is a hint to doxygen to avoid attempting
|
|
|
|
// to link to the object (i.e. `ReplaceBaseComponentType`), which results in a warning.
|
|
|
|
// The `%` is removed from the doxygen text.
|
2019-09-03 03:52:56 +00:00
|
|
|
template <typename NewComponentType>
|
2023-03-16 17:00:47 +00:00
|
|
|
using ReplaceBaseComponentType = NewComponentType;
|
2019-09-03 03:52:56 +00:00
|
|
|
|
2015-08-13 22:53:34 +00:00
|
|
|
/// Copies the components in the given vector into a given Vec object.
|
2014-02-10 18:57:46 +00:00
|
|
|
///
|
2023-03-16 17:00:47 +00:00
|
|
|
template <vtkm::IdComponent destSize>
|
|
|
|
VTKM_EXEC_CONT static void CopyInto(const T& src, vtkm::Vec<ComponentType, destSize>& dest)
|
|
|
|
{
|
|
|
|
dest[0] = src;
|
|
|
|
}
|
2019-06-06 21:28:47 +00:00
|
|
|
};
|
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
template <typename T>
|
|
|
|
using HasVecTraits VTKM_DEPRECATED(2.1, "All types now have VecTraits defined.") = std::true_type;
|
2019-06-06 21:28:47 +00:00
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
// These partial specializations allow VecTraits to work with const and reference qualifiers.
|
2019-08-07 14:04:06 +00:00
|
|
|
template <typename T>
|
2023-03-16 17:00:47 +00:00
|
|
|
struct VTKM_NEVER_EXPORT VecTraits<const T> : VecTraits<T>
|
2019-08-07 14:04:06 +00:00
|
|
|
{
|
|
|
|
};
|
2019-06-06 21:28:47 +00:00
|
|
|
template <typename T>
|
2023-03-16 17:00:47 +00:00
|
|
|
struct VTKM_NEVER_EXPORT VecTraits<T&> : VecTraits<T>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
template <typename T>
|
|
|
|
struct VTKM_NEVER_EXPORT VecTraits<const T&> : VecTraits<T>
|
|
|
|
{
|
|
|
|
};
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
// This partial specialization allows VecTraits to work with pointers.
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2023-03-16 17:00:47 +00:00
|
|
|
struct VTKM_NEVER_EXPORT VecTraits<T*> : VecTraits<T>
|
|
|
|
{
|
|
|
|
VTKM_EXEC_CONT static vtkm::IdComponent GetNumberOfComponents(const T* vector)
|
|
|
|
{
|
|
|
|
return VecTraits<T>::GetNumberOfComponents(*vector);
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT static auto GetComponent(const T* vector, vtkm::IdComponent component)
|
|
|
|
-> decltype(VecTraits<T>::GetComponent(*vector, component))
|
|
|
|
{
|
|
|
|
return VecTraits<T>::GetComponent(*vector, component);
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT static auto GetComponent(T* vector, vtkm::IdComponent component)
|
|
|
|
-> decltype(VecTraits<T>::GetComponent(*vector, component))
|
|
|
|
{
|
|
|
|
return VecTraits<T>::GetComponent(*vector, component);
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT static void SetComponent(T* vector,
|
|
|
|
vtkm::IdComponent component,
|
|
|
|
typename VecTraits<T>::ComponentType value)
|
|
|
|
{
|
|
|
|
VecTraits<T>::SetComponent(*vector, component, value);
|
|
|
|
}
|
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceComponentType =
|
|
|
|
typename VecTraits<T>::template ReplaceComponentType<NewComponentType>*;
|
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceBaseComponentType =
|
|
|
|
typename VecTraits<T>::template ReplaceBaseComponentType<NewComponentType>*;
|
|
|
|
template <vtkm::IdComponent destSize>
|
|
|
|
VTKM_EXEC_CONT static void CopyInto(
|
|
|
|
const T* src,
|
|
|
|
vtkm::Vec<typename VecTraits<T>::ComponentType, destSize>& dest)
|
|
|
|
{
|
|
|
|
VecTraits<T>::CopyInto(*src, dest);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <typename T>
|
|
|
|
struct VTKM_NEVER_EXPORT VecTraits<const T*> : VecTraits<T*>
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
};
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2019-09-19 15:54:44 +00:00
|
|
|
#if defined(VTKM_GCC) && (__GNUC__ <= 5)
|
2019-09-13 00:12:02 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename NewT, vtkm::IdComponent Size>
|
2019-09-19 15:54:44 +00:00
|
|
|
struct VecReplaceComponentTypeGCC4or5
|
2019-09-13 00:12:02 +00:00
|
|
|
{
|
|
|
|
using type = vtkm::Vec<NewT, Size>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, vtkm::IdComponent Size, typename NewT>
|
2019-09-19 15:54:44 +00:00
|
|
|
struct VecReplaceBaseComponentTypeGCC4or5
|
2019-09-13 00:12:02 +00:00
|
|
|
{
|
|
|
|
using type =
|
2023-03-16 17:00:47 +00:00
|
|
|
vtkm::Vec<typename vtkm::VecTraits<T>::template ReplaceBaseComponentType<NewT>, Size>;
|
2019-09-13 00:12:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
#endif // GCC Version 4.8
|
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
|
|
|
|
|
|
|
template <vtkm::IdComponent numComponents, typename ComponentType>
|
|
|
|
struct VecTraitsMultipleComponentChooser
|
|
|
|
{
|
|
|
|
using Type = vtkm::VecTraitsTagMultipleComponents;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename ComponentType>
|
|
|
|
struct VecTraitsMultipleComponentChooser<1, ComponentType>
|
|
|
|
{
|
|
|
|
using Type = typename vtkm::VecTraits<ComponentType>::HasMultipleComponents;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T, vtkm::IdComponent Size>
|
2019-06-06 21:28:47 +00:00
|
|
|
struct VTKM_NEVER_EXPORT VecTraits<vtkm::Vec<T, Size>>
|
2014-02-10 18:57:46 +00:00
|
|
|
{
|
2017-06-23 18:50:34 +00:00
|
|
|
using VecType = vtkm::Vec<T, Size>;
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Type of the components in the vector.
|
|
|
|
///
|
|
|
|
/// If the type is really a scalar, then the component type is the same as the scalar type.
|
2014-02-10 18:57:46 +00:00
|
|
|
///
|
2017-06-23 18:50:34 +00:00
|
|
|
using ComponentType = typename VecType::ComponentType;
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Base component type in the vector.
|
|
|
|
///
|
|
|
|
/// Similar to ComponentType except that for nested vectors (e.g. Vec<Vec<T, M>, N>), it
|
|
|
|
/// returns the base scalar type at the end of the composition (T in this example).
|
|
|
|
///
|
2023-03-16 17:00:47 +00:00
|
|
|
using BaseComponentType = typename vtkm::VecTraits<ComponentType>::BaseComponentType;
|
2019-09-03 03:52:56 +00:00
|
|
|
|
2014-02-10 18:57:46 +00:00
|
|
|
/// Number of components in the vector.
|
|
|
|
///
|
2018-02-27 14:25:25 +00:00
|
|
|
static constexpr vtkm::IdComponent NUM_COMPONENTS = VecType::NUM_COMPONENTS;
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2015-08-07 23:58:52 +00:00
|
|
|
/// Number of components in the given vector.
|
|
|
|
///
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static vtkm::IdComponent GetNumberOfComponents(const VecType&) { return NUM_COMPONENTS; }
|
2015-08-07 23:58:52 +00:00
|
|
|
|
2014-02-10 18:57:46 +00:00
|
|
|
/// A tag specifying whether this vector has multiple components (i.e. is a
|
|
|
|
/// "real" vector). This tag can be useful for creating specialized functions
|
|
|
|
/// when a vector is really just a scalar.
|
|
|
|
///
|
2017-06-23 18:50:34 +00:00
|
|
|
using HasMultipleComponents =
|
2023-02-09 22:27:09 +00:00
|
|
|
typename internal::VecTraitsMultipleComponentChooser<NUM_COMPONENTS, ComponentType>::Type;
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2015-08-07 23:58:52 +00:00
|
|
|
/// A tag specifying whether the size of this vector is known at compile
|
|
|
|
/// time. If set to \c VecTraitsTagSizeStatic, then \c NUM_COMPONENTS is set.
|
|
|
|
/// If set to \c VecTraitsTagSizeVariable, then the number of components is
|
|
|
|
/// not known at compile time and must be queried with \c
|
|
|
|
/// GetNumberOfComponents.
|
|
|
|
///
|
2017-06-23 18:50:34 +00:00
|
|
|
using IsSizeStatic = vtkm::VecTraitsTagSizeStatic;
|
2015-08-07 23:58:52 +00:00
|
|
|
|
2014-02-10 18:57:46 +00:00
|
|
|
/// Returns the value in a given component of the vector.
|
|
|
|
///
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static const ComponentType& GetComponent(const VecType& vector, vtkm::IdComponent component)
|
2014-02-10 18:57:46 +00:00
|
|
|
{
|
|
|
|
return vector[component];
|
|
|
|
}
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static ComponentType& GetComponent(VecType& vector, vtkm::IdComponent component)
|
|
|
|
{
|
2014-02-10 18:57:46 +00:00
|
|
|
return vector[component];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Changes the value in a given component of the vector.
|
|
|
|
///
|
2017-05-26 17:53:28 +00:00
|
|
|
VTKM_EXEC_CONT static void SetComponent(VecType& vector,
|
|
|
|
vtkm::IdComponent component,
|
2017-05-18 14:29:41 +00:00
|
|
|
ComponentType value)
|
|
|
|
{
|
2014-02-10 18:57:46 +00:00
|
|
|
vector[component] = value;
|
|
|
|
}
|
|
|
|
|
2019-09-13 00:12:02 +00:00
|
|
|
/// \brief Get a vector of the same type but with a different component.
|
|
|
|
///
|
|
|
|
/// This type resolves to another vector with a different component type. For example,
|
2020-06-01 15:36:07 +00:00
|
|
|
/// @code vtkm::VecTraits<vtkm::Vec<T, N>>::ReplaceComponentType<T2> @endcode is vtkm::Vec<T2, N>.
|
|
|
|
/// This replacement is not recursive. So @code VecTraits<Vec<Vec<T, M>, N>::ReplaceComponentType<T2> @endcode
|
2019-09-13 00:12:02 +00:00
|
|
|
/// is vtkm::Vec<T2, N>.
|
|
|
|
///@{
|
2019-09-19 15:54:44 +00:00
|
|
|
#if defined(VTKM_GCC) && (__GNUC__ <= 5)
|
2019-09-19 16:30:59 +00:00
|
|
|
// Silly workaround for bug in GCC <= 5
|
2019-09-13 00:12:02 +00:00
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceComponentType =
|
2019-09-19 15:54:44 +00:00
|
|
|
typename detail::VecReplaceComponentTypeGCC4or5<NewComponentType, Size>::type;
|
2019-09-19 16:30:59 +00:00
|
|
|
#else // !GCC <= 5
|
2019-09-03 03:52:56 +00:00
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceComponentType = vtkm::Vec<NewComponentType, Size>;
|
2019-09-13 00:12:02 +00:00
|
|
|
#endif
|
|
|
|
///@}
|
2019-09-03 03:52:56 +00:00
|
|
|
|
2019-09-13 00:12:02 +00:00
|
|
|
/// \brief Get a vector of the same type but with a different base component.
|
|
|
|
///
|
|
|
|
/// This type resolves to another vector with a different base component type. The replacement
|
|
|
|
/// is recursive for nested types. For example,
|
2020-06-01 15:36:07 +00:00
|
|
|
/// @code VecTraits<Vec<Vec<T, M>, N>::ReplaceComponentType<T2> @endcode is Vec<Vec<T2, M>, N>.
|
2019-09-13 00:12:02 +00:00
|
|
|
///@{
|
2019-09-19 15:54:44 +00:00
|
|
|
#if defined(VTKM_GCC) && (__GNUC__ <= 5)
|
2019-09-19 16:30:59 +00:00
|
|
|
// Silly workaround for bug in GCC <= 5
|
2019-09-13 00:12:02 +00:00
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceBaseComponentType =
|
2019-09-19 15:54:44 +00:00
|
|
|
typename detail::VecReplaceBaseComponentTypeGCC4or5<T, Size, NewComponentType>::type;
|
2019-09-19 16:30:59 +00:00
|
|
|
#else // !GCC <= 5
|
2019-09-03 03:52:56 +00:00
|
|
|
template <typename NewComponentType>
|
2023-03-16 17:00:47 +00:00
|
|
|
using ReplaceBaseComponentType = vtkm::Vec<
|
|
|
|
typename vtkm::VecTraits<ComponentType>::template ReplaceBaseComponentType<NewComponentType>,
|
|
|
|
Size>;
|
2019-09-13 00:12:02 +00:00
|
|
|
#endif
|
|
|
|
///@}
|
2019-09-03 03:52:56 +00:00
|
|
|
|
2014-02-10 18:57:46 +00:00
|
|
|
/// Converts whatever type this vector is into the standard VTKm Tuple.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent destSize>
|
|
|
|
VTKM_EXEC_CONT static void CopyInto(const VecType& src, vtkm::Vec<ComponentType, destSize>& dest)
|
2014-02-10 18:57:46 +00:00
|
|
|
{
|
2015-08-07 23:58:52 +00:00
|
|
|
src.CopyInto(dest);
|
2014-02-10 18:57:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2019-06-06 21:28:47 +00:00
|
|
|
struct VTKM_NEVER_EXPORT VecTraits<vtkm::VecC<T>>
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
using VecType = vtkm::VecC<T>;
|
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Type of the components in the vector.
|
|
|
|
///
|
|
|
|
/// If the type is really a scalar, then the component type is the same as the scalar type.
|
2016-11-30 22:03:30 +00:00
|
|
|
///
|
|
|
|
using ComponentType = typename VecType::ComponentType;
|
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Base component type in the vector.
|
|
|
|
///
|
|
|
|
/// Similar to ComponentType except that for nested vectors (e.g. Vec<Vec<T, M>, N>), it
|
|
|
|
/// returns the base scalar type at the end of the composition (T in this example).
|
|
|
|
///
|
|
|
|
using BaseComponentType = typename vtkm::VecTraits<ComponentType>::BaseComponentType;
|
|
|
|
|
2016-11-30 22:03:30 +00:00
|
|
|
/// Number of components in the given vector.
|
|
|
|
///
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static vtkm::IdComponent GetNumberOfComponents(const VecType& vector)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
return vector.GetNumberOfComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A tag specifying whether this vector has multiple components (i.e. is a
|
|
|
|
/// "real" vector). This tag can be useful for creating specialized functions
|
|
|
|
/// when a vector is really just a scalar.
|
|
|
|
///
|
|
|
|
/// The size of a \c VecC is not known until runtime and can always
|
|
|
|
/// potentially have multiple components, this is always set to \c
|
|
|
|
/// HasMultipleComponents.
|
|
|
|
///
|
|
|
|
using HasMultipleComponents = vtkm::VecTraitsTagMultipleComponents;
|
|
|
|
|
|
|
|
/// A tag specifying whether the size of this vector is known at compile
|
|
|
|
/// time. If set to \c VecTraitsTagSizeStatic, then \c NUM_COMPONENTS is set.
|
|
|
|
/// If set to \c VecTraitsTagSizeVariable, then the number of components is
|
|
|
|
/// not known at compile time and must be queried with \c
|
|
|
|
/// GetNumberOfComponents.
|
|
|
|
///
|
|
|
|
using IsSizeStatic = vtkm::VecTraitsTagSizeVariable;
|
|
|
|
|
|
|
|
/// Returns the value in a given component of the vector.
|
|
|
|
///
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static const ComponentType& GetComponent(const VecType& vector, vtkm::IdComponent component)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
return vector[component];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static ComponentType& GetComponent(VecType& vector, vtkm::IdComponent component)
|
|
|
|
{
|
2016-11-30 22:03:30 +00:00
|
|
|
return vector[component];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Changes the value in a given component of the vector.
|
|
|
|
///
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static void SetComponent(VecType& vector, vtkm::IdComponent component, ComponentType value)
|
|
|
|
{
|
2016-11-30 22:03:30 +00:00
|
|
|
vector[component] = value;
|
|
|
|
}
|
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Get a vector of the same type but with a different component.
|
|
|
|
///
|
|
|
|
/// This type resolves to another vector with a different component type. For example,
|
2020-06-01 15:36:07 +00:00
|
|
|
/// @code vtkm::VecTraits<vtkm::Vec<T, N>>::ReplaceComponentType<T2> @endcode is vtkm::Vec<T2, N>.
|
|
|
|
/// This replacement is not recursive. So @code VecTraits<Vec<Vec<T, M>, N>::ReplaceComponentType<T2> @endcode
|
2019-09-03 03:52:56 +00:00
|
|
|
/// is vtkm::Vec<T2, N>.
|
|
|
|
///
|
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceComponentType = vtkm::VecC<NewComponentType>;
|
|
|
|
|
|
|
|
/// \brief Get a vector of the same type but with a different base component.
|
|
|
|
///
|
|
|
|
/// This type resolves to another vector with a different base component type. The replacement
|
|
|
|
/// is recursive for nested types. For example,
|
2020-06-01 15:36:07 +00:00
|
|
|
/// @code VecTraits<Vec<Vec<T, M>, N>::ReplaceComponentType<T2> @endcode is Vec<Vec<T2, M>, N>.
|
2019-09-03 03:52:56 +00:00
|
|
|
///
|
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceBaseComponentType = vtkm::VecC<
|
|
|
|
typename vtkm::VecTraits<ComponentType>::template ReplaceBaseComponentType<NewComponentType>>;
|
|
|
|
|
2016-11-30 22:03:30 +00:00
|
|
|
/// Converts whatever type this vector is into the standard VTKm Tuple.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent destSize>
|
|
|
|
VTKM_EXEC_CONT static void CopyInto(const VecType& src, vtkm::Vec<ComponentType, destSize>& dest)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
src.CopyInto(dest);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2019-06-06 21:28:47 +00:00
|
|
|
struct VTKM_NEVER_EXPORT VecTraits<vtkm::VecCConst<T>>
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
using VecType = vtkm::VecCConst<T>;
|
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Type of the components in the vector.
|
|
|
|
///
|
|
|
|
/// If the type is really a scalar, then the component type is the same as the scalar type.
|
2016-11-30 22:03:30 +00:00
|
|
|
///
|
|
|
|
using ComponentType = typename VecType::ComponentType;
|
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Base component type in the vector.
|
|
|
|
///
|
|
|
|
/// Similar to ComponentType except that for nested vectors (e.g. Vec<Vec<T, M>, N>), it
|
|
|
|
/// returns the base scalar type at the end of the composition (T in this example).
|
|
|
|
///
|
|
|
|
using BaseComponentType = typename vtkm::VecTraits<ComponentType>::BaseComponentType;
|
|
|
|
|
2016-11-30 22:03:30 +00:00
|
|
|
/// Number of components in the given vector.
|
|
|
|
///
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static vtkm::IdComponent GetNumberOfComponents(const VecType& vector)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
return vector.GetNumberOfComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A tag specifying whether this vector has multiple components (i.e. is a
|
|
|
|
/// "real" vector). This tag can be useful for creating specialized functions
|
|
|
|
/// when a vector is really just a scalar.
|
|
|
|
///
|
|
|
|
/// The size of a \c VecCConst is not known until runtime and can always
|
|
|
|
/// potentially have multiple components, this is always set to \c
|
|
|
|
/// HasMultipleComponents.
|
|
|
|
///
|
|
|
|
using HasMultipleComponents = vtkm::VecTraitsTagMultipleComponents;
|
|
|
|
|
|
|
|
/// A tag specifying whether the size of this vector is known at compile
|
|
|
|
/// time. If set to \c VecTraitsTagSizeStatic, then \c NUM_COMPONENTS is set.
|
|
|
|
/// If set to \c VecTraitsTagSizeVariable, then the number of components is
|
|
|
|
/// not known at compile time and must be queried with \c
|
|
|
|
/// GetNumberOfComponents.
|
|
|
|
///
|
|
|
|
using IsSizeStatic = vtkm::VecTraitsTagSizeVariable;
|
|
|
|
|
|
|
|
/// Returns the value in a given component of the vector.
|
|
|
|
///
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static const ComponentType& GetComponent(const VecType& vector, vtkm::IdComponent component)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
return vector[component];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Changes the value in a given component of the vector.
|
|
|
|
///
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static void SetComponent(VecType& vector, vtkm::IdComponent component, ComponentType value)
|
|
|
|
{
|
2016-11-30 22:03:30 +00:00
|
|
|
vector[component] = value;
|
|
|
|
}
|
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
/// \brief Get a vector of the same type but with a different component.
|
|
|
|
///
|
|
|
|
/// This type resolves to another vector with a different component type. For example,
|
2020-06-01 15:36:07 +00:00
|
|
|
/// @code vtkm::VecTraits<vtkm::Vec<T, N>>::ReplaceComponentType<T2> @endcode is vtkm::Vec<T2, N>.
|
|
|
|
/// This replacement is not recursive. So @code VecTraits<Vec<Vec<T, M>, N>::ReplaceComponentType<T2> @endcode
|
2019-09-03 03:52:56 +00:00
|
|
|
/// is vtkm::Vec<T2, N>.
|
|
|
|
///
|
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceComponentType = vtkm::VecCConst<NewComponentType>;
|
|
|
|
|
|
|
|
/// \brief Get a vector of the same type but with a different base component.
|
|
|
|
///
|
|
|
|
/// This type resolves to another vector with a different base component type. The replacement
|
|
|
|
/// is recursive for nested types. For example,
|
2020-06-01 15:36:07 +00:00
|
|
|
/// @code VecTraits<Vec<Vec<T, M>, N>::ReplaceComponentType<T2> @endcode is Vec<Vec<T2, M>, N>.
|
2019-09-03 03:52:56 +00:00
|
|
|
///
|
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceBaseComponentType = vtkm::VecCConst<
|
|
|
|
typename vtkm::VecTraits<ComponentType>::template ReplaceBaseComponentType<NewComponentType>>;
|
|
|
|
|
2016-11-30 22:03:30 +00:00
|
|
|
/// Converts whatever type this vector is into the standard VTKm Tuple.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent destSize>
|
|
|
|
VTKM_EXEC_CONT static void CopyInto(const VecType& src, vtkm::Vec<ComponentType, destSize>& dest)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
src.CopyInto(dest);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
2022-05-24 18:56:20 +00:00
|
|
|
|
2014-10-07 23:27:31 +00:00
|
|
|
/// Used for overriding VecTraits for basic scalar types.
|
2014-02-10 18:57:46 +00:00
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ScalarType>
|
2023-03-16 17:00:47 +00:00
|
|
|
struct VTKM_DEPRECATED(2.1, "VecTraitsBasic is now the default implementation for VecTraits.")
|
|
|
|
VTKM_NEVER_EXPORT VecTraitsBasic
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2017-06-23 18:50:34 +00:00
|
|
|
using ComponentType = ScalarType;
|
2019-09-03 03:52:56 +00:00
|
|
|
using BaseComponentType = ScalarType;
|
2018-02-27 14:25:25 +00:00
|
|
|
static constexpr vtkm::IdComponent NUM_COMPONENTS = 1;
|
2017-06-23 18:50:34 +00:00
|
|
|
using HasMultipleComponents = vtkm::VecTraitsTagSingleComponent;
|
|
|
|
using IsSizeStatic = vtkm::VecTraitsTagSizeStatic;
|
2015-08-07 23:58:52 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static vtkm::IdComponent GetNumberOfComponents(const ScalarType&) { return 1; }
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static const ComponentType& GetComponent(const ScalarType& vector, vtkm::IdComponent)
|
|
|
|
{
|
2014-02-10 18:57:46 +00:00
|
|
|
return vector;
|
|
|
|
}
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
static ComponentType& GetComponent(ScalarType& vector, vtkm::IdComponent) { return vector; }
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
VTKM_EXEC_CONT static void SetComponent(ScalarType& vector,
|
|
|
|
vtkm::IdComponent,
|
2017-05-18 14:29:41 +00:00
|
|
|
ComponentType value)
|
|
|
|
{
|
2014-02-10 18:57:46 +00:00
|
|
|
vector = value;
|
|
|
|
}
|
|
|
|
|
2019-09-03 03:52:56 +00:00
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceComponentType = NewComponentType;
|
|
|
|
|
|
|
|
template <typename NewComponentType>
|
|
|
|
using ReplaceBaseComponentType = NewComponentType;
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent destSize>
|
|
|
|
VTKM_EXEC_CONT static void CopyInto(const ScalarType& src, vtkm::Vec<ScalarType, destSize>& dest)
|
2014-02-10 18:57:46 +00:00
|
|
|
{
|
2015-08-07 23:58:52 +00:00
|
|
|
dest[0] = src;
|
2014-02-10 18:57:46 +00:00
|
|
|
}
|
|
|
|
};
|
2022-05-24 18:56:20 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2023-03-16 17:00:47 +00:00
|
|
|
struct VTKM_DEPRECATED(2.1 "VecTraits now safe to use on any type.") VTKM_NEVER_EXPORT SafeVecTraits
|
|
|
|
: vtkm::VecTraits<T>
|
2022-05-24 18:56:20 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
} // namespace internal
|
2022-05-24 18:56:20 +00:00
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
2022-05-24 18:56:20 +00:00
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
struct VTKM_DEPRECATED(2.1,
|
|
|
|
"VTKM_BASIC_TYPE_VECTOR is no longer necessary because VecTraits implements "
|
|
|
|
"basic type by default.") VTKM_BASIC_TYPE_VECTOR_is_deprecated
|
2022-05-24 18:56:20 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
template <typename T>
|
|
|
|
struct issue_VTKM_BASIC_TYPE_VECTOR_deprecation_warning;
|
2015-05-07 22:34:06 +00:00
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
}
|
2015-09-20 06:01:04 +00:00
|
|
|
|
2022-05-24 18:56:20 +00:00
|
|
|
} // namespace vtkm
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2023-03-16 17:00:47 +00:00
|
|
|
#define VTKM_BASIC_TYPE_VECTOR(type) \
|
|
|
|
namespace vtkm \
|
|
|
|
{ \
|
|
|
|
namespace detail \
|
|
|
|
{ \
|
|
|
|
template <> \
|
|
|
|
struct issue_VTKM_BASIC_TYPE_VECTOR_deprecation_warning<type> \
|
|
|
|
: public vtkm::detail::VTKM_BASIC_TYPE_VECTOR_is_deprecated \
|
|
|
|
{ \
|
|
|
|
}; \
|
|
|
|
} \
|
2015-05-07 22:34:06 +00:00
|
|
|
}
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2014-10-07 23:27:31 +00:00
|
|
|
#endif //vtk_m_VecTraits_h
|