VTK-m  2.2
Bounds.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 
11 #ifndef vtk_m_Bounds_h
12 #define vtk_m_Bounds_h
13 
14 #include <vtkm/Range.h>
15 
16 namespace vtkm
17 {
18 
29 struct Bounds
30 {
40 
44  Bounds() {}
45 
46  Bounds(const Bounds&) = default;
47 
50  Bounds(const vtkm::Range& xRange, const vtkm::Range& yRange, const vtkm::Range& zRange)
51  : X(xRange)
52  , Y(yRange)
53  , Z(zRange)
54  {
55  }
56 
59  template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
60  VTKM_EXEC_CONT Bounds(const T1& minX,
61  const T2& maxX,
62  const T3& minY,
63  const T4& maxY,
64  const T5& minZ,
65  const T6& maxZ)
66  : X(vtkm::Range(minX, maxX))
67  , Y(vtkm::Range(minY, maxY))
68  , Z(vtkm::Range(minZ, maxZ))
69  {
70  }
71 
75  template <typename T>
76  VTKM_EXEC_CONT explicit Bounds(const T bounds[6])
77  : X(vtkm::Range(bounds[0], bounds[1]))
78  , Y(vtkm::Range(bounds[2], bounds[3]))
79  , Z(vtkm::Range(bounds[4], bounds[5]))
80  {
81  }
82 
86  template <typename T>
87  VTKM_EXEC_CONT Bounds(const vtkm::Vec<T, 3>& minPoint, const vtkm::Vec<T, 3>& maxPoint)
88  : X(vtkm::Range(minPoint[0], maxPoint[0]))
89  , Y(vtkm::Range(minPoint[1], maxPoint[1]))
90  , Z(vtkm::Range(minPoint[2], maxPoint[2]))
91  {
92  }
93 
94  vtkm::Bounds& operator=(const vtkm::Bounds& src) = default;
95 
103  bool IsNonEmpty() const
104  {
105  return (this->X.IsNonEmpty() && this->Y.IsNonEmpty() && this->Z.IsNonEmpty());
106  }
107 
110  template <typename T>
111  VTKM_EXEC_CONT bool Contains(const vtkm::Vec<T, 3>& point) const
112  {
113  return (this->X.Contains(point[0]) && this->Y.Contains(point[1]) && this->Z.Contains(point[2]));
114  }
115 
123  {
124  if (this->IsNonEmpty())
125  {
126  return (this->X.Length() * this->Y.Length() * this->Z.Length());
127  }
128  else
129  {
130  return 0.0;
131  }
132  }
133 
141  {
142  if (this->IsNonEmpty())
143  {
144  return (this->X.Length() * this->Y.Length());
145  }
146  else
147  {
148  return 0.0;
149  }
150  }
151 
159  {
160  return vtkm::Vec3f_64(this->X.Center(), this->Y.Center(), this->Z.Center());
161  }
162 
169  vtkm::Vec3f_64 MinCorner() const { return vtkm::Vec3f_64(this->X.Min, this->Y.Min, this->Z.Min); }
170 
177  vtkm::Vec3f_64 MaxCorner() const { return vtkm::Vec3f_64(this->X.Max, this->Y.Max, this->Z.Max); }
178 
185  template <typename T>
187  {
188  this->X.Include(point[0]);
189  this->Y.Include(point[1]);
190  this->Z.Include(point[2]);
191  }
192 
199  void Include(const vtkm::Bounds& bounds)
200  {
201  this->X.Include(bounds.X);
202  this->Y.Include(bounds.Y);
203  this->Z.Include(bounds.Z);
204  }
205 
211  vtkm::Bounds Union(const vtkm::Bounds& otherBounds) const
212  {
213  vtkm::Bounds unionBounds(*this);
214  unionBounds.Include(otherBounds);
215  return unionBounds;
216  }
217 
221  vtkm::Bounds Intersection(const vtkm::Bounds& otherBounds) const
222  {
223  return vtkm::Bounds(this->X.Intersection(otherBounds.X),
224  this->Y.Intersection(otherBounds.Y),
225  this->Z.Intersection(otherBounds.Z));
226  }
227 
231  vtkm::Bounds operator+(const vtkm::Bounds& otherBounds) const { return this->Union(otherBounds); }
232 
234  bool operator==(const vtkm::Bounds& bounds) const
235  {
236  return ((this->X == bounds.X) && (this->Y == bounds.Y) && (this->Z == bounds.Z));
237  }
238 
240  bool operator!=(const vtkm::Bounds& bounds) const
241  {
242  return ((this->X != bounds.X) || (this->Y != bounds.Y) || (this->Z != bounds.Z));
243  }
244 };
245 
248 inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::Bounds& bounds)
249 {
250  return stream << "{ X:" << bounds.X << ", Y:" << bounds.Y << ", Z:" << bounds.Z << " }";
251 }
252 
253 template <>
255 {
258 
259  static constexpr vtkm::IdComponent NUM_COMPONENTS = 3;
261  {
262  return NUM_COMPONENTS;
263  }
266 
268  static const ComponentType& GetComponent(const vtkm::Bounds& bounds, vtkm::IdComponent component)
269  {
270  VTKM_ASSERT((component >= 0) || (component < 3));
271  switch (component)
272  {
273  case 0:
274  return bounds.X;
275  case 1:
276  return bounds.Y;
277  case 2:
278  return bounds.Z;
279  default:
280  // Should never reach here
281  return bounds.X;
282  }
283  }
286  {
287  VTKM_ASSERT((component >= 0) || (component < 3));
288  switch (component)
289  {
290  case 0:
291  return bounds.X;
292  case 1:
293  return bounds.Y;
294  case 2:
295  return bounds.Z;
296  default:
297  // Should never reach here
298  return bounds.X;
299  }
300  }
301 
303  static void SetComponent(vtkm::Bounds& bounds,
304  vtkm::IdComponent component,
305  const ComponentType& value)
306  {
307  VTKM_ASSERT((component >= 0) || (component < 3));
308  switch (component)
309  {
310  case 0:
311  bounds.X = value;
312  break;
313  case 1:
314  bounds.Y = value;
315  break;
316  case 2:
317  bounds.Z = value;
318  break;
319  }
320  }
321 
322  template <typename NewComponentType>
324  template <typename NewComponentType>
327 
328  template <vtkm::IdComponent destSize>
329  VTKM_EXEC_CONT static void CopyInto(const vtkm::Bounds& src,
331  {
332  const vtkm::IdComponent maxComponent = (destSize < NUM_COMPONENTS) ? destSize : NUM_COMPONENTS;
333  for (vtkm::IdComponent component = 0; component < maxComponent; ++component)
334  {
335  dest[component] = GetComponent(src, component);
336  }
337  }
338 };
339 
340 } // namespace vtkm
341 
342 #endif //vtk_m_Bounds_h
vtkm::Bounds::Bounds
Bounds(const vtkm::Vec< T, 3 > &minPoint, const vtkm::Vec< T, 3 > &maxPoint)
Initialize bounds with the minimum corner point and the maximum corner point.
Definition: Bounds.h:87
vtkm::Bounds::Area
vtkm::Float64 Area() const
Returns the area of the bounds in the X-Y-plane.
Definition: Bounds.h:140
vtkm::VecTraitsTagMultipleComponents
A tag for vectors that are "true" vectors (i.e.
Definition: VecTraits.h:23
vtkm::Range::Contains
bool Contains(const T &value) const
Determines if a value is within the range.
Definition: Range.h:79
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::VecTraits< vtkm::Bounds >::CopyInto
static void CopyInto(const vtkm::Bounds &src, vtkm::Vec< ComponentType, destSize > &dest)
Definition: Bounds.h:329
vtkm::Bounds::operator!=
bool operator!=(const vtkm::Bounds &bounds) const
Definition: Bounds.h:240
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::Bounds::IsNonEmpty
bool IsNonEmpty() const
Determine if the bounds are valid (i.e.
Definition: Bounds.h:103
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::Range::Length
vtkm::Float64 Length() const
Returns the length of the range.
Definition: Range.h:91
vtkm::operator<<
std::ostream & operator<<(std::ostream &stream, const vtkm::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:248
vtkm::Bounds::Include
void Include(const vtkm::Bounds &bounds)
Expand bounds to include other bounds.
Definition: Bounds.h:199
vtkm::Bounds::operator+
vtkm::Bounds operator+(const vtkm::Bounds &otherBounds) const
Operator for union
Definition: Bounds.h:231
vtkm::Range::Center
vtkm::Float64 Center() const
Returns the center of the range.
Definition: Range.h:109
vtkm::VecTraits< vtkm::Bounds >::GetNumberOfComponents
static constexpr vtkm::IdComponent GetNumberOfComponents(const vtkm::Bounds &)
Definition: Bounds.h:260
vtkm::Bounds::Intersection
vtkm::Bounds Intersection(const vtkm::Bounds &otherBounds) const
Return the intersection of this and another range.
Definition: Bounds.h:221
vtkm::VecTraits< vtkm::Bounds >::GetComponent
static const ComponentType & GetComponent(const vtkm::Bounds &bounds, vtkm::IdComponent component)
Definition: Bounds.h:268
vtkm::Bounds::Union
vtkm::Bounds Union(const vtkm::Bounds &otherBounds) const
Return the union of this and another bounds.
Definition: Bounds.h:211
vtkm::Bounds::Bounds
Bounds()
Construct an empty bounds.
Definition: Bounds.h:44
vtkm::Bounds::Bounds
Bounds(const vtkm::Range &xRange, const vtkm::Range &yRange, const vtkm::Range &zRange)
Construct a bounds with a given range in the x, y, and z dimensions.
Definition: Bounds.h:50
vtkm::Bounds::Bounds
Bounds(const T bounds[6])
Initialize bounds with an array of 6 values in the order xmin, xmax, ymin, ymax, zmin,...
Definition: Bounds.h:76
vtkm::VecTraits< vtkm::Bounds >::BaseComponentType
vtkm::VecTraits< vtkm::Range >::BaseComponentType BaseComponentType
Definition: Bounds.h:257
vtkm::Vec3f_64
vtkm::Vec< vtkm::Float64, 3 > Vec3f_64
Vec3f_64 corresponds to a 3-dimensional vector of 64-bit floating point values.
Definition: Types.h:1067
vtkm::VecTraits< vtkm::Bounds >::SetComponent
static void SetComponent(vtkm::Bounds &bounds, vtkm::IdComponent component, const ComponentType &value)
Definition: Bounds.h:303
vtkm::Bounds::Center
vtkm::Vec3f_64 Center() const
Returns the center of the range.
Definition: Bounds.h:158
Range.h
vtkm::Bounds::Z
vtkm::Range Z
The range of values in the Z direction.
Definition: Bounds.h:39
vtkm::Bounds::Contains
bool Contains(const vtkm::Vec< T, 3 > &point) const
Determines if a point coordinate is within the bounds.
Definition: Bounds.h:111
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Bounds
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:29
vtkm::Bounds::operator=
vtkm::Bounds & operator=(const vtkm::Bounds &src)=default
vtkm::Range::Include
void Include(const T &value)
Expand range to include a value.
Definition: Range.h:128
vtkm::Vec< T, 3 >
Definition: Types.h:1016
vtkm::Vec< vtkm::Float64, 3 >
vtkm::VecTraitsTagSizeStatic
A tag for vectors where the number of components are known at compile time.
Definition: VecTraits.h:36
vtkm::Bounds::Volume
vtkm::Float64 Volume() const
Returns the volume of the bounds.
Definition: Bounds.h:122
vtkm::Range::Min
vtkm::Float64 Min
The minumum value of the range (inclusive).
Definition: Range.h:34
vtkm::Bounds::MaxCorner
vtkm::Vec3f_64 MaxCorner() const
Returns the max point of the bounds
Definition: Bounds.h:177
vtkm::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:161
vtkm::Bounds::X
vtkm::Range X
The range of values in the X direction.
Definition: Bounds.h:33
vtkm::Bounds::Y
vtkm::Range Y
The range of values in the Y direction.
Definition: Bounds.h:36
VTKM_NEVER_EXPORT
#define VTKM_NEVER_EXPORT
Definition: ExportMacros.h:90
vtkm::Range::Max
vtkm::Float64 Max
Tha maximum value of the range (inclusive).
Definition: Range.h:36
vtkm::VecTraits
Traits that can be queried to treat any type as a Vec.
Definition: VecTraits.h:61
vtkm::VecTraits< vtkm::Bounds >::GetComponent
static ComponentType & GetComponent(vtkm::Bounds &bounds, vtkm::IdComponent component)
Definition: Bounds.h:285
vtkm::Bounds::Include
void Include(const vtkm::Vec< T, 3 > &point)
Expand bounds to include a point.
Definition: Bounds.h:186
vtkm::Bounds::Bounds
Bounds(const T1 &minX, const T2 &maxX, const T3 &minY, const T4 &maxY, const T5 &minZ, const T6 &maxZ)
Construct a bounds with the minimum and maximum coordinates in the x, y, and z directions.
Definition: Bounds.h:60
vtkm::Bounds::operator==
bool operator==(const vtkm::Bounds &bounds) const
Definition: Bounds.h:234
vtkm::Bounds::MinCorner
vtkm::Vec3f_64 MinCorner() const
Returns the min point of the bounds
Definition: Bounds.h:169
vtkm::Range::IsNonEmpty
bool IsNonEmpty() const
Determine if the range is valid (i.e.
Definition: Range.h:70
vtkm::Range::Intersection
vtkm::Range Intersection(const vtkm::Range &otherRange) const
Return the intersection of this and another range.
Definition: Range.h:164
vtkm::Range
Represent a continuous scalar range of values.
Definition: Range.h:31