[vtkusers] vtkImageData and FFT

Stefan Huber Huber.Ste at gmx.at
Mon Apr 14 09:38:38 EDT 2008


Hi

i still have the problems with my vtkImageData object. I want to create an imageData object out of an array and give this object to a fft. My Problem now is, that i don't know how to create such an imagedata correctly. I tried it with the code you can see under. But i hav the problem, that the imagedata isn't order same like the doublearray, which results from the fft. I have tried it with a lots of different ways. But i havn't found the right one. can somebody hel me again please?

Here is my code:
	int x = 3, y = 3, size;
	int * dat;
	double *out;
	int id = 0, len = 0, i = 0;
	double im=0.0, re=0.0;
	
	size = x*y;

	dat = new int [size];

	cout << "Array befuellen" << endl << endl;
	for(int i= 0; i< x; i++){
		for (int j= 0; j <y; j++){
			dat[i*y+j] = 1;
		}  //for
	}  //for

	cout << "********* print Integerarray *************" << endl<<endl;
	writeArray(size,dat);

	cout << "**** Read from Array to ImageData ********" << endl<<endl;

        //one wrong way
	vtkFloatArray *da = vtkFloatArray::New();
	da->SetNumberOfComponents(1);
	da->SetArray((float*)dat,size,1);

	img->SetDimensions(x,y,1);
	img->SetScalarTypeToFloat();
	img->AllocateScalars();
	img->GetPointData()->SetScalars(da);
	da->Delete();

        //another wrong way
	//img->SetDimensions(x,y,1);
	//img->SetScalarTypeToDouble();
	//img->AllocateScalars();

	//double* ptr = (double *) img->GetScalarPointer();
	//for(int i= 0; i< x; i++){
	//	for (int j= 0; j <y; j++){
	//		*ptr++ = 11;
	//	}  //for
	//}  //for

	img->Update();


	cout << "******** print ImageData **************" << endl<<endl;
	writeImageData(5,5);

	cout << "************** FFT *********************"<< endl<<endl;
	vtkImageFFT *ffft = vtkImageFFT::New();
	ffft->SetDimensionality(img->GetNumberOfScalarComponents());
	ffft->SetInput(img);
	ffft->Update();
	len = ffft->GetOutput()->GetNumberOfPoints();
	//len = len*2;
	out = new double [len];

	for (i = 0; i < len; i++){
		im = ffft->GetOutput()->GetPointData()->GetScalars()->GetComponent(id,1);
		re = ffft->GetOutput()->GetPointData()->GetScalars()->GetComponent(id,0);
		out[i] = re;
		i++;
		out[i] = im;
		id ++;
	}  //for

	cout << "************ print DoubleArray **********" << endl<<endl;
	writeDbArray(size,out);

	img->Delete();


	return 0;

Thanks Stefan

-- 
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx



More information about the vtkusers mailing list