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
/
BuildingFinder
/
Staging
/
computeIntersections.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-27
|
6KB
|
274 lines
#include "../header.h"
#include "../stdDefs.h"
/*
*
*
* Read lines from a file and compute intersections at a particular
* angle.
*
*/
int
compute_intersections_region(char *lines, char *corners,
c_handle in_pane, c_handle im, int x1,
int y1, int x2, int y2);
void freeLineList(line *l);
void
computeIntersections()
{
c_handle image;
c_handle view;
c_handle view_trans;
c_handle projection;
double_2 *userPoint;
c_handle im;
char lineFile[80];
char cornerFile[80];
struct c_handle_1_int_3* pick, *pick_a_pane();
c_handle in_pane;
double x1,y1,x2,y2;
/*** User selects the image and a bouding box for intersections
to be searched **/
pick = pick_a_pane(get_interactor(0),1,
"Pick Lower Left Corner");
in_pane = pick->h1;
im = working_image(get_2d_world(top_image(1,in_pane)));
view = top_view(1,in_pane);
view_trans = two_d_to_window_transform(view);
userPoint = (double_2 *) inverse_transform_point(view_trans,
(double)pick->i1,(double)pick->i2,0);
x1 = (int) floor(userPoint->d1);
y1 = (int) floor(userPoint->d2);
pick = pick_a_pane(get_interactor(0),1,
"Pick Upper Right Corner");
userPoint = (double_2 *) inverse_transform_point(view_trans,
(double)pick->i1,(double)pick->i2,0);
x2 = (int) floor(userPoint->d1);
y2 = (int) floor(userPoint->d2);
set_ior_alu(in_pane);
sprintf(lineFile,"../Tokens/ldata.%s",name(get_2d_world(im)));
sprintf(cornerFile,"../Tokens/corners");
compute_intersections_region(lineFile, cornerFile,
in_pane,im, x1,y1,x2,y2);
}
int
compute_intersections_region(char *lineFile, char *cornerFile, c_handle in_pane,
c_handle im, int x1, int y1, int x2, int y2)
{
line *lines;
line *lineptr;
line *rest;
Intersection *Ilist=NULL;
double_2 Ipoint;
double Parm[2];
double avgHeight;
c_handle projectionMat;
int count=0;
projectionMat = get_projection_matrix(get_2d_world(im));
fprintf(stderr,"Loading lines [%s]\n",lineFile);
lines = (line *) load_line_data(x1,y1,x2,y2,lineFile,im);
if (lines == NULL)
fprintf(stderr,"NULL!!!\n");
lineptr = lines;
while (lineptr != NULL) {
rest = lineptr->next;
while (rest != NULL) {
matchConstraints(*lineptr, *rest, projectionMat, &Ipoint);
if (Ipoint.d1 != -1.0 && Ipoint.d2 != -1.0) {
avgHeight = (lineptr->height + rest->height) / 2.0;
Ilist =
addIntersect(Ilist, Ipoint, avgHeight, *lineptr, *rest);
count++;
}
rest = rest->next;
}
lineptr = lineptr->next;
}
printIntersections(in_pane,Ilist, cornerFile);
freeLineList(lines);
return(count);
}
int closeEnough(Point p, line l1, line l2)
/*
* Check to see if point p is "closeEnough" to one of the
* lines 'l1' or 'l2'. That is is the distance between either
* of the lines less than MIN_DIST.
*
*/
{
if (distancePointLineHessian(p,l1) <= LINE_ENDPOINT_WINDOW)
return(TRUE);
if (distancePointLineHessian(p,l2) <= LINE_ENDPOINT_WINDOW)
return(TRUE);
return(FALSE);
}
int
linesProximate(line l1, line l2, double minDist)
/*
* Are the lines close in the plane so that they can be interesected.
* Note, if THREE_D, then lines must be within HEIGHT_BUCKET, of each
* other to be proximate
*
*/
{
Point temp;
double distance;
double tempDist, smallDist = 9999.0;
/** Check that the lines are close in height **/
if (USE_3D)
if ( fabs(l1.height - l2.height) > HEIGHT_BUCKET) {
return(FALSE);
}
if (linesOverlap(l1,l2)) {
temp.x = l2.x1;
temp.y = l2.y1;
tempDist = distancePointLineHessian(temp,l1);
if (tempDist < smallDist)
smallDist = tempDist;
temp.x = l2.x2;
temp.y = l2.y2;
tempDist = distancePointLineHessian(temp,l1);
if (tempDist < smallDist)
smallDist = tempDist;
}
if (linesOverlap(l2,l1)) {
temp.x = l1.x1;
temp.y = l1.y1;
tempDist = distancePointLineHessian(temp,l2);
if (tempDist < smallDist)
smallDist = tempDist;
temp.x = l1.x2;
temp.y = l1.y2;
tempDist = distancePointLineHessian(temp,l2);
if (tempDist < smallDist)
smallDist = tempDist;
}
if (!linesOverlap(l1,l2) && !linesOverlap(l2,l1) ) {
smallDist = SMALL(SMALL(dist(l1.x1,l1.y1,l2.x1,l2.y1),
dist(l1.x1,l1.y1,l2.x2,l2.y2)),
SMALL(dist(l1.x2,l1.y2,l2.x1,l2.y1),
dist(l1.x2,l1.y2,l2.x2,l2.y2)));
if (smallDist < minDist)
return(DISTAL);
} else {
if (smallDist < minDist)
return(OVERLAP);
}
return(FALSE);
}
void
matchConstraints(line l1, line l2, c_handle proj, double_2 *p)
/*
*
* Do these two lines fit the criteria necessary for an intersection
* computation to take place?
*
* 1) Are they proximate in the image?
* 2) Are the oriented at the correct angle?
*
* Returns OVERLAP : if l1 overlaps l2 in the image and they match the
* constraints.
* DISTAL : if they do not overlap but match constraints.
* FALSE : If they do no match the constraints.
*
*/
{
int val;
double_2 pval;
val = linesProximate(l1, l2, LINE_ENDPOINT_WINDOW);
if (val != 0) {
correctAngle(l1, l2, proj, p);
return;
}
else {
p->d1 = -1.0;
p->d2 = -1.0;
return;
}
}
char printType(double s, double t)
{
if (IntersectType(s,t) == T)
return('T');
if (IntersectType(s,t) == X)
return('X');
if (IntersectType(s,t) == L)
return('L');
if (IntersectType(s,t) == N)
return('N');
}
void freeLineList(line *l)
{
line *p, *t;
for (p = l; p != NULL; p = t) {
t = p->next;
free(p);
}
}