[vtkusers] Reading a simple 3D tiff

Cory Quammen cquammen at cs.unc.edu
Tue May 29 11:11:02 EDT 2012


Andrew,

Try adding a call to

vtk_reader->SetFileDimensionality( 3 );

before calling Update().

If that doesn't work, you might have a TIFF file that VTK can't read.
These do exist. I have had better luck with reading 3D TIFF files
using ITK's ImageFileReader, so that might be an option for you.

You could also compile in debug mode, run it through the debugger, and
see where the seg fault is being produced.

- Cory

On Tue, May 29, 2012 at 10:27 AM, Andrew E Slaughter
<andrew.e.slaughter at gmail.com> wrote:
> 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
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



-- 
Cory Quammen
Research Associate
Department of Computer Science
The University of North Carolina at Chapel Hill



More information about the vtkusers mailing list