Advertisement
Guest User

cvMat.h

a guest
Sep 26th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.15 KB | None | 0 0
  1. #ifndef SOFA_OR_COMMON_CVMAT_H
  2. #define SOFA_OR_COMMON_CVMAT_H
  3.  
  4. #include "initplugin.h"
  5.  
  6. #include <sofa/defaulttype/DataTypeInfo.h>
  7. #include <iostream>
  8. #include <opencv2/opencv.hpp>
  9. #include <sstream>
  10.  
  11. namespace sofaor
  12. {
  13. namespace common
  14. {
  15. class SOFA_SOFAORCOMMON_API cvMat : public cv::Mat
  16. {
  17.  public:
  18.   static const char *Name() { return "cvMat"; }
  19.  
  20.   cvMat() : cv::Mat() {}
  21.   cvMat(int rows, int cols, int type) : cv::Mat(rows, cols, type) {}
  22.  
  23.   [...]
  24.  
  25.   inline friend std::istream &operator>>(std::istream &in, cvMat &s)
  26.   {
  27.     size_t rows, cols, depth, channels;
  28.     in >> rows >> cols >> depth >> channels;
  29.  
  30.     //    char separator;
  31.     //    in.read(&separator, 1);
  32.  
  33.     //    cvMat image(rows, cols, CV_MAKETYPE(depth, channels));
  34.     //    if (image.cols * image.rows)
  35.     //    {
  36.     //      in.read((char *)image.data, image.total() * image.elemSize());
  37.     //      image.copyTo(s);
  38.     //    }
  39.     return in;
  40.   }
  41.  
  42.   inline friend std::ostream &operator<<(std::ostream &out, const cvMat &s)
  43.   {
  44.     out << s.rows << " " << s.cols << " " << s.depth() << " " << s.channels()
  45.         /*<< ";"*/;
  46.     //    out.write((char *)s.data, s.total() * s.elemSize());
  47.  
  48.     return out;
  49.   }
  50. };
  51.  
  52. }  // namespace common
  53. }  // namespace sofaor
  54.  
  55. namespace sofa
  56. {
  57. namespace defaulttype
  58. {
  59. template <>
  60. struct DataTypeName<sofaor::common::cvMat>
  61. {
  62.   static const char *name() { return "cvMat"; }
  63. };
  64.  
  65. template <class TDataType>
  66. struct cvMatTypeInfo
  67. {
  68.   typedef TDataType DataType;
  69.   typedef DataType BaseType;
  70.   typedef DataType ValueType;
  71.   typedef long long ConvType;
  72.   typedef ScalarTypeInfo<TDataType> BaseTypeInfo;
  73.   typedef ScalarTypeInfo<TDataType> ValueTypeInfo;
  74.  
  75.   enum
  76.   {
  77.     ValidInfo = BaseTypeInfo::ValidInfo
  78.   };  ///< 1 if this type has valid infos
  79.   enum
  80.   {
  81.     FixedSize = 1
  82.   };  ///< 1 if this type has a fixed size  -> always 1 Image
  83.   enum
  84.   {
  85.     ZeroConstructor = 0
  86.   };  ///< 1 if the constructor is equivalent to setting memory to 0  -> I guess
  87.       ///< so, a default Image is initialzed with nothing
  88.   enum
  89.   {
  90.     SimpleCopy = 0
  91.   };  ///< 1 if copying the data can be done with a memcpy
  92.   enum
  93.   {
  94.     SimpleLayout = 0
  95.   };  ///< 1 if the layout in memory is simply N values of the same base type
  96.   enum
  97.   {
  98.     Integer = 0
  99.   };  ///< 1 if this type uses integer values
  100.   enum
  101.   {
  102.     Scalar = 0
  103.   };  ///< 1 if this type uses scalar values
  104.   enum
  105.   {
  106.     Text = 0
  107.   };  ///< 1 if this type uses text values
  108.   enum
  109.   {
  110.     CopyOnWrite = 1
  111.   };  ///< 1 if this type uses copy-on-write -> it seems to be THE important
  112.       ///< option not to perform too many copies
  113.   enum
  114.   {
  115.     Container = 0
  116.   };  ///< 1 if this type is a container
  117.  
  118.   enum
  119.   {
  120.     Size = 1
  121.   };  ///< largest known fixed size for this type, as returned by size()
  122.  
  123.   static size_t size() { return 1; }
  124.   static size_t byteSize() { return 1; }
  125.  
  126.   static size_t size(const DataType & /*data*/) { return 1; }
  127.  
  128.   static bool setSize(DataType & /*data*/, size_t /*size*/) { return false; }
  129.  
  130.   template <typename T>
  131.   static void getValue(const DataType & /*data*/, size_t /*index*/,
  132.                        T & /*value*/)
  133.   {
  134.     return;
  135.   }
  136.  
  137.   template <typename T>
  138.   static void setValue(DataType & /*data*/, size_t /*index*/,
  139.                        const T & /*value*/)
  140.   {
  141.     return;
  142.   }
  143.  
  144.   static void getValueString(const DataType &data, size_t index,
  145.                              std::string &value)
  146.   {
  147.     if (index != 0) return;
  148.     std::ostringstream o;
  149.     o << data;
  150.     value = o.str();
  151.   }
  152.  
  153.   static void setValueString(DataType &data, size_t index,
  154.                              const std::string &value)
  155.   {
  156.     if (index != 0) return;
  157.     std::istringstream i(value);
  158.     i >> data;
  159.   }
  160.  
  161.   static const void *getValuePtr(const DataType &) { return NULL; }
  162.  
  163.   static void *getValuePtr(DataType &) { return NULL; }
  164. };
  165.  
  166. template <>
  167. struct DataTypeInfo<sofaor::common::cvMat>
  168.     : public cvMatTypeInfo<sofaor::common::cvMat>
  169. {
  170.   static std::string name()
  171.   {
  172.     return "cvMat";
  173.   }
  174. };
  175.  
  176. }  // namespace defaulttype
  177. }  // namespace sofa
  178.  
  179. #endif  // SOFA_OR_COMMON_CVMAT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement