Medical Imaging Interaction Toolkit  2023.04.00
Medical Imaging Interaction Toolkit
mitkCvMatFromVnlMatrix.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 mitkCvMatFromVnlMatrix_h
13 #define mitkCvMatFromVnlMatrix_h
14 
15 #include <mitkEndoMacros.h>
16 #include <mitkEndoDebug.h>
17 #include <vnl/vnl_matrix.h>
18 #include <mitkAlgorithm.h>
19 
20 #include "opencv2/core.hpp"
21 
22 namespace mitk
23 {
31  template <class T>
33  virtual public Algorithm
34  {
35  public:
40  const vnl_matrix<T>* _VnlMatrix,
41  cv::Mat* _CvMat):
42  m_VnlMatrix(_VnlMatrix),
43  m_CvMat(_CvMat)
44  {
45  }
46 
50  template <class T_CvType, class T_VnlType>
51  static void Cast( const vnl_matrix<T_VnlType>& vnlMat, cv::Mat& cvMat )
52  {
53  endodebugvar( vnlMat )
54  cvMat = cv::Mat(vnlMat.rows(), vnlMat.cols(), cv::DataType<T_CvType>::type);
55  for(unsigned int i=0; i<vnlMat.rows(); ++i)
56  {
57  for(unsigned int j=0; j<vnlMat.cols(); ++j)
58  {
59  cvMat.at<T_CvType>(i,j) = static_cast<T_CvType>( vnlMat(i,j) );
60 // endodebugvar( vnlMat(i,j) )
61 // endodebugvar( cvMat.at<T_CvType>(i,j) )
62  }
63  }
64  }
65 
69  void Update() override
70  {
71  Cast<T, T>( *m_VnlMatrix, *m_CvMat );
72  }
73  private:
77  const vnl_matrix<T>* m_VnlMatrix;
81  cv::Mat* m_CvMat;
82  };
83 } // namespace mitk
84 
85 #endif
endodebugvar
#define endodebugvar(var)
Definition: mitkEndoDebug.h:214
mitk::CvMatFromVnlMatrix
Definition: mitkCvMatFromVnlMatrix.h:32
mitk::CvMatFromVnlMatrix::CvMatFromVnlMatrix
CvMatFromVnlMatrix(const vnl_matrix< T > *_VnlMatrix, cv::Mat *_CvMat)
Definition: mitkCvMatFromVnlMatrix.h:39
mitk::CvMatFromVnlMatrix::Update
void Update() override
Definition: mitkCvMatFromVnlMatrix.h:69
mitkEndoDebug.h
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::Algorithm
Definition: mitkAlgorithm.h:22
mitk::CvMatFromVnlMatrix::Cast
static void Cast(const vnl_matrix< T_VnlType > &vnlMat, cv::Mat &cvMat)
Definition: mitkCvMatFromVnlMatrix.h:51
mitkEndoMacros.h
mitkAlgorithm.h