VTK-m  2.0
ScalarsToColors.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_ScalarsToColors_h
11 #define vtk_m_worklet_ScalarsToColors_h
12 
13 #include <vtkm/Range.h>
14 #include <vtkm/cont/ArrayHandle.h>
15 
16 namespace vtkm
17 {
18 namespace worklet
19 {
20 
21 namespace colorconversion
22 {
23 inline void ComputeShiftScale(const vtkm::Range& range, vtkm::Float32& shift, vtkm::Float32& scale)
24 {
25  //This scale logic seems to be unduly complicated
26  shift = static_cast<vtkm::Float32>(-range.Min);
27  scale = static_cast<vtkm::Float32>(range.Length());
28 
29  if (range.Length() <= 0)
30  {
31  scale = -1e17f;
32  }
33  if (scale * scale > 1e-30f)
34  {
35  scale = 1.0f / scale;
36  }
37  scale *= 255.0f;
38 }
39 }
40 
42 {
43  vtkm::Range ValueRange = { 0.0f, 255.0f };
47 
48 public:
50 
52  : ValueRange(range)
53  , Alpha(vtkm::Min(vtkm::Max(alpha, 0.0f), 1.0f))
54  {
55  colorconversion::ComputeShiftScale(range, this->Shift, this->Scale);
56  }
57 
59  : ValueRange(range)
60  {
61  colorconversion::ComputeShiftScale(range, this->Shift, this->Scale);
62  }
63 
65  : ValueRange(0.0f, 255.0f)
66  , Alpha(vtkm::Min(vtkm::Max(alpha, 0.0f), 1.0f))
67  {
68  }
69 
70  void SetRange(const vtkm::Range& range)
71  {
72  this->ValueRange = range;
73  colorconversion::ComputeShiftScale(range, this->Shift, this->Scale);
74  }
75 
76  vtkm::Range GetRange() const { return this->ValueRange; }
77 
78  void SetAlpha(vtkm::Float32 alpha) { this->Alpha = vtkm::Min(vtkm::Max(alpha, 0.0f), 1.0f); }
79 
80  vtkm::Float32 GetAlpha() const { return this->Alpha; }
81 
84  template <typename T, typename S>
85  void Run(const vtkm::cont::ArrayHandle<T, S>& values,
87 
90  template <typename T, typename S>
91  void Run(const vtkm::cont::ArrayHandle<T, S>& values,
93 
94 
97  template <typename T, int N, typename S>
100 
103  template <typename T, int N, typename S>
106 
109  template <typename T, int N, typename S>
111  vtkm::IdComponent comp,
113 
116  template <typename T, int N, typename S>
118  vtkm::IdComponent comp,
120 };
121 }
122 }
123 
124 #include <vtkm/worklet/ScalarsToColors.hxx>
125 
126 #endif
vtkm::cont::ArrayHandle< T, S >
ArrayHandle.h
vtkm::worklet::ScalarsToColors::GetAlpha
vtkm::Float32 GetAlpha() const
Definition: ScalarsToColors.h:80
vtkm::worklet::ScalarsToColors::SetAlpha
void SetAlpha(vtkm::Float32 alpha)
Definition: ScalarsToColors.h:78
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::ScalarsToColors::ScalarsToColors
ScalarsToColors(vtkm::Float32 alpha)
Definition: ScalarsToColors.h:64
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::worklet::ScalarsToColors::ScalarsToColors
ScalarsToColors(const vtkm::Range &range, vtkm::Float32 alpha)
Definition: ScalarsToColors.h:51
vtkm::worklet::ScalarsToColors::ScalarsToColors
ScalarsToColors()
Definition: ScalarsToColors.h:49
vtkm::worklet::ScalarsToColors::Shift
vtkm::Float32 Shift
Definition: ScalarsToColors.h:45
vtkm::worklet::ScalarsToColors::RunMagnitude
void RunMagnitude(const vtkm::cont::ArrayHandle< vtkm::Vec< T, N >, S > &values, vtkm::cont::ArrayHandle< vtkm::Vec4ui_8 > &rgbaOut) const
Use magnitude of a vector to generate RGBA colors.
vtkm::Range::Length
VTKM_EXEC_CONT vtkm::Float64 Length() const
Returns the length of the range.
Definition: Range.h:87
vtkm::worklet::ScalarsToColors::ScalarsToColors
ScalarsToColors(const vtkm::Range &range)
Definition: ScalarsToColors.h:58
vtkm::worklet::ScalarsToColors::GetRange
vtkm::Range GetRange() const
Definition: ScalarsToColors.h:76
Range.h
vtkm::worklet::ScalarsToColors
Definition: ScalarsToColors.h:41
vtkm::worklet::ScalarsToColors::SetRange
void SetRange(const vtkm::Range &range)
Definition: ScalarsToColors.h:70
vtkm::Vec< T, N >
vtkm::worklet::ScalarsToColors::Scale
vtkm::Float32 Scale
Definition: ScalarsToColors.h:46
vtkm::worklet::colorconversion::ComputeShiftScale
void ComputeShiftScale(const vtkm::Range &range, vtkm::Float32 &shift, vtkm::Float32 &scale)
Definition: ScalarsToColors.h:23
vtkm::Range::Min
vtkm::Float64 Min
Definition: Range.h:33
vtkm::Float32
float Float32
Definition: Types.h:154
vtkm::worklet::ScalarsToColors::ValueRange
vtkm::Range ValueRange
Definition: ScalarsToColors.h:43
vtkm::worklet::ScalarsToColors::Run
void Run(const vtkm::cont::ArrayHandle< T, S > &values, vtkm::cont::ArrayHandle< vtkm::Vec4ui_8 > &rgbaOut) const
Use each component to generate RGBA colors.
vtkm::worklet::ScalarsToColors::Alpha
vtkm::Float32 Alpha
Definition: ScalarsToColors.h:44
vtkm::worklet::ScalarsToColors::RunComponent
void RunComponent(const vtkm::cont::ArrayHandle< vtkm::Vec< T, N >, S > &values, vtkm::IdComponent comp, vtkm::cont::ArrayHandle< vtkm::Vec4ui_8 > &rgbaOut) const
Use a single component of a vector to generate RGBA colors.
vtkm::Range
Represent a continuous scalar range of values.
Definition: Range.h:31