Medical Imaging Interaction Toolkit  2021.10.99-1c4db16f
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 #ifndef mitkStringFromCvMat_h
13 #define mitkStringFromCvMat_h
14 
15 #include <string>
16 #include <mitkObservable.h>
17 #include <mitkAlgorithm.h>
18 #include <mitkEndoMacros.h>
19 #include <sstream>
20 
21 #include "opencv2/core.hpp"
22 
23 namespace mitk
24 {
29  virtual public Algorithm
30  {
31  public:
36  const cv::Mat* _CvMat,
37  std::string* _String):
38  m_CvMat(_CvMat),
39  m_String(_String)
40  {
41  }
42 
43 
47  template <typename TCvMat, char T_Delim>
48  void ToString( std::string& string, const cv::Mat& mat )
49  {
50  std::ostringstream s;
51 
52 
53  for(int i=0; i<mat.rows; ++i)
54  {
55  for(int j=0; j<mat.cols; ++j)
56  {
57  s << mat.at<TCvMat>(i,j) << " ";
58  }
59  s << T_Delim;
60  }
61  string = s.str();
62  }
63 
64  void SetMatrix(
65  const cv::Mat* _CvMat )
66  {
67  m_CvMat = _CvMat;
68  }
69 
73  void Update() override
74  {
75  endoAccessCvMat( ToString, '\n', (*m_String), (*m_CvMat) );
76  }
77  private:
81  const cv::Mat* m_CvMat;
85  std::string* m_String;
86  };
87 } // namespace mitk
88 
89 #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)