User:Wfpokorny/DensityFile/WriteDF3Example

From POV-Wiki
< User:Wfpokorny‎ | DensityFile
Revision as of 16:31, 18 August 2016 by Wfpokorny (talk | contribs) (Initial WriteDF3Example page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

As of release 3.7 a macro called ARRAYS_WriteDF3 has been available which can use internal arrays to create and external df3 file in 8 or 16 bit depths. The 32 bit write could not be implemented quickly in a platform independent way. What follows is a simple example using this macro to create, modify, read and print the internal df3 values. The df3 files can, for example, be used to store values render to render or frame to frame.

//---------- Start df3writeReadPrint.pov  -----
#version 3.7;
global_settings { assumed_gamma 1 }

#include "arrays.inc"

//--- Enable printing of some df3 values for this example.
#macro PrintDF3(_X,_Y,FileName)
   #local Pigment_df3 = pigment{
     density_file df3 FileName interpolate 0
   }
   #local Fn_df3 = function{ pigment{ Pigment_df3 }}

   // Access and print df3 values in x=row, y=column order
   #local Dx       =1/_X;
   #local DxVoxCtr =Dx/2;
   #local Dy       =1/_Y;
   #local DyVoxCtr =Dy/2;
   #debug "\n-------------------"
   #for (Y,0,_Y-1)
     #debug "\n"
     #for (X,0,_X-1)
       #local Xi=(X*Dx)+DxVoxCtr;
       #local Yi=(Y*Dy)+DyVoxCtr;
       #debug concat(str(Fn_df3(Xi,Yi,0.50).red,2,2)," ")
     #end
   #end
   #debug "\n-------------------\n"
#end

#declare Xn=10;
#declare Yn=5;

#declare Xn=10;
#declare Yn=5;

#declare AryXY =
 array[Xn][Yn]
 {//   x
  //   | y->
  //   v
     {0.01,0.02,0.03,0.04,0.05},
     {0.11,0.12,0.13,0.14,0.15},
     {0.21,0.22,0.23,0.24,0.25},
     {0.31,0.32,0.33,0.34,0.35},
     {0.41,0.42,0.43,0.44,0.45},
     {0.51,0.52,0.53,0.54,0.55},
     {0.61,0.62,0.63,0.64,0.65},
     {0.71,0.72,0.73,0.74,0.75},
     {0.81,0.82,0.83,0.84,0.85},
     {0.91,0.92,0.93,0.94,0.95}
 }

//--- Write/read/print initial array df3 file
#declare FileName="bits16.df3";
ARRAYS_WriteDF3(AryXY,FileName,16)
PrintDF3(Xn,Yn,FileName)

//--- Modify some internal array values to 0
#declare AryXY[0][2]=0;
#declare AryXY[1][2]=0;
#declare AryXY[2][2]=0;
#declare AryXY[3][2]=0;
#declare AryXY[4][2]=0;

//--- Write/read/print modified values
ARRAYS_WriteDF3(AryXY,FileName,16)
PrintDF3(Xn,Yn,FileName)

//--- Modify other internal array values to 1
#declare AryXY[5][2]=1;
#declare AryXY[6][2]=1;
#declare AryXY[7][2]=1;
#declare AryXY[8][2]=1;
#declare AryXY[9][2]=1;

//--- Write/read/print modified values
ARRAYS_WriteDF3(AryXY,FileName,16)
PrintDF3(Xn,Yn,FileName)

#debug "\n\n"
#error "Stop before actual render for demonstration code."
//---------- End df3writeReadPrint.pov  -----

When the above code is run we see this output:

-------------------
0.01 0.11 0.21 0.31 0.41 0.51 0.61 0.71 0.81 0.91 
0.02 0.12 0.22 0.32 0.42 0.52 0.62 0.72 0.82 0.92 
0.03 0.13 0.23 0.33 0.43 0.53 0.63 0.73 0.83 0.93 
0.04 0.14 0.24 0.34 0.44 0.54 0.64 0.74 0.84 0.94 
0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95 
-------------------

-------------------
0.01 0.11 0.21 0.31 0.41 0.51 0.61 0.71 0.81 0.91 
0.02 0.12 0.22 0.32 0.42 0.52 0.62 0.72 0.82 0.92 
0.00 0.00 0.00 0.00 0.00 0.53 0.63 0.73 0.83 0.93 
0.04 0.14 0.24 0.34 0.44 0.54 0.64 0.74 0.84 0.94 
0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95 
-------------------

-------------------
0.01 0.11 0.21 0.31 0.41 0.51 0.61 0.71 0.81 0.91 
0.02 0.12 0.22 0.32 0.42 0.52 0.62 0.72 0.82 0.92 
0.00 0.00 0.00 0.00 0.00 1.00 1.00 1.00 1.00 1.00 
0.04 0.14 0.24 0.34 0.44 0.54 0.64 0.74 0.84 0.94 
0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95 
-------------------