Пример #1
0
int
main (int argc, char **argv)
{
    int Ch;		/* The current input character */
    int *thresh_val;	/* The threshold value */
    int nm_threshs;	/* How many thresholds? */
    int i;
    unsigned char *bin_color = (unsigned char *)0;/* resultant pixel values */

    if ((nm_threshs = argc - 1) < 1) {
	bu_exit(1, "%s", USAGE);
    }
    if (nm_threshs > 255) {
	bu_exit(1, "bwthresh: Too many thresholds!\n");
    }
    thresh_val = (int *)bu_malloc((unsigned) (nm_threshs * sizeof(int)), "thresh_val");
    bin_color = (unsigned char *)bu_malloc((unsigned) ((nm_threshs + 1) * sizeof(int)), "bin_color");

    for (i = 0; i < nm_threshs; ++i) {
	if (sscanf(*++argv, "%d", thresh_val + i) != 1) {
	    bu_log("bwthresh: Illegal threshold value: '%s'\n", *argv);
	    bu_exit(1, "%s", USAGE);
	}
	if ((unsigned char) thresh_val[i] != thresh_val[i]) {
	    bu_exit(1, "bwthresh: Threshold[%d] value %d out of range.  Need 0 <= value <= 255\n",
		    i, thresh_val[i]);
	}
	if (i > 0) {
	    if (thresh_val[i] <= thresh_val[i - 1]) {
		bu_exit(1, "bwthresh: Threshold values not strictly increasing\n");
	    }
	}
	bin_color[i] = 256 * i / nm_threshs;
    }
    bin_color[i] = 255;

    while ((Ch = getchar()) != EOF) {
	for (i = 0; i < nm_threshs; ++i)
	    if (Ch < thresh_val[i])
		break;
	(void) putchar(bin_color[i]);
    }

    bu_free(thresh_val, "thresh_val");
    bu_free(bin_color, "bin_color");
    return 0;
}
Пример #2
0
/*
 *	U S A G E --- tell user how to invoke this program, then exit
 */
void usage(char *s)
{
    if (s) (void)fputs(s, stderr);

    (void) fprintf(stderr, "Usage: %s [ -%s ] r g b R G B [ < infile > outfile]\n",
		   progname, options);
    bu_exit (1, NULL);
}
Пример #3
0
void
print_usage(int willexit)
{
    if (willexit)
	bu_exit(1, "%s%s", usage1, usage2);
    fprintf(stderr, "%s%s", usage1, usage2);
    fprintf(stderr, "       Program continues running:\n");
}
Пример #4
0
void
ph_cd(struct pkg_conn *UNUSED(pc), char *buf)
{
    if (debug)fprintf(stderr, "ph_cd %s\n", buf);
    if (chdir(buf) < 0)
	bu_exit(1, "ph_cd: chdir(%s) failure\n", buf);
    (void)free(buf);
}
Пример #5
0
void
checkgamma(double g)
{
    if (fabs(g) < 1.0e-10) {
	fprintf(stderr, "fbgamma: gamma too close to zero\n");
	bu_exit(3, "%s", usage);
    }
}
Пример #6
0
/*
	If args[0] is NULL, spawn a shell, otherwise execute the specified
	command line.
	Return the exit status of the program, or -1 if wait() or fork()
	return an error.
*/
int
exec_Shell(char **args)
{
    int child_pid;

    if (args[0] == NULL) {
	char *arg_sh = getenv("SHELL");
	/* $SHELL, if set, DFL_SHELL otherwise. */
	if (arg_sh == NULL)
	    arg_sh = DFL_SHELL;
	args[0] = arg_sh;
	args[1] = NULL;
    }
    switch (child_pid = fork()) {
	case -1 :
	    fb_log("\"%s\" (%d) could not fork.\n",
		    __FILE__, __LINE__
		);
	    return -1;
	case  0 : /* Child process - execute. */
	    sleep(2);
	    (void)execvp(args[0], args);
	    fb_log("%s : could not execute.\n", args[0]);
	    bu_exit(1, NULL);
	default :
	{
	    int pid;
	    int stat_loc;
	    void (*istat)(), (*qstat)(), (*cstat)();
	    istat = signal(SIGINT, SIG_IGN);
	    qstat = signal(SIGQUIT, SIG_IGN);
	    cstat = signal(SIGCLD, SIG_DFL);
	    while (	(pid = wait(&stat_loc)) != -1
			&& pid != child_pid
		)
		;
	    (void)signal(SIGINT, istat);
	    (void)signal(SIGQUIT, qstat);
	    (void)signal(SIGCLD, cstat);
	    if (pid == -1) {
		fb_log("\"%s\" (%d) wait failed : no children.\n",
			__FILE__, __LINE__
		   );
		return -1;
	    }
	    switch (stat_loc & 0377) {
		case 0177 : /* Child stopped. */
		    fb_log("Child stopped.\n");
		    return (stat_loc >> 8) & 0377;
		case 0 :    /* Child exited. */
		    return (stat_loc >> 8) & 0377;
		default :   /* Child terminated. */
		    fb_log("Child terminated.\n");
		    return 1;
	    }
	}
    }
}
Пример #7
0
int
main(int argc, char **argv)
{
    register int i;
    struct timeval tv;

    if ( !get_args( argc, argv ) )  {
	(void)fputs(usage, stderr);
	bu_exit( 1, NULL );
    }

    if ( fps > 0.0 ) {
	tv.tv_sec = (long) (1.0 / fps);
	tv.tv_usec = (long) (((1.0 / fps) - tv.tv_sec) * 1000000);
    }

    if ( (fbp = fb_open( NULL, size, size)) == FBIO_NULL )  {
	fprintf(stderr, "fbcmrot:  fb_open failed\n");
	return	1;
    }

    local_inp = &cm1;
    local_outp = &cm2;
    fb_rmap( fbp, local_inp );

    while (1)  {
	register int from;
	ColorMap *tp;

	/* Build color map for current value */
	for ( i=0, from = increment; i < 256; i++, from++ ) {
	    if ( from < 0 )
		from += 256;
	    else if ( from > 255 )
		from -= 256;
	    local_outp->cm_red[i]   = local_inp->cm_red[from];
	    local_outp->cm_green[i] = local_inp->cm_green[from];
	    local_outp->cm_blue[i]  = local_inp->cm_blue[from];
	}

	fb_wmap( fbp, local_outp );
	tp = local_outp;
	local_outp = local_inp;
	local_inp = tp;

	if ( fps > 0.0 )  {
	    fd_set readfds;

	    FD_ZERO(&readfds);
	    FD_SET(fileno(stdin), &readfds);
	    select(fileno(stdin)+1, &readfds, (fd_set *)0, (fd_set *)0, &tv);
	}
	if ( onestep )
	    break;
    }
    fb_close( fbp );
    return	0;
}
Пример #8
0
int
main(int argc, char *argv[])
{
    static const char usage[] = "Usage:\n%s [-o outfile] [-n count]\n\n  -o file \tFile to write out (default: metaball.g)\n  -n count\tTotal metaball point count (default %d)\n\n";
    static const int COUNTMAX = 555;

    char outfile[MAXPATHLEN] = "metaball.g";
    int optc;
    long count = COUNTMAX;

    if (argc == 1) {
	fprintf(stderr,usage, *argv, COUNTMAX);
    	fprintf(stderr,"       Program continues running:\n");
    }

    while ((optc = bu_getopt(argc, argv, "o:n:h?")) != -1) {
        if (bu_optopt == '?') optc='h';
	switch (optc) {
	    case 'o':
		snprintf(outfile, MAXPATHLEN, "%s", bu_optarg);
		break;
	    case 'n':
		count = atoi(bu_optarg);
		break;
	    default:
		fprintf(stderr,usage, *argv, COUNTMAX);
		return optc == '?' ? EXIT_FAILURE : EXIT_SUCCESS;
	}
    }

    if (count <= 0)
	bu_exit(EXIT_FAILURE, "ERROR: count must be greater than zero");

    if (bu_file_exists(outfile, NULL))
	bu_exit(EXIT_FAILURE, "ERROR: %s already exists.  Remove file and try again.", outfile);

    bu_log("Writing metaballs out to [%s]\n", outfile);

    /* make dinner */
    make_spaghetti(outfile, "meatballs.s", count);

    bu_log("BRL-CAD geometry database file [%s] created.\nDone.\n", outfile);

    return EXIT_SUCCESS;
}
Пример #9
0
void
do_rt_gettrees(struct rt_i *my_rtip, char **object_name, int nm_objects, int *prep)
{
    static char **prev_names = 0;
    static int prev_nm = 0;
    int i;

    if (object_name == NULL) {
	if ((object_name = prev_names) == 0)
	    bu_exit (1, "%s:%d: This shouldn't happen\n", __FILE__, __LINE__);
	nm_objects = prev_nm;
    }

    if (prev_names == 0) {
	prev_names = object_name;
	prev_nm = nm_objects;
    }

    if (silent_flag != SILENT_YES) {
	printf("\nGet trees...");
	fflush(stdout);
    }

    i = rt_gettrees_and_attrs(my_rtip, (const char **)a_tab.attrib, nm_objects, (const char **) object_name, 1);
    if (i) {
	fflush(stdout);
	bu_exit (1, "rt_gettrees() failed\n");
    }

    if (*prep) {
	if (silent_flag != SILENT_YES) {
	    printf("\nPrepping the geometry...");
	    fflush(stdout);
	}
	rt_prep(my_rtip);
	*prep = 0;
    }

    if (silent_flag != SILENT_YES) {
	printf("\n%s", (nm_objects == 1) ? "Object" : "Objects");
	for (i = 0; i < nm_objects; ++i)
	    printf(" '%s'", object_name[i]);
	printf(" processed\n");
    }
}
Пример #10
0
int main(int argc, char **argv)
{
    int	i, n;
    double	*bp;
    double	arg;
    int j;
    size_t ret;

    if ( !get_args( argc, argv ) || isatty(fileno(infp))
	 || isatty(fileno(stdout)) ) {
	bu_exit(1, "Usage: dmod {-a add -s sub -m mult -d div -A(abs) -e exp -r root} [doubles]\n");
    }

    while ( (n = fread(buf, sizeof(*buf), BUFLEN, infp)) > 0 ) {
	for ( i = 0; i < numop; i++ ) {
	    arg = val[ i ];
	    switch ( op[i] ) {
		double d;

		case ADD:
		    bp = &buf[0];
		    for ( j = n; j > 0; j-- ) {
			*bp++ += arg;
		    }
		    break;
		case MULT:
		    bp = &buf[0];
		    for ( j = n; j > 0; j-- ) {
			*bp++ *= arg;
		    }
		    break;
		case POW:
		    bp = &buf[0];
		    for ( j = n; j > 0; j-- ) {
			d = pow( *bp, arg );
			*bp++ = d;
		    }
		    break;
		case ABS:
		    bp = &buf[0];
		    for ( j = n; j > 0; j-- ) {
			if ( *bp < 0.0 )
			    *bp = - *bp;
			bp++;
		    }
		    break;
		default:
		    break;
	    }
	}
	ret = fwrite( buf, sizeof(*buf), n, stdout );
	if (ret != (size_t)n)
	    perror("fwrite");
    }

    return 0;
}
Пример #11
0
int read_point (FILE *fp, fastf_t *c_p, int c_len, int normalize, struct bu_vls *tail)
{
    char		*cp = NULL;
    fastf_t		sum;
    int			i;
    int			return_code = 1;
    static int		line_nm = 0;
    struct bu_vls	*bp;

    for (bp = bu_vls_vlsinit();; bu_vls_trunc(bp, 0))
    {
	if (bu_vls_gets(bp, fp) == -1)
	{
	    return_code = EOF;
	    goto wrap_up;
	}

	++line_nm;
	cp = bu_vls_addr(bp);

	while ((*cp == ' ') || (*cp == '\t'))
	    ++cp;

	if ((*cp == '#') || (*cp == '\0'))
	    continue;

	for (i = 0; i < c_len; ++i)
	{
	    char	*endp;

	    c_p[i] = strtod(cp, &endp);
	    if (endp == cp)
		bu_exit (1, "Illegal input at line %d: '%s'\n",
			 line_nm, bu_vls_addr(bp));
	    cp = endp;
	}

	if (normalize)
	{
	    sum = 0.0;
	    for (i = 0; i < c_len; ++i)
		sum += c_p[i];
	    for (i = 0; i < c_len; ++i)
		c_p[i] /= sum;
	}
	goto wrap_up;
    }

 wrap_up:
    if ((return_code == 1) && (tail != 0))
    {
	bu_vls_trunc(tail, 0);
	bu_vls_strcat(tail, cp);
    }
    bu_vls_vlsfree(bp);
    return (return_code);
}
/*
 * Perform one rewrite step on the root of a Boolean tree
 *
 * This function has two parameters: a Boolean-tree node and a rule
 * number.  Do_bool_tree_rewrite() applies the specified rewrite rule
 * to the subtree rooted at the specified node.
 */
static void do_bool_tree_rewrite (struct bool_tree_node *rp, int rule_nm)
{
    struct bool_tree_node *left;		/* Left child of the root */
    struct bool_tree_node *right;		/* Right "   "   "   "   */
    struct bool_tree_node *a, *b, *c;	/* Subtrees unchanged */

    BU_CKMAG(rp, BOOL_TREE_NODE_MAGIC, "Boolean tree node");

    left = bt_opd(rp, BT_LEFT);
    right = bt_opd(rp, BT_RIGHT);
    BU_CKMAG(left, BOOL_TREE_NODE_MAGIC, "Boolean tree node");
    BU_CKMAG(right, BOOL_TREE_NODE_MAGIC, "Boolean tree node");

    switch (rule_nm) {
	case 0:
	    return;
	case 1:		/* a U (b U c)  :  (a U b) U c */
	case 5:		/* a - (b U c)  :  (a - b) - c */
	case 6:		/* a * (b * c)  :  (a * b) * c */
	case 8:		/* a * (b - c)  :  (a * b) - c */
	    a = left;
	    b = bt_opd(right, BT_LEFT);
	    c = bt_opd(right, BT_RIGHT);
	    bt_opd(rp, BT_LEFT) = right;
	    bt_opd(bt_opd(rp, BT_LEFT), BT_LEFT) = a;
	    bt_opd(bt_opd(rp, BT_LEFT), BT_RIGHT) = b;
	    bt_opd(rp, BT_RIGHT) = c;
	    bt_opn(bt_opd(rp, BT_LEFT)) = bt_opn(rp);
	    if ((rule_nm == 5) || (rule_nm == 8))
		bt_opn(rp) = OPN_DIFFERENCE;
	    break;
	case 2:		/* (a U b) * c  :  (a * c) U (b * c)  */
	case 4:		/* (a U b) - c  :  (a - c) U (b - c)  */
	    a = bt_opd(left, BT_LEFT);
	    b = bt_opd(left, BT_RIGHT);
	    c = right;
	    bt_opn(left) = bt_opn(rp);
	    bt_opd(left, BT_RIGHT) = dup_bool_tree(c);
	    bt_opn(rp) = OPN_UNION;
	    bt_opd(rp, BT_RIGHT) = bt_create_internal(bt_opn(left), b, c);
	    break;
	case 3:		/* a * (b U c)  :  (a * b) U (a * c)  */
	case 7:		/* a - (b * c)  :  (a - b) U (a - c)  */
	case 9:		/* a - (b - c)  :  (a - b) U (a * c)  */
	    a = left;
	    b = bt_opd(right, BT_LEFT);
	    c = bt_opd(right, BT_RIGHT);
	    bt_opd(rp, BT_LEFT) = bt_create_internal(bt_opn(rp), a, b);
	    bt_opn(rp) = OPN_UNION;
	    bt_opn(right) = (rule_nm == 7) ? OPN_DIFFERENCE
		: OPN_INTERSECTION;
	    bt_opd(right, BT_LEFT) = dup_bool_tree(a);
	    break;
	default:
	    bu_exit (1, "Reached %s:%d.  This shouldn't happen\n", __FILE__, __LINE__);
    }
}
Пример #13
0
/**
 *	M A I N
 *
 *	Call parse_args to handle command line arguments first, then
 *	process input.
 */
int main(int ac, char *av[])
{
    /** @struct rt_i
     * This structure contains some global state information for librt
     */
    struct rt_i *rtip;

    struct db_tree_state init_state; /* state table for the hierarchy walker */
    char idbuf[1024] = {0};		/* Database title */
    int arg_count;
    char *tmp_basename;

    /** @struct user_data
     * This is an example structure.
     * It contains anything you want to have available in the region/leaf processing routines
     */
    struct user_data {
	int stuff;
    } user_data;


    arg_count = parse_args(ac, av);

    if ((ac - arg_count) < 1) {
	tmp_basename = bu_basename(av[0]);
	usage(tmp_basename, "bad argument count");
	bu_free(tmp_basename, "tmp_basename free");
    }

    /*
     *  Build an index of what's in the database.
     *  rt_dirbuild() returns an "instance" pointer which describes
     *  the database.  It also gives you back the
     *  title string in the header (ID) record.
     */
    rtip = rt_dirbuild(av[arg_count], idbuf, sizeof(idbuf));
    if (rtip == RTI_NULL) {
	bu_exit(2, "%s: rt_dirbuild failure\n", av[0]);
    }

    arg_count++;

    init_state = rt_initial_tree_state;
    db_walk_tree(rtip->rti_dbip, /* database instance */
		 ac-arg_count,		/* number of trees to get from the database */
		 (const char **)&av[arg_count],
		 1, /* number of cpus to use */
		 &init_state,
		 region_start,
		 region_end,
		 leaf_func,
		 (genptr_t)&user_data);

    /* at this point you can do things with the geometry you have obtained */

    return 0;
}
Пример #14
0
int
main(int argc, char *argv[])
{
    int function_num = 0;

    if (argc < 3) {
	bu_exit(1, "Argument format: <function_number> <args> [%s]\n", argv[0]);
    }

    sscanf(argv[1], "%d", &function_num);

    switch (function_num) {
    case 1:
	return test_bn_table_make_uniform(argc, argv);
    case 2:
	return test_bn_tabdata_add(argc, argv);
    case 3:
	return test_bn_tabdata_mul(argc, argv);
    case 4:
	return test_bn_tabdata_mul3(argc, argv);
    case 5:
	return test_bn_tabdata_incr_mul3_scale(argc, argv);
    case 6:
	return test_bn_tabdata_incr_mul2_scale(argc, argv);
    case 7:
	return test_bn_tabdata_scale(argc, argv);
    case 8:
	return test_bn_table_scale(argc, argv);
    case 9:
	return test_bn_tabdata_join1(argc, argv);
    case 10:
	return test_bn_tabdata_join2(argc, argv);
    case 11:
	return test_bn_tabdata_blend2(argc, argv);
    case 12:
	return test_bn_tabdata_blend3(argc, argv);
    case 13:
	return test_bn_tabdata_area1(argc, argv);
    case 14:
	return test_bn_tabdata_area2(argc, argv);
    case 15:
	return test_bn_tabdata_mul_area1(argc, argv);
    case 16:
	return test_bn_tabdata_mul_area2(argc, argv);
    case 17:
	return test_bn_table_lin_interp(argc, argv);
    case 18:
	return test_bn_tabdata_copy(argc, argv);
    case 19:
	return test_bn_tabdata_dup(argc, argv);
    case 20:
	return test_bn_tabdata_get_constval(argc, argv);
    }

    bu_log("ERROR: function_num %d is not valid [%s]\n", function_num, argv[0]);
    return 1;
}
Пример #15
0
int
main(int argc, char **argv)
{
    FBIO *fbp;
    FILE *fp;
    int fbsize = 512;
    int i;

    while (argc > 1) {
	if (BU_STR_EQUAL(argv[1], "-h")) {
	    fbsize = 1024;
	} else if (argv[1][0] == '-') {
	    /* unknown flag */
	    bu_exit(1, "%s", usage);
	} else
	    break;	/* must be a filename */
	argc--;
	argv++;
    }

    if (argc > 1) {
	if ((fp = fopen(argv[1], "wb")) == NULL) {
	    fprintf(stderr, "fb-cmap: can't open \"%s\"\n", argv[1]);
	    bu_exit(2, "%s", usage);
	}
    } else
	fp = stdout;

    if ((fbp = fb_open(NULL, fbsize, fbsize)) == FBIO_NULL)
	bu_exit(2, "Unable to open framebuffer\n");

    i = fb_rmap(fbp, &cm);
    fb_close(fbp);
    if (i < 0) {
	bu_exit(3, "fb-cmap: can't read colormap\n");
    }

    for (i = 0; i <= 255; i++) {
	fprintf(fp, "%d\t%04x %04x %04x\n", i,
		cm.cm_red[i], cm.cm_green[i], cm.cm_blue[i]);
    }

    return 0;
}
Пример #16
0
int
main(int argc, char **argv)
{
    int	in, out, num;
    FILE	*finp, *foutp;

    /* check for input file */
    if ( argc > 1 ) {
#if defined(_WIN32) && !defined(__CYGWIN__)
	if ((finp = fopen( argv[1], "rb")) == NULL) {
#else
	    if ((finp = fopen( argv[1], "r")) == NULL) {
#endif
		bu_exit(1, "bw-pix: can't open \"%s\"\n", argv[1] );
	    }
	} else
	    finp = stdin;

	/* check for output file */
	if ( argc > 2 ) {
#if defined(_WIN32) && !defined(__CYGWIN__)
	    if ((foutp = fopen( argv[2], "wb")) == NULL) {
#else
		if ((foutp = fopen( argv[2], "w")) == NULL) {
#endif
		    bu_exit(2, "bw-pix: can't open \"%s\"\n", argv[2] );
		}
	    } else
		foutp = stdout;

	    if ( argc > 3 || isatty(fileno(finp)) || isatty(fileno(foutp)) ) {
		bu_exit( 3, "Usage: bw-pix [in.bw] [out.pix]\n" );
	    }

	    while ( (num = fread( ibuf, sizeof( char ), 1024, finp )) > 0 ) {
		for ( in = out = 0; in < num; in++, out += 3 ) {
		    obuf[out] = ibuf[in];
		    obuf[out+1] = ibuf[in];
		    obuf[out+2] = ibuf[in];
		}
		fwrite( obuf, sizeof( char ), 3*num, foutp );
	    }
	    return 0;
	}
Пример #17
0
HIDDEN void
get_large_field_input(FILE *fp, int write_flag)
{
    char **tmp_rec;
    size_t field_no;
    size_t card_len;
    size_t last_field;
    size_t i;

    tmp_rec = prev_rec;
    prev_rec = curr_rec;
    curr_rec = tmp_rec;

    for (field_no=0; field_no < NO_OF_FIELDS; field_no ++)
	curr_rec[field_no][0] = '\0';

    card_len = strlen(line);
    last_field = (card_len - 8)/16 + 1;
    if (((last_field - 1) * 16 + 8) < card_len)
	last_field++;
    if (last_field > 5)
	last_field = 5;
    bu_strlcpy(curr_rec[0], line, 8);
    curr_rec[0][8] = '\0';
    for (field_no=1; field_no < last_field; field_no++) {
	bu_strlcpy(curr_rec[field_no], &line[field_no*16 - 8], 16);
	curr_rec[field_no][16] = '\0';
    }

    /* remove the newline from the end of the last field */
    i = strlen(curr_rec[last_field-1]) - 1;
    while (isspace((int)curr_rec[last_field-1][i]) || curr_rec[last_field-1][i] == '\012' || curr_rec[last_field-1][i] == '\015')
	i--;
    curr_rec[last_field-1][++i] = '\0';

    if (next_line[0] == '*') {
	if (!get_next_record(fp, 0, 0)) {
	    bu_exit(1, "unexpected end of INPUT at line #%ld\n", line_count);
	}

	card_len = strlen(line);
	last_field = (card_len - 8)/16 + 1;
	if (((last_field - 1) * 16 + 8) < card_len)
	    last_field++;
	if (last_field > 5)
	    last_field = 5;
	last_field += 4;
	for (field_no=5; field_no < last_field; field_no++) {
	    bu_strlcpy(curr_rec[field_no], &line[(field_no-4)*16 - 8], 16);
	    curr_rec[field_no][16] = '\0';
	}
    }

    if (write_flag)
	write_fields();
}
Пример #18
0
/*
 *		 C O M P A R E _ V E R T E X _ L A B E L S ( )
 */
int compare_vertex_labels (void *v1, void *v2)
{
    struct vertex	*vert1 = (struct vertex *) v1;
    struct vertex	*vert2 = (struct vertex *) v2;

    BU_CKMAG(vert1, VERTEX_MAGIC, "vertex");
    BU_CKMAG(vert2, VERTEX_MAGIC, "vertex");
    if (vert1 -> v_label == '\0')
	bu_exit (1, "compare_vertex_labels: null label in vertex <x%x> %d\n", vert1, vert1 -> v_index);
    if (vert2 -> v_label == '\0')
	bu_exit (1, "compare_vertex_labels: null label in vertex <x%x> %d\n", vert2, vert2 -> v_index);

    if (*(vert1 -> v_label) < *(vert2 -> v_label))
	return -1;
    else if (*(vert1 -> v_label) > *(vert2 -> v_label))
	return 1;
    else
	return (strcmp(vert1 -> v_label, vert2 -> v_label));
}
Пример #19
0
void
usage_seq(void)
{
    fprintf(stderr, "Usage: vas4 sequence [n nf] [start]\n");
    fprintf(stderr, "\t[n nf]\tthe number of images n must be > 1\n");
    fprintf(stderr, "\t\tand the number of frames nf  must be > 1\n");
    fprintf(stderr, "\t[start] is the starting sequence number\n");
    fprintf(stderr, "\t\tIf start is specified, n and nf must also be specified\n");
    bu_exit(1, NULL);
}
Пример #20
0
int
main(int argc, char **argv)
{
    int	x, y;
    int	xin, yin;		/* number of sceen output lines */

    height = width = 512;		/* Defaults */

    if ( !get_args( argc, argv ) )  {
	(void)fputs(usage, stderr);
	bu_exit( 1, NULL );
    }

    /* Open Display Device */
    if ((fbp = fb_open(framebuffer, width, height )) == NULL ) {
	fprintf( stderr, "fb_open failed\n");
	bu_exit( 1, NULL );
    }

    /* determine "reasonable" behavior */
    xin = fb_getwidth(fbp) - scr_xoff;
    if ( xin < 0 ) xin = 0;
    if ( xin > width ) xin = width;
    yin = fb_getheight(fbp) - scr_yoff;
    if ( yin < 0 ) yin = 0;
    if ( yin > height ) yin = height;

    for ( y = scr_yoff; y < scr_yoff + yin; y++ )  {
	if ( inverse ) {
	    (void)fb_read( fbp, scr_xoff, fb_getheight(fbp)-1-y, inbuf, xin );
	} else {
	    (void)fb_read( fbp, scr_xoff, y, inbuf, xin );
	}
	for ( x = 0; x < xin; x++ ) {
	    obuf[x] = (((int)inbuf[3*x+RED]) + ((int)inbuf[3*x+GRN])
		       + ((int)inbuf[3*x+BLU])) / 3;
	}
	fwrite( &obuf[0], sizeof( char ), xin, outfp );
    }

    fb_close( fbp );
    bu_exit( 0, NULL );
}
Пример #21
0
int
lines_read(FILE *fp, long int numlines,
	   struct lineseg *lines,
	   long int width, long int height,
	   double warpfrac, double pb)
{
    long int i, j;
    double x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4;

    for (i = 0; i < numlines; i++, lines++) {
	if (fscanf(fp, "%lf %lf %lf %lf %lf %lf %lf %lf ",
		   &x_1, &y_1, &x_2, &y_2, &x_3, &y_3, &x_4, &y_4) < 4) {
	    bu_exit(1, "pixmorph: lines_read: failure\n");
	}

	if ((fabs(x_1-x_2) < EPSILON && fabs(y_1-y_2) < EPSILON) ||
	    (fabs(x_3-x_4) < EPSILON && fabs(y_3-y_4) < EPSILON)) {
	    fprintf(stderr, "pixmorph: warning: zero-length line segment\n");
	    --numlines;
	    continue;
	}

	lines->s[FIRST].x_1 = (double)width*x_1;
	lines->s[FIRST].y_1 = (double)height*y_1;
	lines->s[FIRST].x_2 = (double)width*x_2;
	lines->s[FIRST].y_2 = (double)height*y_2;
	lines->s[LAST].x_1 = (double)width*x_3;
	lines->s[LAST].y_1 = (double)height*y_3;
	lines->s[LAST].x_2 = (double)width*x_4;
	lines->s[LAST].y_2 = (double)height*y_4;

	/* Now, the other useful information. */

	lines->s[MIDDLE].x_1 = DBLEND(lines->s[FIRST].x_1,
				      lines->s[LAST].x_1, warpfrac);
	lines->s[MIDDLE].y_1 = DBLEND(lines->s[FIRST].y_1,
				      lines->s[LAST].y_1, warpfrac);
	lines->s[MIDDLE].x_2 = DBLEND(lines->s[FIRST].x_2,
				      lines->s[LAST].x_2, warpfrac);
	lines->s[MIDDLE].y_2 = DBLEND(lines->s[FIRST].y_2,
				      lines->s[LAST].y_2, warpfrac);

	for (j = 0; j < 3; j++) {
	    lines->s[j].xdelta = lines->s[j].x_2 - lines->s[j].x_1;
	    lines->s[j].ydelta = lines->s[j].y_2 - lines->s[j].y_1;
	    lines->s[j].oolensq = 1.0/(lines->s[j].xdelta*lines->s[j].xdelta +
				       lines->s[j].ydelta*lines->s[j].ydelta);
	    lines->s[j].oolen = sqrt(lines->s[j].oolensq);
	    lines->s[j].len = 1.0/lines->s[j].oolen;
	    lines->s[j].len_pb = pow(lines->s[j].len, pb);
	}
    }

    return numlines;
}
Пример #22
0
/*
 *			D O _ F I L E
 */
void
do_file(void)
{
    char	*output_file;
    FILE	*ifp, *ofp;
    int	i;

    if ( (ifp = fopen( input_file, "rb" )) == NULL )  {
	perror(input_file);
	bu_exit(1, NULL);
    }
    output_file = (char *)bu_malloc( strlen(input_file)+10, "output_file" );
    snprintf(output_file, strlen(input_file)+9, "MOD_%s", input_file);

    if ( (ofp = fopen( output_file, "wb" )) == NULL )  {
	perror(output_file);
	fclose(ifp);
	bu_free(output_file, "output_file");
	bu_exit(2, NULL);
    }
    bu_free(output_file, "output_file");

    /* Shift cmap to be more useful */
    for ( i=0; i<256; i++ )  {
	map.cm_red[i] >>= 8;
	map.cm_green[i] >>= 8;
	map.cm_blue[i] >>= 8;
    }

    while ( !feof(ifp) )  {
	i = map.cm_red[getc(ifp)];
	putc( i, ofp );

	i = map.cm_green[getc(ifp)];
	putc( i, ofp );

	i = map.cm_blue[getc(ifp)];
	putc( i, ofp );
    }
    fclose(ifp);
    fclose(ofp);
}
int
Put_vertex(struct vertex *v, struct iges_edge_use *edge)
{
    struct iges_edge_list *e_list;
    struct iges_edge_list *el;
    struct iges_vertex_list *v_list;
    int vert_index;
    int vert_de;

    if ((e_list = Get_edge_list(edge)) == NULL)
	return 0;


    el = e_list;
    while (el && el->edge_de != edge->edge_de)
	el = el->next;

    if (!el) {
	bu_exit(1, "Cannot find an edge list with edge_de = %d\n", edge->edge_de);
    }

    if (edge->orient) {
	vert_de = el->i_edge[edge->index-1].start_vert_de;
	vert_index = el->i_edge[edge->index-1].start_vert_index-1;
    } else {
	vert_de = el->i_edge[edge->index-1].end_vert_de;
	vert_index = el->i_edge[edge->index-1].end_vert_index-1;
    }


    if ((v_list = Get_vertex_list(vert_de)) == NULL)
	return 0;

    if (v_list->i_verts[vert_index].v) {
	bu_log("vertex already assigned %p, trying to assign %p\n",
	       (void *)v_list->i_verts[vert_index].v, (void *)v);
	bu_exit(1, "Multiple vertex assignments\n");
    }

    v_list->i_verts[vert_index].v = v;
    return 1;
}
Пример #24
0
void
ph_restart(struct pkg_conn *UNUSED(pc), char *buf)
{

    if (debug)fprintf(stderr, "ph_restart %s\n", buf);
    bu_log("Restarting\n");
    pkg_close(pcsrv);
    execlp("rtsrv", "rtsrv", control_host, tcp_port, (char *)0);
    perror("rtsrv");
    bu_exit(1, NULL);
}
Пример #25
0
int
main(int argc, char **argv)
{
    FILE *ofp = stdout;
    size_t num = 0;
    size_t scans_per_patch, bytes_per_patch;
    size_t y;

    outwidth = outheight = DEFAULT_SIZE;

    if (!get_args(argc, argv)) {
	(void)fputs(usage, stderr);
	bu_exit (1, NULL);
    }

    if (encapsulated) {
	xpoints = width;
	ypoints = height;
    } else {
	xpoints = outwidth * 72 + 0.5;
	ypoints = outheight * 72 + 0.5;
    }
    prolog(ofp, file_name, xpoints, ypoints);

    scans_per_patch = MAX_BYTES / width;
    if (scans_per_patch > height)
	scans_per_patch = height;
    bytes_per_patch = scans_per_patch * width;

    for (y = 0; y < height; y += scans_per_patch) {
	/* start a patch */
	fprintf(ofp, "save\n");
	fprintf(ofp, "%lu %lu 8 [%lu 0 0 %lu 0 %lu] {<\n ",
		(unsigned long)width, (unsigned long)scans_per_patch,		/* patch size */
		(unsigned long)width, (unsigned long)height,			/* total size = 1.0 */
		(unsigned long)-y);				/* patch y origin */

	/* data */
	num = 0;
	while (num < bytes_per_patch) {
	    fprintf(ofp, "%02x", getc(infp));
	    if ((++num % 32) == 0)
		fprintf(ofp, "\n ");
	}

	/* close this patch */
	fprintf(ofp, ">} image\n");
	fprintf(ofp, "restore\n");
    }

    postlog(ofp);
    return 0;
}
Пример #26
0
HIDDEN void
get_small_field_input(FILE *fp, int write_flag)
{
    char **tmp_rec;
    int field_no;
    int card_len;
    int last_field;

    tmp_rec = prev_rec;
    prev_rec = curr_rec;
    curr_rec = tmp_rec;

    for ( field_no=0; field_no < NO_OF_FIELDS; field_no ++ )
	curr_rec[field_no][0] = '\0';

    card_len = strlen( line );
    last_field = card_len/8 + 1;
    if ( (last_field * 8) < card_len )
	last_field++;
    if ( last_field > 9 )
	last_field = 9;
    bu_strlcpy( curr_rec[0], line, 8 );
    curr_rec[0][8] = '\0';
    for ( field_no=2; field_no < last_field+1; field_no++ )
    {
	bu_strlcpy( curr_rec[field_no-1], &line[(field_no-1)*8], 8 );
	curr_rec[field_no-1][8] = '\0';
    }

    if ( next_line[0] == '+' )
    {
	if ( !get_next_record( fp, 0, 0 ) )
	{
	    bu_exit(1, "unexpected end of INPUT at line #%d\n", line_count );
	}

	card_len = strlen( line );
	last_field = card_len/8 + 1;
	if ( (last_field * 8) < card_len )
	    last_field++;
	if ( last_field > 9 )
	    last_field = 9;
	last_field += 9;
	for ( field_no=10; field_no < last_field+1; field_no++ )
	{
	    bu_strlcpy( curr_rec[field_no-1], &line[(field_no-9)*8], 8 );
	    curr_rec[field_no-1][8] = '\0';
	}
    }

    if ( write_flag )
	write_fields();
}
Пример #27
0
void
usage(char *str, int stopprog)
{
    if (str) (void)fputs(str, stderr);

    (void) fprintf(stderr, "Usage: %s [ -0123 ] \n%s\"%s\"\n%s\"%s\"\n",
		   progname,
		   "       Create NMG to mged database ",mfilename,
		   "       and plot3 file ",plotfilename);
    if (stopprog) bu_exit(1, NULL);
    fprintf(stderr,"       Program continues running:\n");
}
Пример #28
0
int main()
{
    char in_filename[120];
    int width, height;
    icv_image_t *bif;
    printf("Input file Name\n");
    if (scanf("%s", in_filename ) != 1) {
	bu_exit(1,"Wrong Arguments");
    }

    printf("input the width height of the Image file : ");
    if(scanf("%d %d", &width, &height)!=2)
	bu_exit(1,"Wrong Arguments");


    bif = pix_load(in_filename, width, height);
    printf("...\nImage Loaded Successfully\n...\n");
    icv_image_save(bif, OUT_IMAGE, ICV_IMAGE_PIX);
    printf("...\nImage Saved Successfully\n...\n");
    return 0;
}
Пример #29
0
int
main(int argc, char *argv[])
{
    static const char usage[] = "Usage:\n%s [-o outfile] \n\n  -o file \tFile to write out (default: ringworld.g)\n\n";

    char outfile[MAXPATHLEN] = "ringworld.g";
    int optc;
    struct rt_wdb *fp;

    while ((optc = bu_getopt(argc, argv, "o:h?")) != -1) {
    	if (bu_optopt == '?') optc='h';
	switch (optc) {
	    case 'o':
		snprintf(outfile, MAXPATHLEN, "%s", bu_optarg);
		break;
	    default:
		fprintf(stderr,usage, *argv);
		return optc == '?' ? EXIT_FAILURE : EXIT_SUCCESS;
	}
    }

    if (argc == 1) {
	fprintf(stderr,usage, *argv);
    	fprintf(stderr,"       Program continues running:\n");
    }

    if (bu_file_exists(outfile, NULL))
	bu_exit(EXIT_FAILURE, "ERROR: %s already exists.  Remove file and try again.", outfile);

    bu_log("Writing ringworld out to [%s]\n", outfile);

    fp = wdb_fopen(outfile);

    mk_sol(fp, SUN_DIAMETER);
    mk_ring(fp, RING_ORBIT, RING_WIDTH, RING_FLOOR_THICKNESS, RING_WALL_THICKNESS, RING_WALL_HEIGHT);
    mk_shadowring(fp, SHADOWRING_ORBIT, SHADOWRING_NUM, SHADOWRING_WIDTH, SHADOWRING_LENGTH, SHADOWRING_THICKNESS);

    /* generate a comb all.g */
    {
	struct wmember c;
	BU_LIST_INIT(&c.l);
	mk_addmember("ring.r", &c.l, NULL, WMOP_UNION);
	mk_addmember("sun.r", &c.l, NULL, WMOP_UNION);
	/* mk_addmember("shadowring.r", &c.l, NULL, WMOP_UNION); */
	mk_lcomb(fp, "all.g", &c, 0, NULL, NULL, NULL, 0);
    }


    wdb_close(fp);
    bu_log("BRL-CAD geometry database file [%s] created.\nDone.\n", outfile);

    return EXIT_SUCCESS;
}
Пример #30
0
/*
 *			D O _ F B
 */
void
do_fb(void)
{
    FBIO	*fbp;

    if ( (fbp = fb_open( framebuffer, 0, 0 )) == FBIO_NULL ) {
	bu_exit( 2, "Unable to open framebuffer\n" );
    }
    if ( fb_wmap( fbp, &map ) < 0 )
	fprintf( stderr, "fbgammamod: unable to write color map\n");
    fb_close(fbp);
}