Viskores  1.0
RangeId3.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_RangeId3_h
19 #define viskores_RangeId3_h
20 
21 #include <viskores/RangeId.h>
22 
23 namespace viskores
24 {
25 
35 struct RangeId3
36 {
46 
48  RangeId3() = default;
49 
52  RangeId3(const viskores::RangeId& xrange,
53  const viskores::RangeId& yrange,
54  const viskores::RangeId& zrange)
55  : X(xrange)
56  , Y(yrange)
57  , Z(zrange)
58  {
59  }
60 
64  viskores::Id maxX,
65  viskores::Id minY,
66  viskores::Id maxY,
67  viskores::Id minZ,
68  viskores::Id maxZ)
69  : X(viskores::RangeId(minX, maxX))
70  , Y(viskores::RangeId(minY, maxY))
71  , Z(viskores::RangeId(minZ, maxZ))
72  {
73  }
74 
79  explicit RangeId3(const viskores::Id range[6])
80  : X(viskores::RangeId(range[0], range[1]))
81  , Y(viskores::RangeId(range[2], range[3]))
82  , Z(viskores::RangeId(range[4], range[5]))
83  {
84  }
85 
89  RangeId3(const viskores::Id3& min, const viskores::Id3& max)
90  : X(viskores::RangeId(min[0], max[0]))
91  , Y(viskores::RangeId(min[1], max[1]))
92  , Z(viskores::RangeId(min[2], max[2]))
93  {
94  }
95 
101  bool IsNonEmpty() const
102  {
103  return (this->X.IsNonEmpty() && this->Y.IsNonEmpty() && this->Z.IsNonEmpty());
104  }
105 
109  bool Contains(const viskores::Id3& val) const
110  {
111  return (this->X.Contains(val[0]) && this->Y.Contains(val[1]) && this->Z.Contains(val[2]));
112  }
113 
120  {
121  return viskores::Id3(this->X.Center(), this->Y.Center(), this->Z.Center());
122  }
123 
126  {
127  return viskores::Id3(this->X.Length(), this->Y.Length(), this->Z.Length());
128  }
129 
136  template <typename T>
138  {
139  this->X.Include(point[0]);
140  this->Y.Include(point[1]);
141  this->Z.Include(point[2]);
142  }
143 
150  void Include(const viskores::RangeId3& range)
151  {
152  this->X.Include(range.X);
153  this->Y.Include(range.Y);
154  this->Z.Include(range.Z);
155  }
156 
163  {
164  viskores::RangeId3 unionRangeId3(*this);
165  unionRangeId3.Include(other);
166  return unionRangeId3;
167  }
168 
172  viskores::RangeId3 operator+(const viskores::RangeId3& other) const { return this->Union(other); }
173 
175  bool operator==(const viskores::RangeId3& range) const
176  {
177  return ((this->X == range.X) && (this->Y == range.Y) && (this->Z == range.Z));
178  }
179 
181  bool operator!=(const viskores::RangeId3& range) const
182  {
183  return ((this->X != range.X) || (this->Y != range.Y) || (this->Z != range.Z));
184  }
187  {
188  if (c <= 0)
189  {
190  return this->X;
191  }
192  else if (c == 1)
193  {
194  return this->Y;
195  }
196  else
197  {
198  return this->Z;
199  }
200  }
201 
203  const viskores::RangeId& operator[](IdComponent c) const noexcept
204  {
205  if (c <= 0)
206  {
207  return this->X;
208  }
209  else if (c == 1)
210  {
211  return this->Y;
212  }
213  else
214  {
215  return this->Z;
216  }
217  }
218 };
219 
222 inline VISKORES_CONT std::ostream& operator<<(std::ostream& stream, const viskores::RangeId3& range)
223 {
224  return stream << "{ X:" << range.X << ", Y:" << range.Y << ", Z:" << range.Z << " }";
225 } // Declared inside of viskores namespace so that the operator work with ADL lookup
226 } // namespace viskores
227 
228 #endif //viskores_RangeId3_h
viskores::RangeId3::RangeId3
RangeId3(const viskores::Id range[6])
Initialize range with an array of 6 values in the order xmin, xmax, ymin, ymax, zmin,...
Definition: RangeId3.h:79
viskores::RangeId::IsNonEmpty
bool IsNonEmpty() const
Determine if the range is valid.
Definition: RangeId.h:67
viskores::RangeId3::RangeId3
RangeId3(viskores::Id minX, viskores::Id maxX, viskores::Id minY, viskores::Id maxY, viskores::Id minZ, viskores::Id maxZ)
Construct a range with the given minimum (inclusive) and maximum (exclusive) points.
Definition: RangeId3.h:63
viskores::RangeId::Contains
bool Contains(viskores::Id value) const
Determines if a value is within the range.
Definition: RangeId.h:75
viskores::RangeId3::Include
void Include(const viskores::Vec< T, 3 > &point)
Expand range to include a value.
Definition: RangeId3.h:137
viskores::RangeId3::X
viskores::RangeId X
The range of values in the X direction.
Definition: RangeId3.h:39
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::RangeId3::operator[]
viskores::RangeId & operator[](IdComponent c) noexcept
Definition: RangeId3.h:186
viskores::RangeId3::operator!=
bool operator!=(const viskores::RangeId3 &range) const
Definition: RangeId3.h:181
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::Vec< T, 3 >
Definition: Types.h:1025
viskores::RangeId3::Union
viskores::RangeId3 Union(const viskores::RangeId3 &other) const
Return the union of this and another range.
Definition: RangeId3.h:162
viskores::RangeId3::Z
viskores::RangeId Z
The range of values in the Z direction.
Definition: RangeId3.h:45
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::RangeId3::operator[]
const viskores::RangeId & operator[](IdComponent c) const noexcept
Definition: RangeId3.h:203
viskores::RangeId3::Center
viskores::Id3 Center() const
Returns the center of the range.
Definition: RangeId3.h:119
viskores::RangeId::Include
void Include(viskores::Id value)
Expand range to include a value.
Definition: RangeId.h:99
viskores::Id3
viskores::Vec< viskores::Id, 3 > Id3
Id3 corresponds to a 3-dimensional index for 3d arrays.
Definition: Types.h:1053
viskores::RangeId::Center
viskores::Id Center() const
Returns the center of the range.
Definition: RangeId.h:90
viskores::RangeId3::Include
void Include(const viskores::RangeId3 &range)
Expand range to include other range.
Definition: RangeId3.h:150
viskores::RangeId3::IsNonEmpty
bool IsNonEmpty() const
Determine if the range is non-empty.
Definition: RangeId3.h:101
viskores::RangeId3
Represent 3D integer range.
Definition: RangeId3.h:35
viskores::RangeId3::RangeId3
RangeId3(const viskores::RangeId &xrange, const viskores::RangeId &yrange, const viskores::RangeId &zrange)
Construct a range with the given x, y, and z directions.
Definition: RangeId3.h:52
viskores::RangeId3::Dimensions
viskores::Id3 Dimensions() const
Definition: RangeId3.h:125
viskores::RangeId3::operator==
bool operator==(const viskores::RangeId3 &range) const
Definition: RangeId3.h:175
viskores::RangeId3::Contains
bool Contains(const viskores::Id3 &val) const
Determines if an Id3 value is within the range.
Definition: RangeId3.h:109
viskores::RangeId
Represent a range of viskores::Id values.
Definition: RangeId.h:36
viskores::RangeId3::RangeId3
RangeId3(const viskores::Id3 &min, const viskores::Id3 &max)
Initialize range with the minimum and the maximum corners.
Definition: RangeId3.h:89
viskores::RangeId3::operator+
viskores::RangeId3 operator+(const viskores::RangeId3 &other) const
Operator for union
Definition: RangeId3.h:172
viskores::RangeId::Length
viskores::Id Length() const
Returns the length of the range.
Definition: RangeId.h:83
viskores::Vec< viskores::Id, 3 >
viskores::RangeId3::RangeId3
RangeId3()=default
Construct an empty 3D range.
viskores::RangeId3::Y
viskores::RangeId Y
The range of values in the Y direction.
Definition: RangeId3.h:42