PortalTraits.h
Go to the documentation of this file.
//=============================================================================
//
// 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 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#ifndef vtkmlib_PortalTraits_h
#define vtkmlib_PortalTraits_h
#include "vtkmConfig.h" //required for general vtkm setup
#include <vtkm/Types.h>
#include <vtkm/internal/Assume.h>
#include <type_traits>
namespace tovtkm
{
struct vtkPortalOfVecOfVecValues;
struct vtkPortalOfVecOfValues;
struct vtkPortalOfScalarValues;
template <typename T>
struct vtkPortalTraits
{
using TagType = vtkPortalOfScalarValues;
using ComponentType = typename std::remove_const<T>::type;
using Type = ComponentType;
static constexpr vtkm::IdComponent NUM_COMPONENTS = 1;
static inline void SetComponent(Type& t, vtkm::IdComponent, const ComponentType& v) { t = v; }
static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent) { return t; }
};
template <typename T, int N>
struct vtkPortalTraits<vtkm::Vec<T, N> >
{
using TagType = vtkPortalOfVecOfValues;
using ComponentType = typename std::remove_const<T>::type;
using Type = vtkm::Vec<T, N>;
static constexpr vtkm::IdComponent NUM_COMPONENTS = N;
static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
{
VTKM_ASSUME((i >= 0 && i < N));
t[i] = v;
}
static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
{
VTKM_ASSUME((i >= 0 && i < N));
return t[i];
}
};
template <typename T, int N>
struct vtkPortalTraits<const vtkm::Vec<T, N> >
{
using TagType = vtkPortalOfVecOfValues;
using ComponentType = typename std::remove_const<T>::type;
using Type = vtkm::Vec<T, N>;
static constexpr vtkm::IdComponent NUM_COMPONENTS = N;
static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
{
VTKM_ASSUME((i >= 0 && i < N));
t[i] = v;
}
static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
{
VTKM_ASSUME((i >= 0 && i < N));
return t[i];
}
};
template <typename T, int N, int M>
struct vtkPortalTraits<vtkm::Vec<vtkm::Vec<T, N>, M> >
{
using TagType = vtkPortalOfVecOfVecValues;
using ComponentType = typename std::remove_const<T>::type;
using Type = vtkm::Vec<vtkm::Vec<T, N>, M>;
static constexpr vtkm::IdComponent NUM_COMPONENTS = N * M;
static constexpr vtkm::IdComponent NUM_COMPONENTS_OUTER = M;
static constexpr vtkm::IdComponent NUM_COMPONENTS_INNER = N;
static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
{
VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
// We need to convert i back to a 2d index
const vtkm::IdComponent j = i % N;
t[i / N][j] = v;
}
static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
{
VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
// We need to convert i back to a 2d index
const vtkm::IdComponent j = i % N;
return t[i / N][j];
}
};
template <typename T, int N, int M>
struct vtkPortalTraits<const vtkm::Vec<vtkm::Vec<T, N>, M> >
{
using TagType = vtkPortalOfVecOfVecValues;
using ComponentType = typename std::remove_const<T>::type;
using Type = vtkm::Vec<vtkm::Vec<T, N>, M>;
static constexpr vtkm::IdComponent NUM_COMPONENTS = N * M;
static constexpr vtkm::IdComponent NUM_COMPONENTS_OUTER = M;
static constexpr vtkm::IdComponent NUM_COMPONENTS_INNER = N;
static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
{
VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
// We need to convert i back to a 2d index
const vtkm::IdComponent j = i % N;
t[i / N][j] = v;
}
static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
{
VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
// We need to convert i back to a 2d index
const vtkm::IdComponent j = i % N;
return t[i / N][j];
}
};
} // namespace vtkmlib
#endif // vtkmlib_PortalsTraits_h
tovtkm::vtkPortalTraits< vtkm::Vec< T, N > >::ComponentType
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:51
vtkm
Definition: vtkmDataSet.h:28
tovtkm::vtkPortalTraits< vtkm::Vec< T, N > >::GetComponent
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:61
tovtkm::vtkPortalTraits< const vtkm::Vec< vtkm::Vec< T, N >, M > >::SetComponent
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:128
vtkX3D::type
@ type
Definition: vtkX3D.h:522
tovtkm::vtkPortalTraits::SetComponent
static void SetComponent(Type &t, vtkm::IdComponent, const ComponentType &v)
Definition: PortalTraits.h:42
tovtkm::vtkPortalTraits< const vtkm::Vec< vtkm::Vec< T, N >, M > >::Type
vtkm::Vec< vtkm::Vec< T, N >, M > Type
Definition: PortalTraits.h:122
tovtkm::vtkPortalTraits< vtkm::Vec< T, N > >::Type
vtkm::Vec< T, N > Type
Definition: PortalTraits.h:52
tovtkm::vtkPortalTraits< const vtkm::Vec< T, N > >::Type
vtkm::Vec< T, N > Type
Definition: PortalTraits.h:73
tovtkm::vtkPortalTraits::NUM_COMPONENTS
static constexpr vtkm::IdComponent NUM_COMPONENTS
Definition: PortalTraits.h:40
tovtkm::vtkPortalTraits::ComponentType
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:38
tovtkm::vtkPortalTraits< const vtkm::Vec< T, N > >::TagType
vtkPortalOfVecOfValues TagType
Definition: PortalTraits.h:71
tovtkm::vtkPortalTraits< vtkm::Vec< T, N > >::SetComponent
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:55
tovtkm::vtkPortalTraits< vtkm::Vec< vtkm::Vec< T, N >, M > >::SetComponent
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:100
tovtkm::vtkPortalTraits< const vtkm::Vec< T, N > >::SetComponent
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:76
tovtkm::vtkPortalTraits< const vtkm::Vec< vtkm::Vec< T, N >, M > >::GetComponent
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:136
tovtkm::vtkPortalTraits< vtkm::Vec< vtkm::Vec< T, N >, M > >::TagType
vtkPortalOfVecOfVecValues TagType
Definition: PortalTraits.h:92
tovtkm::vtkPortalTraits::Type
ComponentType Type
Definition: PortalTraits.h:39
tovtkm::vtkPortalTraits< const vtkm::Vec< vtkm::Vec< T, N >, M > >::ComponentType
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:121
tovtkm::vtkPortalTraits< vtkm::Vec< vtkm::Vec< T, N >, M > >::ComponentType
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:93
tovtkm::vtkPortalTraits< const vtkm::Vec< T, N > >::GetComponent
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:82
tovtkm::vtkPortalTraits< vtkm::Vec< vtkm::Vec< T, N >, M > >::GetComponent
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:108
tovtkm::vtkPortalTraits
Definition: PortalTraits.h:35
tovtkm::vtkPortalTraits< vtkm::Vec< vtkm::Vec< T, N >, M > >::Type
vtkm::Vec< vtkm::Vec< T, N >, M > Type
Definition: PortalTraits.h:94
tovtkm::vtkPortalTraits< const vtkm::Vec< vtkm::Vec< T, N >, M > >::TagType
vtkPortalOfVecOfVecValues TagType
Definition: PortalTraits.h:120
tovtkm::vtkPortalTraits< vtkm::Vec< T, N > >::TagType
vtkPortalOfVecOfValues TagType
Definition: PortalTraits.h:50
tovtkm
Definition: vtkmClip.h:35
tovtkm::vtkPortalTraits::TagType
vtkPortalOfScalarValues TagType
Definition: PortalTraits.h:37
tovtkm::vtkPortalTraits::GetComponent
static ComponentType GetComponent(const Type &t, vtkm::IdComponent)
Definition: PortalTraits.h:44
tovtkm::vtkPortalTraits< const vtkm::Vec< T, N > >::ComponentType
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:72