[vtkusers] Sampling a 3D volume using vtkStructuredGrid

Eyal Ben-Ishai eyalbi007 at gmail.com
Thu Sep 15 09:19:48 EDT 2011


Hi all,

I have a 3D volume (read using vtkMetaImageReader) and a vtkStructuredGrid
object, and I wish to sample the volume according to the grid. The result
should be a 2D image, with same dimensions as the grid. I tried using
vtkProbeFilter
to do so but I'm getting an error (the code is attached below). Can someone
please detect what I'm doing wrong here? In addition, it seems like the
probing action takes a lot of time (over half a second in release mode),
which means it's not suitable for interactive view. What's the fastest way
of sampling a volume given a structured grid?

Thanks,
Eyal.

int main(int argc, char* argv[])
{
  // Verify input arguments
  if ( argc != 2 )
    {
    std::cout << "Usage: " << argv[0]
              << " Filename(.xyz)" << std::endl;
    return EXIT_FAILURE;
    }
    double x, y, z;

  // Get all data from the file
  std::string filename = argv[1];
  std::ifstream fin(filename.c_str());

  std::string line;
  vtkSmartPointer<vtkPoints> points =
    vtkSmartPointer<vtkPoints>::New();

  while(std::getline(fin, line))
    {
  std::stringstream linestream;
  linestream << line;
  linestream >> x >> y >> z;
  points->InsertNextPoint(x, y, z);
    }

  // Create a grid
  vtkSmartPointer<vtkStructuredGrid> structuredGrid =
    vtkSmartPointer<vtkStructuredGrid>::New();

  // Specify the dimensions of the grid
  structuredGrid->SetDimensions(701,957,1);
  structuredGrid->SetPoints(points);

  int* dims = structuredGrid->GetDimensions();

  // Load the volume
  std::string inputFilename = "volume.mhd";
  vtkSmartPointer<vtkMetaImageReader> reader =
vtkSmartPointer<vtkMetaImageReader>::New();
  reader->SetFileName(inputFilename.c_str());
  reader->Update();
   // Probe
  vtkSmartPointer<vtkProbeFilter> probe =
    vtkSmartPointer<vtkProbeFilter>::New();
  probe->SetSource(reader->GetOutput());
  probe->SetInput(structuredGrid);
  probe->Update();

  return 0;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110915/9add4d5f/attachment.htm>


More information about the vtkusers mailing list