34 #ifndef DEPTH_IMAGE_PROC_DEPTH_TRAITS
35 #define DEPTH_IMAGE_PROC_DEPTH_TRAITS
46 template<
typename T>
struct DepthTraits {};
49 struct DepthTraits<uint16_t>
51 static inline bool valid(uint16_t depth) {
return depth != 0; }
52 static inline float toMeters(uint16_t depth) {
return depth * 0.001f; }
53 static inline uint16_t fromMeters(
float depth) {
return (depth * 1000.0f) + 0.5f; }
54 static inline void initializeBuffer(std::vector<uint8_t>& buffer) {}
58 struct DepthTraits<float>
60 static inline bool valid(
float depth) {
return std::isfinite(depth); }
61 static inline float toMeters(
float depth) {
return depth; }
62 static inline float fromMeters(
float depth) {
return depth; }
64 static inline void initializeBuffer(std::vector<uint8_t>& buffer)
66 float*
start =
reinterpret_cast<float*
>(&buffer[0]);
67 float* end =
reinterpret_cast<float*
>(&buffer[0] + buffer.size());
68 std::fill(start, end, std::numeric_limits<float>::quiet_NaN());