Viskores  1.0
ScalarsToColors.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_worklet_ScalarsToColors_h
19 #define viskores_worklet_ScalarsToColors_h
20 
21 #include <viskores/Range.h>
23 
24 namespace viskores
25 {
26 namespace worklet
27 {
28 
29 namespace colorconversion
30 {
31 inline void ComputeShiftScale(const viskores::Range& range,
32  viskores::Float32& shift,
33  viskores::Float32& scale)
34 {
35  //This scale logic seems to be unduly complicated
36  shift = static_cast<viskores::Float32>(-range.Min);
37  scale = static_cast<viskores::Float32>(range.Length());
38 
39  if (range.Length() <= 0)
40  {
41  scale = -1e17f;
42  }
43  if (scale * scale > 1e-30f)
44  {
45  scale = 1.0f / scale;
46  }
47  scale *= 255.0f;
48 }
49 }
50 
52 {
53  viskores::Range ValueRange = { 0.0f, 255.0f };
57 
58 public:
60 
62  : ValueRange(range)
63  , Alpha(viskores::Min(viskores::Max(alpha, 0.0f), 1.0f))
64  {
65  colorconversion::ComputeShiftScale(range, this->Shift, this->Scale);
66  }
67 
69  : ValueRange(range)
70  {
71  colorconversion::ComputeShiftScale(range, this->Shift, this->Scale);
72  }
73 
75  : ValueRange(0.0f, 255.0f)
76  , Alpha(viskores::Min(viskores::Max(alpha, 0.0f), 1.0f))
77  {
78  }
79 
80  void SetRange(const viskores::Range& range)
81  {
82  this->ValueRange = range;
83  colorconversion::ComputeShiftScale(range, this->Shift, this->Scale);
84  }
85 
86  viskores::Range GetRange() const { return this->ValueRange; }
87 
89  {
90  this->Alpha = viskores::Min(viskores::Max(alpha, 0.0f), 1.0f);
91  }
92 
93  viskores::Float32 GetAlpha() const { return this->Alpha; }
94 
97  template <typename T, typename S>
98  void Run(const viskores::cont::ArrayHandle<T, S>& values,
100 
103  template <typename T, typename S>
104  void Run(const viskores::cont::ArrayHandle<T, S>& values,
106 
107 
110  template <typename T, int N, typename S>
113 
116  template <typename T, int N, typename S>
119 
122  template <typename T, int N, typename S>
126 
129  template <typename T, int N, typename S>
133 };
134 }
135 }
136 
137 #include <viskores/worklet/ScalarsToColors.hxx>
138 
139 #endif
viskores::worklet::ScalarsToColors::GetAlpha
viskores::Float32 GetAlpha() const
Definition: ScalarsToColors.h:93
ArrayHandle.h
viskores::worklet::ScalarsToColors::SetAlpha
void SetAlpha(viskores::Float32 alpha)
Definition: ScalarsToColors.h:88
viskores::worklet::ScalarsToColors::Alpha
viskores::Float32 Alpha
Definition: ScalarsToColors.h:54
viskores::Range::Length
viskores::Float64 Length() const
Returns the length of the range.
Definition: Range.h:99
viskores::Range::Min
viskores::Float64 Min
The minumum value of the range (inclusive).
Definition: Range.h:42
viskores::worklet::ScalarsToColors::GetRange
viskores::Range GetRange() const
Definition: ScalarsToColors.h:86
viskores::worklet::ScalarsToColors::ScalarsToColors
ScalarsToColors(const viskores::Range &range)
Definition: ScalarsToColors.h:68
viskores::worklet::colorconversion::ComputeShiftScale
void ComputeShiftScale(const viskores::Range &range, viskores::Float32 &shift, viskores::Float32 &scale)
Definition: ScalarsToColors.h:31
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::worklet::ScalarsToColors::SetRange
void SetRange(const viskores::Range &range)
Definition: ScalarsToColors.h:80
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::worklet::ScalarsToColors::RunMagnitude
void RunMagnitude(const viskores::cont::ArrayHandle< viskores::Vec< T, N >, S > &values, viskores::cont::ArrayHandle< viskores::Vec4ui_8 > &rgbaOut) const
Use magnitude of a vector to generate RGBA colors.
viskores::worklet::ScalarsToColors::ScalarsToColors
ScalarsToColors(viskores::Float32 alpha)
Definition: ScalarsToColors.h:74
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::worklet::ScalarsToColors::ValueRange
viskores::Range ValueRange
Definition: ScalarsToColors.h:53
viskores::Float32
float Float32
Base type to use for 32-bit floating-point numbers.
Definition: Types.h:165
viskores::worklet::ScalarsToColors::Scale
viskores::Float32 Scale
Definition: ScalarsToColors.h:56
Range.h
viskores::Range
Represent a continuous scalar range of values.
Definition: Range.h:39
viskores::worklet::ScalarsToColors
Definition: ScalarsToColors.h:51
viskores::worklet::ScalarsToColors::ScalarsToColors
ScalarsToColors(const viskores::Range &range, viskores::Float32 alpha)
Definition: ScalarsToColors.h:61
viskores::worklet::ScalarsToColors::RunComponent
void RunComponent(const viskores::cont::ArrayHandle< viskores::Vec< T, N >, S > &values, viskores::IdComponent comp, viskores::cont::ArrayHandle< viskores::Vec4ui_8 > &rgbaOut) const
Use a single component of a vector to generate RGBA colors.
viskores::worklet::ScalarsToColors::Run
void Run(const viskores::cont::ArrayHandle< T, S > &values, viskores::cont::ArrayHandle< viskores::Vec4ui_8 > &rgbaOut) const
Use each component to generate RGBA colors.
viskores::worklet::ScalarsToColors::Shift
viskores::Float32 Shift
Definition: ScalarsToColors.h:55
viskores::Vec
A short fixed-length array.
Definition: Types.h:365
viskores::worklet::ScalarsToColors::ScalarsToColors
ScalarsToColors()
Definition: ScalarsToColors.h:59