2015-08-14 14:10:17 +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.
|
|
|
|
//
|
|
|
|
// Copyright 2015 Sandia Corporation.
|
|
|
|
// Copyright 2015 UT-Battelle, LLC.
|
|
|
|
// Copyright 2015 Los Alamos National Security.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
2016-10-25 20:55:48 +00:00
|
|
|
#ifndef vtk_m_VecFromPortalPermute_h
|
|
|
|
#define vtk_m_VecFromPortalPermute_h
|
2015-08-14 14:10:17 +00:00
|
|
|
|
|
|
|
#include <vtkm/Math.h>
|
|
|
|
#include <vtkm/Types.h>
|
|
|
|
#include <vtkm/TypeTraits.h>
|
|
|
|
#include <vtkm/VecTraits.h>
|
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
|
|
|
|
/// \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.
|
|
|
|
///
|
|
|
|
template<typename IndexVecType, typename PortalType>
|
|
|
|
class VecFromPortalPermute
|
|
|
|
{
|
|
|
|
public:
|
2016-10-12 17:28:36 +00:00
|
|
|
using ComponentType =
|
|
|
|
typename std::remove_const<typename PortalType::ValueType>::type;
|
|
|
|
|
2015-08-14 14:10:17 +00:00
|
|
|
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
2015-08-14 14:10:17 +00:00
|
|
|
VecFromPortalPermute() { }
|
|
|
|
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
2015-10-19 21:37:36 +00:00
|
|
|
VecFromPortalPermute(const IndexVecType *indices, const PortalType &portal)
|
2015-08-14 14:10:17 +00:00
|
|
|
: Indices(indices), Portal(portal) { }
|
|
|
|
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
2015-08-14 14:10:17 +00:00
|
|
|
vtkm::IdComponent GetNumberOfComponents() const {
|
2015-10-19 21:37:36 +00:00
|
|
|
return this->Indices->GetNumberOfComponents();
|
2015-08-14 14:10:17 +00:00
|
|
|
}
|
|
|
|
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2015-08-14 14:10:17 +00:00
|
|
|
template<vtkm::IdComponent DestSize>
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-08-14 14:10:17 +00:00
|
|
|
void CopyInto(vtkm::Vec<ComponentType,DestSize> &dest) const
|
|
|
|
{
|
|
|
|
vtkm::IdComponent numComponents =
|
|
|
|
vtkm::Min(DestSize, this->GetNumberOfComponents());
|
|
|
|
for (vtkm::IdComponent index = 0; index < numComponents; index++)
|
|
|
|
{
|
2015-10-19 21:37:36 +00:00
|
|
|
dest[index] = (*this)[index];
|
2015-08-14 14:10:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 15:56:24 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-08-14 14:10:17 +00:00
|
|
|
ComponentType operator[](vtkm::IdComponent index) const
|
|
|
|
{
|
2015-10-19 21:37:36 +00:00
|
|
|
return this->Portal.Get((*this->Indices)[index]);
|
2015-08-14 14:10:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-19 21:37:36 +00:00
|
|
|
const IndexVecType *Indices;
|
2015-08-14 14:10:17 +00:00
|
|
|
PortalType Portal;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename IndexVecType, typename PortalType>
|
|
|
|
struct TypeTraits<
|
2016-10-25 20:55:48 +00:00
|
|
|
vtkm::VecFromPortalPermute<IndexVecType,PortalType> >
|
2015-08-14 14:10:17 +00:00
|
|
|
{
|
|
|
|
private:
|
2016-10-25 20:55:48 +00:00
|
|
|
typedef vtkm::VecFromPortalPermute<IndexVecType,PortalType>
|
2015-08-14 14:10:17 +00:00
|
|
|
VecType;
|
|
|
|
typedef typename PortalType::ValueType ComponentType;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef typename vtkm::TypeTraits<ComponentType>::NumericTag NumericTag;
|
|
|
|
typedef TypeTraitsVectorTag DimensionalityTag;
|
|
|
|
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
2015-08-14 14:10:17 +00:00
|
|
|
static VecType ZeroInitialization()
|
|
|
|
{
|
|
|
|
return VecType();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename IndexVecType, typename PortalType>
|
|
|
|
struct VecTraits<
|
2016-10-25 20:55:48 +00:00
|
|
|
vtkm::VecFromPortalPermute<IndexVecType,PortalType> >
|
2015-08-14 14:10:17 +00:00
|
|
|
{
|
2016-10-25 20:55:48 +00:00
|
|
|
typedef vtkm::VecFromPortalPermute<IndexVecType,PortalType>
|
2015-08-14 14:10:17 +00:00
|
|
|
VecType;
|
|
|
|
|
|
|
|
typedef typename VecType::ComponentType ComponentType;
|
|
|
|
typedef vtkm::VecTraitsTagMultipleComponents HasMultipleComponents;
|
|
|
|
typedef vtkm::VecTraitsTagSizeVariable IsSizeStatic;
|
|
|
|
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
2015-08-14 14:10:17 +00:00
|
|
|
static vtkm::IdComponent GetNumberOfComponents(const VecType &vector) {
|
|
|
|
return vector.GetNumberOfComponents();
|
|
|
|
}
|
|
|
|
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
2015-08-14 14:10:17 +00:00
|
|
|
static ComponentType GetComponent(const VecType &vector,
|
|
|
|
vtkm::IdComponent componentIndex)
|
|
|
|
{
|
|
|
|
return vector[componentIndex];
|
|
|
|
}
|
|
|
|
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2015-08-14 14:10:17 +00:00
|
|
|
template<vtkm::IdComponent destSize>
|
2016-10-25 20:55:48 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-08-14 14:10:17 +00:00
|
|
|
static void CopyInto(const VecType &src,
|
|
|
|
vtkm::Vec<ComponentType,destSize> &dest)
|
|
|
|
{
|
|
|
|
src.CopyInto(dest);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace vtkm
|
|
|
|
|
2016-10-25 20:55:48 +00:00
|
|
|
#endif //vtk_m_VecFromPortalPermute_h
|