#include <stdio.h>
#include <iostream>
using std::cerr;
static void
{
cerr << "Usage: " << program << "\n\t-t <light transform> \n";
cerr << "\t-x <x resolution> -y <y resolution>\n";
cerr << "\t-l <projection type> <focal length> <aperture> <ortho width>\n";
cerr << "\t-i <I3D file>\n";
cerr << "\t-f <DSM file>\n";
cerr << "\t[-s <Step size>]\n";
cerr << "\t[-d <Max Depth>]\n";
}
static void
float dist,
float step,
float tau)
{
float pixel[3];
float den, pden, zval, zinc;
int i, nsteps;
p0 = orig;
p1 = orig + dist*dir;
if (
dot(p1-p0, dir) <= 0)
return;
nsteps = (
int)((p1-p0).length() / step);
#if 0
fprintf(stderr,
"Integrating %d steps (from %f %f %f to %f %f %f)\n",
nsteps, p0[0], p0[1], p0[2], p1[0], p1[1], p1[2]);
#endif
pden = 0;
zinc = step*dir.length();
for (i = 0; i < nsteps; i++)
{
den = 0;
i1 = p0 + (
float)i*step*dir;
den *= tau*step;
if (den > 0)
{
pden = den + (1-den)*pden;
pixel[0] = pixel[1] = pixel[2] = pden;
#if 0
fprintf(stderr,
"Storing pixel data: %f %f %f %f\n",
pixel[0], pixel[1], pixel[2], pixel[3]);
#endif
}
zval += zinc;
}
}
int
{
float dist, step, zoom, xwin, ywin, tau, orthow;
const char *fname;
const char *iname;
int xres, yres;
bool ortho = true;
dist = 1000;
tau = 1;
step = 0.05;
orthow = 1;
fname = iname = 0;
{
{
cerr << "Invalid transform parameters "
"(example: [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])\n";
return 1;
}
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
trans(i, j) = atof(argv[i*4+j]);
}
else
{
cerr << "Must specify global transformation (-t)\n";
return 1;
}
{
xres = args.
iargp(
'x', 0);
yres = args.
iargp(
'y', 0);
ortho = args.
iargp(
'l', 0) == 1;
if (ortho)
{
orthow = args.
fargp(
'l', 3);
zoom = 1;
}
else
{
if (args.
fargp(
'l', 2) == 0)
{
cerr << "Must specify non-zero light aperture\n";
return 1;
}
}
}
else
{
cerr << "Must specify light parameters\n";
return 1;
}
if (!fname || !iname)
{
cerr << "Must specify DSM and I3D file names\n";
return 1;
}
{
cerr << "Could not open I3D texture " << iname << "\n";
return 1;
}
{
cerr << "Could not open density channel of " << iname << "\n";
return 1;
}
std::cout << "Creating DSM " << fname << " from i3d " << iname << "\n";
xwin = orthow * 0.5F / zoom;
ywin = xwin * (yres / (
float)xres);
dsm.
setOption(
"depth_planes",
"zfront,zback");
dsm.
create(fname, xres, yres, 1, 1);
if (!ortho)
{
for (j = 0; j < yres; j++)
{
for (i = 0; i < xres; i++)
{
dir =
UT_Vector3(xwin*2*(i+0.5F)/(
float)xres-xwin,
ywin*2*(j+0.5F)/(float)yres-ywin, -1);
fillPixel(writer, i3d, orig, dir, dist, step, tau);
}
}
}
else
{
for (j = 0; j < yres; j++)
{
for (i = 0; i < xres; i++)
{
orig =
UT_Vector3(xwin*2*(i+0.5F)/(
float)xres-xwin,
ywin*2*(j+0.5F)/(float)yres-ywin, 0);
fillPixel(writer, i3d, orig, dir, dist, step, tau);
}
}
}
return 0;
}