VTK-m  2.0
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 {
31 
32  RangeId2() = default;
33 
35  RangeId2(const vtkm::RangeId& xrange, const vtkm::RangeId& yrange)
36  : X(xrange)
37  , Y(yrange)
38  {
39  }
40 
42  RangeId2(vtkm::Id minX, vtkm::Id maxX, vtkm::Id minY, vtkm::Id maxY)
43  : X(vtkm::RangeId(minX, maxX))
44  , Y(vtkm::RangeId(minY, maxY))
45  {
46  }
47 
52  explicit RangeId2(const vtkm::Id range[4])
53  : X(vtkm::RangeId(range[0], range[1]))
54  , Y(vtkm::RangeId(range[2], range[3]))
55  {
56  }
57 
61  RangeId2(const vtkm::Id2& min, const vtkm::Id2& max)
62  : X(vtkm::RangeId(min[0], max[0]))
63  , Y(vtkm::RangeId(min[1], max[1]))
64  {
65  }
66 
72  bool IsNonEmpty() const { return (this->X.IsNonEmpty() && this->Y.IsNonEmpty()); }
73 
77  bool Contains(const vtkm::Id2& val) const
78  {
79  return (this->X.Contains(val[0]) && this->Y.Contains(val[1]));
80  }
81 
87  vtkm::Id2 Center() const { return vtkm::Id2(this->X.Center(), this->Y.Center()); }
88 
90  vtkm::Id2 Dimensions() const { return vtkm::Id2(this->X.Length(), this->Y.Length()); }
91 
98  template <typename T>
100  {
101  this->X.Include(point[0]);
102  this->Y.Include(point[1]);
103  }
104 
111  void Include(const vtkm::RangeId2& range)
112  {
113  this->X.Include(range.X);
114  this->Y.Include(range.Y);
115  }
116 
122  vtkm::RangeId2 Union(const vtkm::RangeId2& other) const
123  {
124  vtkm::RangeId2 unionRangeId2(*this);
125  unionRangeId2.Include(other);
126  return unionRangeId2;
127  }
128 
132  vtkm::RangeId2 operator+(const vtkm::RangeId2& other) const { return this->Union(other); }
133 
135  bool operator==(const vtkm::RangeId2& range) const
136  {
137  return ((this->X == range.X) && (this->Y == range.Y));
138  }
139 
141  bool operator!=(const vtkm::RangeId2& range) const
142  {
143  return ((this->X != range.X) || (this->Y != range.Y));
144  }
145 
148  {
149  if (c <= 0)
150  {
151  return this->X;
152  }
153  else
154  {
155  return this->Y;
156  }
157  }
158 
160  const vtkm::RangeId& operator[](IdComponent c) const noexcept
161  {
162  if (c <= 0)
163  {
164  return this->X;
165  }
166  else
167  {
168  return this->Y;
169  }
170  }
171 };
172 
173 } // namespace vtkm
174 
177 static inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::RangeId2& range)
178 {
179  return stream << "{ X:" << range.X << ", Y:" << range.Y << " }";
180 }
181 
182 #endif //vtk_m_RangeId2_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::RangeId2::RangeId2
VTKM_EXEC_CONT RangeId2(vtkm::Id minX, vtkm::Id maxX, vtkm::Id minY, vtkm::Id maxY)
Definition: RangeId2.h:42
vtkm::RangeId2::IsNonEmpty
VTKM_EXEC_CONT bool IsNonEmpty() const
Determine if the range is non-empty.
Definition: RangeId2.h:72
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::RangeId2
Represent 2D integer range.
Definition: RangeId2.h:27
vtkm::RangeId2::operator[]
const VTKM_EXEC_CONT vtkm::RangeId & operator[](IdComponent c) const noexcept
Definition: RangeId2.h:160
vtkm::RangeId
Represent a range of vtkm::Id values.
Definition: RangeId.h:28
vtkm::RangeId2::Include
VTKM_EXEC_CONT void Include(const vtkm::Vec< T, 2 > &point)
Expand range to include a value.
Definition: RangeId2.h:99
vtkm::RangeId2::operator!=
VTKM_EXEC_CONT bool operator!=(const vtkm::RangeId2 &range) const
Definition: RangeId2.h:141
vtkm::RangeId::IsNonEmpty
VTKM_EXEC_CONT bool IsNonEmpty() const
Determine if the range is valid.
Definition: RangeId.h:54
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::RangeId2::Contains
VTKM_EXEC_CONT bool Contains(const vtkm::Id2 &val) const
Determines if an Id2 value is within the range.
Definition: RangeId2.h:77
vtkm::RangeId2::operator==
VTKM_EXEC_CONT bool operator==(const vtkm::RangeId2 &range) const
Definition: RangeId2.h:135
vtkm::RangeId2::operator+
VTKM_EXEC_CONT vtkm::RangeId2 operator+(const vtkm::RangeId2 &other) const
Operator for union
Definition: RangeId2.h:132
RangeId.h
vtkm::RangeId::Center
VTKM_EXEC_CONT vtkm::Id Center() const
Returns the center of the range.
Definition: RangeId.h:77
vtkm::RangeId2::RangeId2
VTKM_EXEC_CONT RangeId2(const vtkm::RangeId &xrange, const vtkm::RangeId &yrange)
Definition: RangeId2.h:35
vtkm::Vec< T, 2 >
Definition: Types.h:859
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::RangeId2::RangeId2
VTKM_EXEC_CONT RangeId2(const vtkm::Id range[4])
Initialize range with an array of 6 values in the order xmin, xmax, ymin, ymax, zmin,...
Definition: RangeId2.h:52
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::RangeId2::Dimensions
VTKM_EXEC_CONT vtkm::Id2 Dimensions() const
Definition: RangeId2.h:90
vtkm::RangeId2::RangeId2
VTKM_EXEC_CONT RangeId2(const vtkm::Id2 &min, const vtkm::Id2 &max)
Initialize range with the minimum and the maximum corners.
Definition: RangeId2.h:61
vtkm::RangeId2::Center
VTKM_EXEC_CONT vtkm::Id2 Center() const
Returns the center of the range.
Definition: RangeId2.h:87
vtkm::RangeId2::RangeId2
RangeId2()=default
vtkm::Vec< vtkm::Id, 2 >
vtkm::RangeId2::operator[]
VTKM_EXEC_CONT vtkm::RangeId & operator[](IdComponent c) noexcept
Definition: RangeId2.h:147
vtkm::RangeId::Include
VTKM_EXEC_CONT void Include(vtkm::Id value)
Expand range to include a value.
Definition: RangeId.h:86
vtkm::RangeId2::Include
VTKM_EXEC_CONT void Include(const vtkm::RangeId2 &range)
Expand range to include other range.
Definition: RangeId2.h:111
vtkm::RangeId2::X
vtkm::RangeId X
Definition: RangeId2.h:29
vtkm::RangeId2::Union
VTKM_EXEC_CONT vtkm::RangeId2 Union(const vtkm::RangeId2 &other) const
Return the union of this and another range.
Definition: RangeId2.h:122
vtkm::RangeId2::Y
vtkm::RangeId Y
Definition: RangeId2.h:30
vtkm::Id2
vtkm::Vec< vtkm::Id, 2 > Id2
Id2 corresponds to a 2-dimensional index.
Definition: Types.h:885