diff --git a/stim/image/image.h b/stim/image/image.h index 674bf9f..beae621 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace stim{ /// This static class provides the STIM interface for loading, saving, and storing 2D images. @@ -57,13 +58,23 @@ class image{ int cv_type(){ - if(std::is_same::value) return CV_MAKETYPE(CV_8U, (int)C()); - else if(std::is_same::value) return CV_MAKETYPE(CV_8S, (int)C()); - else if(std::is_same::value) return CV_MAKETYPE(CV_16U, (int)C()); - else if(std::is_same::value) return CV_MAKETYPE(CV_16S, (int)C()); - else if(std::is_same::value) return CV_MAKETYPE(CV_32S, (int)C()); - else if(std::is_same::value) return CV_MAKETYPE(CV_32F, (int)C()); - else if(std::is_same::value) return CV_MAKETYPE(CV_64F, (int)C()); + // The following is C++ 11 code, but causes problems on some compilers (ex. nvcc). Below is my best approximation to a solution + + //if(std::is_same::value) return CV_MAKETYPE(CV_8U, (int)C()); + //if(std::is_same::value) return CV_MAKETYPE(CV_8S, (int)C()); + //if(std::is_same::value) return CV_MAKETYPE(CV_16U, (int)C()); + //if(std::is_same::value) return CV_MAKETYPE(CV_16S, (int)C()); + //if(std::is_same::value) return CV_MAKETYPE(CV_32S, (int)C()); + //if(std::is_same::value) return CV_MAKETYPE(CV_32F, (int)C()); + //if(std::is_same::value) return CV_MAKETYPE(CV_64F, (int)C()); + + if(typeid(T) == typeid(unsigned char)) return CV_MAKETYPE(CV_8U, (int)C()); + if(typeid(T) == typeid(char)) return CV_MAKETYPE(CV_8S, (int)C()); + if(typeid(T) == typeid(unsigned short)) return CV_MAKETYPE(CV_16U, (int)C()); + if(typeid(T) == typeid(short)) return CV_MAKETYPE(CV_16S, (int)C()); + if(typeid(T) == typeid(int)) return CV_MAKETYPE(CV_32S, (int)C()); + if(typeid(T) == typeid(float)) return CV_MAKETYPE(CV_32F, (int)C()); + if(typeid(T) == typeid(double)) return CV_MAKETYPE(CV_64F, (int)C()); std::cout<<"ERROR in stim::image::cv_type - no valid data type found"<::value) return UCHAR_MAX; - else if(std::is_same::value) return SHRT_MAX; - else if(std::is_same::value) return UINT_MAX; - else if(std::is_same::value) return ULONG_MAX; - else if(std::is_same::value) return ULLONG_MAX; - else if(std::is_same::value) return 1.0f; - else if(std::is_same::value) return 1.0; + // The following is C++ 11 code, but causes problems on some compilers (ex. nvcc). Below is my best approximation to a solution + + //if(std::is_same::value) return UCHAR_MAX; + //if(std::is_same::value) return SHRT_MAX; + //if(std::is_same::value) return UINT_MAX; + //if(std::is_same::value) return ULONG_MAX; + //if(std::is_same::value) return ULLONG_MAX; + //if(std::is_same::value) return 1.0f; + //if(std::is_same::value) return 1.0; + + if(typeid(T) == typeid(unsigned char)) return UCHAR_MAX; + if(typeid(T) == typeid(unsigned short)) return SHRT_MAX; + if(typeid(T) == typeid(unsigned)) return UINT_MAX; + if(typeid(T) == typeid(unsigned long)) return ULONG_MAX; + if(typeid(T) == typeid(unsigned long long)) return ULLONG_MAX; + if(typeid(T) == typeid(float)) return 1.0f; + if(typeid(T) == typeid(double)) return 1.0; std::cout<<"ERROR in stim::image::white - no white value known for this data type"<