#! /usr/bin/gawk -f # Last edited on 2020-03-08 11:05:43 by jstolfi # Reads a file with Vicon marker positions sampled at multiple times. # Creares a ".pov" file for each sampling time, with those positions # formatted as a POV-Ray array. # Assumes that each line of the file is one /data frame/ corresponding to one sampling time. # It has two integers (frame and sub-frame index) then the coordinates of {N=20} markers, # (in mm, relative to the scene coordinate system). # Caller must define (with -v {NAME}={VALUE}): # {skip} Number of data frames to skip at the start of the file. # {step} Subsampling factor: process only one frame out of {step}. # {maxims} Max number of frames to generate. BEGIN { skip = skip + 0; step = step + 0; maxims = maxims + 0; ndf = 0; # Num data frames read. nims = 0; # Num movie frames written. M = 20; # Number of markers. split("", ctr) # Average of all markers in first frame. } # Exit if done: (nims >= maxims) { exit(0); } # Ignore blank and comment lines: /^[ ]*($|[#])/ { next; } /[0-9]/ { # Data frame line. if (NF != 62) { printf "%s:%d: ** bad NF = %d\n", FILENAME, FNR, NF > "/dev/stderr"; exit(1); } if ((ndf > skip) && ((ndf - skip) % step) == 0) { # Process this line. fname = sprintf("out/%s_frame_%06d.pov", wkname, nims); printf "#version 3.7;\n" >> fname; printf "global_settings{ max_trace_level 6 assumed_gamma 1.0 }\n" >> fname; printf "background{ color rgb < 0.005, 0.005, 0.005 > }\n" >> fname; printf "#include \"nmhus_textures.inc\"\n" >> fname; printf "#include \"homunculus.inc\"\n" >> fname; printf "#declare XYZ = array[%d] {\n", M >> fname; for (k = 0; k < M; k++) { if ( k > 0) { printf ",\n" >> fname; } X = $(3+3*k); Y = $(4+3*k); Z = $(5+3*k); printf " < %4.0f, %4.0f, %4.0f >", X, Y, Z >> fname; if (nims == 0) { ctr[0] += X; ctr[1] += Y; ctr[2] += Z; } } if (nims == 0) { ctr[0] /= M; ctr[1] /= M; ctr[2] /= M; } printf "\n" >> fname; printf " }\n" >> fname; printf "object{ homunculus(XYZ, tx_bleu) }\n" >> fname; printf "#include \"camlight.inc\"\n" >> fname; printf "#declare centro_cena = < %.0f, %.0f, %.0f >;\n", ctr[0], ctr[1], ctr[2] >> fname; printf "#declare raio_cena = 2400.0;\n" >> fname; printf "#declare dir_camera = < +20.00, -30.00, +10.00 >;\n" >> fname; printf "#declare dist_camera = 10*raio_cena;\n" >> fname; printf "#declare intens_luz = 1.20;\n" >> fname; printf "camlight(centro_cena, raio_cena, dir_camera, dist_camera, z, intens_luz)\n" >> fname; close(fname); nims++; } ndf++; next; } // { printf "%s:%d: ** bad format [%s]\n", FILENAME, FNR, $0 > "/dev/stderr"; exit(1); } END { printf "%8d data frames read\n", ndf > "/dev/stderr"; printf "%8d movie frames created\n", ndf > "/dev/stderr"; }