VTK-m  2.0
ShiftScaleToRGBA.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 #ifndef vtk_m_worklet_colorconversion_ShiftScaleToRGBA_h
11 #define vtk_m_worklet_colorconversion_ShiftScaleToRGBA_h
12 
15 
16 #include <vtkm/Math.h>
17 
18 namespace vtkm
19 {
20 namespace worklet
21 {
22 namespace colorconversion
23 {
24 
26 {
30 
31  using ControlSignature = void(FieldIn in, FieldOut out);
32  using ExecutionSignature = _2(_1);
33 
35  : WorkletMapField()
36  , Shift(shift)
37  , Scale(scale)
38  , Alpha(alpha)
39  {
40  }
41 
42  template <typename T>
43  VTKM_EXEC vtkm::Vec4ui_8 operator()(const T& in) const
44  { //vtkScalarsToColorsLuminanceToRGBA
45  vtkm::Float32 l = (static_cast<vtkm::Float32>(in) + this->Shift) * this->Scale;
47  const vtkm::UInt8 lc = static_cast<vtkm::UInt8>(l + 0.5);
48  return vtkm::Vec4ui_8{ lc, lc, lc, colorconversion::ColorToUChar(this->Alpha) };
49  }
50 
51  template <typename T>
53  { //vtkScalarsToColorsLuminanceAlphaToRGBA
54  vtkm::Vec2f_32 la(in);
55  la = (la + vtkm::Vec2f_32(this->Shift)) * this->Scale;
57 
58  const vtkm::UInt8 lc = static_cast<vtkm::UInt8>(la[0] + 0.5f);
59  return vtkm::Vec4ui_8{ lc, lc, lc, static_cast<vtkm::UInt8>((la[1] * this->Alpha) + 0.5f) };
60  }
61 
62  template <typename T>
64  { //vtkScalarsToColorsRGBToRGBA
65  vtkm::Vec3f_32 rgb(in);
66  rgb = (rgb + vtkm::Vec3f_32(this->Shift)) * this->Scale;
68  return vtkm::Vec4ui_8{ static_cast<vtkm::UInt8>(rgb[0] + 0.5f),
69  static_cast<vtkm::UInt8>(rgb[1] + 0.5f),
70  static_cast<vtkm::UInt8>(rgb[2] + 0.5f),
71  colorconversion::ColorToUChar(this->Alpha) };
72  }
73 
74  template <typename T>
76  { //vtkScalarsToColorsRGBAToRGBA
77  vtkm::Vec4f_32 rgba(in);
78  rgba = (rgba + vtkm::Vec4f_32(this->Shift)) * this->Scale;
80 
81  rgba[3] *= this->Alpha;
82  return vtkm::Vec4ui_8{ static_cast<vtkm::UInt8>(rgba[0] + 0.5f),
83  static_cast<vtkm::UInt8>(rgba[1] + 0.5f),
84  static_cast<vtkm::UInt8>(rgba[2] + 0.5f),
85  static_cast<vtkm::UInt8>(rgba[3] + 0.5f) };
86  }
87 };
88 }
89 }
90 }
91 #endif
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
WorkletMapField.h
vtkm::worklet::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::worklet::colorconversion::ShiftScaleToRGBA::ShiftScaleToRGBA
ShiftScaleToRGBA(vtkm::Float32 shift, vtkm::Float32 scale, vtkm::Float32 alpha)
Definition: ShiftScaleToRGBA.h:34
vtkm::Vec4f_32
vtkm::Vec< vtkm::Float32, 4 > Vec4f_32
Vec4f_32 corresponds to a 4-dimensional vector of 32-bit floating point values.
Definition: Types.h:1136
vtkm::Vec3f_32
vtkm::Vec< vtkm::Float32, 3 > Vec3f_32
Vec3f_32 corresponds to a 3-dimensional vector of 32-bit floating point values.
Definition: Types.h:1020
vtkm::worklet::colorconversion::ShiftScaleToRGBA::operator()
VTKM_EXEC vtkm::Vec4ui_8 operator()(const vtkm::Vec< T, 2 > &in) const
Definition: ShiftScaleToRGBA.h:52
Conversions.h
vtkm::worklet::colorconversion::ShiftScaleToRGBA::Shift
const vtkm::Float32 Shift
Definition: ShiftScaleToRGBA.h:27
vtkm::Vec2f_32
vtkm::Vec< vtkm::Float32, 2 > Vec2f_32
Vec2f_32 corresponds to a 2-dimensional vector of 32-bit floating point values.
Definition: Types.h:902
vtkm::worklet::colorconversion::ShiftScaleToRGBA::Alpha
const vtkm::Float32 Alpha
Definition: ShiftScaleToRGBA.h:29
vtkm::Vec< T, 4 >
Definition: Types.h:1093
Math.h
vtkm::worklet::colorconversion::ShiftScaleToRGBA::Scale
const vtkm::Float32 Scale
Definition: ShiftScaleToRGBA.h:28
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::colorconversion::ShiftScaleToRGBA::operator()
VTKM_EXEC vtkm::Vec4ui_8 operator()(const vtkm::Vec< T, 4 > &in) const
Definition: ShiftScaleToRGBA.h:75
vtkm::Vec< T, 2 >
Definition: Types.h:859
vtkm::worklet::colorconversion::ShiftScaleToRGBA::ControlSignature
void(FieldIn in, FieldOut out) ControlSignature
Definition: ShiftScaleToRGBA.h:31
vtkm::UInt8
uint8_t UInt8
Definition: Types.h:157
vtkm::worklet::colorconversion::ColorToUChar
VTKM_EXEC vtkm::UInt8 ColorToUChar(T t)
Definition: Conversions.h:21
vtkm::Vec< T, 3 >
Definition: Types.h:975
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::worklet::colorconversion::ShiftScaleToRGBA::operator()
VTKM_EXEC vtkm::Vec4ui_8 operator()(const vtkm::Vec< T, 3 > &in) const
Definition: ShiftScaleToRGBA.h:63
vtkm::Float32
float Float32
Definition: Types.h:154
vtkm::worklet::colorconversion::ShiftScaleToRGBA
Definition: ShiftScaleToRGBA.h:25
vtkm::worklet::colorconversion::ShiftScaleToRGBA::operator()
VTKM_EXEC vtkm::Vec4ui_8 operator()(const T &in) const
Definition: ShiftScaleToRGBA.h:43
vtkm::worklet::colorconversion::ShiftScaleToRGBA::ExecutionSignature
_2(_1) ExecutionSignature
Definition: ShiftScaleToRGBA.h:32
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38
vtkm::worklet::colorconversion::Clamp
VTKM_EXEC void Clamp(vtkm::Float32 &val)
Definition: Conversions.h:39