VTK-m  2.2
RangeId3.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_RangeId3_h
11 #define vtk_m_RangeId3_h
12 
13 #include <vtkm/RangeId.h>
14 
15 namespace vtkm
16 {
17 
27 struct RangeId3
28 {
38 
40  RangeId3() = default;
41 
44  RangeId3(const vtkm::RangeId& xrange, const vtkm::RangeId& yrange, const vtkm::RangeId& zrange)
45  : X(xrange)
46  , Y(yrange)
47  , Z(zrange)
48  {
49  }
50 
53  RangeId3(vtkm::Id minX, vtkm::Id maxX, vtkm::Id minY, vtkm::Id maxY, vtkm::Id minZ, vtkm::Id maxZ)
54  : X(vtkm::RangeId(minX, maxX))
55  , Y(vtkm::RangeId(minY, maxY))
56  , Z(vtkm::RangeId(minZ, maxZ))
57  {
58  }
59 
64  explicit RangeId3(const vtkm::Id range[6])
65  : X(vtkm::RangeId(range[0], range[1]))
66  , Y(vtkm::RangeId(range[2], range[3]))
67  , Z(vtkm::RangeId(range[4], range[5]))
68  {
69  }
70 
74  RangeId3(const vtkm::Id3& min, const vtkm::Id3& max)
75  : X(vtkm::RangeId(min[0], max[0]))
76  , Y(vtkm::RangeId(min[1], max[1]))
77  , Z(vtkm::RangeId(min[2], max[2]))
78  {
79  }
80 
86  bool IsNonEmpty() const
87  {
88  return (this->X.IsNonEmpty() && this->Y.IsNonEmpty() && this->Z.IsNonEmpty());
89  }
90 
94  bool Contains(const vtkm::Id3& val) const
95  {
96  return (this->X.Contains(val[0]) && this->Y.Contains(val[1]) && this->Z.Contains(val[2]));
97  }
98 
105  {
106  return vtkm::Id3(this->X.Center(), this->Y.Center(), this->Z.Center());
107  }
108 
111  {
112  return vtkm::Id3(this->X.Length(), this->Y.Length(), this->Z.Length());
113  }
114 
121  template <typename T>
123  {
124  this->X.Include(point[0]);
125  this->Y.Include(point[1]);
126  this->Z.Include(point[2]);
127  }
128 
135  void Include(const vtkm::RangeId3& range)
136  {
137  this->X.Include(range.X);
138  this->Y.Include(range.Y);
139  this->Z.Include(range.Z);
140  }
141 
147  vtkm::RangeId3 Union(const vtkm::RangeId3& other) const
148  {
149  vtkm::RangeId3 unionRangeId3(*this);
150  unionRangeId3.Include(other);
151  return unionRangeId3;
152  }
153 
157  vtkm::RangeId3 operator+(const vtkm::RangeId3& other) const { return this->Union(other); }
158 
160  bool operator==(const vtkm::RangeId3& range) const
161  {
162  return ((this->X == range.X) && (this->Y == range.Y) && (this->Z == range.Z));
163  }
164 
166  bool operator!=(const vtkm::RangeId3& range) const
167  {
168  return ((this->X != range.X) || (this->Y != range.Y) || (this->Z != range.Z));
169  }
172  {
173  if (c <= 0)
174  {
175  return this->X;
176  }
177  else if (c == 1)
178  {
179  return this->Y;
180  }
181  else
182  {
183  return this->Z;
184  }
185  }
186 
188  const vtkm::RangeId& operator[](IdComponent c) const noexcept
189  {
190  if (c <= 0)
191  {
192  return this->X;
193  }
194  else if (c == 1)
195  {
196  return this->Y;
197  }
198  else
199  {
200  return this->Z;
201  }
202  }
203 };
204 
207 inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::RangeId3& range)
208 {
209  return stream << "{ X:" << range.X << ", Y:" << range.Y << ", Z:" << range.Z << " }";
210 } // Declared inside of vtkm namespace so that the operator work with ADL lookup
211 } // namespace vtkm
212 
213 #endif //vtk_m_RangeId3_h
vtkm::RangeId3::RangeId3
RangeId3(const vtkm::Id range[6])
Initialize range with an array of 6 values in the order xmin, xmax, ymin, ymax, zmin,...
Definition: RangeId3.h:64
vtkm::RangeId::IsNonEmpty
bool IsNonEmpty() const
Determine if the range is valid.
Definition: RangeId.h:59
vtkm::RangeId3::X
vtkm::RangeId X
The range of values in the X direction.
Definition: RangeId3.h:31
vtkm::RangeId3::RangeId3
RangeId3(const vtkm::Id3 &min, const vtkm::Id3 &max)
Initialize range with the minimum and the maximum corners.
Definition: RangeId3.h:74
vtkm::RangeId3::Include
void Include(const vtkm::Vec< T, 3 > &point)
Expand range to include a value.
Definition: RangeId3.h:122
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::RangeId3::operator+
vtkm::RangeId3 operator+(const vtkm::RangeId3 &other) const
Operator for union
Definition: RangeId3.h:157
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::RangeId3::Y
vtkm::RangeId Y
The range of values in the Y direction.
Definition: RangeId3.h:34
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::RangeId3::Union
vtkm::RangeId3 Union(const vtkm::RangeId3 &other) const
Return the union of this and another range.
Definition: RangeId3.h:147
vtkm::RangeId3::Dimensions
vtkm::Id3 Dimensions() const
Definition: RangeId3.h:110
vtkm::RangeId::Center
vtkm::Id Center() const
Returns the center of the range.
Definition: RangeId.h:82
vtkm::operator<<
std::ostream & operator<<(std::ostream &stream, const vtkm::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:248
vtkm::RangeId
Represent a range of vtkm::Id values.
Definition: RangeId.h:28
vtkm::RangeId::Include
void Include(vtkm::Id value)
Expand range to include a value.
Definition: RangeId.h:91
vtkm::RangeId::Contains
bool Contains(vtkm::Id value) const
Determines if a value is within the range.
Definition: RangeId.h:67
vtkm::RangeId3::RangeId3
RangeId3()=default
Construct an empty 3D range.
vtkm::RangeId3::Include
void Include(const vtkm::RangeId3 &range)
Expand range to include other range.
Definition: RangeId3.h:135
RangeId.h
vtkm::RangeId3::Z
vtkm::RangeId Z
The range of values in the Z direction.
Definition: RangeId3.h:37
vtkm::RangeId3::operator[]
vtkm::RangeId & operator[](IdComponent c) noexcept
Definition: RangeId3.h:171
vtkm::RangeId3::RangeId3
RangeId3(const vtkm::RangeId &xrange, const vtkm::RangeId &yrange, const vtkm::RangeId &zrange)
Construct a range with the given x, y, and z directions.
Definition: RangeId3.h:44
vtkm::RangeId3::operator!=
bool operator!=(const vtkm::RangeId3 &range) const
Definition: RangeId3.h:166
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::RangeId3::IsNonEmpty
bool IsNonEmpty() const
Determine if the range is non-empty.
Definition: RangeId3.h:86
vtkm::Id3
vtkm::Vec< vtkm::Id, 3 > Id3
Id3 corresponds to a 3-dimensional index for 3d arrays.
Definition: Types.h:1041
vtkm::RangeId::Length
vtkm::Id Length() const
Returns the length of the range.
Definition: RangeId.h:75
vtkm::Vec< T, 3 >
Definition: Types.h:1013
vtkm::Vec< vtkm::Id, 3 >
vtkm::RangeId3::Contains
bool Contains(const vtkm::Id3 &val) const
Determines if an Id3 value is within the range.
Definition: RangeId3.h:94
vtkm::RangeId3
Represent 3D integer range.
Definition: RangeId3.h:27
vtkm::RangeId3::operator==
bool operator==(const vtkm::RangeId3 &range) const
Definition: RangeId3.h:160
vtkm::RangeId3::RangeId3
RangeId3(vtkm::Id minX, vtkm::Id maxX, vtkm::Id minY, vtkm::Id maxY, vtkm::Id minZ, vtkm::Id maxZ)
Construct a range with the given minimum (inclusive) and maximum (exclusive) points.
Definition: RangeId3.h:53
vtkm::RangeId3::Center
vtkm::Id3 Center() const
Returns the center of the range.
Definition: RangeId3.h:104
vtkm::RangeId3::operator[]
const vtkm::RangeId & operator[](IdComponent c) const noexcept
Definition: RangeId3.h:188