VTK-m  2.0
ArrayPortalUniformPointCoordinates.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_internal_ArrayPortalUniformPointCoordinates_h
11 #define vtk_m_internal_ArrayPortalUniformPointCoordinates_h
12 
13 #include <vtkm/Assert.h>
14 #include <vtkm/Types.h>
15 
16 namespace vtkm
17 {
18 namespace internal
19 {
20 
23 class VTKM_ALWAYS_EXPORT ArrayPortalUniformPointCoordinates
24 {
25 public:
26  using ValueType = vtkm::Vec3f;
27 
29  ArrayPortalUniformPointCoordinates()
30  : Dimensions(0)
31  , NumberOfValues(0)
32  , Origin(0, 0, 0)
33  , Spacing(1, 1, 1)
34  {
35  }
36 
38  ArrayPortalUniformPointCoordinates(vtkm::Id3 dimensions, ValueType origin, ValueType spacing)
39  : Dimensions(dimensions)
40  , NumberOfValues(dimensions[0] * dimensions[1] * dimensions[2])
41  , Origin(origin)
42  , Spacing(spacing)
43  {
44  }
45 
47  vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
48 
50  ValueType Get(vtkm::Id index) const
51  {
52  VTKM_ASSERT(index >= 0);
53  VTKM_ASSERT(index < this->GetNumberOfValues());
54  return this->Get(vtkm::Id3(index % this->Dimensions[0],
55  (index / this->Dimensions[0]) % this->Dimensions[1],
56  index / (this->Dimensions[0] * this->Dimensions[1])));
57  }
58 
60  vtkm::Id3 GetRange3() const { return this->Dimensions; }
61 
63  ValueType Get(vtkm::Id3 index) const
64  {
65  VTKM_ASSERT((index[0] >= 0) && (index[1] >= 0) && (index[2] >= 0));
66  VTKM_ASSERT((index[0] < this->Dimensions[0]) && (index[1] < this->Dimensions[1]) &&
67  (index[2] < this->Dimensions[2]));
68  return ValueType(this->Origin[0] + this->Spacing[0] * static_cast<vtkm::FloatDefault>(index[0]),
69  this->Origin[1] + this->Spacing[1] * static_cast<vtkm::FloatDefault>(index[1]),
70  this->Origin[2] +
71  this->Spacing[2] * static_cast<vtkm::FloatDefault>(index[2]));
72  }
73 
75  const vtkm::Id3& GetDimensions() const { return this->Dimensions; }
76 
78  const ValueType& GetOrigin() const { return this->Origin; }
79 
81  const ValueType& GetSpacing() const { return this->Spacing; }
82 
83 private:
84  vtkm::Id3 Dimensions = { 0, 0, 0 };
85  vtkm::Id NumberOfValues = 0;
86  ValueType Origin = { 0.0f, 0.0f, 0.0f };
87  ValueType Spacing = { 0.0f, 0.0f, 0.0f };
88 };
89 }
90 } // namespace vtkm::internal
91 
92 #endif //vtk_m_internal_ArrayPortalUniformPointCoordinates_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::Get
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT auto Get(const vtkm::Tuple< Ts... > &tuple) -> decltype(tuple.template Get< Index >())
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:83
Assert.h
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::Vec3f
vtkm::Vec< vtkm::FloatDefault, 3 > Vec3f
Vec3f corresponds to a 3-dimensional vector of floating point values.
Definition: Types.h:1014
vtkm::Vec< vtkm::Id, 3 >
vtkm::FloatDefault
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:198
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92