POV-Ray : Newsgroups : povray.general : density files : Re: density files Server Time
10 Aug 2024 03:24:27 EDT (-0400)
  Re: density files  
From: Nieminen Juha
Date: 21 Mar 2000 04:30:19
Message: <38d7412b@news.povray.org>
They are pretty simple, but you need to know some programming language
(which is able to write binary files) in order to do one. Currently you
can't do one with povray itself.
  The documentation helps here:

"The df3 format consists of a 6 byte header of three 16-bit integers
with high order byte first. These three values give the x,y,z size of
the data in pixels (or more appropriately called voxels). This is
followed by x*y*z unsigned integer bytes of data. The data in the
range of 0 to 255 is scaled into a float value in the range 0.0 to
1.0. It remains at 0.0 for all areas beyond the unit cube. The pattern
occupies the unit cube regardless of the dimensions in voxels."

  So suppose that you want to create a 64x64x64 density file.
  Open the destination .df3 file for binary writing and write the first
six bytes denoting the dimensions. As the documentation above says,
you should first output a 0 and then a 64, and this three times.
  Now output 64*64*64 values between 0 and 255. 0 means density 0.0 and
255 means density 1.0. The values will form a cube consisting of 64x64x64
smaller cubes (ie. 64 cubes per side).

  For example, if you want to create just a spherical density (density 1
at the center and 0 at the borders) you can do it in this way (with C):

  int XSize=64, YSize=64, ZSize=64;
  int indX, indY, indZ;
  double x, y, z, d;
  FILE* outfile = fopen("sphere.df3", "wb");

  fputc(XSize/256, outfile); fputc(XSize%256, outfile);
  fputc(YSize/256, outfile); fputc(YSize%256, outfile);
  fputc(ZSize/256, outfile); fputc(ZSize%256, outfile);

  for(indZ=0; indZ<ZSize; indZ++)
  {
    z = (indZ*2.0)/ZSize - .5; /* z goes from -1 to 1 */
    for(indY=0; indY<YSize; indY++)
    {
      y = (indY*2.0)/YSize - .5; /* y goes from -1 to 1 */
      for(indX=0; indX<XSize; indX++)
      {
        x = (indX*2.0)/XSize - .5; /* x goes from -1 to 1 */

        d = sqrt(x*x+y*y+z*z); /* distance from origin */
        if(d <= 1) /* if we are inside the unit sphere */
        {
          fputc((char)(255*(1-d)), outfile);
        }
        else
        {
          fputc(0, outfile);
        }
      }
    }
  }
  fclose(outfile);

  (NOTE: This program is untested)

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.