[Insight-users] Using an existing datapointer for vnl_matrix

Atwood, Robert C r.atwood at imperial.ac.uk
Fri Jan 12 11:26:10 EST 2007


Here's how I've done it (details of inputting the matrix data omitted
since it's all in 'c' rather than 'c++')

#include <vnl/vnl_matrix_fixed.h>
#include <vnl/vnl_matrix.h>
#include <vnl/vnl_vector.h>
#include <vnl/algo/vnl_symmetric_eigensystem.h>
#include <vnl/algo/vnl_svd.h>
#include <stdio.h>
....

typedef vnl_matrix<double> Mx;
void read_data (FILE * datfile,double ** data,unsigned int * r, unsigned
int *c);

....
   Mx *p;
   double * data;
   unsigned int r,c;
   FILE * datfile;

....
/*call routine that gets values of r and c, and allocates and fills data
with rxc values  */
   read_data(datfile,&data, &r, &c); 

   p=new Mx(r,c);
   p->set(data);



> -----Original Message-----
> From: insight-users-bounces+r.atwood=imperial.ac.uk at itk.org 
> [mailto:insight-users-bounces+r.atwood=imperial.ac.uk at itk.org]
>  On Behalf Of Arne Hansen
> Sent: 12 January 2007 08:58
> To: insight-users
> Subject: [Insight-users] Using an existing datapointer for vnl_matrix
> 
> Hello. I have loaded a matrix from a binary file using 
> standard c++ fstream. I allocated the memory using new, and 
> have a pointer pointing at it. Now i want to use this data in 
> a vnl-matrix. How can i do that?
>  
> If there is an example i would appreciate it. 
>  
> Thank you
> 


More information about the Insight-users mailing list