Go to the documentation of this file.00001 #ifndef DEPTH_IMAGE_PROC_DEPTH_TRAITS
00002 #define DEPTH_IMAGE_PROC_DEPTH_TRAITS
00003
00004 #include <algorithm>
00005 #include <limits>
00006
00007 namespace depth_image_proc {
00008
00009
00010 template<typename T> struct DepthTraits {};
00011
00012 template<>
00013 struct DepthTraits<uint16_t>
00014 {
00015 static inline bool valid(uint16_t depth) { return depth != 0; }
00016 static inline float toMeters(uint16_t depth) { return depth * 0.001f; }
00017 static inline uint16_t fromMeters(float depth) { return (depth * 1000.0f) + 0.5f; }
00018 static inline void initializeBuffer(std::vector<uint8_t>& buffer) {}
00019 };
00020
00021 template<>
00022 struct DepthTraits<float>
00023 {
00024 static inline bool valid(float depth) { return std::isfinite(depth); }
00025 static inline float toMeters(float depth) { return depth; }
00026 static inline float fromMeters(float depth) { return depth; }
00027
00028 static inline void initializeBuffer(std::vector<uint8_t>& buffer)
00029 {
00030 float* start = reinterpret_cast<float*>(&buffer[0]);
00031 float* end = reinterpret_cast<float*>(&buffer[0] + buffer.size());
00032 std::fill(start, end, std::numeric_limits<float>::quiet_NaN());
00033 }
00034 };
00035
00036 }
00037
00038 #endif