VTK-m  2.0
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 {
32 
33  RangeId3() = default;
34 
36  RangeId3(const vtkm::RangeId& xrange, const vtkm::RangeId& yrange, const vtkm::RangeId& zrange)
37  : X(xrange)
38  , Y(yrange)
39  , Z(zrange)
40  {
41  }
42 
44  RangeId3(vtkm::Id minX, vtkm::Id maxX, vtkm::Id minY, vtkm::Id maxY, vtkm::Id minZ, vtkm::Id maxZ)
45  : X(vtkm::RangeId(minX, maxX))
46  , Y(vtkm::RangeId(minY, maxY))
47  , Z(vtkm::RangeId(minZ, maxZ))
48  {
49  }
50 
55  explicit RangeId3(const vtkm::Id range[6])
56  : X(vtkm::RangeId(range[0], range[1]))
57  , Y(vtkm::RangeId(range[2], range[3]))
58  , Z(vtkm::RangeId(range[4], range[5]))
59  {
60  }
61 
65  RangeId3(const vtkm::Id3& min, const vtkm::Id3& max)
66  : X(vtkm::RangeId(min[0], max[0]))
67  , Y(vtkm::RangeId(min[1], max[1]))
68  , Z(vtkm::RangeId(min[2], max[2]))
69  {
70  }
71 
77  bool IsNonEmpty() const
78  {
79  return (this->X.IsNonEmpty() && this->Y.IsNonEmpty() && this->Z.IsNonEmpty());
80  }
81 
85  bool Contains(const vtkm::Id3& val) const
86  {
87  return (this->X.Contains(val[0]) && this->Y.Contains(val[1]) && this->Z.Contains(val[2]));
88  }
89 
95  vtkm::Id3 Center() const
96  {
97  return vtkm::Id3(this->X.Center(), this->Y.Center(), this->Z.Center());
98  }
99 
102  {
103  return vtkm::Id3(this->X.Length(), this->Y.Length(), this->Z.Length());
104  }
105 
112  template <typename T>
114  {
115  this->X.Include(point[0]);
116  this->Y.Include(point[1]);
117  this->Z.Include(point[2]);
118  }
119 
126  void Include(const vtkm::RangeId3& range)
127  {
128  this->X.Include(range.X);
129  this->Y.Include(range.Y);
130  this->Z.Include(range.Z);
131  }
132 
138  vtkm::RangeId3 Union(const vtkm::RangeId3& other) const
139  {
140  vtkm::RangeId3 unionRangeId3(*this);
141  unionRangeId3.Include(other);
142  return unionRangeId3;
143  }
144 
148  vtkm::RangeId3 operator+(const vtkm::RangeId3& other) const { return this->Union(other); }
149 
151  bool operator==(const vtkm::RangeId3& range) const
152  {
153  return ((this->X == range.X) && (this->Y == range.Y) && (this->Z == range.Z));
154  }
155 
157  bool operator!=(const vtkm::RangeId3& range) const
158  {
159  return ((this->X != range.X) || (this->Y != range.Y) || (this->Z != range.Z));
160  }
163  {
164  if (c <= 0)
165  {
166  return this->X;
167  }
168  else if (c == 1)
169  {
170  return this->Y;
171  }
172  else
173  {
174  return this->Z;
175  }
176  }
177 
179  const vtkm::RangeId& operator[](IdComponent c) const noexcept
180  {
181  if (c <= 0)
182  {
183  return this->X;
184  }
185  else if (c == 1)
186  {
187  return this->Y;
188  }
189  else
190  {
191  return this->Z;
192  }
193  }
194 };
195 
198 inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::RangeId3& range)
199 {
200  return stream << "{ X:" << range.X << ", Y:" << range.Y << ", Z:" << range.Z << " }";
201 } // Declared inside of vtkm namespace so that the operator work with ADL lookup
202 } // namespace vtkm
203 
204 #endif //vtk_m_RangeId3_h
vtkm::RangeId3::operator+
VTKM_EXEC_CONT vtkm::RangeId3 operator+(const vtkm::RangeId3 &other) const
Operator for union
Definition: RangeId3.h:148
vtkm::RangeId3::X
vtkm::RangeId X
Definition: RangeId3.h:29
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::RangeId3::Y
vtkm::RangeId Y
Definition: RangeId3.h:30
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::RangeId3::operator==
VTKM_EXEC_CONT bool operator==(const vtkm::RangeId3 &range) const
Definition: RangeId3.h:151
vtkm::RangeId
Represent a range of vtkm::Id values.
Definition: RangeId.h:28
vtkm::RangeId::IsNonEmpty
VTKM_EXEC_CONT bool IsNonEmpty() const
Determine if the range is valid.
Definition: RangeId.h:54
vtkm::RangeId3::RangeId3
VTKM_EXEC_CONT RangeId3(const vtkm::RangeId &xrange, const vtkm::RangeId &yrange, const vtkm::RangeId &zrange)
Definition: RangeId3.h:36
vtkm::RangeId3::Include
VTKM_EXEC_CONT void Include(const vtkm::RangeId3 &range)
Expand range to include other range.
Definition: RangeId3.h:126
vtkm::RangeId3::Center
VTKM_EXEC_CONT vtkm::Id3 Center() const
Returns the center of the range.
Definition: RangeId3.h:95
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::RangeId3::RangeId3
RangeId3()=default
vtkm::RangeId3::operator[]
VTKM_EXEC_CONT vtkm::RangeId & operator[](IdComponent c) noexcept
Definition: RangeId3.h:162
RangeId.h
vtkm::RangeId3::Z
vtkm::RangeId Z
Definition: RangeId3.h:31
vtkm::RangeId3::operator!=
VTKM_EXEC_CONT bool operator!=(const vtkm::RangeId3 &range) const
Definition: RangeId3.h:157
vtkm::RangeId::Center
VTKM_EXEC_CONT vtkm::Id Center() const
Returns the center of the range.
Definition: RangeId.h:77
vtkm::operator<<
VTKM_CONT std::ostream & operator<<(std::ostream &stream, const vtkm::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:237
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::RangeId::Contains
VTKM_EXEC_CONT bool Contains(vtkm::Id value) const
Determines if a value is within the range.
Definition: RangeId.h:62
vtkm::RangeId::Length
VTKM_EXEC_CONT vtkm::Id Length() const
Returns the length of the range.
Definition: RangeId.h:70
vtkm::RangeId3::IsNonEmpty
VTKM_EXEC_CONT bool IsNonEmpty() const
Determine if the range is non-empty.
Definition: RangeId3.h:77
vtkm::Id3
vtkm::Vec< vtkm::Id, 3 > Id3
Id3 corresponds to a 3-dimensional index for 3d arrays.
Definition: Types.h:1003
vtkm::RangeId3::Include
VTKM_EXEC_CONT void Include(const vtkm::Vec< T, 3 > &point)
Expand range to include a value.
Definition: RangeId3.h:113
vtkm::Vec< T, 3 >
Definition: Types.h:975
vtkm::Vec< vtkm::Id, 3 >
vtkm::RangeId3::operator[]
const VTKM_EXEC_CONT vtkm::RangeId & operator[](IdComponent c) const noexcept
Definition: RangeId3.h:179
vtkm::RangeId::Include
VTKM_EXEC_CONT void Include(vtkm::Id value)
Expand range to include a value.
Definition: RangeId.h:86
vtkm::RangeId3::Union
VTKM_EXEC_CONT vtkm::RangeId3 Union(const vtkm::RangeId3 &other) const
Return the union of this and another range.
Definition: RangeId3.h:138
vtkm::RangeId3::RangeId3
VTKM_EXEC_CONT 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:55
vtkm::RangeId3
Represent 3D integer range.
Definition: RangeId3.h:27
vtkm::RangeId3::Contains
VTKM_EXEC_CONT bool Contains(const vtkm::Id3 &val) const
Determines if an Id3 value is within the range.
Definition: RangeId3.h:85
vtkm::RangeId3::RangeId3
VTKM_EXEC_CONT RangeId3(vtkm::Id minX, vtkm::Id maxX, vtkm::Id minY, vtkm::Id maxY, vtkm::Id minZ, vtkm::Id maxZ)
Definition: RangeId3.h:44
vtkm::RangeId3::Dimensions
VTKM_EXEC_CONT vtkm::Id3 Dimensions() const
Definition: RangeId3.h:101
vtkm::RangeId3::RangeId3
VTKM_EXEC_CONT RangeId3(const vtkm::Id3 &min, const vtkm::Id3 &max)
Initialize range with the minimum and the maximum corners.
Definition: RangeId3.h:65