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:<br>
<br>
<div style="margin-left: 40px;"><span style="font-family: courier new,monospace;"> if (stat(argv[1], &file_info) == -1) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> perror("Unable to stat file!\n\t");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return -1;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fptr = fopen(argv[1], "r");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if ((data = (char*)malloc(file_info.st_size)) == NULL) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> perror("Unable to allocate memory!\n\t");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return -1;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> dataptr = data;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fread(dataptr, 1, 4, fptr);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> dataptr += 4;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> printf("\n\n");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> for(int i=0; i<xdim; i++) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fread(dataptr, ydim,zdim, fptr);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> dataptr += (ydim * zdim);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> vtkImageImport *import = vtkImageImport::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> import->AddObserver(vtkCommand::ProgressEvent, progress);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> import->SetDataScalarTypeToUnsignedChar();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> import->SetNumberOfScalarComponents(1);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> import->SetWholeExtent(1, xdim-1,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
1, ydim-1,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
1, zdim-1);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> import->SetDataExtentToWholeExtent();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> import->SetImportVoidPointer(data + skip);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> vtkDataSetWriter *writer = vtkDataSetWriter::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> writer->SetInput(import->GetOutput());</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> writer->SetFileName("resulting.vtk");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> writer->Write();</span><br>
</div>
<br>
<br>
When I run this, however, the output VTK file only contains the following:<br>
<div style="margin-left: 40px;"><span style="font-family: times new roman,serif;"># vtk DataFile Version 3.0</span><br style="font-family: times new roman,serif;">
<span style="font-family: times new roman,serif;">vtk output</span><br style="font-family: times new roman,serif;">
<span style="font-family: times new roman,serif;">ASCII</span><br style="font-family: times new roman,serif;">
<span style="font-family: times new roman,serif;">DATASET STRUCTURED_POINTS</span><br style="font-family: times new roman,serif;">
<span style="font-family: times new roman,serif;">DIMENSIONS 2191 2191 800</span><br style="font-family: times new roman,serif;">
<span style="font-family: times new roman,serif;">SPACING 1 1 1</span><br style="font-family: times new roman,serif;">
<span style="font-family: times new roman,serif;">ORIGIN 1 1 1</span><br>
</div>
<br>
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. <br>
<br>
A stack trace of the core dumps only reveals this:<br><br>
<div style="margin-left: 40px; font-family: times new roman,serif;">[8:50:48am]% dbx imageimport<br>
dbx version 7.3.4 (86441_Nov11 MR) Nov 11 2002 11:31:55<br>
Core from signal SIGSEGV: Segmentation violation<br>
(dbx) where<br>
<br>
Thread 0x10000<br>
> 0 vtkDataArrayTemplate<unsigned
char>::ComputeScalarRange(int)(this = 0xf4eb83c0, comp = 0)
["/viz/home/rhand/src/ezViz/Utilities/VTK/Common/vtkDataArrayTemplate.txx":644,
0x85f2758]<br>
(dbx)<br>
(dbx) quit<br>
</div>
<br>
<br>
<br>-- <br>Randall Hand<br><a href="http://www.yeraze.com">http://www.yeraze.com</a>