DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
utlVNLIO.h
Go to the documentation of this file.
1 
17 #ifndef __utlVNLIO_h
18 #define __utlVNLIO_h
19 
20 #include "utlCore.h"
21 #include "utlVector.h"
22 #include "utlNDArray.h"
23 #include "utlVNL.h"
24 #include <vnl/vnl_matrix_fixed.h>
25 
26 namespace utl
27 {
28 
32 template <class T>
33 void
34 VnlMatrixToUtlMatrix( const vnl_matrix<T>& mat, utl::NDArray<T,2>& matUtl )
35 {
36  matUtl.ReSize(mat.rows(),mat.cols());
37  matUtl.CopyData((T* const)mat.data_block(), mat.rows(), mat.cols() );
38 }
39 
40 template <class T, unsigned rows, unsigned cols>
41 void
42 VnlMatrixToUtlMatrix( const vnl_matrix_fixed<T, rows, cols>& mat, utl::NDArray<T,2>& matUtl )
43 {
44  matUtl.ReSize(mat.rows(),mat.cols());
45  matUtl.CopyData((T* const)mat.data_block(), mat.rows(), mat.cols() );
46 }
47 
48 template <class T>
50 VnlMatrixToUtlMatrix( const vnl_matrix<T>& mat )
51 {
52  utl::NDArray<T,2> result;
53  VnlMatrixToUtlMatrix(mat, result);
54  return result;
55 }
56 
57 template <class T>
58 void
59 UtlMatrixToVnlMatrix( const NDArray<T,2>& mat, vnl_matrix<T>& matVnl )
60 {
61  matVnl.set_size(mat.Rows(), mat.Cols());
62  matVnl.copy_in(mat.GetData());
63 }
64 
65 template <class T>
66 vnl_matrix<T>
68 {
69  vnl_matrix<T> result(mat.GetData(), mat.Rows(), mat.Cols());
70  return result;
71 }
72 
73 template <class T>
75 VnlVectorToUtlVector( const vnl_vector<T>& vec )
76 {
77  utl::NDArray<T,1> result(vec.data_block(), vec.size());
78  return result;
79 }
80 
81 template <class T>
82 vnl_vector<T>
84 {
85  vnl_vector<T> result(vec.GetData(), vec.Size());
86  return result;
87 }
88 
90 }
91 
92 #endif
NDArray<T,1> is a vector class which uses blas mkl.
Definition: utlVector.h:36
vnl_vector< T > UtlVectorToVnlVector(const NDArray< T, 1 > &vec)
Definition: utlVNLIO.h:83
SizeType Rows() const
Definition: utlMatrix.h:136
NDArray<T,2> is a row-major matrix.
Definition: utlMatrix.h:37
Definition: utl.h:90
void VnlMatrixToUtlMatrix(const vnl_matrix< T > &mat, utl::NDArray< T, 2 > &matUtl)
Definition: utlVNLIO.h:34
SizeType Cols() const
Definition: utlMatrix.h:138
void CopyData(T *const data, const unsigned rows, const unsigned cols)
Definition: utlMatrix.h:198
void UtlMatrixToVnlMatrix(const NDArray< T, 2 > &mat, vnl_matrix< T > &matVnl)
Definition: utlVNLIO.h:59
utl::NDArray<T,1> class which uses blas mkl
SizeType Size() const
Definition: utlNDArray.h:321
bool ReSize(const SizeType rows, const SizeType cols)
Definition: utlMatrix.h:140
utl::NDArray< T, 1 > VnlVectorToUtlVector(const vnl_vector< T > &vec)
Definition: utlVNLIO.h:75
help functions for VNL