Medical Imaging Interaction Toolkit  2023.04.00
Medical Imaging Interaction Toolkit
mitkVnlMatrixFromCvMat.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 mitkVnlMatrixFromCvMat_h
13 #define mitkVnlMatrixFromCvMat_h
14 
15 #include <vnl/vnl_matrix.h>
16 #include <opencv2/core.hpp>
17 #include <mitkObservable.h>
18 #include <mitkAlgorithm.h>
19 #include <mitkEndoMacros.h>
20 
21 namespace mitk
22 {
26  template <class T>
28  virtual public Algorithm
29  {
30  public:
35  const cv::Mat* _CvMat,
36  vnl_matrix<T>* _VnlMatrix):
37  m_CvMat(_CvMat),
38  m_VnlMatrix(_VnlMatrix)
39  {
40  }
41 
42 
46  template <typename TCvMat, typename TVnlMat>
47  void ToVnlMatrix( vnl_matrix<TVnlMat>& vnlMat, const cv::Mat& mat )
48  {
49  vnlMat.set_size( mat.rows, mat.cols );
50  for(int i=0; i<mat.rows; ++i)
51  for(int j=0; j<mat.cols; ++j)
52  vnlMat(i,j) = static_cast<TVnlMat>( mat.at<TCvMat>(i,j) );
53  }
54 
58  void Update() override
59  {
60  endoAccessCvMat( ToVnlMatrix, T, (*m_VnlMatrix), (*m_CvMat) );
61  }
62  private:
66  const cv::Mat* m_CvMat;
70  vnl_matrix<T>* m_VnlMatrix;
71  };
72 } // namespace mitk
73 
74 #endif
endoAccessCvMat
#define endoAccessCvMat(function, T, arg1, arg2)
Definition: mitkEndoMacros.h:22
mitk::VnlMatrixFromCvMat
Definition: mitkVnlMatrixFromCvMat.h:27
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::VnlMatrixFromCvMat::VnlMatrixFromCvMat
VnlMatrixFromCvMat(const cv::Mat *_CvMat, vnl_matrix< T > *_VnlMatrix)
Definition: mitkVnlMatrixFromCvMat.h:34
mitkObservable.h
mitk::VnlMatrixFromCvMat::Update
void Update() override
Definition: mitkVnlMatrixFromCvMat.h:58
mitk::Algorithm
Definition: mitkAlgorithm.h:22
mitkEndoMacros.h
mitkAlgorithm.h
mitk::VnlMatrixFromCvMat::ToVnlMatrix
void ToVnlMatrix(vnl_matrix< TVnlMat > &vnlMat, const cv::Mat &mat)
Definition: mitkVnlMatrixFromCvMat.h:47