vtk-m/vtkm/VecFromPortalPermute.h

184 lines
5.4 KiB
C
Raw Normal View History

2015-08-14 14:10:17 +00:00
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
2015-08-14 14:10:17 +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.
//============================================================================
#ifndef vtk_m_VecFromPortalPermute_h
#define vtk_m_VecFromPortalPermute_h
2015-08-14 14:10:17 +00:00
#include <vtkm/Math.h>
#include <vtkm/TypeTraits.h>
2017-05-18 14:51:24 +00:00
#include <vtkm/Types.h>
2015-08-14 14:10:17 +00:00
#include <vtkm/VecTraits.h>
2017-05-18 14:29:41 +00:00
namespace vtkm
{
2015-08-14 14:10:17 +00:00
/// \brief A short vector from an ArrayPortal and a vector of indices.
///
/// The \c VecFromPortalPermute class is a Vec-like class that holds an array
/// portal and a second Vec-like containing indices into the array. Each value
/// of this vector is the value from the array with the respective index.
///
2017-05-18 14:29:41 +00:00
template <typename IndexVecType, typename PortalType>
2015-08-14 14:10:17 +00:00
class VecFromPortalPermute
{
public:
2017-05-18 14:29:41 +00:00
using ComponentType = typename std::remove_const<typename PortalType::ValueType>::type;
2015-08-14 14:10:17 +00:00
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
2017-05-18 14:29:41 +00:00
VecFromPortalPermute() {}
2015-08-14 14:10:17 +00:00
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
2017-05-18 14:29:41 +00:00
VecFromPortalPermute(const IndexVecType* indices, const PortalType& portal)
: Indices(indices)
, Portal(portal)
{
}
2015-08-14 14:10:17 +00:00
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
2017-05-18 14:29:41 +00:00
vtkm::IdComponent GetNumberOfComponents() const { return this->Indices->GetNumberOfComponents(); }
2015-08-14 14:10:17 +00:00
VTKM_SUPPRESS_EXEC_WARNINGS
2017-05-18 14:29:41 +00:00
template <vtkm::IdComponent DestSize>
VTKM_EXEC_CONT void CopyInto(vtkm::Vec<ComponentType, DestSize>& dest) const
2015-08-14 14:10:17 +00:00
{
2017-05-18 14:29:41 +00:00
vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->GetNumberOfComponents());
2015-08-14 14:10:17 +00:00
for (vtkm::IdComponent index = 0; index < numComponents; index++)
{
dest[index] = (*this)[index];
2015-08-14 14:10:17 +00:00
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
2015-08-14 14:10:17 +00:00
ComponentType operator[](vtkm::IdComponent index) const
{
return this->Portal.Get((*this->Indices)[index]);
2015-08-14 14:10:17 +00:00
}
private:
const IndexVecType* const Indices;
2015-08-14 14:10:17 +00:00
PortalType Portal;
};
template <typename IndexVecType, typename PortalType>
class VecFromPortalPermute<IndexVecType, const PortalType*>
{
public:
using ComponentType = typename std::remove_const<typename PortalType::ValueType>::type;
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
VecFromPortalPermute() {}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
VecFromPortalPermute(const IndexVecType* indices, const PortalType* const portal)
: Indices(indices)
, Portal(portal)
{
}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
vtkm::IdComponent GetNumberOfComponents() const { return this->Indices->GetNumberOfComponents(); }
VTKM_SUPPRESS_EXEC_WARNINGS
template <vtkm::IdComponent DestSize>
VTKM_EXEC_CONT void CopyInto(vtkm::Vec<ComponentType, DestSize>& dest) const
{
vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->GetNumberOfComponents());
for (vtkm::IdComponent index = 0; index < numComponents; index++)
{
dest[index] = (*this)[index];
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
ComponentType operator[](vtkm::IdComponent index) const
{
return this->Portal->Get((*this->Indices)[index]);
}
private:
const IndexVecType* const Indices;
const PortalType* const Portal;
};
2017-05-18 14:29:41 +00:00
template <typename IndexVecType, typename PortalType>
struct TypeTraits<vtkm::VecFromPortalPermute<IndexVecType, PortalType>>
2015-08-14 14:10:17 +00:00
{
private:
2018-02-22 13:29:13 +00:00
using VecType = vtkm::VecFromPortalPermute<IndexVecType, PortalType>;
using ComponentType = typename PortalType::ValueType;
2015-08-14 14:10:17 +00:00
public:
2018-02-22 13:29:13 +00:00
using NumericTag = typename vtkm::TypeTraits<ComponentType>::NumericTag;
using DimensionalityTag = TypeTraitsVectorTag;
2015-08-14 14:10:17 +00:00
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
2017-05-18 14:29:41 +00:00
static VecType ZeroInitialization() { return VecType(); }
2015-08-14 14:10:17 +00:00
};
2017-05-18 14:29:41 +00:00
template <typename IndexVecType, typename PortalType>
struct VecTraits<vtkm::VecFromPortalPermute<IndexVecType, PortalType>>
2015-08-14 14:10:17 +00:00
{
2018-02-22 13:29:13 +00:00
using VecType = vtkm::VecFromPortalPermute<IndexVecType, PortalType>;
2015-08-14 14:10:17 +00:00
2018-02-22 13:29:13 +00:00
using ComponentType = typename VecType::ComponentType;
using BaseComponentType = typename vtkm::VecTraits<ComponentType>::BaseComponentType;
2018-02-22 13:29:13 +00:00
using HasMultipleComponents = vtkm::VecTraitsTagMultipleComponents;
using IsSizeStatic = vtkm::VecTraitsTagSizeVariable;
2015-08-14 14:10:17 +00:00
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
2017-05-18 14:29:41 +00:00
static vtkm::IdComponent GetNumberOfComponents(const VecType& vector)
{
2015-08-14 14:10:17 +00:00
return vector.GetNumberOfComponents();
}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT
2017-05-18 14:29:41 +00:00
static ComponentType GetComponent(const VecType& vector, vtkm::IdComponent componentIndex)
2015-08-14 14:10:17 +00:00
{
return vector[componentIndex];
}
VTKM_SUPPRESS_EXEC_WARNINGS
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)
2015-08-14 14:10:17 +00:00
{
src.CopyInto(dest);
}
};
2018-01-19 15:41:21 +00:00
template <typename IndexVecType, typename PortalType>
inline VTKM_EXEC VecFromPortalPermute<IndexVecType, PortalType> make_VecFromPortalPermute(
const IndexVecType* index,
const PortalType& portal)
{
return VecFromPortalPermute<IndexVecType, PortalType>(index, portal);
}
template <typename IndexVecType, typename PortalType>
inline VTKM_EXEC VecFromPortalPermute<IndexVecType, const PortalType*> make_VecFromPortalPermute(
const IndexVecType* index,
const PortalType* const portal)
{
return VecFromPortalPermute<IndexVecType, const PortalType*>(index, portal);
}
2015-08-14 14:10:17 +00:00
} // namespace vtkm
#endif //vtk_m_VecFromPortalPermute_h