Well, I have an addition 4 bytes at the end of the file to skip as
well.. I suppose I could postprocess & write a new file without
these final 4 bytes, but that's gonna be pretty wasteful of disk
space. Is there a way to skip them?<br>
<br>
<br><br><div><span class="gmail_quote">On 5/27/05, <b class="gmail_sendername">Mathieu Malaterre</b> <<a href="mailto:mathieu.malaterre@kitware.com">mathieu.malaterre@kitware.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Randall,<br><br> Could you instead give vtkImageReader a try. Just specify the lenght of<br>data you want to read: 3,840,384,800 bytes. By default vtkImageReader<br>start reading from the end. Thefore you are garantee to skip a header if
<br>any (4 bytes in your case apparently).<br><br>HTH<br>Mathieu<br><br>Randall Hand wrote:<br>> I'm attempting to load a simple "Brick of Bytes (BoB)" format file into<br>> VTK. It is 2191x2191x800 unsigned chars (3,840,384,800 bytes). With 4
<br>> bytes at the beginning that I have to skip (Gotta love fortran). My<br>> code is like the following:<br>><br>> if (stat(argv[1], &file_info) == -1) {<br>> perror("Unable to stat file!\n\t");
<br>> return -1;<br>> }<br>> fptr = fopen(argv[1], "r");<br>> if ((data = (char*)malloc(file_info.st_size)) == NULL) {<br>> perror("Unable to allocate memory!\n\t");
<br>> return -1;<br>> }<br>> dataptr = data;<br>> fread(dataptr, 1, 4, fptr);<br>> dataptr += 4;<br>> printf("\n\n");<br>> for(int i=0; i<xdim; i++) {<br>> fread(dataptr, ydim,zdim, fptr);
<br>> dataptr += (ydim * zdim);<br>> }<br>><br>> vtkImageImport *import = vtkImageImport::New();<br>> import->AddObserver(vtkCommand::ProgressEvent, progress);<br>> import->SetDataScalarTypeToUnsignedChar();
<br>> import->SetNumberOfScalarComponents(1);<br>> import->SetWholeExtent(1, xdim-1,<br>> 1,
ydim-1,<br>> 1,
zdim-1);<br>> import->SetDataExtentToWholeExtent();<br>> import->SetImportVoidPointer(data + skip);<br>><br>> vtkDataSetWriter *writer = vtkDataSetWriter::New();<br>> writer->SetInput(import->GetOutput());
<br>> writer->SetFileName("resulting.vtk");<br>> writer->Write();<br>><br>><br>> When I run this, however, the output VTK file only contains the following:<br>> # vtk DataFile Version
3.0<br>> vtk output<br>> ASCII<br>> DATASET STRUCTURED_POINTS<br>> DIMENSIONS 2191 2191 800<br>> SPACING 1 1 1<br>> ORIGIN 1 1 1<br>><br>> No data is actually written to the file. When I try to connect this to
<br>> a rendering pipeline or start querying the resulting vtkDataSet for<br>> properties (Scalar ranges, number of points, etc) I get strange results<br>> and eventually I get Segfault/Core dumps. Often times the number of
<br>> points listed comes out as a large negative number, instead of the<br>> 3.8bil that it should be.<br>><br>> A stack trace of the core dumps only reveals this:<br>><br>> [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
<br>> = 0xf4eb83c0, comp = 0)<br>> ["/viz/home/rhand/src/ezViz/Utilities/VTK/Common/vtkDataArrayTemplate.txx":644,<br>> 0x85f2758]<br>> (dbx)<br>> (dbx) quit<br>><br>><br>><br>> --<br>
> Randall Hand<br>> <a href="http://www.yeraze.com">http://www.yeraze.com</a><br>><br>><br>> ------------------------------------------------------------------------<br>><br>> _______________________________________________
<br>> This is the private VTK discussion list.<br>> Please keep messages on-topic. Check the FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a><br>> Follow this link to subscribe/unsubscribe:
<br>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a><br><br></blockquote></div><br><br><br>-- <br>Randall Hand<br><a href="http://www.yeraze.com">http://www.yeraze.com
</a>