[vtkusers] Re: [Insight-users] Using an existing datapointer for vnl_matrix

Arne Hansen bsd.diverse at gmail.com
Fri Jan 12 12:01:51 EST 2007


Hi Robert. Thank you. I also have now done more or less like that. I have a
slight problem however, and this is when i try to transfer data from the
vnl_matrix to a vtkImage. I do the following:


vtkImageData* importData(SDMdatatype *data1,int *dims){
 vtkImageImport *importer = vtkImageImport::New();
 importer->SetDataScalarTypeToFloat();
 importer->SetDataOrigin(0,0,0);
 importer->SetImportVoidPointer(data1);

 importer->SetWholeExtent(0,dims[0]-1,0,dims[1]-1,0,dims[2]-1);//If not 3D
image set 3D extent = 0.
 importer->SetDataExtentToWholeExtent();

 importer->Update();

 vtkImageData *img=importer->GetOutput();
 img->Update();
 return img;
}
I do the following when calling this function:

vtkImageData *Temporopolar_region_left_data=
importData(*(meanShape.extract(N,1,
0*N,0).data_array()),D);

where meanShape is my vnl_matrix


I know that the matrix meanShape contains correct data, but when i have
called the importData data function, and on the returned vtkImageData object
call the function

SDMdatatype* a =
(SDMdatatype*)Temporopolar_region_left_data->GetScalarPointer();

a null pointer is returned. Am I missing something ?
Thank you for your help.
Regards

2007/1/12, Atwood, Robert C <r.atwood at imperial.ac.uk>:
>
> 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
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070112/e6683ce5/attachment.htm>


More information about the vtkusers mailing list