[vtkusers] fill vtkImageData in 3D

kwayeke bigvision82 at yahoo.com
Fri Jan 7 17:11:20 EST 2011


I am actually importing these stack of images from Matlab in a VtkArray.
Since I want to display these images as a volume, I want to iterate over the
vtkArray and vtkImageData copying the data from vtkArray to vtkImageData.
This is what I have done but the program still crashes.  
--------------------------------------------------------------------------------------------------------
vtkMatlabMexAdapter *matlabMexAdapter = vtkMatlabMexAdapter::New();   

	vtkArray
*edata=matlabMexAdapter->mxArrayTovtkArray(const_cast<mxArray*>(prhs[0]));
	vtkSmartPointer<vtkImageData> ImageData =
vtkSmartPointer<vtkImageData>::New();
	ImageData->SetDimensions(254,254,384);
    ImageData->SetOrigin(0.0,0.0,0.0);
    ImageData->SetSpacing(1.0,1.0,1.0);
    ImageData->SetScalarTypeToDouble();
    	ImageData->AllocateScalars();

	
	for(int i=0; i<z_dim-1; i++)
	   {
	 
	    for(int j=0;j<y_dim-1;j++)
		   { 
			   
			for(int k=0;k<x_dim-1;j++)
				{   vtkVariant *p=&(edata->GetVariantValue(k, j, i));
					    double *pix;
						pix[0]=p[0].ToDouble();
						pix[1]=p[1].ToDouble();
						pix[2]=p[2].ToDouble();					
					    double* pixel =
static_cast<double*>(ImageData->GetScalarPointer(k,j,i));                         
					pixel[0] = pix[0];
					pixel[1] = pix[1];
					pixel[2] = pix[2];	        }
		    }
		
	  }
------------------------------------------------------------------------

Thanks
-- 
View this message in context: http://vtk.1045678.n5.nabble.com/fill-vtkImageData-in-3D-tp3331674p3332540.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list