VTK-m  2.0
Conversions.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_Conversions_h
11 #define vtk_m_worklet_colorconversion_Conversions_h
12 
13 namespace vtkm
14 {
15 namespace worklet
16 {
17 namespace colorconversion
18 {
19 
20 template <typename T>
22 {
23  return static_cast<vtkm::UInt8>(t);
24 }
25 
26 template <>
28 {
29  return static_cast<vtkm::UInt8>(t * 255.0f + 0.5f);
30 }
31 
32 template <>
34 {
35  return static_cast<vtkm::UInt8>(t * 255.0f + 0.5f);
36 }
37 
38 
39 VTKM_EXEC inline void Clamp(vtkm::Float32& val)
40 {
41  val = vtkm::Min(255.0f, vtkm::Max(0.0f, val));
42 }
43 VTKM_EXEC inline void Clamp(vtkm::Vec2f_32& val)
44 {
45  val[0] = vtkm::Min(255.0f, vtkm::Max(0.0f, val[0]));
46  val[1] = vtkm::Min(255.0f, vtkm::Max(0.0f, val[1]));
47 }
48 VTKM_EXEC inline void Clamp(vtkm::Vec3f_32& val)
49 {
50  val[0] = vtkm::Min(255.0f, vtkm::Max(0.0f, val[0]));
51  val[1] = vtkm::Min(255.0f, vtkm::Max(0.0f, val[1]));
52  val[2] = vtkm::Min(255.0f, vtkm::Max(0.0f, val[2]));
53 }
54 VTKM_EXEC inline void Clamp(vtkm::Vec4f_32& val)
55 {
56  val[0] = vtkm::Min(255.0f, vtkm::Max(0.0f, val[0]));
57  val[1] = vtkm::Min(255.0f, vtkm::Max(0.0f, val[1]));
58  val[2] = vtkm::Min(255.0f, vtkm::Max(0.0f, val[2]));
59  val[3] = vtkm::Min(255.0f, vtkm::Max(0.0f, val[3]));
60 }
61 }
62 }
63 }
64 #endif
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
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
A short fixed-length array.
Definition: Types.h:767
vtkm::Float32
float Float32
Definition: Types.h:154
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::colorconversion::Clamp
VTKM_EXEC void Clamp(vtkm::Float32 &val)
Definition: Conversions.h:39