Add vtkm::RangeId and vtkm::RangeId3
This commit is contained in:
parent
7ee57a822e
commit
d618728356
@ -40,6 +40,8 @@ set(headers
|
|||||||
NewtonsMethod.h
|
NewtonsMethod.h
|
||||||
Pair.h
|
Pair.h
|
||||||
Range.h
|
Range.h
|
||||||
|
RangeId.h
|
||||||
|
RangeId3.h
|
||||||
StaticAssert.h
|
StaticAssert.h
|
||||||
TopologyElementTag.h
|
TopologyElementTag.h
|
||||||
Transform3D.h
|
Transform3D.h
|
||||||
|
153
vtkm/RangeId.h
Normal file
153
vtkm/RangeId.h
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
//============================================================================
|
||||||
|
// Copyright (c) Kitware, Inc.
|
||||||
|
// All rights reserved.
|
||||||
|
// See LICENSE.txt for details.
|
||||||
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||||
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
// PURPOSE. See the above copyright notice for more information.
|
||||||
|
//
|
||||||
|
// Copyright 2017 Sandia Corporation.
|
||||||
|
// Copyright 2017 UT-Battelle, LLC.
|
||||||
|
// Copyright 2017 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
#ifndef vtk_m_RangeId_h
|
||||||
|
#define vtk_m_RangeId_h
|
||||||
|
|
||||||
|
#include <vtkm/Math.h>
|
||||||
|
#include <vtkm/Types.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
|
||||||
|
/// \brief Represent a range of vtkm::Id values.
|
||||||
|
///
|
||||||
|
/// \c vtkm::RangeId is a helper class for representing a range of vtkm::Id
|
||||||
|
/// values. This is specified simply with a \c Min and \c Max value, where
|
||||||
|
/// \c Max is exclusive.
|
||||||
|
///
|
||||||
|
/// \c RangeId also contains several helper functions for computing and
|
||||||
|
/// maintaining the range.
|
||||||
|
///
|
||||||
|
struct RangeId
|
||||||
|
{
|
||||||
|
vtkm::Id Min;
|
||||||
|
vtkm::Id Max;
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
RangeId()
|
||||||
|
: Min(0)
|
||||||
|
, Max(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
RangeId(vtkm::Id min, vtkm::Id max)
|
||||||
|
: Min(min)
|
||||||
|
, Max(max)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Determine if the range is valid.
|
||||||
|
///
|
||||||
|
/// \c IsNonEmpty return true if the range contains some valid values between
|
||||||
|
/// \c Min and \c Max. If \c Max <= \c Min, then no values satisfy
|
||||||
|
/// the range and \c IsNonEmpty returns false. Otherwise, return true.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
bool IsNonEmpty() const { return (this->Min < this->Max); }
|
||||||
|
|
||||||
|
/// \b Determines if a value is within the range.
|
||||||
|
///
|
||||||
|
/// \c Contains returns true if the give value is within the range, false
|
||||||
|
/// otherwise.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
bool Contains(vtkm::Id value) const { return ((this->Min <= value) && (this->Max > value)); }
|
||||||
|
|
||||||
|
/// \b Returns the length of the range.
|
||||||
|
///
|
||||||
|
/// \c Length computes the distance between the min and max. If the range
|
||||||
|
/// is empty, 0 is returned.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
vtkm::Id Length() const { return this->Max - this->Min; }
|
||||||
|
|
||||||
|
/// \b Returns the center of the range.
|
||||||
|
///
|
||||||
|
/// \c Center computes the middle value of the range.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
vtkm::Id Center() const { return (this->Min + this->Max) / 2; }
|
||||||
|
|
||||||
|
/// \b Expand range to include a value.
|
||||||
|
///
|
||||||
|
/// This version of \c Include expands the range just enough to include the
|
||||||
|
/// given value. If the range already includes this value, then nothing is
|
||||||
|
/// done.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
void Include(vtkm::Id value)
|
||||||
|
{
|
||||||
|
this->Min = vtkm::Min(this->Min, value);
|
||||||
|
this->Max = vtkm::Max(this->Max, value + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Expand range to include other range.
|
||||||
|
///
|
||||||
|
/// This version of \c Include expands this range just enough to include that
|
||||||
|
/// of another range. Esentially it is the union of the two ranges.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
void Include(const vtkm::RangeId& range)
|
||||||
|
{
|
||||||
|
this->Min = vtkm::Min(this->Min, range.Min);
|
||||||
|
this->Max = vtkm::Max(this->Max, range.Max);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Return the union of this and another range.
|
||||||
|
///
|
||||||
|
/// This is a nondestructive form of \c Include.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
vtkm::RangeId Union(const vtkm::RangeId& other) const
|
||||||
|
{
|
||||||
|
vtkm::RangeId unionRange(*this);
|
||||||
|
unionRange.Include(other);
|
||||||
|
return unionRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Operator for union
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
vtkm::RangeId operator+(const vtkm::RangeId& other) const { return this->Union(other); }
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
bool operator==(const vtkm::RangeId& other) const
|
||||||
|
{
|
||||||
|
return ((this->Min == other.Min) && (this->Max == other.Max));
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
bool operator!=(const vtkm::RangeId& other) const
|
||||||
|
{
|
||||||
|
return ((this->Min != other.Min) || (this->Max != other.Max));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace vtkm
|
||||||
|
|
||||||
|
/// Helper function for printing ranges during testing
|
||||||
|
///
|
||||||
|
static inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::RangeId& range)
|
||||||
|
{
|
||||||
|
return stream << "[" << range.Min << ".." << range.Max << ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // vtk_m_RangeId_h
|
183
vtkm/RangeId3.h
Normal file
183
vtkm/RangeId3.h
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
//============================================================================
|
||||||
|
// Copyright (c) Kitware, Inc.
|
||||||
|
// All rights reserved.
|
||||||
|
// See LICENSE.txt for details.
|
||||||
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||||
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
// PURPOSE. See the above copyright notice for more information.
|
||||||
|
//
|
||||||
|
// Copyright 2017 Sandia Corporation.
|
||||||
|
// Copyright 2017 UT-Battelle, LLC.
|
||||||
|
// Copyright 2017 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
#ifndef vtk_m_RangeId3_h
|
||||||
|
#define vtk_m_RangeId3_h
|
||||||
|
|
||||||
|
#include <vtkm/RangeId.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
|
||||||
|
/// \brief Represent 3D integer range.
|
||||||
|
///
|
||||||
|
/// \c vtkm::RangeId3 is a helper class for representing a 3D range of integer
|
||||||
|
/// values. The typical use of this class is to express a box of indices
|
||||||
|
/// in the x, y, and z directions.
|
||||||
|
///
|
||||||
|
/// \c RangeId3 also contains several helper functions for computing and
|
||||||
|
/// maintaining the range.
|
||||||
|
///
|
||||||
|
struct RangeId3
|
||||||
|
{
|
||||||
|
vtkm::RangeId X;
|
||||||
|
vtkm::RangeId Y;
|
||||||
|
vtkm::RangeId Z;
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
RangeId3() = default;
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
RangeId3(const vtkm::RangeId& xrange, const vtkm::RangeId& yrange, const vtkm::RangeId& zrange)
|
||||||
|
: X(xrange)
|
||||||
|
, Y(yrange)
|
||||||
|
, Z(zrange)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
RangeId3(vtkm::Id minX, vtkm::Id maxX, vtkm::Id minY, vtkm::Id maxY, vtkm::Id minZ, vtkm::Id maxZ)
|
||||||
|
: X(vtkm::RangeId(minX, maxX))
|
||||||
|
, Y(vtkm::RangeId(minY, maxY))
|
||||||
|
, Z(vtkm::RangeId(minZ, maxZ))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialize range with an array of 6 values in the order xmin, xmax,
|
||||||
|
/// ymin, ymax, zmin, zmax.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
explicit RangeId3(const vtkm::Id range[6])
|
||||||
|
: X(vtkm::RangeId(range[0], range[1]))
|
||||||
|
, Y(vtkm::RangeId(range[2], range[3]))
|
||||||
|
, Z(vtkm::RangeId(range[4], range[5]))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialize range with the minimum and the maximum corners
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
RangeId3(const vtkm::Id3& min, const vtkm::Id3& max)
|
||||||
|
: X(vtkm::RangeId(min[0], max[0]))
|
||||||
|
, Y(vtkm::RangeId(min[1], max[1]))
|
||||||
|
, Z(vtkm::RangeId(min[2], max[2]))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Determine if the range is non-empty.
|
||||||
|
///
|
||||||
|
/// \c IsNonEmpty returns true if the range is non-empty.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
bool IsNonEmpty() const
|
||||||
|
{
|
||||||
|
return (this->X.IsNonEmpty() && this->Y.IsNonEmpty() && this->Z.IsNonEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Determines if an Id3 value is within the range.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
bool Contains(const vtkm::Id3& val) const
|
||||||
|
{
|
||||||
|
return (this->X.Contains(val[0]) && this->Y.Contains(val[1]) && this->Z.Contains(val[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Returns the center of the range.
|
||||||
|
///
|
||||||
|
/// \c Center computes the middle of the range.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
vtkm::Id3 Center() const
|
||||||
|
{
|
||||||
|
return vtkm::Id3(this->X.Center(), this->Y.Center(), this->Z.Center());
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
vtkm::Id3 Dimensions() const
|
||||||
|
{
|
||||||
|
return vtkm::Id3(this->X.Length(), this->Y.Length(), this->Z.Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Expand range to include a value.
|
||||||
|
///
|
||||||
|
/// This version of \c Include expands the range just enough to include the
|
||||||
|
/// given value. If the range already include this value, then
|
||||||
|
/// nothing is done.
|
||||||
|
///
|
||||||
|
template <typename T>
|
||||||
|
VTKM_EXEC_CONT void Include(const vtkm::Vec<T, 3>& point)
|
||||||
|
{
|
||||||
|
this->X.Include(point[0]);
|
||||||
|
this->Y.Include(point[1]);
|
||||||
|
this->Z.Include(point[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Expand range to include other range.
|
||||||
|
///
|
||||||
|
/// This version of \c Include expands the range just enough to include
|
||||||
|
/// the other range. Esentially it is the union of the two ranges.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
void Include(const vtkm::RangeId3& range)
|
||||||
|
{
|
||||||
|
this->X.Include(range.X);
|
||||||
|
this->Y.Include(range.Y);
|
||||||
|
this->Z.Include(range.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Return the union of this and another range.
|
||||||
|
///
|
||||||
|
/// This is a nondestructive form of \c Include.
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
vtkm::RangeId3 Union(const vtkm::RangeId3& other) const
|
||||||
|
{
|
||||||
|
vtkm::RangeId3 unionRangeId3(*this);
|
||||||
|
unionRangeId3.Include(other);
|
||||||
|
return unionRangeId3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \b Operator for union
|
||||||
|
///
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
vtkm::RangeId3 operator+(const vtkm::RangeId3& other) const { return this->Union(other); }
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
bool operator==(const vtkm::RangeId3& range) const
|
||||||
|
{
|
||||||
|
return ((this->X == range.X) && (this->Y == range.Y) && (this->Z == range.Z));
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
bool operator!=(const vtkm::RangeId3& range) const
|
||||||
|
{
|
||||||
|
return ((this->X != range.X) || (this->Y != range.Y) || (this->Z != range.Z));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace vtkm
|
||||||
|
|
||||||
|
/// Helper function for printing range during testing
|
||||||
|
///
|
||||||
|
static inline VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::RangeId3& range)
|
||||||
|
{
|
||||||
|
return stream << "{ X:" << range.X << ", Y:" << range.Y << ", Z:" << range.Z << " }";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //vtk_m_RangeId3_h
|
Loading…
Reference in New Issue
Block a user