User:Wfpokorny/DensityFile/DepthMap64BitDf3RsltStoreExample

From POV-Wiki
Jump to navigation Jump to search

A 10x10 orthogonal, 64 bit, depth map using a few arraycoupleddf3s.inc macros.

The example prints trace(), vlength, depth values. The values are then stored in a df3 file after which a function is used to access and print the stored values. Lastly, it reads the created df3 into a second array and then writes a duplicate df3 file.

//----------------------------- Start example ---------------------------------------
#version 3.7;
global_settings { assumed_gamma 1 }

#include "arrays.inc"           // For ARRAYS_WriteDF3()
#include "arraycoupleddf3s.inc" // Array coupled df3 macros & functions.

#declare Sphere00=sphere { <0,0,10> 1.0 }
#declare Xn=10;
#declare Yn=10;
#declare Zn=9;
#declare AryDepth=array[Xn][Yn][Zn];
#declare Dx=1/Xn;
#declare Dy=1/Yn;
#declare Dz=1/Zn;
#declare Norm=<0,0,0>;
#declare Range=20.0;   // Using DBL's accuracy over limited range.
#for (Y,0,Yn-1)
  #debug "\n"
  #for (X,0,Xn-1)
    #local Xr=-0.5+(X*Dx)+(Dx/2);
    #local Yr=-0.5+(Y*Dy)+(Dy/2);
    #local tmpVal=vlength(trace(Sphere00,<Xr,Yr,0>,<0,0,1>,Norm)-<Xr,Yr,0>);
    NxNx9DBLtoArrayEntry(AryDepth,X,Y,Range,tmpVal)
    #debug concat(str(tmpVal,0,4)," ")
  #end
#end
#debug "\n"

#declare DepthFileName="Depth.df3";
ARRAYS_WriteDF3(AryDepth,DepthFileName,8) // Write +-64bit encoded depth measures

#declare FnctDepthDF3=function{
  pattern{density_file df3 DepthFileName interpolate 0}
}
#declare FnctDepth=FnctNxNx9ArrayEntryToDBL(AryDepth,FnctDepthDF3)
//--- Write the DF3 stored DBL values to the screen.
#for (Y,0,Yn-1)
  #debug "\n"
  #for (X,0,Xn-1)
    #local Xi=(X*Dx)+(Dx/2);
    #local Yi=(Y*Dy)+(Dy/2);
    #debug concat(str(FnctDepth(Xi,Yi,Dz,Range),0,4)," ")
  #end
#end

//--- Read the stored DF3 values into second array
#declare AryDepth2=array[Xn][Yn][Zn];
ARRAYS_ReadDF3(AryDepth2,DepthFileName)

//--- And write a duplicate DF3 file
#declare DepthFileName2="Depth2.df3";
ARRAYS_WriteDF3(AryDepth2,DepthFileName2,8)

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