VTK-m  2.2
RangeId2.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_RangeId2_h
11 #define vtk_m_RangeId2_h
12 
13 #include <vtkm/RangeId.h>
14 
15 namespace vtkm
16 {
17 
27 struct RangeId2
28 {
35 
37  RangeId2() = default;
38 
41  RangeId2(const vtkm::RangeId& xrange, const vtkm::RangeId& yrange)
42  : X(xrange)
43  , Y(yrange)
44  {
45  }
46 
49  RangeId2(vtkm::Id minX, vtkm::Id maxX, vtkm::Id minY, vtkm::Id maxY)
50  : X(vtkm::RangeId(minX, maxX))
51  , Y(vtkm::RangeId(minY, maxY))
52  {
53  }
54 
59  explicit RangeId2(const vtkm::Id range[4])
60  : X(vtkm::RangeId(range[0], range[1]))
61  , Y(vtkm::RangeId(range[2], range[3]))
62  {
63  }
64 
68  RangeId2(const vtkm::Id2& min, const vtkm::Id2& max)
69  : X(vtkm::RangeId(min[0], max[0]))
70  , Y(vtkm::RangeId(min[1], max[1]))
71  {
72  }
73 
79  bool IsNonEmpty() const { return (this->X.IsNonEmpty() && this->Y.IsNonEmpty()); }
80 
84  bool Contains(const vtkm::Id2& val) const
85  {
86  return (this->X.Contains(val[0]) && this->Y.Contains(val[1]));
87  }
88 
94  vtkm::Id2 Center() const { return vtkm::Id2(this->X.Center(), this->Y.Center()); }
95 
97  vtkm::Id2 Dimensions() const { return vtkm::Id2(this->X.Length(), this->Y.Length()); }
98 
105  template <typename T>
107  {
108  this->X.Include(point[0]);
109  this->Y.Include(point[1]);
110  }
111 
118  void Include(const vtkm::RangeId2& range)
119  {
120  this->X.Include(range.X);
121  this->Y.Include(range.Y);
122  }
123 
129  vtkm::RangeId2 Union(const vtkm::RangeId2& other) const
130  {
131  vtkm::RangeId2 unionRangeId2(*this);
132  unionRangeId2.Include(other);
133  return unionRangeId2;
134  }
135 
139  vtkm::RangeId2 operator+(const vtkm::RangeId2& other) const { return this->Union(other); }
140 
142  bool operator==(const vtkm::RangeId2& range) const
143  {
144  return ((this->X == range.X) && (this->Y == range.Y));
145  }
146 
148  bool operator!=(const vtkm::RangeId2& range) const
149  {
150  return ((this->X != range.X) || (this->Y != range.Y));
151  }
152 
155  {
156  if (c <= 0)
157  {
158  return this->X;
159  }
160  else
161  {
162  return this->Y;
163  }
164  }
165 
167  const vtkm::RangeId& operator[](IdComponent c) const noexcept
168  {
169  if (c <= 0)
170  {
171  return this->X;
172  }
173  else
174  {
175  return this->Y;
176  }
177  }
178 };
179 
180 } // namespace vtkm
181 
184 static inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::RangeId2& range)
185 {
186  return stream << "{ X:" << range.X << ", Y:" << range.Y << " }";
187 }
188 
189 #endif //vtk_m_RangeId2_h
vtkm::RangeId2::IsNonEmpty
bool IsNonEmpty() const
Determine if the range is non-empty.
Definition: RangeId2.h:79
vtkm::RangeId::IsNonEmpty
bool IsNonEmpty() const
Determine if the range is valid.
Definition: RangeId.h:59
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::RangeId2::operator[]
vtkm::RangeId & operator[](IdComponent c) noexcept
Definition: RangeId2.h:154
vtkm::RangeId2::operator!=
bool operator!=(const vtkm::RangeId2 &range) const
Definition: RangeId2.h:148
vtkm::RangeId2::Dimensions
vtkm::Id2 Dimensions() const
Definition: RangeId2.h:97
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::RangeId2::operator[]
const vtkm::RangeId & operator[](IdComponent c) const noexcept
Definition: RangeId2.h:167
vtkm::RangeId2
Represent 2D integer range.
Definition: RangeId2.h:27
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::RangeId2::operator==
bool operator==(const vtkm::RangeId2 &range) const
Definition: RangeId2.h:142
vtkm::RangeId
Represent a range of vtkm::Id values.
Definition: RangeId.h:28
vtkm::RangeId2::operator+
vtkm::RangeId2 operator+(const vtkm::RangeId2 &other) const
Operator for union
Definition: RangeId2.h:139
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::RangeId2::Center
vtkm::Id2 Center() const
Returns the center of the range.
Definition: RangeId2.h:94
vtkm::RangeId2::RangeId2
RangeId2(const vtkm::Id range[4])
Initialize range with an array of 4 values in the order xmin, xmax, ymin, ymax.
Definition: RangeId2.h:59
vtkm::RangeId2::RangeId2
RangeId2(const vtkm::Id2 &min, const vtkm::Id2 &max)
Initialize range with the minimum and the maximum corners.
Definition: RangeId2.h:68
RangeId.h
vtkm::RangeId2::RangeId2
RangeId2(const vtkm::RangeId &xrange, const vtkm::RangeId &yrange)
Construct a range with the given x and y directions.
Definition: RangeId2.h:41
vtkm::RangeId2::Include
void Include(const vtkm::Vec< T, 2 > &point)
Expand range to include a value.
Definition: RangeId2.h:106
vtkm::Vec< T, 2 >
Definition: Types.h:900
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::RangeId2::RangeId2
RangeId2(vtkm::Id minX, vtkm::Id maxX, vtkm::Id minY, vtkm::Id maxY)
Construct a range with the given minimum (inclusive) and maximum (exclusive) points.
Definition: RangeId2.h:49
vtkm::RangeId::Length
vtkm::Id Length() const
Returns the length of the range.
Definition: RangeId.h:75
vtkm::RangeId2::RangeId2
RangeId2()=default
Construct an empty 2D range.
vtkm::Vec< vtkm::Id, 2 >
vtkm::RangeId2::X
vtkm::RangeId X
The range of values in the X direction.
Definition: RangeId2.h:31
vtkm::RangeId2::Include
void Include(const vtkm::RangeId2 &range)
Expand range to include other range.
Definition: RangeId2.h:118
vtkm::RangeId2::Contains
bool Contains(const vtkm::Id2 &val) const
Determines if an Id2 value is within the range.
Definition: RangeId2.h:84
vtkm::RangeId2::Union
vtkm::RangeId2 Union(const vtkm::RangeId2 &other) const
Return the union of this and another range.
Definition: RangeId2.h:129
vtkm::RangeId2::Y
vtkm::RangeId Y
The range of values in the Y direction.
Definition: RangeId2.h:34
vtkm::Id2
vtkm::Vec< vtkm::Id, 2 > Id2
Id2 corresponds to a 2-dimensional index.
Definition: Types.h:926