home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
gdead.berkeley.edu
/
gdead.berkeley.edu.tar
/
gdead.berkeley.edu
/
pub
/
cad-tools
/
ciftomann.tar
/
smash.c
< prev
Wrap
C/C++ Source or Header
|
1988-01-28
|
5KB
|
211 lines
#include <stdio.h>
#include <math.h>
#include "ciftomann.h"
#include "Out_Box.h"
#include "fd.h"
#define BAD_BOX 1
#define GOOD_BOX 0
#define round_up(x) ((int) ceil( (double) x ))
#define round_even(x) ( (int) floor( ( (double) (x) ) + .5) )
/*
* compute_inc is used to compute what size boxes are used
* to tile oversize boxes with. It is carefull to assure that
* the last box used to tile is not required to be smaller
* than is allowed
*/
#define compute_inc(Orig, Max, Min, Inc, Num)\
{\
Num = round_up( ((float) Orig)/Max );\
Inc = grid_size*round_up( ((float) Orig)/(grid_size*Num) );\
while ( (Orig - (Num-1)*Inc) < Min ) {\
Inc -= grid_size;\
Num = round_up( ((float) Orig)/Inc);\
}\
}
#define LAST (OUT_BOX *) 0
char *LayerName[8] = {
"Not A Layer",
"NG",
"NI",
"NB",
"ND",
"NP",
"NM",
"NC"
};
int stage_min;
int stage_max;
int aperture_min;
int aperture_max;
int grid_size;
float scale_factor;
int Layer;
int CharCount;
extern char *ProgName;
OUT_BOX *GetBox();
main(argc, argv)
int argc;
char **argv;
{
int H, W, X, Y, h_inc, w_inc, x_center, y_center;
int h_num, w_num, x_start, w_final, h_final, i, j;
OUT_BOX *boxptr;
Layer = 2;
ProgName = "Smash";
/*
* The various parameters of the target pattern
* generator are read off of the command line
* of the program
*/
sscanf(argv[1],"%d %d %d %d %d %f", &stage_min, &stage_max,
&aperture_min, &aperture_max, &grid_size, &scale_factor);
while ( (boxptr = GetBox()) != LAST ) {
if ( rescale(boxptr, &X, &Y, &W, &H) == BAD_BOX ) {
continue;
}
/*
* the box is too big for the pattern generator,
* break it up into smaller boxes.
*
* The boxes are made as big as possible, to
* minimize the number of flashes. The last box is
* always smaller though, because the widths must
* always be rounded to the resolution grid of the
* pattern generator
*/
if ( H > aperture_max || W > aperture_max ) {
compute_inc(H, aperture_max, aperture_min, h_inc, h_num);
compute_inc(W, aperture_max, aperture_min, w_inc, w_num);
y_center = Y - ( (float) H )/2. + ( (float) h_inc )/2.;
x_start = X - ( (float) W )/2. + ( (float) w_inc )/2.;
for (i = 0; i < (h_num - 1); i++) {
x_center = x_start;
for (j = 0; j < (w_num - 1); j++) {
EmitBox(x_center, y_center, w_inc, h_inc);
x_center += w_inc;
}
x_center = (x_center - w_inc/2 + X + W/2)/2;
w_final = 2*(X + W/2 - x_center);
EmitBox(x_center, y_center, w_final, h_inc);
y_center += h_inc;
}
y_center = (y_center - h_inc/2 + Y + H/2)/2;
h_final = 2*(Y + H/2 - y_center);
x_center = x_start;
for (j = 0; j < (w_num - 1); j++) {
EmitBox(x_center, y_center, w_inc, h_final);
x_center += w_inc;
}
x_center = (x_center - w_inc/2 + X + W/2)/2;
w_final = 2*(X + W/2 - x_center);
EmitBox(x_center, y_center, w_final, h_final);
} else {
EmitBox(X, Y, W, H);
}
}
exit(0);
}
#define grid_round(value, grid) ( grid*round_even( value*scale_factor\
/( (float) grid) ) )
/*
* Change the units of the coordinates and change the format
* from left, bottom, right, top to center, width, height
*/
rescale(boxptr, x, y, w, h)
OUT_BOX *boxptr;
int *x, *y, *w, *h;
{
int xmax,ymax,xmin,ymin;
xmax = grid_round(boxptr->xmax, grid_size);
ymax = grid_round(boxptr->ymax, grid_size);
xmin = grid_round(boxptr->xmin, grid_size);
ymin = grid_round(boxptr->ymin, grid_size);
*x = (xmax + xmin)/2;
*y = (ymax + ymin)/2;
*w = (xmax - xmin);
*h = (ymax - ymin);
if (*h < aperture_min || *w < aperture_min) {
fprintf(stderr,"box from (%d,%d) to (%d,%d) has been deleted because it is\n",
boxptr->xmin, boxptr->ymin, boxptr->xmax, boxptr->ymax);
fprintf(stderr,"smaller than the minimum aperature size for the pattern generator\n");
return(BAD_BOX);
}
return(GOOD_BOX);
}
OUT_BOX *GetBox()
{
int status;
static OUT_BOX box;
status = fread(&box, sizeof(OUT_BOX), 1, stdin);
if (status == 0) {
return(LAST);
}
return(&box);
}
EmitBox(X, Y, W, H)
int X, Y, W, H;
{
#ifdef DEBUG
fprintf(stderr, "Smash : Box %d by %d at %d, %d\n", W, H, X, Y);
Layer = ((Layer - 1) % 6) + 2; /* increment, but keep <= 7, >= 2 */
#endif
printf("B %d %d %d %d;\n", W, H, X, Y);
}
error(str,x,y)
char *str;
int x,y;
{
fprintf(stderr,"Error : %s at (%d,%d) \n",str,x,y);
}