

Le 16/02/2014 23:38, Bertrand nous fit lire :
> Dear Povray community,
>
> I am trying to write a small program in Fortran to have a density .df3 file. I
> have read the different post on the topic but I still do not understand the data
> that should be written in this file.
> I am posting an example of what I am doing in fortran at the end of this post. I
> force the unformatted file to be written in bigendian format with the
> compiler.
> The written data is:
> header: 6 byte three times 16bit integers
> data: 6 byte three times integer and one real at the end (the actual density)
>
> in ASCII, what is written is
>
> 10 10 10 (the size of the lattice)
> 1 1 1 0.5d0
> 1 2 1 0.4d0
> .....
>
> one value of the density per box (that you call voxel) per line. There are
> several things I would like to ask.
>
>  is it the good format ;)? (first question of course)
>  what if the density has a position that can only be expressed in terms of
> double precision number?
>  How does povray places the density on the actual graph?
>
> I am sorry if these questions were treated already but I could not find them but
> it is the first time that I am trying something this with povray and I am really
> in the mist.
>
> Thanks a lot for your help,
> Bertrand
>
>
My Fortran is rusted.
The df3 reader is inside source/backend/pattern/pattern.cpp, in
Read_Density_File function (for sources of povray 3.7)
The file start with the number of sampling in each axis of a Unit cube.
These numbers are unsigned 16 bits, Most significant byte first.
Let's call them Xn, Yn and Zn.
Then there is Xn*Yn*Zn sample values (more on that in a few lines): the
cube is explored with an external loop on Z, the intermediate on Y and
the inner on X.
There is no associated coordinates with a sample, it's implicit by the
position in the file/sequence.
do i_z = 1, Zn
do i_y = 1, Yn
do i_x = 1, Xn
write single value around < (i_x0.5)/Xn, (i_y0.5)/Yn, (i_z0.5)/Zn >
enddo
enddo
enddo
Now, about the sample value, there can either be:
* 1 byte, unsigned
* 2 bytes, 16 bits unsigned, most significant byte first
* 4 bytes, 32 bits unsigned, most significant byte first
The choice is made once and for all values, and the detection uses the
total file length to recover the choice (you cannot pipe a density
file). If the file is incomplete, it's an error.
The sample value ranges from 0 to Max, but that range is transposed,
whatever the number of bits of the value, into a 0 to 1 range, as a DBL
(usually a floating point with 64 bits, 11 exponent and 52 mantissa, per
IEEE754).
Then povray might use different interpolations when computing the actual
value of a point inside the unitcube:
* none : value of nearest center of cell
* trilinear : take a cube of 8 compact cells (2x2x2) and perform linear
interpolation on the 3 axes between the 8 values. (the cube is an
hypertorus as faces wrap when near 1)
* tricubic : take a cube of 64 compact cells (4x4x4)... (once again,
cube is rather an hypertorus)
>
OPEN(70,FILE=fname,action='write',status='unknown',form='unformatted',access="direct",recl=6*(3+product(dim_lat)))
>
> Write(70,rec=1) (dim_lat(i),i=1,3)
>
> do i_x=1,dim_lat(1)
> do i_y=1,dim_lat(2)
> Write(70,rec=i_y+(i_x1)*dim_lat(2))
> (Spin(k,i_x,i_y),k=1,2),1,toto(i_x,i_y)/pi(4.0d0)/surface
> enddo
> enddo
> close(70)
>
>
Post a reply to this message

