Medical Imaging Interaction Toolkit  2016.11.0
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,
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 mitkCvMatFromVnlMatrix_h
17 #define mitkCvMatFromVnlMatrix_h
18 
19 #include <mitkEndoMacros.h>
20 #include <mitkEndoDebug.h>
21 #include <cv.h>
22 #include <vnl/vnl_matrix.h>
23 #include <mitkAlgorithm.h>
24 
25 namespace mitk
26 {
34  template <class T>
36  virtual public Algorithm
37  {
38  public:
43  const vnl_matrix<T>* _VnlMatrix,
44  cv::Mat* _CvMat):
45  m_VnlMatrix(_VnlMatrix),
46  m_CvMat(_CvMat)
47  {
48  }
49 
53  template <class T_CvType, class T_VnlType>
54  static void Cast( const vnl_matrix<T_VnlType>& vnlMat, cv::Mat& cvMat )
55  {
56  endodebugvar( vnlMat )
57  cvMat = cv::Mat(vnlMat.rows(), vnlMat.cols(), cv::DataType<T_CvType>::type);
58  for(unsigned int i=0; i<vnlMat.rows(); ++i)
59  {
60  for(unsigned int j=0; j<vnlMat.cols(); ++j)
61  {
62  cvMat.at<T_CvType>(i,j) = static_cast<T_CvType>( vnlMat(i,j) );
63 // endodebugvar( vnlMat(i,j) )
64 // endodebugvar( cvMat.at<T_CvType>(i,j) )
65  }
66  }
67  }
68 
72  void Update() override
73  {
74  Cast<T, T>( *m_VnlMatrix, *m_CvMat );
75  }
76  private:
80  const vnl_matrix<T>* m_VnlMatrix;
84  cv::Mat* m_CvMat;
85  };
86 } // namespace mitk
87 
88 #endif // mitkCvMatFromVnlMatrix_h
DataCollection - Class to facilitate loading/accessing structured data.
static void Cast(const vnl_matrix< T_VnlType > &vnlMat, cv::Mat &cvMat)
#define endodebugvar(var)
CvMatFromVnlMatrix(const vnl_matrix< T > *_VnlMatrix, cv::Mat *_CvMat)