VTK-m  2.0
VecFromPortal.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_VecFromPortal_h
11 #define vtk_m_VecFromPortal_h
12 
13 #include <vtkm/Math.h>
14 #include <vtkm/TypeTraits.h>
15 #include <vtkm/Types.h>
16 #include <vtkm/VecTraits.h>
17 
19 
20 namespace vtkm
21 {
22 
28 template <typename PortalType>
30 {
31 public:
32  using ComponentType = typename std::remove_const<typename PortalType::ValueType>::type;
33 
37  : NumComponents(0)
38  , Offset(0)
39  {
40  }
41 
44  VecFromPortal(const PortalType& portal, vtkm::IdComponent numComponents = 0, vtkm::Id offset = 0)
45  : Portal(portal)
46  , NumComponents(numComponents)
47  , Offset(offset)
48  {
49  }
50 
53 
54  template <typename T, vtkm::IdComponent DestSize>
56  {
57  vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->NumComponents);
58  for (vtkm::IdComponent index = 0; index < numComponents; index++)
59  {
60  dest[index] = this->Portal.Get(index + this->Offset);
61  }
62  }
63 
66  vtkm::internal::ArrayPortalValueReference<PortalType> operator[](vtkm::IdComponent index) const
67  {
68  return vtkm::internal::ArrayPortalValueReference<PortalType>(this->Portal,
69  index + this->Offset);
70  }
71 
72 private:
73  PortalType Portal;
76 };
77 
78 template <typename PortalType>
79 struct TypeTraits<vtkm::VecFromPortal<PortalType>>
80 {
81 private:
82  using ComponentType = typename PortalType::ValueType;
83 
84 public:
87 
91  {
93  }
94 };
95 
96 template <typename PortalType>
97 struct VecTraits<vtkm::VecFromPortal<PortalType>>
98 {
100 
105 
109  {
110  return vector.GetNumberOfComponents();
111  }
112 
115  static ComponentType GetComponent(const VecType& vector, vtkm::IdComponent componentIndex)
116  {
117  return vector[componentIndex];
118  }
119 
121  template <vtkm::IdComponent destSize>
123  {
124  src.CopyInto(dest);
125  }
126 };
127 
128 } // namespace vtkm
129 
130 #endif //vtk_m_VecFromPortal_h
vtkm::VecFromPortal::operator[]
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT vtkm::internal::ArrayPortalValueReference< PortalType > operator[](vtkm::IdComponent index) const
Definition: VecFromPortal.h:66
vtkm::VecTraitsTagMultipleComponents
A tag for vectors that are "true" vectors (i.e.
Definition: VecTraits.h:21
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in VTKm (an...
Definition: TypeTraits.h:61
Types.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::TypeTraits< vtkm::VecFromPortal< PortalType > >::ZeroInitialization
VTKM_SUPPRESS_EXEC_WARNINGS static VTKM_EXEC_CONT vtkm::VecFromPortal< PortalType > ZeroInitialization()
Definition: VecFromPortal.h:90
vtkm::VecFromPortal::Offset
vtkm::Id Offset
Definition: VecFromPortal.h:75
vtkm::VecFromPortal::Portal
PortalType Portal
Definition: VecFromPortal.h:73
vtkm::VecFromPortal::VecFromPortal
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortal(const PortalType &portal, vtkm::IdComponent numComponents=0, vtkm::Id offset=0)
Definition: VecFromPortal.h:44
vtkm::VecTraits::BaseComponentType
typename vtkm::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Base component type in the vector.
Definition: VecTraits.h:80
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
TypeTraits.h
vtkm::VecTraitsTagSizeVariable
A tag for vectors where the number of components are not determined until run time.
Definition: VecTraits.h:41
vtkm::VecFromPortal::CopyInto
VTKM_EXEC_CONT void CopyInto(vtkm::Vec< T, DestSize > &dest) const
Definition: VecFromPortal.h:55
Math.h
vtkm::VecFromPortal::GetNumberOfComponents
VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const
Definition: VecFromPortal.h:52
ArrayPortalValueReference.h
vtkm::VecTraits< vtkm::VecFromPortal< PortalType > >::GetComponent
VTKM_SUPPRESS_EXEC_WARNINGS static VTKM_EXEC_CONT ComponentType GetComponent(const VecType &vector, vtkm::IdComponent componentIndex)
Definition: VecFromPortal.h:115
vtkm::TypeTraits< vtkm::VecFromPortal< PortalType > >::ComponentType
typename PortalType::ValueType ComponentType
Definition: VecFromPortal.h:82
vtkm::VecFromPortal::NumComponents
vtkm::IdComponent NumComponents
Definition: VecFromPortal.h:74
vtkm::TypeTraitsUnknownTag
Tag used to identify types that aren't Real, Integer, Scalar or Vector.
Definition: TypeTraits.h:20
vtkm::TypeTraitsVectorTag
Tag used to identify 1 dimensional types (vectors).
Definition: TypeTraits.h:51
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::VecFromPortal::ComponentType
typename std::remove_const< typename PortalType::ValueType >::type ComponentType
Definition: VecFromPortal.h:32
vtkm::VecTraits< vtkm::VecFromPortal< PortalType > >::BaseComponentType
typename vtkm::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Definition: VecFromPortal.h:102
vtkm::VecFromPortal::VecFromPortal
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortal()
Definition: VecFromPortal.h:36
vtkm::VecTraits< vtkm::VecFromPortal< PortalType > >::ComponentType
typename VecType::ComponentType ComponentType
Definition: VecFromPortal.h:101
vtkm::VecTraits
The VecTraits class gives several static members that define how to use a given type as a vector.
Definition: VecTraits.h:66
vtkm::VecTraits< vtkm::VecFromPortal< PortalType > >::GetNumberOfComponents
VTKM_SUPPRESS_EXEC_WARNINGS static VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents(const VecType &vector)
Definition: VecFromPortal.h:108
vtkm::VecFromPortal
A short variable-length array from a window in an ArrayPortal.
Definition: VecFromPortal.h:29
vtkm::VecTraits< vtkm::VecFromPortal< PortalType > >::CopyInto
VTKM_SUPPRESS_EXEC_WARNINGS static VTKM_EXEC_CONT void CopyInto(const VecType &src, vtkm::Vec< ComponentType, destSize > &dest)
Definition: VecFromPortal.h:122
VTKM_SUPPRESS_EXEC_WARNINGS
#define VTKM_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:53
VecTraits.h
vtkm::TypeTraits< vtkm::VecFromPortal< PortalType > >::NumericTag
typename vtkm::TypeTraits< ComponentType >::NumericTag NumericTag
Definition: VecFromPortal.h:85