Viskores  1.0
CastInvalidValue.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_cont_internal_CastInvalidValue_h
19 #define viskores_cont_internal_CastInvalidValue_h
20 
21 #include <viskores/Math.h>
22 #include <viskores/Types.h>
23 #include <viskores/VecTraits.h>
24 
25 namespace viskores
26 {
27 namespace cont
28 {
29 namespace internal
30 {
31 
44 template <typename T>
45 T CastInvalidValue(viskores::Float64 invalidValue)
46 {
47  using ComponentType = typename viskores::VecTraits<T>::BaseComponentType;
48 
49  if (std::is_same<viskores::TypeTraitsIntegerTag,
50  typename viskores::TypeTraits<T>::NumericTag>::value)
51  {
52  // Casting to integer types
53  if (viskores::IsFinite(invalidValue))
54  {
55  return T(static_cast<ComponentType>(invalidValue));
56  }
57  else if (viskores::IsInf(invalidValue) && (invalidValue > 0))
58  {
59  return T(std::numeric_limits<ComponentType>::max());
60  }
61  else
62  {
63  return T(std::numeric_limits<ComponentType>::min());
64  }
65  }
66  else
67  {
68  // Not an integer type. Assume can be directly cast
69  return T(static_cast<ComponentType>(invalidValue));
70  }
71 }
72 }
73 }
74 } // namespace viskores::cont::internal
75 
76 #endif //viskores_cont_internal_CastInvalidValue_h
Types.h
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Math.h
viskores::TypeTraitsUnknownTag
Tag used to identify types that aren't Real, Integer, Scalar or Vector.
Definition: TypeTraits.h:28
viskores::VecTraits::BaseComponentType
T BaseComponentType
Base component type in the vector.
Definition: VecTraits.h:86
viskores::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:169
viskores::TypeTraitsIntegerTag
Tag used to identify types that store integer numbers.
Definition: TypeTraits.h:44
VecTraits.h