home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascender.tar.Z
/
ascender.tar
/
Triangulate
/
fbip.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-13
|
5KB
|
196 lines
/*
* HISTORY
*
* 30-Dec-94 Chris McGlone (jcm) at the Digital Mapping Laboratory,
* School of Computer Science at Carnegie-Mellon University.
* Installed. Originally supplied by Lynn Quam (quam@ai.sri.com)
* for use with classified RADIUS imagery.
*
*/
#include "fbip.h"
#define DEBUG_HEIGHT 0
COORDINATE *make_coordinate_vector ()
{
return ((COORDINATE *) malloc(3*sizeof(COORDINATE)));
}
int fbip_project_in_block (fbip, coeffs, from_position, to_position)
FBIP fbip;
double *coeffs;
COORDINATE *from_position, *to_position;
{
double x, y, z0, z;
double **hic;
int n_levels = fbip->n_levels;
int level, ci;
double u, v;
if (to_position == 0) {to_position = make_coordinate_vector();}
x = from_position[0]; y = from_position[1]; z0 = from_position[2];
z = z0 - fbip->zorg;
/*
printf("inside block 1 \n");
*/
hic = fbip->height_interpolation_coeffs;
u = 0.0; v = 0.0;
for (level = 0, ci=0; level<n_levels; level++, ci+=8){
double coeff, cz, denom, ul, vl;
int power; double zn;
/*
printf("inside block 2 \n");
*/
/* compute u,v for this level by interpolation */
denom = x*coeffs[ci+6] + y*coeffs[ci+7] + 1.0;
ul = (x*coeffs[ci ] + y*coeffs[ci+1] + coeffs[ci+2]) / denom;
vl = (x*coeffs[ci+3] + y*coeffs[ci+4] + coeffs[ci+5]) / denom;
/* calculate this portion of the height interpolation */
for (power = 0, zn = 1.0; power < n_levels; power++, zn = zn*z){
coeff = hic[power][level];
cz = coeff*zn;
u += ul*cz;
v += vl*cz;
/*
printf("inside block 3 \n");
*/
}
}
to_position[0] = u;
to_position[1] = v;
return(1);
}
double *fbip_compute_inverse_block_projective_coeffs_array (coeffs, inv_coeffs, n)
double *coeffs, *inv_coeffs;
int n;
{
double a,b,c,d,e,f,g,h,q;
int j;
for (j = 0; j < n; j+=8)
{a = coeffs[j];
b = coeffs[j+1];
c = coeffs[j+2];
d = coeffs[j+3];
e = coeffs[j+4];
f = coeffs[j+5];
g = coeffs[j+6];
h = coeffs[j+7];
q = 1.0 / (b*d - a*e);
inv_coeffs[j] = q * (f*h - e);
inv_coeffs[j+1] = q * (b - c*h);
inv_coeffs[j+2] = q * (c*e - b*f);
inv_coeffs[j+3] = q * (d - g*f);
inv_coeffs[j+4] = q * (c*g - a);
inv_coeffs[j+5] = q * (a*f - c*d);
inv_coeffs[j+6] = q * (e*g - d*h);
inv_coeffs[j+7] = q * (a*h - b*g);
}
return(inv_coeffs);
}
int fbip_project_to_world (fbip, view_position, world_position)
FBIP fbip;
COORDINATE *view_position, *world_position;
{
int ui, vi;
double *coeffs, *inv_coeffs;
inv_coeffs = fbip->inv_coeffs;
ui = (int) ((view_position[0] - fbip->umin) / fbip->du);
vi = (int) ((view_position[1] - fbip->vmin) / fbip->dv);
ui = ui<0 ? 0 : (ui>=fbip->blocks_wide ? fbip->blocks_wide-1 : ui);
vi = vi<0 ? 0 : (vi>=fbip->blocks_hi ? fbip->blocks_hi-1 : vi);
coeffs = fbip->block_projective_coeffs_array[ui][vi];
inv_coeffs = fbip_compute_inverse_block_projective_coeffs_array(coeffs, inv_coeffs,
8*fbip->n_levels);
fbip_project_in_block(fbip, inv_coeffs, view_position, world_position);
world_position[0] += fbip->xorg;
world_position[1] += fbip->yorg;
world_position[2] = view_position[2];
return (1);
}
void fbip_make_arrays (fbip)
FBIP fbip;
{
int i,j, ncoeffs, n_levels, blocks_wide, blocks_hi;
double ***block_projective_coeffs_array;
double **height_interpolation_coeffs;
blocks_wide = fbip->blocks_wide;
blocks_hi = fbip->blocks_hi;
n_levels = fbip->n_levels;
ncoeffs = 8*n_levels;
block_projective_coeffs_array = (double ***) malloc(blocks_wide * sizeof(double **));
for (i=0; i<blocks_wide; i++)
{block_projective_coeffs_array[i] = (double **) malloc (blocks_hi * sizeof(double *));
for (j = 0; j<blocks_hi; j++)
{block_projective_coeffs_array[i][j] = (double *) malloc (ncoeffs * sizeof(double));
}}
fbip->block_projective_coeffs_array = block_projective_coeffs_array;
height_interpolation_coeffs = (double **) malloc(n_levels * sizeof(double *));
for (i = 0; i<n_levels; i++)
{height_interpolation_coeffs[i] = (double *) malloc(n_levels * sizeof(double));}
fbip->height_interpolation_coeffs = height_interpolation_coeffs;
fbip->inv_coeffs = (double *) malloc(ncoeffs*sizeof(double));
}
#ifdef JCM
FBIP make_fbip(blocks_wide, blocks_hi, n_levels, z_levels)
int blocks_wide, blocks_hi, n_levels;
double *z_levels;
{
FBIP fbip;
fbip = (FBIP) malloc(sizeof(struct fbip_struct));
fbip->blocks_wide = blocks_wide;
fbip->blocks_hi = blocks_hi;
fbip->n_blocks = blocks_wide * blocks_hi;
fbip->n_levels = n_levels;
fbip->z_levels = (double *) malloc(n_levels*sizeof(double));
{int i;
for (i = 0; i<n_levels; i++)
{fbip->z_levels[i] = z_levels[i];}
}
fbip_make_arrays(fbip);
return (fbip);
}
void repeat_fbip_project_to_view (n, fbip, from, to)
int n;
FBIP fbip;
COORDINATE *from, *to;
{
int i;
for (i = 0; i<n; i++)
{fbip_project_to_view(fbip, from, to);
}
}
#endif