[vtkusers] Reading a simple 3D tiff
Andrew E Slaughter
andrew.e.slaughter at gmail.com
Tue May 29 10:27:02 EDT 2012
I am receiving segmentation faults when trying to read a 3D *.tif file
with vtkTIFFReader. This seems like a simple problem but I can't
figure out what to do next, the list seems to have a number of
unresolved posts on this issue.
I would like to open a *.tif file and convert it to a vtkImageData
object. Here is what I have that seems to me should work.
#include <string>
using std::string;
#include <vtkSmartPointer.h>
#include <vtkTIFFReader.h>
#include <vtkImageData.h>
int main(){
// Test file (4 x 4 x 4 cube with the inner 2 x 2 x 2 set to 1
the rest is 0; the file opens correctly with ImageJ)
string input_file("../data/v2m/input/test.tif");
// Create VTK pointers for reader and image object
vtkSmartPointer<vtkTIFFReader> vtk_reader =
vtkSmartPointer<vtkTIFFReader>::New();
vtkSmartPointer<vtkImageData> vtk_image = vtkSmartPointer<vtkImageData>::New();
// Test if the file is readable (returns 3)
int readable = vtk_reader->CanReadFile(input_file.c_str());
printf("Can read: %d\n", readable);
// Read the file and store in the VTK image object
vtk_reader->SetFileName(input_file.c_str());
vtk_reader->SetOutput(vtk_image);
vtk_reader->Update(); //
Segmentation fault here
}
This produces the following output:
Can read: 3
Segmentation fault (core dumped)
Any help is greatly appreciated.
Thanks,
Andrew
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.tif
Type: image/tiff
Size: 812 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120529/72ccc110/attachment.tif>
More information about the vtkusers
mailing list