Viskores  1.0
VecAxisAlignedPointCoordinates.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 
19 #ifndef viskores_VecAxisAlignedPointCoordinates_h
20 #define viskores_VecAxisAlignedPointCoordinates_h
21 
22 #include <viskores/Math.h>
23 #include <viskores/TypeTraits.h>
24 #include <viskores/Types.h>
25 #include <viskores/VecTraits.h>
27 
28 namespace viskores
29 {
30 
31 namespace detail
32 {
33 
37 template <viskores::IdComponent NumDimensions>
38 struct VecAxisAlignedPointCoordinatesNumComponents;
39 
40 template <>
41 struct VecAxisAlignedPointCoordinatesNumComponents<1>
42 {
43  static constexpr viskores::IdComponent NUM_COMPONENTS = 2;
44 };
45 
46 template <>
47 struct VecAxisAlignedPointCoordinatesNumComponents<2>
48 {
49  static constexpr viskores::IdComponent NUM_COMPONENTS = 4;
50 };
51 
52 template <>
53 struct VecAxisAlignedPointCoordinatesNumComponents<3>
54 {
55  static constexpr viskores::IdComponent NUM_COMPONENTS = 8;
56 };
57 
58 struct VecAxisAlignedPointCoordinatesOffsetTable
59 {
61  {
63  { 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f },
64  { 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f, 1.0f }
65  };
66  return offsetTable[i][j];
67  }
68 };
69 
70 } // namespace detail
71 
85 template <viskores::IdComponent NumDimensions>
87 {
88 public:
90 
92  detail::VecAxisAlignedPointCoordinatesNumComponents<NumDimensions>::NUM_COMPONENTS;
93 
96  ComponentType spacing = ComponentType(1, 1, 1))
97  : Origin(origin)
98  , Spacing(spacing)
99  {
100  }
101 
104 
105  template <viskores::IdComponent DestSize>
107  {
108  viskores::IdComponent numComponents = viskores::Min(DestSize, this->GetNumberOfComponents());
109  for (viskores::IdComponent index = 0; index < numComponents; index++)
110  {
111  dest[index] = (*this)[index];
112  }
113  }
114 
117  {
118  detail::VecAxisAlignedPointCoordinatesOffsetTable table;
119  return ComponentType(this->Origin[0] + table.Get(index, 0) * this->Spacing[0],
120  this->Origin[1] + table.Get(index, 1) * this->Spacing[1],
121  this->Origin[2] + table.Get(index, 2) * this->Spacing[2]);
122  }
123 
125  const ComponentType& GetOrigin() const { return this->Origin; }
126 
128  const ComponentType& GetSpacing() const { return this->Spacing; }
129 
130 private:
131  // Position of lower left point.
133 
134  // Spacing in the x, y, and z directions.
136 };
137 
138 template <viskores::IdComponent NumDimensions>
140 {
143 
146  {
148  viskores::Vec3f(0, 0, 0));
149  }
150 };
151 
152 template <viskores::IdComponent NumDimensions>
154 {
156 
161 
162  static constexpr viskores::IdComponent NUM_COMPONENTS = VecType::NUM_COMPONENTS;
163 
166 
168  static ComponentType GetComponent(const VecType& vector, viskores::IdComponent componentIndex)
169  {
170  return vector[componentIndex];
171  }
172 
173  // These are a bit of a hack since VecAxisAlignedPointCoordinates only supports one component
174  // type. Using these might not work as expected.
175  template <typename NewComponentType>
177  template <typename NewComponentType>
180 
181  template <viskores::IdComponent destSize>
182  VISKORES_EXEC_CONT static void CopyInto(const VecType& src,
184  {
185  src.CopyInto(dest);
186  }
187 };
188 
191 template <viskores::IdComponent NumDimensions>
192 inline VISKORES_CONT std::ostream& operator<<(
193  std::ostream& stream,
195 {
196  stream << "[";
197  for (viskores::IdComponent component = 0; component < vec.NUM_COMPONENTS - 1; component++)
198  {
199  stream << vec[component] << ",";
200  }
201  return stream << vec[vec.NUM_COMPONENTS - 1] << "]";
202 }
203 
204 } // namespace viskores
205 
206 #endif //viskores_VecAxisAlignedPointCoordinates_h
viskores::VecAxisAlignedPointCoordinates::GetSpacing
const ComponentType & GetSpacing() const
Definition: VecAxisAlignedPointCoordinates.h:128
viskores::VecAxisAlignedPointCoordinates::NUM_COMPONENTS
static constexpr viskores::IdComponent NUM_COMPONENTS
Definition: VecAxisAlignedPointCoordinates.h:91
viskores::VecAxisAlignedPointCoordinates::operator[]
ComponentType operator[](viskores::IdComponent index) const
Definition: VecAxisAlignedPointCoordinates.h:116
viskores::VecAxisAlignedPointCoordinates
An implicit vector for point coordinates in axis aligned cells.
Definition: VecAxisAlignedPointCoordinates.h:86
viskores::VecTraits< viskores::VecAxisAlignedPointCoordinates< NumDimensions > >::GetNumberOfComponents
static viskores::IdComponent GetNumberOfComponents(const VecType &)
Definition: VecAxisAlignedPointCoordinates.h:165
Types.h
viskores::VecTraitsTagSizeStatic
A tag for vectors where the number of components are known at compile time.
Definition: VecTraits.h:44
viskores::VecTraitsTagMultipleComponents
A tag for vectors that are "true" vectors (i.e.
Definition: VecTraits.h:31
viskores::VecAxisAlignedPointCoordinates::ComponentType
viskores::Vec3f ComponentType
Definition: VecAxisAlignedPointCoordinates.h:89
viskores::VecTraits< viskores::VecAxisAlignedPointCoordinates< NumDimensions > >::CopyInto
static void CopyInto(const VecType &src, viskores::Vec< ComponentType, destSize > &dest)
Definition: VecAxisAlignedPointCoordinates.h:182
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::VecAxisAlignedPointCoordinates::Spacing
ComponentType Spacing
Definition: VecAxisAlignedPointCoordinates.h:135
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
ExportMacros.h
TypeTraits.h
viskores::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in Viskores...
Definition: TypeTraits.h:69
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores::operator<<
std::ostream & operator<<(std::ostream &stream, const viskores::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:268
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Math.h
viskores::TypeTraitsRealTag
Tag used to identify types that store real (floating-point) numbers.
Definition: TypeTraits.h:36
viskores::VecTraits::NUM_COMPONENTS
static constexpr viskores::IdComponent NUM_COMPONENTS
Number of components in the vector.
Definition: VecTraits.h:93
viskores::VecTraits
Traits that can be queried to treat any type as a Vec.
Definition: VecTraits.h:69
viskores::VecAxisAlignedPointCoordinates::GetOrigin
const ComponentType & GetOrigin() const
Definition: VecAxisAlignedPointCoordinates.h:125
VISKORES_STATIC_CONSTEXPR_ARRAY
#define VISKORES_STATIC_CONSTEXPR_ARRAY
Definition: ExportMacros.h:115
viskores::VecTraits< viskores::VecAxisAlignedPointCoordinates< NumDimensions > >::GetComponent
static ComponentType GetComponent(const VecType &vector, viskores::IdComponent componentIndex)
Definition: VecAxisAlignedPointCoordinates.h:168
viskores::Int32
int32_t Int32
Base type to use for 32-bit signed integer numbers.
Definition: Types.h:189
viskores::VecAxisAlignedPointCoordinates::Origin
ComponentType Origin
Definition: VecAxisAlignedPointCoordinates.h:132
viskores::VecAxisAlignedPointCoordinates::VecAxisAlignedPointCoordinates
VecAxisAlignedPointCoordinates(ComponentType origin=ComponentType(0, 0, 0), ComponentType spacing=ComponentType(1, 1, 1))
Definition: VecAxisAlignedPointCoordinates.h:95
viskores::FloatDefault
viskores::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:244
viskores::Get
auto Get(const viskores::Tuple< Ts... > &tuple)
Retrieve the object from a viskores::Tuple at the given index.
Definition: Tuple.h:89
viskores::TypeTraits< viskores::VecAxisAlignedPointCoordinates< NumDimensions > >::ZeroInitialization
static viskores::VecAxisAlignedPointCoordinates< NumDimensions > ZeroInitialization()
Definition: VecAxisAlignedPointCoordinates.h:145
viskores::VecTraits< viskores::VecAxisAlignedPointCoordinates< NumDimensions > >::BaseComponentType
viskores::FloatDefault BaseComponentType
Definition: VecAxisAlignedPointCoordinates.h:158
viskores::TypeTraitsVectorTag
Tag used to identify 1 dimensional types (vectors).
Definition: TypeTraits.h:59
viskores::Vec< viskores::FloatDefault, 3 >
VecTraits.h
viskores::Vec3f
viskores::Vec< viskores::FloatDefault, 3 > Vec3f
Vec3f corresponds to a 3-dimensional vector of floating point values.
Definition: Types.h:1064
viskores::VecAxisAlignedPointCoordinates::CopyInto
void CopyInto(viskores::Vec< ComponentType, DestSize > &dest) const
Definition: VecAxisAlignedPointCoordinates.h:106
viskores::VecAxisAlignedPointCoordinates::GetNumberOfComponents
viskores::IdComponent GetNumberOfComponents() const
Definition: VecAxisAlignedPointCoordinates.h:103