Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkStringFromCvMat.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 #ifndef mitkStringFromCvMat_h
17 #define mitkStringFromCvMat_h
18 
19 #include <cv.h>
20 #include <string>
21 #include <mitkObservable.h>
22 #include <mitkAlgorithm.h>
23 #include <mitkEndoMacros.h>
24 #include <sstream>
25 
26 namespace mitk
27 {
32  virtual public Algorithm
33  {
34  public:
39  const cv::Mat* _CvMat,
40  std::string* _String):
41  m_CvMat(_CvMat),
42  m_String(_String)
43  {
44  }
45 
46 
50  template <typename TCvMat, char T_Delim>
51  void ToString( std::string& string, const cv::Mat& mat )
52  {
53  std::ostringstream s;
54 
55 
56  for(int i=0; i<mat.rows; ++i)
57  {
58  for(int j=0; j<mat.cols; ++j)
59  {
60  s << mat.at<TCvMat>(i,j) << " ";
61  }
62  s << T_Delim;
63  }
64  string = s.str();
65  }
66 
67  void SetMatrix(
68  const cv::Mat* _CvMat )
69  {
70  m_CvMat = _CvMat;
71  }
72 
76  void Update() override
77  {
78  endoAccessCvMat( ToString, '\n', (*m_String), (*m_CvMat) );
79  }
80  private:
84  const cv::Mat* m_CvMat;
88  std::string* m_String;
89  };
90 } // namespace mitk
91 
92 #endif // mitkStringFromCvMat_h
void ToString(std::string &string, const cv::Mat &mat)
#define endoAccessCvMat(function, T, arg1, arg2)
DataCollection - Class to facilitate loading/accessing structured data.
StringFromCvMat(const cv::Mat *_CvMat, std::string *_String)
void SetMatrix(const cv::Mat *_CvMat)