[vtkusers] 3D TIFF -> STL

Gib Bogle g.bogle at auckland.ac.nz
Wed Jan 4 17:05:50 EST 2012


Since GetFileDimensionality() returns 2, when I expect 3, I'm wondering if 
either ITK is saving my 3D TIFF as a 2D VTK image file, or VTK does not read a 
3D image.

I'd be grateful if someone could tell me how to get a 3D segmented image into 
VTK, so that I can use vtkContourFilter on it.

Thanks
Gib

On 4/01/2012 10:18 p.m., Gib Bogle wrote:
> I am wanting to generate a stereolithographic (STL) file from a 3D binary TIFF 
> file (containing only 0 and 255).  I found a suggestion that the steps are as 
> follows:
>
> 1. In ITK, read TIFF and write VTK file
> 2. In VTK, read VTK file and create a surface mesh using vtkContourFilter
> 3. Save the mesh with vtkSTLWriter
>
> I have created test.vtk from test.tif, by simply providing this filename to 
> itk::ImageFileWriter.  Apparently since test.vtk contains image data, it 
> should be possible to read it with vtkImageReader (or vtkImageReader2).  I've 
> written code to read test.vtk, run it through vtkContourFilter and write the 
> result out with vtkSTLWriter, but the resulting STL file contains no 
> triangles.  The reason, I see, is that GetDataExtent() returns an array of 
> 0s.  Clearly the vtk file is not being read correctly.
>
>   vtkSmartPointer<vtkImageReader2> reader = 
> vtkSmartPointer<vtkImageReader2>::New();
>   reader->SetFileName(inputFilename.c_str());
>   reader->Update();
>   int ext[6];
>   reader->GetDataExtent(ext);
>   printf("Data extent: %d %d %d %d %d 
> %d\n",ext[0],ext[1],ext[2],ext[3],ext[4],ext[5]);
>
> I see from the FAQ that VTK can read a couple of different 3D VTK file 
> formats, VTK Structured Grid and VTK Poly Data.  Clearly my test.vtk is 
> neither of these - it's an image file.  I also see mention of "VTK legacy file 
> format", which makes me wonder if I'm trying to do something that is no longer 
> supported.
>
> I'm sure there is a simple explanation ...
>
> Thanks
> Gib



More information about the vtkusers mailing list