Viskores  1.0
RangeId2.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_RangeId2_h
19 #define viskores_RangeId2_h
20 
21 #include <viskores/RangeId.h>
22 
23 namespace viskores
24 {
25 
35 struct RangeId2
36 {
43 
45  RangeId2() = default;
46 
49  RangeId2(const viskores::RangeId& xrange, const viskores::RangeId& yrange)
50  : X(xrange)
51  , Y(yrange)
52  {
53  }
54 
58  : X(viskores::RangeId(minX, maxX))
59  , Y(viskores::RangeId(minY, maxY))
60  {
61  }
62 
67  explicit RangeId2(const viskores::Id range[4])
68  : X(viskores::RangeId(range[0], range[1]))
69  , Y(viskores::RangeId(range[2], range[3]))
70  {
71  }
72 
76  RangeId2(const viskores::Id2& min, const viskores::Id2& max)
77  : X(viskores::RangeId(min[0], max[0]))
78  , Y(viskores::RangeId(min[1], max[1]))
79  {
80  }
81 
87  bool IsNonEmpty() const { return (this->X.IsNonEmpty() && this->Y.IsNonEmpty()); }
88 
92  bool Contains(const viskores::Id2& val) const
93  {
94  return (this->X.Contains(val[0]) && this->Y.Contains(val[1]));
95  }
96 
102  viskores::Id2 Center() const { return viskores::Id2(this->X.Center(), this->Y.Center()); }
103 
105  viskores::Id2 Dimensions() const { return viskores::Id2(this->X.Length(), this->Y.Length()); }
106 
113  template <typename T>
115  {
116  this->X.Include(point[0]);
117  this->Y.Include(point[1]);
118  }
119 
126  void Include(const viskores::RangeId2& range)
127  {
128  this->X.Include(range.X);
129  this->Y.Include(range.Y);
130  }
131 
138  {
139  viskores::RangeId2 unionRangeId2(*this);
140  unionRangeId2.Include(other);
141  return unionRangeId2;
142  }
143 
147  viskores::RangeId2 operator+(const viskores::RangeId2& other) const { return this->Union(other); }
148 
150  bool operator==(const viskores::RangeId2& range) const
151  {
152  return ((this->X == range.X) && (this->Y == range.Y));
153  }
154 
156  bool operator!=(const viskores::RangeId2& range) const
157  {
158  return ((this->X != range.X) || (this->Y != range.Y));
159  }
160 
163  {
164  if (c <= 0)
165  {
166  return this->X;
167  }
168  else
169  {
170  return this->Y;
171  }
172  }
173 
175  const viskores::RangeId& operator[](IdComponent c) const noexcept
176  {
177  if (c <= 0)
178  {
179  return this->X;
180  }
181  else
182  {
183  return this->Y;
184  }
185  }
186 };
187 
188 } // namespace viskores
189 
192 static inline VISKORES_CONT std::ostream& operator<<(std::ostream& stream,
193  const viskores::RangeId2& range)
194 {
195  return stream << "{ X:" << range.X << ", Y:" << range.Y << " }";
196 }
197 
198 #endif //viskores_RangeId2_h
viskores::RangeId2::RangeId2
RangeId2(const viskores::RangeId &xrange, const viskores::RangeId &yrange)
Construct a range with the given x and y directions.
Definition: RangeId2.h:49
viskores::Id2
viskores::Vec< viskores::Id, 2 > Id2
Id2 corresponds to a 2-dimensional index.
Definition: Types.h:935
viskores::RangeId2::operator==
bool operator==(const viskores::RangeId2 &range) const
Definition: RangeId2.h:150
viskores::RangeId::IsNonEmpty
bool IsNonEmpty() const
Determine if the range is valid.
Definition: RangeId.h:67
viskores::RangeId2::Include
void Include(const viskores::Vec< T, 2 > &point)
Expand range to include a value.
Definition: RangeId2.h:114
viskores::RangeId::Contains
bool Contains(viskores::Id value) const
Determines if a value is within the range.
Definition: RangeId.h:75
viskores::RangeId2::IsNonEmpty
bool IsNonEmpty() const
Determine if the range is non-empty.
Definition: RangeId2.h:87
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::RangeId2::RangeId2
RangeId2(viskores::Id minX, viskores::Id maxX, viskores::Id minY, viskores::Id maxY)
Construct a range with the given minimum (inclusive) and maximum (exclusive) points.
Definition: RangeId2.h:57
viskores::RangeId2::RangeId2
RangeId2(const viskores::Id2 &min, const viskores::Id2 &max)
Initialize range with the minimum and the maximum corners.
Definition: RangeId2.h:76
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::Vec< T, 2 >
Definition: Types.h:909
viskores::RangeId2::Dimensions
viskores::Id2 Dimensions() const
Definition: RangeId2.h:105
viskores::RangeId2::RangeId2
RangeId2()=default
Construct an empty 2D range.
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores::operator<<
std::ostream & operator<<(std::ostream &stream, const viskores::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:268
RangeId.h
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::RangeId2::Y
viskores::RangeId Y
The range of values in the Y direction.
Definition: RangeId2.h:42
viskores::RangeId2::operator[]
viskores::RangeId & operator[](IdComponent c) noexcept
Definition: RangeId2.h:162
viskores::RangeId::Include
void Include(viskores::Id value)
Expand range to include a value.
Definition: RangeId.h:99
viskores::RangeId::Center
viskores::Id Center() const
Returns the center of the range.
Definition: RangeId.h:90
viskores::RangeId2
Represent 2D integer range.
Definition: RangeId2.h:35
viskores::RangeId2::RangeId2
RangeId2(const viskores::Id range[4])
Initialize range with an array of 4 values in the order xmin, xmax, ymin, ymax.
Definition: RangeId2.h:67
viskores::RangeId2::operator!=
bool operator!=(const viskores::RangeId2 &range) const
Definition: RangeId2.h:156
viskores::RangeId2::X
viskores::RangeId X
The range of values in the X direction.
Definition: RangeId2.h:39
viskores::RangeId
Represent a range of viskores::Id values.
Definition: RangeId.h:36
viskores::RangeId2::operator[]
const viskores::RangeId & operator[](IdComponent c) const noexcept
Definition: RangeId2.h:175
viskores::RangeId::Length
viskores::Id Length() const
Returns the length of the range.
Definition: RangeId.h:83
viskores::Vec< viskores::Id, 2 >
viskores::RangeId2::Union
viskores::RangeId2 Union(const viskores::RangeId2 &other) const
Return the union of this and another range.
Definition: RangeId2.h:137
viskores::RangeId2::operator+
viskores::RangeId2 operator+(const viskores::RangeId2 &other) const
Operator for union
Definition: RangeId2.h:147
viskores::RangeId2::Contains
bool Contains(const viskores::Id2 &val) const
Determines if an Id2 value is within the range.
Definition: RangeId2.h:92
viskores::RangeId2::Include
void Include(const viskores::RangeId2 &range)
Expand range to include other range.
Definition: RangeId2.h:126
viskores::RangeId2::Center
viskores::Id2 Center() const
Returns the center of the range.
Definition: RangeId2.h:102