2
votes

I am trying to create a gray-scale .inr image for the cgal library, but I am having trouble with the file format.
This seems to be the best description of the format, but it does not look like it is complete and only talk about the header, not the data itself.
This seems to have a bit more information about the format, but unfortunately it is in French.

What I am trying to do is to represent an object as a 3D array filled with boolean, so a position would have value 1 if it is inside the object and 0 if it is outside.

What I have done for now, based on the second link if I understood it correctly, is to write after the header each z plane on a line, with the next z plane on a new line.
So I have the x values of the columns on a line representing the first row, then the x values of the second row on the same line, and like that y times till the last row. I then jump a line for the new z plane and write the data in the same way.

I have created the following .inr file, but when I try to mesh it, the result is a cube instead of a cylinder, as if cgal (I used mesh_optimization_lloyd_example) did not care about the boolean values and just meshed the whole volume.

I tried looking at the .inr files provided with the examples (like skull_2.9.inr), but while the header was perfectly legible, no text editor could read the image data, which makes me think there might be something more than just writing 0s or 1s.

Is it something about the .inr that is wrong? Or maybe I am using cgal wrong?

1

1 Answers

3
votes

I've finally managed to make it work, here is what is needed in case it helps someone.

Header: It must be a multiple of 256 bytes, including the carriage return after the end of the header, here is an example.

#INRIMAGE-4#{ // format type
XDIM=150 // x dimension
YDIM=200 // y dimension
ZDIM=100 // z dimension
VDIM=1 // dimension of the data, here 1 for scalar or 3 for thing like RGB values
VX=5 // voxel size in x
VY=5 // voxel size in y
VZ=5 // voxel size in z
// a higher voxel size results in a more precise 3D mesh
TYPE=unsigned fixed // type of data written, can float, signed fixed or unsigned fixed, unclear if it makes a difference in my case
SCALE=2**0 // not used by most programs apparently
PIXSIZE=8 bits // size of a char, can be 8, 16, 32 or 64
CPU=pc // the type of cpu for little/big endianness, pc is little endian

// Fill with carriage returns until the header is a multiple of 256 bytes, including the end of the header (4 bytes including the line break)

##} // the line break is included in the header count

Now the data itself:
Despite what the documentation seems to imply, there are no line breaks in it, everything is contiguous. The data must be written in binary and not ASCII (so in my case in C++ this would be static_cast(space[i][j][k])), replace the char with the type of data you use).

One last quirk, the file seems to be in column-major order, so if you have a 3d array in C (which is row-major) you need to transpose the (x,y) planes before writing them.