[vtkusers] vtkImageImport Segfault

Mathieu Malaterre mathieu.malaterre at kitware.com
Fri May 27 11:31:47 EDT 2005


Randall,

	Could you instead give vtkImageReader a try. Just specify the lenght of 
data you want to read: 3,840,384,800 bytes. By default vtkImageReader 
start reading from the end. Thefore you are garantee to skip a header if 
any (4 bytes in your case apparently).

HTH
Mathieu

Randall Hand wrote:
> I'm attempting to load a simple "Brick of Bytes (BoB)" format file into 
> VTK.  It is 2191x2191x800 unsigned chars (3,840,384,800 bytes). With 4 
> bytes at the beginning that I have to skip (Gotta love fortran).  My 
> code is like the following:
> 
>     if (stat(argv[1], &file_info) == -1) {
>         perror("Unable to stat file!\n\t");
>         return -1;
>     }
>     fptr = fopen(argv[1], "r");
>     if ((data = (char*)malloc(file_info.st_size)) == NULL) {
>         perror("Unable to allocate memory!\n\t");
>         return -1;
>     }
>     dataptr = data;
>     fread(dataptr, 1, 4, fptr);
>     dataptr += 4;
>     printf("\n\n");
>     for(int i=0; i<xdim; i++) {
>         fread(dataptr, ydim,zdim,  fptr);
>         dataptr += (ydim * zdim);
>     }
> 
>     vtkImageImport *import = vtkImageImport::New();
>     import->AddObserver(vtkCommand::ProgressEvent, progress);
>     import->SetDataScalarTypeToUnsignedChar();
>     import->SetNumberOfScalarComponents(1);
>     import->SetWholeExtent(1, xdim-1,
>                            1, ydim-1,
>                            1, zdim-1);
>     import->SetDataExtentToWholeExtent();
>     import->SetImportVoidPointer(data + skip);
> 
>     vtkDataSetWriter *writer = vtkDataSetWriter::New();
>     writer->SetInput(import->GetOutput());
>     writer->SetFileName("resulting.vtk");
>     writer->Write();
> 
> 
> When I run this, however, the output VTK file only contains the following:
> # vtk DataFile Version 3.0
> vtk output
> ASCII
> DATASET STRUCTURED_POINTS
> DIMENSIONS 2191 2191 800
> SPACING 1 1 1
> ORIGIN 1 1 1
> 
> No data is actually written to the file.  When I try to connect this to 
> a rendering pipeline or start querying the resulting vtkDataSet for 
> properties (Scalar ranges, number of points, etc) I get strange results 
> and eventually I get Segfault/Core dumps.  Often times the number of 
> points listed comes out as a large negative number, instead of the 
> 3.8bil that it should be.
> 
> A stack trace of the core dumps only reveals this:
> 
> [8:50:48am]% dbx imageimport
> dbx version 7.3.4 (86441_Nov11 MR) Nov 11 2002 11:31:55
> Core from signal SIGSEGV: Segmentation violation
> (dbx) where
> 
> Thread 0x10000
>  >  0 vtkDataArrayTemplate<unsigned char>::ComputeScalarRange(int)(this 
> = 0xf4eb83c0, comp = 0) 
> ["/viz/home/rhand/src/ezViz/Utilities/VTK/Common/vtkDataArrayTemplate.txx":644, 
> 0x85f2758]
> (dbx)
> (dbx) quit
> 
> 
> 
> -- 
> Randall Hand
> http://www.yeraze.com
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list