Viskores  1.0
ArrayPortalUniformPointCoordinates.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 #ifndef viskores_internal_ArrayPortalUniformPointCoordinates_h
19 #define viskores_internal_ArrayPortalUniformPointCoordinates_h
20 
21 #include <viskores/Assert.h>
22 #include <viskores/Types.h>
23 
24 namespace viskores
25 {
26 namespace internal
27 {
28 
31 class VISKORES_ALWAYS_EXPORT ArrayPortalUniformPointCoordinates
32 {
33 public:
34  using ValueType = viskores::Vec3f;
35 
37  ArrayPortalUniformPointCoordinates()
38  : Dimensions(0)
39  , NumberOfValues(0)
40  , Origin(0, 0, 0)
41  , Spacing(1, 1, 1)
42  {
43  }
44 
46  ArrayPortalUniformPointCoordinates(viskores::Id3 dimensions, ValueType origin, ValueType spacing)
47  : Dimensions(dimensions)
48  , NumberOfValues(dimensions[0] * dimensions[1] * dimensions[2])
49  , Origin(origin)
50  , Spacing(spacing)
51  {
52  }
53 
55  viskores::Id GetNumberOfValues() const { return this->NumberOfValues; }
56 
58  ValueType Get(viskores::Id index) const
59  {
60  VISKORES_ASSERT(index >= 0);
61  VISKORES_ASSERT(index < this->GetNumberOfValues());
62  return this->Get(viskores::Id3(index % this->Dimensions[0],
63  (index / this->Dimensions[0]) % this->Dimensions[1],
64  index / (this->Dimensions[0] * this->Dimensions[1])));
65  }
66 
68  viskores::Id3 GetRange3() const { return this->Dimensions; }
69 
71  ValueType Get(viskores::Id3 index) const
72  {
73  VISKORES_ASSERT((index[0] >= 0) && (index[1] >= 0) && (index[2] >= 0));
74  VISKORES_ASSERT((index[0] < this->Dimensions[0]) && (index[1] < this->Dimensions[1]) &&
75  (index[2] < this->Dimensions[2]));
76  return ValueType(
77  this->Origin[0] + this->Spacing[0] * static_cast<viskores::FloatDefault>(index[0]),
78  this->Origin[1] + this->Spacing[1] * static_cast<viskores::FloatDefault>(index[1]),
79  this->Origin[2] + this->Spacing[2] * static_cast<viskores::FloatDefault>(index[2]));
80  }
81 
83  const viskores::Id3& GetDimensions() const { return this->Dimensions; }
84 
86  const ValueType& GetOrigin() const { return this->Origin; }
87 
89  const ValueType& GetSpacing() const { return this->Spacing; }
90 
91 private:
92  viskores::Id3 Dimensions = { 0, 0, 0 };
93  viskores::Id NumberOfValues = 0;
94  ValueType Origin = { 0.0f, 0.0f, 0.0f };
95  ValueType Spacing = { 0.0f, 0.0f, 0.0f };
96 };
97 }
98 } // namespace viskores::internal
99 
100 #endif //viskores_internal_ArrayPortalUniformPointCoordinates_h
Types.h
Assert.h
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
VISKORES_ASSERT
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
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::Vec< viskores::Id, 3 >
viskores::Vec3f
viskores::Vec< viskores::FloatDefault, 3 > Vec3f
Vec3f corresponds to a 3-dimensional vector of floating point values.
Definition: Types.h:1064