Medical Imaging Interaction Toolkit  2023.12.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
mitk::StringFromCvMat::Update
void Update() override
Definition: mitkStringFromCvMat.h:73
endoAccessCvMat
#define endoAccessCvMat(function, T, arg1, arg2)
Definition: mitkEndoMacros.h:22
mitk::StringFromCvMat::StringFromCvMat
StringFromCvMat(const cv::Mat *_CvMat, std::string *_String)
Definition: mitkStringFromCvMat.h:35
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitkObservable.h
mitk::StringFromCvMat
Definition: mitkStringFromCvMat.h:28
mitk::Algorithm
Definition: mitkAlgorithm.h:22
mitk::StringFromCvMat::ToString
void ToString(std::string &string, const cv::Mat &mat)
Definition: mitkStringFromCvMat.h:48
mitkEndoMacros.h
mitkAlgorithm.h
mitk::StringFromCvMat::SetMatrix
void SetMatrix(const cv::Mat *_CvMat)
Definition: mitkStringFromCvMat.h:64