Medical Imaging Interaction Toolkit  2016.11.0
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,
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 mitkVnlMatrixFromCvMat_h
17 #define mitkVnlMatrixFromCvMat_h
18 
19 #include <vnl/vnl_matrix.h>
20 #include <cv.h>
21 #include <mitkObservable.h>
22 #include <mitkAlgorithm.h>
23 #include <mitkEndoMacros.h>
24 
25 namespace mitk
26 {
30  template <class T>
32  virtual public Algorithm
33  {
34  public:
39  const cv::Mat* _CvMat,
40  vnl_matrix<T>* _VnlMatrix):
41  m_CvMat(_CvMat),
42  m_VnlMatrix(_VnlMatrix)
43  {
44  }
45 
46 
50  template <typename TCvMat, typename TVnlMat>
51  void ToVnlMatrix( vnl_matrix<TVnlMat>& vnlMat, const cv::Mat& mat )
52  {
53  vnlMat.set_size( mat.rows, mat.cols );
54  for(int i=0; i<mat.rows; ++i)
55  for(int j=0; j<mat.cols; ++j)
56  vnlMat(i,j) = static_cast<TVnlMat>( mat.at<TCvMat>(i,j) );
57  }
58 
62  void Update() override
63  {
64  endoAccessCvMat( ToVnlMatrix, T, (*m_VnlMatrix), (*m_CvMat) );
65  }
66  private:
70  const cv::Mat* m_CvMat;
74  vnl_matrix<T>* m_VnlMatrix;
75  };
76 } // namespace mitk
77 
78 #endif // mitkVnlMatrixFromCvMat_h
#define endoAccessCvMat(function, T, arg1, arg2)
DataCollection - Class to facilitate loading/accessing structured data.
VnlMatrixFromCvMat(const cv::Mat *_CvMat, vnl_matrix< T > *_VnlMatrix)
void ToVnlMatrix(vnl_matrix< TVnlMat > &vnlMat, const cv::Mat &mat)