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-internal.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-13
|
4KB
|
151 lines
#include <stdio.h>
#include "fbip.h"
/*
* 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.
*
*/
double block_overlap_slop = .1; /* pixels */
int fbip_point_in_image_block(fbip, vector, ui, vi)
FBIP fbip;
COORDINATE *vector;
int ui, vi;
{
double x, y, ull, vll, slop;
slop = block_overlap_slop;
x = vector[0];
y = vector[1];
ull = fbip->umin + fbip->du*ui;
vll = fbip->vmin + fbip->dv*vi;
return ( (x >= (ull - slop))
&& (x <= (ull + fbip->du + slop))
&& (y >= (vll - slop))
&& (y <= (vll + fbip->dv + slop)));
}
typedef enum __fbip_project_to_view_status__ {
CLIPPED_P_STATUS,
OK_STATUS
} fbip_project_to_view_status_code;
fbip_project_to_view_status_code
fbip_extrapolate_block(fbip, view_position, ui2, vi2)
FBIP fbip;
COORDINATE *view_position;
int *ui2, *vi2;
{
int ui,vi;
fbip_project_to_view_status_code status;
ui = (int) ((view_position[0] - fbip->umin) / fbip->du);
vi = (int) ((view_position[1] - fbip->vmin) / fbip->dv);
status = OK_STATUS;
if (ui < 0) {ui = 0; status = CLIPPED_P_STATUS;}
else if (ui >= fbip->blocks_wide) {ui = fbip->blocks_wide-1; status = CLIPPED_P_STATUS;}
if (vi < 0) {vi = 0; status = CLIPPED_P_STATUS;}
else if (vi >= fbip->blocks_hi) {vi = fbip->blocks_hi-1; status = CLIPPED_P_STATUS;}
*ui2 = ui; *vi2 = vi;
return(status);
}
static COORDINATE tmp_coordinate_vector[3];
int fbip_project_to_view_max_iterations = 10;
BOOLEAN verbose_switch = TRUE;
COORDINATE *fbip_project_to_view (fbip, world_position, view_position)
FBIP fbip;
COORDINATE *world_position;
COORDINATE *view_position;
{
COORDINATE world_vector[3];
COORDINATE *make_coordinate_vector();
if (view_position == FALSE) view_position = make_coordinate_vector();
if (world_position == view_position) view_position = tmp_coordinate_vector;
world_vector[0] = world_position[0] - fbip->xorg;
world_vector[1] = world_position[1] - fbip->yorg;
world_vector[2] = world_position[2];
{
int i, ui, vi, next_ui, next_vi, status;
BOOLEAN clipped_p;
BOOLEAN last_block_on_boundary = FALSE;
ui = fbip->prev_block_ui;
vi = fbip->prev_block_vi;
/*
printf("checkpoint 1 \n");
*/
for (i = 0; i < fbip_project_to_view_max_iterations; i++){
fbip_project_in_block(fbip, fbip->block_projective_coeffs_array[ui][vi],
&world_vector[0], view_position);
/*
printf("checkpoint 2 \n");
*/
if (fbip_point_in_image_block(fbip, view_position, ui, vi)){
break;
}
/*
printf("checkpoint 3 \n");
*/
status = fbip_extrapolate_block(fbip, view_position, &next_ui, &next_vi);
clipped_p = (status == CLIPPED_P_STATUS);
if (clipped_p && (! last_block_on_boundary)){
ui = next_ui; vi = next_vi; last_block_on_boundary = TRUE;
}
else if (clipped_p || ((next_ui == ui) && (next_vi == vi))){
break;
}
else {
ui = next_ui; vi = next_vi;
}
}
if (i == fbip_project_to_view_max_iterations){
fprintf (stderr, "FBIP-PROJECT-TO-VIEW failed to converge after ~%d iterations.\n",
fbip_project_to_view_max_iterations);
}
fbip->prev_block_ui = ui;
fbip->prev_block_vi = vi;
if (view_position == tmp_coordinate_vector){
world_position[0] = view_position[0];
world_position[1] = view_position[1];
return(world_position);
}
else {
view_position[2] = world_position[2];
return(view_position);
}
}}