Post date: Apr 10, 2016 3:20:40 AM
An integer array is declared as
int int_array[3] = { 0, 1, 2 };
passing to a function merely requires
void myFunction(int array[])
and array of pointers to integers would be declared
int* int_array_ptr[3];
and addressing this array to the previous integer array is done by
int_array_ptr[1] = &(int_array[1]);
and passing this to a function
void myFunction(int* array[])
So an Eigen MatrixXf (floating dynamic matrix) is declared
MatrixXf mat_array[3];
similarly, a pointer array to this is declared
MatrixXf* mat_array_ptr[3];
and it is passed to a function
void myFunction(MatrixXf* ptrs[])
The pointers are set similar to how integers are set
mat_array_ptr[0] = &(mat_array[0]);
So making a short cut to skip the MatrixXf array use the copy constructor
mat_array_ptr[2] = new MatrixXf(.....);
More Eigen matrix pointer magic. Now to print a single element in say MatrixXf mat_array you do
mat_array[0](0, 1)
now for pointers, you do
(*mat_array_ptr[1])(0, 2)
and finally (hopefully), say you want a function to return an array of Eigen matrix pointers by calling them this way,
MatrixXf* arrp = ReturnPointers();
then the function would be
MatrixXf* ReturnPointers()
{
MatrixXf* arrp = new MatrixXf[3];
arrp[0] = *(new MatrixXf(maketestmatrixf(2, 2)));
arrp[1] = *(new MatrixXf(maketestmatrixf(3, 3)));
arrp[2] = *(new MatrixXf(maketestmatrixf(4, 4)));
return arrp;
}
(maketestmatrixf() is my own routine that returns an eigen MatrixXf of specified dimensions)
Okay one more last go :) Say you have the above function ReturnPointers() and you want to pass it to another function to print or do something else. In the code calling ReturnPointers() you will have
MatrixXf* arrq = ReturnPointers();
PrintArrays(&arrq);
Then the PrintArrays function will be like
void PrintArrays(MatrixXf* para[])
{
for (int i = 0; i < (*para)->size(); i++)
cout << (*para)[i] << endl;
}
Just when you think you got it figured out ......