vtk-m/vtkm/rendering/raytracing/Worklets.h

162 lines
3.6 KiB
C
Raw Permalink Normal View History

2016-01-20 22:40:54 +00:00
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
2016-01-20 22:40:54 +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_rendering_raytracing_Worklets_h
#define vtk_m_rendering_raytracing_Worklets_h
#include <vtkm/worklet/WorkletMapField.h>
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace rendering
{
namespace raytracing
{
2016-01-20 22:40:54 +00:00
//
// Utility memory set functor
//
2017-05-18 14:29:41 +00:00
template <class T>
2016-01-20 22:40:54 +00:00
class MemSet : public vtkm::worklet::WorkletMapField
{
T Value;
2017-05-18 14:29:41 +00:00
2016-01-20 22:40:54 +00:00
public:
VTKM_CONT
2016-01-20 22:40:54 +00:00
MemSet(T value)
: Value(value)
2017-05-18 14:29:41 +00:00
{
}
using ControlSignature = void(FieldOut);
using ExecutionSignature = void(_1);
VTKM_EXEC
2017-05-18 14:29:41 +00:00
void operator()(T& outValue) const { outValue = Value; }
2016-01-20 22:40:54 +00:00
}; //class MemSet
template <typename FloatType>
class CopyAndOffset : public vtkm::worklet::WorkletMapField
{
FloatType Offset;
public:
VTKM_CONT
CopyAndOffset(const FloatType offset = 0.00001)
: Offset(offset)
{
}
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
VTKM_EXEC inline void operator()(const FloatType& inValue, FloatType& outValue) const
{
outValue = inValue + Offset;
}
}; //class Copy and iffset
template <typename FloatType>
class CopyAndOffsetMask : public vtkm::worklet::WorkletMapField
{
FloatType Offset;
vtkm::UInt8 MaskValue;
public:
VTKM_CONT
CopyAndOffsetMask(const FloatType offset = 0.00001, const vtkm::UInt8 mask = 1)
: Offset(offset)
, MaskValue(mask)
{
}
using ControlSignature = void(FieldIn, FieldInOut, FieldIn);
using ExecutionSignature = void(_1, _2, _3);
template <typename MaskType>
VTKM_EXEC inline void operator()(const FloatType& inValue,
FloatType& outValue,
const MaskType& mask) const
{
if (mask == MaskValue)
outValue = inValue + Offset;
}
}; //class Copy and iffset
template <class T>
class Mask : public vtkm::worklet::WorkletMapField
{
T Value;
public:
VTKM_CONT
Mask(T value)
: Value(value)
{
}
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
template <typename O>
VTKM_EXEC void operator()(const T& inValue, O& outValue) const
{
if (inValue == Value)
outValue = static_cast<O>(1);
else
outValue = static_cast<O>(0);
}
}; //class mask
template <class T, int N>
class ManyMask : public vtkm::worklet::WorkletMapField
{
vtkm::Vec<T, N> Values;
public:
VTKM_CONT
ManyMask(vtkm::Vec<T, N> values)
: Values(values)
{
}
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
template <typename O>
VTKM_EXEC void operator()(const T& inValue, O& outValue) const
{
bool doMask = false;
for (vtkm::Int32 i = 0; i < N; ++i)
{
if (inValue == Values[i])
doMask = true;
}
if (doMask)
outValue = static_cast<O>(1);
else
outValue = static_cast<O>(0);
}
2018-08-07 21:50:41 +00:00
}; //class double mask
2016-01-20 22:40:54 +00:00
struct MaxValue
{
2017-05-18 14:29:41 +00:00
template <typename T>
VTKM_EXEC_CONT T operator()(const T& a, const T& b) const
2016-01-20 22:40:54 +00:00
{
return (a > b) ? a : b;
}
2016-03-28 15:16:35 +00:00
2016-01-20 22:40:54 +00:00
}; //struct MaxValue
struct MinValue
{
2017-05-18 14:29:41 +00:00
template <typename T>
VTKM_EXEC_CONT T operator()(const T& a, const T& b) const
2016-01-20 22:40:54 +00:00
{
return (a < b) ? a : b;
}
2016-03-28 15:16:35 +00:00
2016-01-20 22:40:54 +00:00
}; //struct MinValue
2017-05-18 14:29:41 +00:00
}
}
} //namespace vtkm::rendering::raytracing
2016-01-20 22:40:54 +00:00
#endif //vtk_m_rendering_raytracing_Worklets_h