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
/
list.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-29
|
4KB
|
215 lines
#include "../polygons.h"
cList *read_corners_from_file(char *file)
{
FILE *fp, *fopen();
cList *list;
int x,y;
int value;
double leg1Dx, leg1Dy, leg2Dx, leg2Dy;
double Dx1, Dy1, Dx2, Dy2;
double height;
if ( (fp = fopen(file,"r")) == NULL) {
fprintf(stderr,"Cannot open Corner Data file.\n");
fprintf(stderr,"[%s]\n",file);
return(NULL);
}
list = NULL;
while (fscanf(fp,"%d %d %lf %d %lf %lf %lf %lf",
&x,&y,&height,&value,&Dx1,&Dy1,&Dx2,&Dy2) != EOF) {
/** As a convention, Axis2 points primarally in the Y
direction, while AXIS1 points in the X.
This helps to decide how to assign the corner vectors
to an axis. It is a cludge only needed because of
the dfs_visit implementation **/
if (fabs(Dx1) > fabs(Dy1)) {
leg1Dx = Dx1; leg1Dy = Dy1;
leg2Dx = Dx2; leg2Dy = Dy2;
} else {
leg1Dx = Dx2; leg1Dy = Dy2;
leg2Dx = Dx1; leg2Dy = Dy1;
}
if (list == NULL) {
list = create_list(x,y,height,value,
leg1Dx,leg1Dy,leg2Dx,leg2Dy);
} else {
list = insert_corner(list,x,y,height,value,
leg1Dx,leg1Dy,leg2Dx,leg2Dy);
}
}
fclose(fp);
return(list);
}
cList *create_list(int x, int y, double height, int mag,
double leg1Dx, double leg1Dy, double leg2Dx, double leg2Dy)
{
cList *list;
list = (cList *) malloc(sizeof(cList));
list->x = x; list->y = y;
list->height = height;
list->magnitude = mag;
list->leg1Dx = leg1Dx;
list->leg1Dy = leg1Dy;
list->leg2Dx = leg2Dx;
list->leg2Dy = leg2Dy;
list->P = 0;
list->last = NULL;
list->next = NULL;
list->eList = NULL;
return(list);
}
cList *insert_corner(cList *list,int x,int y,double height, int mag,
double leg1Dx, double leg1Dy, double leg2Dx, double leg2Dy)
{
cList *ptr;
int done=FALSE;
cList *newList;
newList = list;
ptr = list;
while (!done) {
if (mag >= ptr->magnitude) {
newList = insert(list,ptr,x,y,height,mag,
leg1Dx,leg1Dy,leg2Dx,leg2Dy);
done = TRUE;
} else
if (ptr->next == NULL) {
insert_end(ptr,x,y,height,mag,leg1Dx,leg1Dy,leg2Dx,
leg2Dy);
done = TRUE;
}
ptr = ptr->next;
}
return(newList);
}
cList *insert(cList *list, cList *ptr, int x, int y, double height, int mag,
double leg1Dx, double leg1Dy, double leg2Dx,
double leg2Dy)
{
cList *newNode;
newNode = (cList *) malloc(sizeof(cList));
newNode->x = x;
newNode->y = y;
newNode->height = height;
newNode->leg1Dx = leg1Dx;
newNode->leg1Dy = leg1Dy;
newNode->leg2Dx = leg2Dx;
newNode->leg2Dy = leg2Dy;
newNode->P = 0;
newNode->magnitude = mag;
newNode->next = ptr;
newNode->last = ptr->last;
newNode->eList = NULL;
ptr->last = newNode;
if (newNode->last != NULL) {
newNode->last->next = newNode;
return(list);
}
else {
return(newNode);
}
}
void insert_end(cList *ptr, int x, int y, double height, int mag,
double leg1Dx, double leg1Dy, double leg2Dx, double leg2Dy)
{
cList *newNode;
newNode = (cList *) malloc(sizeof(cList));
newNode->x = x;
newNode->y = y;
newNode->height = height;
newNode->P = 0;
newNode->leg1Dx = leg1Dx;
newNode->leg1Dy = leg1Dy;
newNode->leg2Dx = leg2Dx;
newNode->leg2Dy = leg2Dy;
newNode->magnitude = mag;
newNode->next = NULL;
newNode->last = ptr;
newNode->eList = NULL;
ptr->next = newNode;
}
void print_corner_list(cList *ptr)
{
cList *temp;
fprintf(stderr," CORNER DATA \n\n");
temp = ptr;
while (temp != NULL) {
fprintf(stderr,"(%d %d %f) %d\n",temp->x,temp->y,
temp->height,
temp->magnitude);
draw_fat_point(in_pane,(double)temp->x,(double)temp->y,3.0);
temp=temp->next;
}
}
void write_corner_list_to_file(char *fname, cList *ptr)
{
FILE *fopen(), *fp;
cList *temp;
if ( (fp = fopen(fname,"w")) == NULL) {
fprintf(stderr,"Cannot open Corner Data File.\n");
exit(1);
}
temp = ptr;
while(temp != NULL) {
fprintf(fp,"%d %d %d\n",temp->x,temp->y,temp->magnitude);
temp = temp->next;
}
fclose(fp);
}
void clear_list(cList *list)
{
cList *p, *q;
for (p = list; p != NULL; p = q) {
q = p->next;
free(p);
}
}