|
|
First shot at it
Ingo
---8<---8<---
#version 3.7;
#macro Arraytopgm16(Array, Filename)
/*
Marcro to write 16 bit (greyscale) .pgm files from a 2d array.
Array: 2 dimensional array
Filename: Name of file the data are written to
Uninitialised elements of the array are written as 0. Content of
arrays are
not scaled to fit max range nor any gamma-correction is done.
Maxvalue in
header is always set to 65535. It is to the user to provid a
fitting array.
.pgm file header:
magic number in ASCII( 'P5' = fixed)
width height in ASCII (dimension_sizes from Array)
maxvalue in ASCII (65535 = fixed)
values 16 bit unsigned, big endian
*/
#if (dimensions(Array)!=2)
#error "Arraytopgm16: not the right array dimension, needs 2\n"
#end
#local SizeX = dimension_size(Array,1); //test for zero?
#local SizeY = dimension_size(Array,2);
#fopen Fpgm Filename write
#write (Fpgm, "P5\n", SizeX," ", SizeY,"\n65535\n")//.pgm header
#for (IndY, 0, SizeY-1)
#for(IndX, 0, SizeX-1)
#ifdef(Array[IndX][IndY])
#local Value = Array[IndX][IndY]; //test for value
#else
#local Value = 0;
#end
#write (Fpgm, uint16be Value)
#end
#end
#fclose Fpgm
#end
global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}
#declare MyGrid = array[50][50]
#declare MyGrid[25][25]=65535;
Arraytopgm16(MyGrid,"test.pgm")
height_field {
pgm "test.pgm"
smooth
double_illuminate
translate<-0.5,-0.0,-0.5>
texture{pigment{rgb 1}}
scale<10,10,10>
}
light_source{< 3000,3000,-3000> rgb 1}
camera {
perspective angle 55
location <0 , 15 ,-15>
right x*image_width/image_height
look_at <0,0,0>
}
Post a reply to this message
|
|