How to integrate spline evaluation module into POV-Ray?
- The following process is based on
“How to add own internal function”
(by Wlodzimierz ABX Skiba).
Note that
the
green parts need to be replaced
by the user with proper stuff.
-
Download spline evaluation module
(eval_spline_6dir_FCC.cpp)
in $POVRAYSRCPATH$/source
(where fnintern.cpp is located).
($POVRAYSRCPATH$/source
is the path where the POV-Ray source files are located.)
-
Open the file fnintern.cpp.
-
Add the function declaration at the beginning
in the "Global functions" list.
DBL f_eval_spline_6dir_FCC(DBL *ptr, unsigned int fn);
-
Append the function pointer at the end of the array variable
POVFPU_TrapTable[].
Note that the position in the array becomes the function id of that function.
You can find the index for each function pointers in POVFPU_TrapTable[]
at each line.
This id will be used later when modifying $POVRAYSRCPATH$/include/functions.inc.
{ f_eval_spline_6dir_FCC, 0 + 4 },
-
Increase the value of the variable POVFPU_TrapTableSize by 1.
-
Implement the body of the function
DBL f_eval_spline_6dir_FCC(DBL *ptr, unsigned int).
Below is an example which loads (only once)
the FCC dataset in the global variable g_dataset_fcc.
The dataset is assumed to be stored in the absolute path
FULL_PATH_WHERE_DATASET_IS_STORED.
Various ways of loading dataset is possible.
#include "eval_spline_6dir_FCC.cpp"
TFCC g_dataset_fcc;
DBL f_eval_spline_6dir_FCC(DBL *ptr, unsigned int)
{
double p[3] = {PARAM_X, PARAM_Y, PARAM_Z};
static bool dataset_loaded = false;
if(!dataset_loaded)
{
printf("\ndataset about to be loaded\n");
if(load_fcc(g_dataset_fcc,"FULL_PATH_WHERE_DATASET_IS_STORED"))
{
printf("\ndataset loaded successfully\n");
report_fcc(g_dataset_fcc);
}
else
{
printf("\ndataset failed to be loaded\n");
}
dataset_loaded = true;
}
return eval_spline_6dir_FCC(g_dataset_fcc,p, PARAM(0));
}
-
Now it's time to connect the function id to the actual function name
so that the POV-Ray engine can recognize it.
Open
$POVRAYSRCPATH$/include/functions.inc
and insert the following
where FUNCTION_ID is the function id
obtained above.
#declare f_eval_spline_6dir_FCC = function{internal(FUNCTION_ID)};
-
Rebuilt POV-Ray by make install in $POVRAYSRCPATH$.
unpacked vs. packed file format
When considering the FCC lattice as a sub-lattice of Cartesian lattice (as integer lattice)
such that the sum of coordinates is even, we can store the FCC dataset
in a 3D array but ends up wasting about half of the space.
On the other hand, on any all-even coordinate lattice point
(2i,2j,2k),
which is also an FCC lattice point,
we can group four points
(2i,2j,2k),
(2i,2j+1,2k+1),
(2i+1,2j,2k+1) and
(2i+1,2j+1,2k)
and cover the whole FCC lattice points.
In this way we waste only small amount of storage (even no waste in some cases).
Therefore, in packed file format, we store the FCC dataset in a 4D array
with their indices mapped as follows:
(mod and ⌊⋅⌋
are the modulo and floor operators, respectively.)
-
if mod((x,y,z),2) == (0,0,0) then
(x,y,z) → (⌊x/2⌋,⌊y/2⌋,⌊z/2⌋,0)
-
if mod((x,y,z),2) == (0,1,1) then
(x,y,z) → (⌊x/2⌋,⌊y/2⌋,⌊z/2⌋,1)
-
if mod((x,y,z),2) == (1,0,1) then
(x,y,z) → (⌊x/2⌋,⌊y/2⌋,⌊z/2⌋,2)
-
if mod((x,y,z),2) == (1,1,0) then
(x,y,z) → (⌊x/2⌋,⌊y/2⌋,⌊z/2⌋,3)