VTK-m  2.2
VecAxisAlignedPointCoordinates.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 
11 #ifndef vtk_m_VecAxisAlignedPointCoordinates_h
12 #define vtk_m_VecAxisAlignedPointCoordinates_h
13 
14 #include <vtkm/Math.h>
15 #include <vtkm/TypeTraits.h>
16 #include <vtkm/Types.h>
17 #include <vtkm/VecTraits.h>
19 
20 namespace vtkm
21 {
22 
23 namespace detail
24 {
25 
29 template <vtkm::IdComponent NumDimensions>
30 struct VecAxisAlignedPointCoordinatesNumComponents;
31 
32 template <>
33 struct VecAxisAlignedPointCoordinatesNumComponents<1>
34 {
35  static constexpr vtkm::IdComponent NUM_COMPONENTS = 2;
36 };
37 
38 template <>
39 struct VecAxisAlignedPointCoordinatesNumComponents<2>
40 {
41  static constexpr vtkm::IdComponent NUM_COMPONENTS = 4;
42 };
43 
44 template <>
45 struct VecAxisAlignedPointCoordinatesNumComponents<3>
46 {
47  static constexpr vtkm::IdComponent NUM_COMPONENTS = 8;
48 };
49 
50 struct VecAxisAlignedPointCoordinatesOffsetTable
51 {
53  {
55  { 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f },
56  { 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f, 1.0f }
57  };
58  return offsetTable[i][j];
59  }
60 };
61 
62 } // namespace detail
63 
77 template <vtkm::IdComponent NumDimensions>
79 {
80 public:
82 
83  static constexpr vtkm::IdComponent NUM_COMPONENTS =
84  detail::VecAxisAlignedPointCoordinatesNumComponents<NumDimensions>::NUM_COMPONENTS;
85 
88  ComponentType spacing = ComponentType(1, 1, 1))
89  : Origin(origin)
90  , Spacing(spacing)
91  {
92  }
93 
96 
97  template <vtkm::IdComponent DestSize>
99  {
100  vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->GetNumberOfComponents());
101  for (vtkm::IdComponent index = 0; index < numComponents; index++)
102  {
103  dest[index] = (*this)[index];
104  }
105  }
106 
109  {
110  detail::VecAxisAlignedPointCoordinatesOffsetTable table;
111  return ComponentType(this->Origin[0] + table.Get(index, 0) * this->Spacing[0],
112  this->Origin[1] + table.Get(index, 1) * this->Spacing[1],
113  this->Origin[2] + table.Get(index, 2) * this->Spacing[2]);
114  }
115 
117  const ComponentType& GetOrigin() const { return this->Origin; }
118 
120  const ComponentType& GetSpacing() const { return this->Spacing; }
121 
122 private:
123  // Position of lower left point.
125 
126  // Spacing in the x, y, and z directions.
128 };
129 
130 template <vtkm::IdComponent NumDimensions>
132 {
135 
138  {
140  vtkm::Vec3f(0, 0, 0));
141  }
142 };
143 
144 template <vtkm::IdComponent NumDimensions>
146 {
148 
153 
154  static constexpr vtkm::IdComponent NUM_COMPONENTS = VecType::NUM_COMPONENTS;
155 
158 
160  static ComponentType GetComponent(const VecType& vector, vtkm::IdComponent componentIndex)
161  {
162  return vector[componentIndex];
163  }
164 
165  // These are a bit of a hack since VecAxisAlignedPointCoordinates only supports one component
166  // type. Using these might not work as expected.
167  template <typename NewComponentType>
169  template <typename NewComponentType>
171 
172  template <vtkm::IdComponent destSize>
174  {
175  src.CopyInto(dest);
176  }
177 };
178 
181 template <vtkm::IdComponent NumDimensions>
182 inline VTKM_CONT std::ostream& operator<<(
183  std::ostream& stream,
185 {
186  stream << "[";
187  for (vtkm::IdComponent component = 0; component < vec.NUM_COMPONENTS - 1; component++)
188  {
189  stream << vec[component] << ",";
190  }
191  return stream << vec[vec.NUM_COMPONENTS - 1] << "]";
192 }
193 
194 } // namespace vtkm
195 
196 #endif //vtk_m_VecAxisAlignedPointCoordinates_h
vtkm::VecAxisAlignedPointCoordinates
An implicit vector for point coordinates in axis aligned cells.
Definition: VecAxisAlignedPointCoordinates.h:78
vtkm::VecTraitsTagMultipleComponents
A tag for vectors that are "true" vectors (i.e.
Definition: VecTraits.h:23
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::VecAxisAlignedPointCoordinates::ComponentType
vtkm::Vec3f ComponentType
Definition: VecAxisAlignedPointCoordinates.h:81
vtkm::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in VTKm (an...
Definition: TypeTraits.h:61
vtkm::Get
auto Get(const vtkm::Tuple< Ts... > &tuple)
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:81
vtkm::TypeTraits< vtkm::VecAxisAlignedPointCoordinates< NumDimensions > >::ZeroInitialization
static vtkm::VecAxisAlignedPointCoordinates< NumDimensions > ZeroInitialization()
Definition: VecAxisAlignedPointCoordinates.h:137
Types.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
VTKM_STATIC_CONSTEXPR_ARRAY
#define VTKM_STATIC_CONSTEXPR_ARRAY
Definition: ExportMacros.h:107
vtkm::VecTraits::NUM_COMPONENTS
static constexpr vtkm::IdComponent NUM_COMPONENTS
Number of components in the vector.
Definition: VecTraits.h:85
vtkm::operator<<
std::ostream & operator<<(std::ostream &stream, const vtkm::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:248
vtkm::VecAxisAlignedPointCoordinates::Spacing
ComponentType Spacing
Definition: VecAxisAlignedPointCoordinates.h:127
vtkm::VecAxisAlignedPointCoordinates::Origin
ComponentType Origin
Definition: VecAxisAlignedPointCoordinates.h:124
vtkm::VecAxisAlignedPointCoordinates::operator[]
ComponentType operator[](vtkm::IdComponent index) const
Definition: VecAxisAlignedPointCoordinates.h:108
vtkm::TypeTraitsRealTag
Tag used to identify types that store real (floating-point) numbers.
Definition: TypeTraits.h:28
vtkm::VecAxisAlignedPointCoordinates::CopyInto
void CopyInto(vtkm::Vec< ComponentType, DestSize > &dest) const
Definition: VecAxisAlignedPointCoordinates.h:98
ExportMacros.h
TypeTraits.h
Math.h
vtkm::VecTraits< vtkm::VecAxisAlignedPointCoordinates< NumDimensions > >::GetNumberOfComponents
static vtkm::IdComponent GetNumberOfComponents(const VecType &)
Definition: VecAxisAlignedPointCoordinates.h:157
vtkm::VecTraits< vtkm::VecAxisAlignedPointCoordinates< NumDimensions > >::CopyInto
static void CopyInto(const VecType &src, vtkm::Vec< ComponentType, destSize > &dest)
Definition: VecAxisAlignedPointCoordinates.h:173
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::VecAxisAlignedPointCoordinates::GetSpacing
const ComponentType & GetSpacing() const
Definition: VecAxisAlignedPointCoordinates.h:120
vtkm::VecAxisAlignedPointCoordinates::GetOrigin
const ComponentType & GetOrigin() const
Definition: VecAxisAlignedPointCoordinates.h:117
vtkm::Vec3f
vtkm::Vec< vtkm::FloatDefault, 3 > Vec3f
Vec3f corresponds to a 3-dimensional vector of floating point values.
Definition: Types.h:1052
vtkm::TypeTraitsVectorTag
Tag used to identify 1 dimensional types (vectors).
Definition: TypeTraits.h:51
vtkm::Vec< vtkm::FloatDefault, 3 >
vtkm::FloatDefault
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:236
vtkm::VecTraitsTagSizeStatic
A tag for vectors where the number of components are known at compile time.
Definition: VecTraits.h:36
vtkm::VecTraits< vtkm::VecAxisAlignedPointCoordinates< NumDimensions > >::GetComponent
static ComponentType GetComponent(const VecType &vector, vtkm::IdComponent componentIndex)
Definition: VecAxisAlignedPointCoordinates.h:160
vtkm::VecTraits< vtkm::VecAxisAlignedPointCoordinates< NumDimensions > >::BaseComponentType
vtkm::FloatDefault BaseComponentType
Definition: VecAxisAlignedPointCoordinates.h:150
vtkm::Int32
int32_t Int32
Base type to use for 32-bit signed integer numbers.
Definition: Types.h:181
vtkm::VecAxisAlignedPointCoordinates::NUM_COMPONENTS
static constexpr vtkm::IdComponent NUM_COMPONENTS
Definition: VecAxisAlignedPointCoordinates.h:83
vtkm::VecTraits
Traits that can be queried to treat any type as a Vec.
Definition: VecTraits.h:61
VecTraits.h
vtkm::VecAxisAlignedPointCoordinates::GetNumberOfComponents
vtkm::IdComponent GetNumberOfComponents() const
Definition: VecAxisAlignedPointCoordinates.h:95
vtkm::VecAxisAlignedPointCoordinates::VecAxisAlignedPointCoordinates
VecAxisAlignedPointCoordinates(ComponentType origin=ComponentType(0, 0, 0), ComponentType spacing=ComponentType(1, 1, 1))
Definition: VecAxisAlignedPointCoordinates.h:87