2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2017-12-14 18:13:55 +00:00
|
|
|
// 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.
|
2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2017-12-14 18:13:55 +00:00
|
|
|
|
|
|
|
#include <vtkm/worklet/ScalarsToColors.h>
|
|
|
|
|
2019-09-09 19:01:03 +00:00
|
|
|
#include <vtkm/VecTraits.h>
|
2017-12-14 18:13:55 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleExtractComponent.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleTransform.h>
|
|
|
|
|
|
|
|
#include <vtkm/worklet/DispatcherMapField.h>
|
|
|
|
#include <vtkm/worklet/colorconversion/ConvertToRGB.h>
|
|
|
|
#include <vtkm/worklet/colorconversion/ConvertToRGBA.h>
|
|
|
|
#include <vtkm/worklet/colorconversion/Portals.h>
|
|
|
|
#include <vtkm/worklet/colorconversion/ShiftScaleToRGB.h>
|
|
|
|
#include <vtkm/worklet/colorconversion/ShiftScaleToRGBA.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
|
|
|
namespace colorconversion
|
|
|
|
{
|
|
|
|
inline bool needShiftScale(vtkm::Float32, vtkm::Float32 shift, vtkm::Float32 scale)
|
|
|
|
{
|
|
|
|
return !((shift == -0.0f || shift == 0.0f) && (scale == 255.0f));
|
|
|
|
}
|
|
|
|
inline bool needShiftScale(vtkm::Float64, vtkm::Float32 shift, vtkm::Float32 scale)
|
|
|
|
{
|
|
|
|
return !((shift == -0.0f || shift == 0.0f) && (scale == 255.0f));
|
|
|
|
}
|
|
|
|
inline bool needShiftScale(vtkm::UInt8, vtkm::Float32 shift, vtkm::Float32 scale)
|
|
|
|
{
|
|
|
|
return !((shift == -0.0f || shift == 0.0f) && (scale == 1.0f));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool needShiftScale(T, vtkm::Float32, vtkm::Float32)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// \brief Use each component to generate RGBA colors
|
|
|
|
///
|
2018-10-17 19:17:29 +00:00
|
|
|
template <typename T, typename S>
|
2017-12-14 18:13:55 +00:00
|
|
|
void ScalarsToColors::Run(const vtkm::cont::ArrayHandle<T, S>& values,
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const
|
2017-12-14 18:13:55 +00:00
|
|
|
{
|
|
|
|
using namespace vtkm::worklet::colorconversion;
|
|
|
|
//If our shift is 0 and our scale == 1 no need to apply them
|
2019-09-09 19:01:03 +00:00
|
|
|
using BaseT = typename vtkm::VecTraits<T>::BaseComponentType;
|
2017-12-14 18:13:55 +00:00
|
|
|
const bool shiftscale = needShiftScale(BaseT{}, this->Shift, this->Scale);
|
|
|
|
if (shiftscale)
|
|
|
|
{
|
2018-08-28 20:36:50 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<ShiftScaleToRGBA> dispatcher(
|
2017-12-14 18:13:55 +00:00
|
|
|
ShiftScaleToRGBA(this->Shift, this->Scale, this->Alpha));
|
|
|
|
dispatcher.Invoke(values, rgbaOut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-28 20:36:50 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<ConvertToRGBA> dispatcher(ConvertToRGBA(this->Alpha));
|
2017-12-14 18:13:55 +00:00
|
|
|
dispatcher.Invoke(values, rgbaOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Use each component to generate RGB colors
|
|
|
|
///
|
2018-10-17 19:17:29 +00:00
|
|
|
template <typename T, typename S>
|
2017-12-14 18:13:55 +00:00
|
|
|
void ScalarsToColors::Run(const vtkm::cont::ArrayHandle<T, S>& values,
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const
|
2017-12-14 18:13:55 +00:00
|
|
|
{
|
|
|
|
using namespace vtkm::worklet::colorconversion;
|
2019-09-09 19:01:03 +00:00
|
|
|
using BaseT = typename vtkm::VecTraits<T>::BaseComponentType;
|
2017-12-14 18:13:55 +00:00
|
|
|
const bool shiftscale = needShiftScale(BaseT{}, this->Shift, this->Scale);
|
|
|
|
if (shiftscale)
|
|
|
|
{
|
2018-08-28 20:36:50 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<ShiftScaleToRGB> dispatcher(
|
2017-12-14 18:13:55 +00:00
|
|
|
ShiftScaleToRGB(this->Shift, this->Scale));
|
|
|
|
dispatcher.Invoke(values, rgbOut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-28 20:36:50 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<ConvertToRGB> dispatcher;
|
2017-12-14 18:13:55 +00:00
|
|
|
dispatcher.Invoke(values, rgbOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Use magnitude of a vector to generate RGBA colors
|
|
|
|
///
|
2018-10-17 19:17:29 +00:00
|
|
|
template <typename T, int N, typename S>
|
2019-07-31 16:20:38 +00:00
|
|
|
void ScalarsToColors::RunMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const
|
2017-12-14 18:13:55 +00:00
|
|
|
{
|
|
|
|
//magnitude is a complex situation. the default scale factor is incorrect
|
|
|
|
//
|
|
|
|
using namespace vtkm::worklet::colorconversion;
|
|
|
|
//If our shift is 0 and our scale == 1 no need to apply them
|
2019-09-09 19:01:03 +00:00
|
|
|
using BaseT = typename vtkm::VecTraits<T>::BaseComponentType;
|
2017-12-14 18:13:55 +00:00
|
|
|
const bool shiftscale = needShiftScale(BaseT{}, this->Shift, this->Scale);
|
|
|
|
if (shiftscale)
|
|
|
|
{
|
2018-08-28 20:36:50 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<ShiftScaleToRGBA> dispatcher(
|
2017-12-14 18:13:55 +00:00
|
|
|
ShiftScaleToRGBA(this->Shift, this->Scale, this->Alpha));
|
|
|
|
dispatcher.Invoke(
|
|
|
|
vtkm::cont::make_ArrayHandleTransform(values, colorconversion::MagnitudePortal()), rgbaOut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-28 20:36:50 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<ConvertToRGBA> dispatcher(ConvertToRGBA(this->Alpha));
|
2017-12-14 18:13:55 +00:00
|
|
|
dispatcher.Invoke(
|
|
|
|
vtkm::cont::make_ArrayHandleTransform(values, colorconversion::MagnitudePortal()), rgbaOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Use magnitude of a vector to generate RGB colors
|
|
|
|
///
|
2018-10-17 19:17:29 +00:00
|
|
|
template <typename T, int N, typename S>
|
2017-12-14 18:13:55 +00:00
|
|
|
void ScalarsToColors::RunMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const
|
2017-12-14 18:13:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
using namespace vtkm::worklet::colorconversion;
|
2019-09-09 19:01:03 +00:00
|
|
|
using BaseT = typename vtkm::VecTraits<T>::BaseComponentType;
|
2017-12-14 18:13:55 +00:00
|
|
|
const bool shiftscale = needShiftScale(BaseT{}, this->Shift, this->Scale);
|
|
|
|
if (shiftscale)
|
|
|
|
{
|
2018-08-28 20:36:50 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<ShiftScaleToRGB> dispatcher(
|
2017-12-14 18:13:55 +00:00
|
|
|
ShiftScaleToRGB(this->Shift, this->Scale));
|
|
|
|
dispatcher.Invoke(
|
|
|
|
vtkm::cont::make_ArrayHandleTransform(values, colorconversion::MagnitudePortal()), rgbOut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-28 20:36:50 +00:00
|
|
|
vtkm::worklet::DispatcherMapField<ConvertToRGB> dispatcher;
|
2017-12-14 18:13:55 +00:00
|
|
|
dispatcher.Invoke(
|
|
|
|
vtkm::cont::make_ArrayHandleTransform(values, colorconversion::MagnitudePortal()), rgbOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Use a single component of a vector to generate RGBA colors
|
|
|
|
///
|
2018-10-17 19:17:29 +00:00
|
|
|
template <typename T, int N, typename S>
|
2019-07-31 16:20:38 +00:00
|
|
|
void ScalarsToColors::RunComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
|
|
|
|
vtkm::IdComponent comp,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const
|
2017-12-14 18:13:55 +00:00
|
|
|
{
|
|
|
|
this->Run(vtkm::cont::make_ArrayHandleTransform(values, colorconversion::ComponentPortal(comp)),
|
2018-10-17 19:17:29 +00:00
|
|
|
rgbaOut);
|
2017-12-14 18:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Use a single component of a vector to generate RGB colors
|
|
|
|
///
|
2018-10-17 19:17:29 +00:00
|
|
|
template <typename T, int N, typename S>
|
2017-12-14 18:13:55 +00:00
|
|
|
void ScalarsToColors::RunComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
|
|
|
|
vtkm::IdComponent comp,
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const
|
2017-12-14 18:13:55 +00:00
|
|
|
{
|
|
|
|
this->Run(vtkm::cont::make_ArrayHandleTransform(values, colorconversion::ComponentPortal(comp)),
|
2018-10-17 19:17:29 +00:00
|
|
|
rgbOut);
|
2017-12-14 18:13:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|