VTK-m  2.2
RangeId.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_RangeId_h
11 #define vtk_m_RangeId_h
12 
13 #include <vtkm/Math.h>
14 #include <vtkm/Types.h>
15 
16 namespace vtkm
17 {
18 
28 struct RangeId
29 {
34 
38  : Min(0)
39  , Max(0)
40  {
41  }
42 
47  : Min(min)
48  , Max(max)
49  {
50  }
51 
59  bool IsNonEmpty() const { return (this->Min < this->Max); }
60 
67  bool Contains(vtkm::Id value) const { return ((this->Min <= value) && (this->Max > value)); }
68 
75  vtkm::Id Length() const { return this->Max - this->Min; }
76 
82  vtkm::Id Center() const { return (this->Min + this->Max) / 2; }
83 
91  void Include(vtkm::Id value)
92  {
93  this->Min = vtkm::Min(this->Min, value);
94  this->Max = vtkm::Max(this->Max, value + 1);
95  }
96 
103  void Include(const vtkm::RangeId& range)
104  {
105  this->Min = vtkm::Min(this->Min, range.Min);
106  this->Max = vtkm::Max(this->Max, range.Max);
107  }
108 
114  vtkm::RangeId Union(const vtkm::RangeId& other) const
115  {
116  vtkm::RangeId unionRange(*this);
117  unionRange.Include(other);
118  return unionRange;
119  }
120 
124  vtkm::RangeId operator+(const vtkm::RangeId& other) const { return this->Union(other); }
125 
127  bool operator==(const vtkm::RangeId& other) const
128  {
129  return ((this->Min == other.Min) && (this->Max == other.Max));
130  }
131 
133  bool operator!=(const vtkm::RangeId& other) const
134  {
135  return ((this->Min != other.Min) || (this->Max != other.Max));
136  }
137 };
138 
141 static inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::RangeId& range)
142 {
143  return stream << "[" << range.Min << ".." << range.Max << ")";
144 } // Declared inside of vtkm namespace so that the operator work with ADL lookup
145 } // namespace vtkm
146 
147 #endif // vtk_m_RangeId_h
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
Types.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::RangeId::operator!=
bool operator!=(const vtkm::RangeId &other) const
Definition: RangeId.h:133
vtkm::RangeId::operator==
bool operator==(const vtkm::RangeId &other) const
Definition: RangeId.h:127
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::Max
vtkm::Id Max
The maximum index of the range (exclusive).
Definition: RangeId.h:33
vtkm::RangeId::Contains
bool Contains(vtkm::Id value) const
Determines if a value is within the range.
Definition: RangeId.h:67
Math.h
vtkm::RangeId::RangeId
RangeId(vtkm::Id min, vtkm::Id max)
Construct a range with the given minimum (inclusive) and maximum (exclusive) indices.
Definition: RangeId.h:46
vtkm::RangeId::Min
vtkm::Id Min
The minimum index of the range (inclusive).
Definition: RangeId.h:31
vtkm::RangeId::Include
void Include(const vtkm::RangeId &range)
Expand range to include other range.
Definition: RangeId.h:103
vtkm::RangeId::RangeId
RangeId()
Construct a range with no indices.
Definition: RangeId.h:37
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::RangeId::Length
vtkm::Id Length() const
Returns the length of the range.
Definition: RangeId.h:75
vtkm::RangeId::Union
vtkm::RangeId Union(const vtkm::RangeId &other) const
Return the union of this and another range.
Definition: RangeId.h:114
vtkm::RangeId::operator+
vtkm::RangeId operator+(const vtkm::RangeId &other) const
Operator for union
Definition: RangeId.h:124