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).&nbsp; My code is like the following:<br>
<br>
<div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; if (stat(argv[1], &amp;file_info) == -1) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror(&quot;Unable to stat file!\n\t&quot;);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; fptr = fopen(argv[1], &quot;r&quot;);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; if ((data = (char*)malloc(file_info.st_size)) == NULL) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror(&quot;Unable to allocate memory!\n\t&quot;);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; dataptr = data;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; fread(dataptr, 1, 4, fptr);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; dataptr += 4;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; printf(&quot;\n\n&quot;);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; for(int i=0; i&lt;xdim; i++) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread(dataptr, ydim,zdim,&nbsp; fptr);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dataptr += (ydim * zdim);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; vtkImageImport *import = vtkImageImport::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; import-&gt;AddObserver(vtkCommand::ProgressEvent, progress);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; import-&gt;SetDataScalarTypeToUnsignedChar();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; import-&gt;SetNumberOfScalarComponents(1);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; import-&gt;SetWholeExtent(1, xdim-1,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1, ydim-1,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1, zdim-1);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; import-&gt;SetDataExtentToWholeExtent();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; import-&gt;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;">&nbsp;&nbsp;&nbsp; vtkDataSetWriter *writer = vtkDataSetWriter::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; writer-&gt;SetInput(import-&gt;GetOutput());</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; writer-&gt;SetFileName(&quot;resulting.vtk&quot;);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; writer-&gt;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.&nbsp; 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.&nbsp; 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>
&gt;&nbsp; 0 vtkDataArrayTemplate&lt;unsigned
char&gt;::ComputeScalarRange(int)(this = 0xf4eb83c0, comp = 0)
[&quot;/viz/home/rhand/src/ezViz/Utilities/VTK/Common/vtkDataArrayTemplate.txx&quot;: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>