[vtkusers] vtkImageImport Segfault

Randall Hand randall.hand at gmail.com
Fri May 27 10:24:35 EDT 2005


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050527/ddc8747d/attachment.htm>


More information about the vtkusers mailing list