[vtkusers] vtkImageData
Stefan Huber
Huber.Ste at gmx.at
Tue Apr 8 10:07:37 EDT 2008
Hi
i tried the methode GetScalarPointer befor, but it wasn't working.
i get an array with wrong numbers. my code:
int* writeDataFromImageData(int x, int y){
int size = x*y;
int *arr = (int *) malloc(sizeof(int *)*size);
int l = 0;
int * p = (int *) img->GetScalarPointer();
//I think somewhere here is the mistake
for(int i= 0; i< x; i++){
for (int j= 0; j <y; j++){
arr[(i*x)+j]= (int)*p;
p++;
} //for
} //for
writeArray(size,arr);
return arr;
} //writeDataFromImageData
bool readArray2ImageData(int* dat, int x, int y){
//write array to vtkimagedata
try{
img->SetDimensions(x,y,1);
img->SetScalarTypeToFloat();
vtkFloatArray *scalars = vtkFloatArray::New();
for(int i= 0; i< x; i++){
for (int j= 0; j <y; j++){
scalars->InsertTuple1((i*x)+j,dat[i*x+j]);
} //for
} //for
img->GetPointData()->SetScalars(scalars);
img->Update();
return true;
} catch(std::bad_alloc &ex){
return false;
} //catch
} //readArray2ImageData
int* forwardFFT(int *dat, int x, int y){
if(!readArray2ImageData(dat,x,y))
return NULL;
else {
vtkImageFFT *ffft = vtkImageFFT::New();
ffft->SetDimensionality(2);
ffft->SetInput(img);
ffft->Update();
img=ffft->GetOutput();
img->Update();
img->UpdateData();
return writeDataFromImageData(x,y);
} //else
} //forwardFFT
can you help me please?
thanx Stefan
-------- Original-Nachricht --------
> Datum: Tue, 08 Apr 2008 08:25:50 -0500
> Von: Amy Squillacote <ahs at cfdrc.com>
> An: Mike Jackson <imikejackson at gmail.com>
> CC: Stefan Huber <Huber.Ste at gmx.at>, vtkusers at vtk.org
> Betreff: Re: [vtkusers] vtkImageData
> You're close; the name of the method is GetScalarPointer(). See
> http://www.vtk.org/doc/nightly/html/classvtkImageData.html.
>
> - Amy
>
> Mike Jackson wrote:
> > I _think_ there is a call in vtkImageData called "GetVoidPointer(0)"
> > which will return a void pointer to the first element of the array.
> > Simply cast this to the proper type and do what you need to do.
> >
>
> --
> Amy Squillacote Phone: (256) 726-4839
> Computer Scientist Fax: (256) 726-4806
> CFD Research Corporation Web: http://www.cfdrc.com
> 215 Wynn Drive, Suite 501
> Huntsville, AL 35805
>
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
More information about the vtkusers
mailing list