[vtkusers] VTK/Examples/Cxx/ImageData/IterateImageData

Rachel aracha2010 at gmail.com
Mon Dec 13 09:14:50 EST 2010


Thank you Davis. i got the same results as you but when i change the code as
you see below, it gives me 0:

I change the input image and I assigned 2.0 to each pixel (as in the example
) 
int main(){
// Create an image data
  vtkSmartPointer<vtkImageData> imageData = 
    vtkSmartPointer<vtkImageData>::New();
  
	//imageData= LoadImage(OutputImage);
	vtkSmartPointer<vtkPNGReader> reader =
    vtkSmartPointer<vtkPNGReader>::New();
  reader->SetFileName(OutputImage);
  reader->Update();
  imageData= reader->GetOutput();
 
  //i removed these three lines
  // Specify the size of the image data
 /* imageData->SetDimensions(2,3,1);
  imageData->SetNumberOfScalarComponents(1);
  imageData->SetScalarTypeToDouble();*/
 
  int* dims = imageData->GetDimensions();
 
  std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: "
<< dims[2] << std::endl;
  std::cout << "Number of points: " << imageData->GetNumberOfPoints() <<
std::endl;
  std::cout << "Number of cells: " << imageData->GetNumberOfCells() <<
std::endl;
 
  // Fill every entry of the image data with "2.0"
 for (int z = 0; z < dims[2]; z++)
    {
    for (int y = 0; y < dims[1]; y++)
      {
      for (int x = 0; x < dims[0]; x++)
        {

        double* pixel =
static_cast<double*>(imageData->GetScalarPointer(x,y,z));
        pixel[0] = 2.0;

       }
    }
  }


  // Retrieve the entries from the image data and print them to the screen
  for (int z = 0; z < dims[2]; z++)
    {
    for (int y = 0; y < dims[1]; y++)
      {
      for (int x = 0; x < dims[0]; x++)
        {
        double* pixel =
static_cast<double*>(imageData->GetScalarPointer(x,y,z));
        // do something with v
        std::cout << pixel[0] << " ";
        }
    std::cout << std::endl;
      }
    std::cout << std::endl;
    }
   return EXIT_SUCCESS;
} 
-- 
View this message in context: http://vtk.1045678.n5.nabble.com/VTK-Examples-Cxx-ImageData-IterateImageData-tp3300844p3303147.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list