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
/
ascendMar8.tar
/
UMass
/
Triangulate
/
fbip-build.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-13
|
6KB
|
234 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"
#include <stdio.h>
#include "nrutil.h"
/*
originally in nolisp.c
*/
COORDINATE *project_to_world(projection, view_pt, world_pt)
COORDINATE_PROJECTION projection;
COORDINATE view_pt[3];
COORDINATE world_pt[3];
{
return(0);
}
/*
calculates the inverse of the matrix
1 Zl Zl^2
1 Zm Zm^2
1 Zh Zh^2
as discussed in "documentation"
*/
void fbip_compute_height_interpolation_coeffs (fbip)
FBIP fbip;
{
int i,j,n;
double z, zn;
double ** array;
n = fbip->n_levels;
array = dmatrix(0,n-1,0,n-1);
for (i = 0; i<n; i++){
z = fbip->z_levels[i] - fbip->zorg;
for (j = 0, zn=1.0; j<n; j++, zn=zn*z){
array[i][j] = zn;
}
}
matrixinvert(array,n);
for (i = 0 ; i < n; i++)
for (j = 0; j < n; j++)
fbip->height_interpolation_coeffs[i][j] = array[i][j];
free_dmatrix(array,0,n-1,0,n-1);
}
void fbip_compute_block_coeffs_from_corner_coords (fbip, uv_vects, xy_vects,
projective_coeffs)
FBIP fbip;
COORDINATE uv_vects[4][2];
COORDINATE xy_vects[][4][2];
double *projective_coeffs;
{
int n_levels, n;
double **proj_mat, *proj_rhs;
int *indx, level, i, j, j2, i1, corner;
double d, u, v, x, y;
n = 8;
proj_mat = dmatrix(0,n-1,0,n-1);
proj_rhs = dvector(0,n-1);
indx = (int *)calloc(n, sizeof(int));
n_levels = fbip->n_levels;
for (level = 0, j=0; level<n_levels; level++, j+=8){
for (corner = 0, i=0; corner<4; corner++, i+=2){
i1 = i+1;
u = uv_vects[corner][0];
v = uv_vects[corner][1];
x = xy_vects[level][corner][0] - fbip->xorg;
y = xy_vects[level][corner][1] - fbip->yorg;
proj_rhs[i] = u;
proj_mat[i][0] = x;
proj_mat[i][1] = y;
proj_mat[i][2] = 1.0;
proj_mat[i][3] = 0.0;
proj_mat[i][4] = 0.0;
proj_mat[i][5] = 0.0;
proj_mat[i][6] = - x*u;
proj_mat[i][7] = - y*u;
proj_rhs[i1] = v;
proj_mat[i1][0] = 0.0;
proj_mat[i1][1] = 0.0;
proj_mat[i1][2] = 0.0;
proj_mat[i1][3] = x;
proj_mat[i1][4] = y;
proj_mat[i1][5] = 1.0;
proj_mat[i1][6] = - x*v;
proj_mat[i1][7] = - y*v;
}
ludcmp(proj_mat, n, indx, &d);
lubksb(proj_mat, n, indx, proj_rhs);
for (i = 0, j2 = j; i < n; i++, j2++){
projective_coeffs[j2] = proj_rhs[i];
}
}
cfree(indx);
free_dvector(proj_rhs,0,n-1);
free_dmatrix(proj_mat,0,n-1,0,n-1);
}
void fbip_generate_corners_array (fbip, projection, corners_array)
FBIP fbip;
COORDINATE_PROJECTION projection;
double ***corners_array;
{
int ui, vi, level, k;
double u,v,z;
COORDINATE *view_vector, *world_vector;
for (ui=0, u = fbip->umin; ui<=fbip->blocks_wide; ui++, u+=fbip->du)
{view_vector[0] = u;
for (vi=0, v =fbip->vmin; vi<=fbip->blocks_hi; vi++, v+=fbip->dv)
{corners_array[ui][vi][0] = u;
corners_array[ui][vi][1] = v;
view_vector[1] = v;
for (level = 0, k=2; level<fbip->n_levels; level++, k+=2)
{z = fbip->z_levels[level];
view_vector[2]= z;
project_to_world(projection, view_vector, world_vector);
corners_array[ui][vi][k ] = world_vector[0];
corners_array[ui][vi][k+1] = world_vector[1];
}}}}
typedef double CORNER_COORDS[4][2];
void fill_fbip (fbip, corners_array)
FBIP fbip;
double ***corners_array;
{
double uv_vects[4][2];
/* double *xy_vects[4][2]; */
CORNER_COORDS *xy_vects;
int level, n_levels, ui, vi, ui2, vi2, corner, k;
n_levels = fbip->n_levels;
/* debprintf("fill_fbip ...");*/
xy_vects = (CORNER_COORDS *) malloc(n_levels*8*sizeof(double));
/* debprintf("allocated xy_vects ... ");*/
for (ui = 0; ui<fbip->blocks_wide; ui++)
{for (vi=0; vi<fbip->blocks_hi; vi++)
{for (corner = 0; corner<4; corner++)
{switch (corner)
{case 0: ui2 = ui; vi2=vi; break;
case 1: ui2 = ui+1; vi2=vi; break;
case 2: ui2 = ui; vi2=vi+1; break;
case 3: ui2 = ui+1; vi2=vi+1;break;
}
uv_vects[corner][0]= corners_array[ui2][vi2][0];
uv_vects[corner][1]= corners_array[ui2][vi2][1];
for (level = 0, k = 0; level<n_levels; level++, k+=2)
{xy_vects[level][corner][0] = corners_array[ui2][vi2][k+2];
xy_vects[level][corner][1] = corners_array[ui2][vi2][k+3];
}
}
fbip_compute_block_coeffs_from_corner_coords
(fbip,
uv_vects,
xy_vects,
fbip->block_projective_coeffs_array[ui][vi]);
}}
/* debprintf("done\n");*/
free(xy_vects);
}
double *** allocate_corners_array(blocks_wide, blocks_hi, n_levels)
int blocks_wide;
int blocks_hi;
int n_levels;
{
double ***corners_array;
int ui, vi, rec_size;
rec_size = (2+2*n_levels)*sizeof(double);
corners_array = (double ***) malloc((blocks_wide+1)*sizeof (double **));
for (ui=0; ui<=blocks_wide; ui++)
{corners_array[ui]= (double **) malloc((blocks_hi+1)*sizeof(double *));
for (vi=0; vi<=blocks_hi; vi++)
corners_array[ui][vi]= (double *) malloc(rec_size);
}
return(corners_array);
}
void deallocate_corners_array(corners_array, blocks_wide, blocks_hi)
double ***corners_array;
int blocks_wide;
int blocks_hi;
{
int ui, vi;
for (ui=0; ui<=blocks_wide; ui++)
{for (vi=0; vi<=blocks_hi; vi++)
free(corners_array[ui][vi]);
free(corners_array[ui]);
}
free(corners_array);
}