VTK-m  2.0
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 {
32 
35  : Min(0)
36  , Max(0)
37  {
38  }
39 
42  : Min(min)
43  , Max(max)
44  {
45  }
46 
54  bool IsNonEmpty() const { return (this->Min < this->Max); }
55 
62  bool Contains(vtkm::Id value) const { return ((this->Min <= value) && (this->Max > value)); }
63 
70  vtkm::Id Length() const { return this->Max - this->Min; }
71 
77  vtkm::Id Center() const { return (this->Min + this->Max) / 2; }
78 
86  void Include(vtkm::Id value)
87  {
88  this->Min = vtkm::Min(this->Min, value);
89  this->Max = vtkm::Max(this->Max, value + 1);
90  }
91 
98  void Include(const vtkm::RangeId& range)
99  {
100  this->Min = vtkm::Min(this->Min, range.Min);
101  this->Max = vtkm::Max(this->Max, range.Max);
102  }
103 
109  vtkm::RangeId Union(const vtkm::RangeId& other) const
110  {
111  vtkm::RangeId unionRange(*this);
112  unionRange.Include(other);
113  return unionRange;
114  }
115 
119  vtkm::RangeId operator+(const vtkm::RangeId& other) const { return this->Union(other); }
120 
122  bool operator==(const vtkm::RangeId& other) const
123  {
124  return ((this->Min == other.Min) && (this->Max == other.Max));
125  }
126 
128  bool operator!=(const vtkm::RangeId& other) const
129  {
130  return ((this->Min != other.Min) || (this->Max != other.Max));
131  }
132 };
133 
136 static inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::RangeId& range)
137 {
138  return stream << "[" << range.Min << ".." << range.Max << ")";
139 } // Declared inside of vtkm namespace so that the operator work with ADL lookup
140 } // namespace vtkm
141 
142 #endif // vtk_m_RangeId_h
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::RangeId
VTKM_EXEC_CONT RangeId(vtkm::Id min, vtkm::Id max)
Definition: RangeId.h:41
vtkm::RangeId
Represent a range of vtkm::Id values.
Definition: RangeId.h:28
vtkm::RangeId::Max
vtkm::Id Max
Definition: RangeId.h:31
vtkm::RangeId::operator+
VTKM_EXEC_CONT vtkm::RangeId operator+(const vtkm::RangeId &other) const
Operator for union
Definition: RangeId.h:119
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
Math.h
vtkm::RangeId::Center
VTKM_EXEC_CONT vtkm::Id Center() const
Returns the center of the range.
Definition: RangeId.h:77
vtkm::RangeId::Include
VTKM_EXEC_CONT void Include(const vtkm::RangeId &range)
Expand range to include other range.
Definition: RangeId.h:98
vtkm::RangeId::Min
vtkm::Id Min
Definition: RangeId.h:30
vtkm::RangeId::Union
VTKM_EXEC_CONT vtkm::RangeId Union(const vtkm::RangeId &other) const
Return the union of this and another range.
Definition: RangeId.h:109
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::RangeId::operator==
VTKM_EXEC_CONT bool operator==(const vtkm::RangeId &other) const
Definition: RangeId.h:122
vtkm::RangeId::Include
VTKM_EXEC_CONT void Include(vtkm::Id value)
Expand range to include a value.
Definition: RangeId.h:86
vtkm::RangeId::RangeId
VTKM_EXEC_CONT RangeId()
Definition: RangeId.h:34
vtkm::RangeId::operator!=
VTKM_EXEC_CONT bool operator!=(const vtkm::RangeId &other) const
Definition: RangeId.h:128