[vtkusers] ITERATE VTKARRAY

kwayeke bigvision82 at yahoo.com
Sat Jan 8 00:02:19 EST 2011


I have my data from matlab which I want to input to VTK using
vtkMatlabMexAdapter but the data is a 3D array of intensity values of images
at each point (x,y,z). Is it possible to iterate over vtkArray to store it
in vtkImageData to display it as a volume? Here is what I have done but not
seem to work.
------------------------------------------------------------------------------------------------ 
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; i++)
           {
         
            for(int j=0;j<y;j++)
                   {
                           
                        for(int k=0;k<x;j++)
                                {   vtkVariant p=(edata->GetVariantValue(k,
j, i));

                                                double pix=p.ToDouble();
                                                
                 double* pixel =
static_cast<double*>(ImageData->GetScalarPointer(k,j,i));                        
                                        pixel[0] = pix;
                                 }
                   }
               
          }
------------------------------------------------------------------------

Thanks 
-- 
View this message in context: http://vtk.1045678.n5.nabble.com/ITERATE-VTKARRAY-tp3332849p3332849.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list