Rafik Mebarki
Wrapper for TooN C++
TooN matrices and variables sizes need to be specified before any corresponding computation. In addition the resize can be performed only where the array has been created; or where the array is visible. This is quite inconvenient and make TooN efficient only for arrays with static dimension.
For example, to stack matrix2
to matrix1
you would need to create a third Matrix
matrix3 whose number of rows equals the sum of that related to matrix1
and matrix2
, then copy from matrix{1,2}
to matrix3
. Doing so many times would become tedious and make the code less readable. The other problem is visibility. Imagine Matrix mat
is declared in toto.h
but need to be resized with a function from another class... To my knowledge TooN so far does handle these and you will get something like segmentation fault...
The c++ wrapper handles the highlighted issues. For instance, the stacking problem pointed out above can be performed as easily as
irToonHandler::stackMatrix(&matrix1, matrix2);
where matrix1
should have been declared as a pointer:
Matrix<Dynamic, Dynamic> * matrix1;
Do not forget to free the corresponding memory at the end:
delete matrix1;
For info, accessing element (i,j) of matrix1
can be done as
(*matrix1)[i][j] = val;
The c++ source code for the wrapper can be downloaded from TooN-cpp-wrapper-mebarki.tar.gz. It also covers arrays juxtaposition, inversion, and copy, etc.
Example (c++ sample code)
#include <iostream>
#include <cstdio>
#include "irToonHandler.h"
using namespace std;
using namespace TooN;
int main(){
Matrix<3, 4> mat1 = Data(1, -2, 33, 4,\
5, 66, -7, 8,\
9, 10, 11, 12);
cout << "mat1: " << endl << mat1 << endl;
// Matrix with dynamic size
Matrix <Dynamic, Dynamic> * matrix1;
// This allows to copy the size and content of mat1 to matrix1
irToonHandler::copyMat(mat1, &matrix1);
cout << "matrix1: " << endl << *matrix1 << endl;
Matrix<2, 4> matrix2 = Data(21, 22, 23, 24,\
25, 26, 27, 28);
cout << "matrix2: " << endl << matrix2 << endl;
// Stack matrix2 to matrix 1
// matrix1 <- [ matrix1
// matrix2]
//
irToonHandler::stackMatrix(&matrix1, matrix2);
cout << "matrix1 after stack: " << endl << *matrix1 << endl;
delete matrix1;
return 0;
}
Result with the above code:
mat1:
1 -2 33 4
5 66 -7 8
9 10 11 12
matrix1:
1 -2 33 4
5 66 -7 8
9 10 11 12
matrix2:
21 22 23 24
25 26 27 28
matrix1 after stack:
1 -2 33 4
5 66 -7 8
9 10 11 12
21 22 23 24
25 26 27 28
You can send you
inquiries to rafik.mebarkiATgmail.com