Commit e252a6d63bd93e6525e71e3969673fd02aea5412

Authored by David Mayerich
1 parent 9339fbad

somehow the C++11 changes for stim::image got rewound, re-implemented them

Showing 1 changed file with 36 additions and 14 deletions   Show diff stats
stim/image/image.h
... ... @@ -6,6 +6,7 @@
6 6 #include <vector>
7 7 #include <iostream>
8 8 #include <limits>
  9 +#include <typeinfo>
9 10  
10 11 namespace stim{
11 12 /// This static class provides the STIM interface for loading, saving, and storing 2D images.
... ... @@ -57,13 +58,23 @@ class image{
57 58  
58 59  
59 60 int cv_type(){
60   - if(std::is_same<T, unsigned char>::value) return CV_MAKETYPE(CV_8U, (int)C());
61   - else if(std::is_same<T, char>::value) return CV_MAKETYPE(CV_8S, (int)C());
62   - else if(std::is_same<T, unsigned short>::value) return CV_MAKETYPE(CV_16U, (int)C());
63   - else if(std::is_same<T, short>::value) return CV_MAKETYPE(CV_16S, (int)C());
64   - else if(std::is_same<T, int>::value) return CV_MAKETYPE(CV_32S, (int)C());
65   - else if(std::is_same<T, float>::value) return CV_MAKETYPE(CV_32F, (int)C());
66   - else if(std::is_same<T, double>::value) return CV_MAKETYPE(CV_64F, (int)C());
  61 + // The following is C++ 11 code, but causes problems on some compilers (ex. nvcc). Below is my best approximation to a solution
  62 +
  63 + //if(std::is_same<T, unsigned char>::value) return CV_MAKETYPE(CV_8U, (int)C());
  64 + //if(std::is_same<T, char>::value) return CV_MAKETYPE(CV_8S, (int)C());
  65 + //if(std::is_same<T, unsigned short>::value) return CV_MAKETYPE(CV_16U, (int)C());
  66 + //if(std::is_same<T, short>::value) return CV_MAKETYPE(CV_16S, (int)C());
  67 + //if(std::is_same<T, int>::value) return CV_MAKETYPE(CV_32S, (int)C());
  68 + //if(std::is_same<T, float>::value) return CV_MAKETYPE(CV_32F, (int)C());
  69 + //if(std::is_same<T, double>::value) return CV_MAKETYPE(CV_64F, (int)C());
  70 +
  71 + if(typeid(T) == typeid(unsigned char)) return CV_MAKETYPE(CV_8U, (int)C());
  72 + if(typeid(T) == typeid(char)) return CV_MAKETYPE(CV_8S, (int)C());
  73 + if(typeid(T) == typeid(unsigned short)) return CV_MAKETYPE(CV_16U, (int)C());
  74 + if(typeid(T) == typeid(short)) return CV_MAKETYPE(CV_16S, (int)C());
  75 + if(typeid(T) == typeid(int)) return CV_MAKETYPE(CV_32S, (int)C());
  76 + if(typeid(T) == typeid(float)) return CV_MAKETYPE(CV_32F, (int)C());
  77 + if(typeid(T) == typeid(double)) return CV_MAKETYPE(CV_64F, (int)C());
67 78  
68 79 std::cout<<"ERROR in stim::image::cv_type - no valid data type found"<<std::endl;
69 80 exit(1);
... ... @@ -71,15 +82,26 @@ class image{
71 82  
72 83 /// Returns the value for "white" based on the dynamic range (assumes white is 1.0 for floating point images)
73 84 T white(){
74   - if(std::is_same<T, unsigned char>::value) return UCHAR_MAX;
75   - else if(std::is_same<T, unsigned short>::value) return SHRT_MAX;
76   - else if(std::is_same<T, unsigned>::value) return UINT_MAX;
77   - else if(std::is_same<T, unsigned long>::value) return ULONG_MAX;
78   - else if(std::is_same<T, unsigned long long>::value) return ULLONG_MAX;
79   - else if(std::is_same<T, float>::value) return 1.0f;
80   - else if(std::is_same<T, double>::value) return 1.0;
  85 + // The following is C++ 11 code, but causes problems on some compilers (ex. nvcc). Below is my best approximation to a solution
  86 +
  87 + //if(std::is_same<T, unsigned char>::value) return UCHAR_MAX;
  88 + //if(std::is_same<T, unsigned short>::value) return SHRT_MAX;
  89 + //if(std::is_same<T, unsigned>::value) return UINT_MAX;
  90 + //if(std::is_same<T, unsigned long>::value) return ULONG_MAX;
  91 + //if(std::is_same<T, unsigned long long>::value) return ULLONG_MAX;
  92 + //if(std::is_same<T, float>::value) return 1.0f;
  93 + //if(std::is_same<T, double>::value) return 1.0;
  94 +
  95 + if(typeid(T) == typeid(unsigned char)) return UCHAR_MAX;
  96 + if(typeid(T) == typeid(unsigned short)) return SHRT_MAX;
  97 + if(typeid(T) == typeid(unsigned)) return UINT_MAX;
  98 + if(typeid(T) == typeid(unsigned long)) return ULONG_MAX;
  99 + if(typeid(T) == typeid(unsigned long long)) return ULLONG_MAX;
  100 + if(typeid(T) == typeid(float)) return 1.0f;
  101 + if(typeid(T) == typeid(double)) return 1.0;
81 102  
82 103 std::cout<<"ERROR in stim::image::white - no white value known for this data type"<<std::endl;
  104 + exit(1);
83 105  
84 106 }
85 107  
... ...