2015-07-21 17:22:05 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-07-21 17:22:05 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_BinaryOperators_h
|
|
|
|
#define vtk_m_BinaryOperators_h
|
|
|
|
|
2016-11-23 20:18:58 +00:00
|
|
|
#include <vtkm/Math.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/internal/ExportMacros.h>
|
2015-07-21 17:22:05 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
2015-07-21 17:22:05 +00:00
|
|
|
|
2015-08-05 12:55:28 +00:00
|
|
|
// Disable conversion warnings for Sum and Product on GCC only.
|
|
|
|
// GCC creates false positive warnings for signed/unsigned char* operations.
|
|
|
|
// This occurs because the values are implicitly casted up to int's for the
|
|
|
|
// operation, and than casted back down to char's when return.
|
|
|
|
// This causes a false positive warning, even when the values is within
|
|
|
|
// the value types range
|
2016-01-12 14:00:07 +00:00
|
|
|
#if (defined(VTKM_GCC) || defined(VTKM_CLANG))
|
2015-08-05 12:55:28 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wconversion"
|
|
|
|
#endif // gcc || clang
|
|
|
|
|
2015-07-21 17:22:05 +00:00
|
|
|
/// Binary Predicate that takes two arguments argument \c x, and \c y and
|
|
|
|
/// returns sum (addition) of the two values.
|
|
|
|
/// Note: Requires Type \p T implement the + operator.
|
|
|
|
struct Sum
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT T operator()(const T& x, const T& y) const
|
2015-07-21 17:22:05 +00:00
|
|
|
{
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Binary Predicate that takes two arguments argument \c x, and \c y and
|
|
|
|
/// returns product (multiplication) of the two values.
|
|
|
|
/// Note: Requires Type \p T implement the * operator.
|
|
|
|
struct Product
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT T operator()(const T& x, const T& y) const
|
2015-07-21 17:22:05 +00:00
|
|
|
{
|
|
|
|
return x * y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-12 14:00:07 +00:00
|
|
|
#if (defined(VTKM_GCC) || defined(VTKM_CLANG))
|
2015-08-05 12:55:28 +00:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif // gcc || clang
|
|
|
|
|
2015-07-21 17:22:05 +00:00
|
|
|
/// Binary Predicate that takes two arguments argument \c x, and \c y and
|
|
|
|
/// returns the \c x if x > y otherwise returns \c y.
|
|
|
|
/// Note: Requires Type \p T implement the < operator.
|
|
|
|
//needs to be full length to not clash with vtkm::math function Max.
|
|
|
|
struct Maximum
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT T operator()(const T& x, const T& y) const
|
2015-07-21 17:22:05 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return x < y ? y : x;
|
2015-07-21 17:22:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Binary Predicate that takes two arguments argument \c x, and \c y and
|
|
|
|
/// returns the \c x if x < y otherwise returns \c y.
|
|
|
|
/// Note: Requires Type \p T implement the < operator.
|
|
|
|
//needs to be full length to not clash with vtkm::math function Min.
|
|
|
|
struct Minimum
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT T operator()(const T& x, const T& y) const
|
2015-07-21 17:22:05 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return x < y ? x : y;
|
2015-07-21 17:22:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-23 20:18:58 +00:00
|
|
|
/// Binary Predicate that takes two arguments argument \c x, and \c y and
|
2016-11-25 18:04:26 +00:00
|
|
|
/// returns a vtkm::Vec<T,2> that represents the minimum and maximum values
|
2016-11-23 20:18:58 +00:00
|
|
|
/// Note: Requires Type \p T implement the vtkm::Min and vtkm::Max functions.
|
|
|
|
template <typename T>
|
|
|
|
struct MinAndMax
|
|
|
|
{
|
2019-04-10 18:31:33 +00:00
|
|
|
VTKM_EXEC_CONT
|
|
|
|
vtkm::Vec<T, 2> operator()(const T& a) const { return vtkm::make_Vec(a, a); }
|
|
|
|
|
2016-11-23 20:18:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<T, 2> operator()(const T& a, const T& b) const
|
2016-11-23 20:18:58 +00:00
|
|
|
{
|
2016-11-25 18:04:26 +00:00
|
|
|
return vtkm::make_Vec(vtkm::Min(a, b), vtkm::Max(a, b));
|
2016-11-23 20:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<T, 2> operator()(const vtkm::Vec<T, 2>& a, const vtkm::Vec<T, 2>& b) const
|
2016-11-23 20:18:58 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return vtkm::make_Vec(vtkm::Min(a[0], b[0]), vtkm::Max(a[1], b[1]));
|
2016-11-23 20:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<T, 2> operator()(const T& a, const vtkm::Vec<T, 2>& b) const
|
2016-11-23 20:18:58 +00:00
|
|
|
{
|
2016-11-25 18:04:26 +00:00
|
|
|
return vtkm::make_Vec(vtkm::Min(a, b[0]), vtkm::Max(a, b[1]));
|
2016-11-23 20:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<T, 2> operator()(const vtkm::Vec<T, 2>& a, const T& b) const
|
2016-11-23 20:18:58 +00:00
|
|
|
{
|
2016-11-25 18:04:26 +00:00
|
|
|
return vtkm::make_Vec(vtkm::Min(a[0], b), vtkm::Max(a[1], b));
|
2016-11-23 20:18:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-21 17:22:05 +00:00
|
|
|
/// Binary Predicate that takes two arguments argument \c x, and \c y and
|
|
|
|
/// returns the bitwise operation <tt>x&y</tt>
|
|
|
|
/// Note: Requires Type \p T implement the & operator.
|
|
|
|
struct BitwiseAnd
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT T operator()(const T& x, const T& y) const
|
2015-07-21 17:22:05 +00:00
|
|
|
{
|
|
|
|
return x & y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Binary Predicate that takes two arguments argument \c x, and \c y and
|
|
|
|
/// returns the bitwise operation <tt>x|y</tt>
|
|
|
|
/// Note: Requires Type \p T implement the | operator.
|
|
|
|
struct BitwiseOr
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT T operator()(const T& x, const T& y) const
|
2015-07-21 17:22:05 +00:00
|
|
|
{
|
|
|
|
return x | y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Binary Predicate that takes two arguments argument \c x, and \c y and
|
|
|
|
/// returns the bitwise operation <tt>x^y</tt>
|
|
|
|
/// Note: Requires Type \p T implement the ^ operator.
|
|
|
|
struct BitwiseXor
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT T operator()(const T& x, const T& y) const
|
2015-07-21 17:22:05 +00:00
|
|
|
{
|
|
|
|
return x ^ y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace vtkm
|
|
|
|
|
2015-09-17 13:44:56 +00:00
|
|
|
#endif //vtk_m_BinaryOperators_h
|