VTK-m  2.0
CastInvalidValue.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_cont_internal_CastInvalidValue_h
11 #define vtk_m_cont_internal_CastInvalidValue_h
12 
13 #include <vtkm/Math.h>
14 #include <vtkm/Types.h>
15 #include <vtkm/VecTraits.h>
16 
17 namespace vtkm
18 {
19 namespace cont
20 {
21 namespace internal
22 {
23 
36 template <typename T>
37 T CastInvalidValue(vtkm::Float64 invalidValue)
38 {
39  using ComponentType = typename vtkm::VecTraits<T>::BaseComponentType;
40 
41  if (std::is_same<vtkm::TypeTraitsIntegerTag, typename vtkm::TypeTraits<T>::NumericTag>::value)
42  {
43  // Casting to integer types
44  if (vtkm::IsFinite(invalidValue))
45  {
46  return T(static_cast<ComponentType>(invalidValue));
47  }
48  else if (vtkm::IsInf(invalidValue) && (invalidValue > 0))
49  {
50  return T(std::numeric_limits<ComponentType>::max());
51  }
52  else
53  {
54  return T(std::numeric_limits<ComponentType>::min());
55  }
56  }
57  else
58  {
59  // Not an integer type. Assume can be directly cast
60  return T(static_cast<ComponentType>(invalidValue));
61  }
62 }
63 }
64 }
65 } // namespace vtkm::cont::internal
66 
67 #endif //vtk_m_cont_internal_CastInvalidValue_h
vtkm::TypeTraitsIntegerTag
Tag used to identify types that store integer numbers.
Definition: TypeTraits.h:36
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
vtkm::VecTraits::BaseComponentType
typename vtkm::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Base component type in the vector.
Definition: VecTraits.h:80
Math.h
vtkm::TypeTraitsUnknownTag
Tag used to identify types that aren't Real, Integer, Scalar or Vector.
Definition: TypeTraits.h:20
vtkm::Float64
double Float64
Definition: Types.h:155
VecTraits.h