summaryrefslogtreecommitdiff
path: root/meme/meme.c
blob: fcafdb9e4ceac4ce0aa182ca6d8045b979862c1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * meme.c - Measmesh command-line processing and setup
 *
 * Written 2014-2015 by Werner Almesberger
 * Copyright 2014-2015 by Werner Almesberger
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include "time.h"
#include "mesh.h"
#include "stl.h"


extern void gui(const char *logfile);


static bool count_edge(const struct vertex *a, const struct vertex *b,
    void *user)
{
	unsigned *count = user;

	(*count)++;
	return 0;
}


static unsigned count_edges(void)
{
	unsigned count = 0;

	edge_foreach(count_edge, &count);
	return count;
}


static void usage(const char *name)
{
	fprintf(stderr, "usage: %s [file.stl]\n", name);
	exit(1);
}


int main(int argc, char **argv)
{
	int c;
	const char *logfile = 0;
	struct time t_load;

	while ((c = getopt(argc, argv, "l:")) != EOF)
		switch (c) {
		case 'l':
			logfile = optarg;
			break;
		default:
			usage(*argv);
		}

	switch (argc - optind) {
	case 0:
		time_start(&t_load);
		stl_load_file(stdin);
		time_stop(&t_load);
		break;
	case 1:
		time_start(&t_load);
		stl_load(argv[optind]);
		time_stop(&t_load);
		break;
	default:
		usage(*argv);
	}

	fprintf(stderr, "STL loaded in %.3f s\n", time_ms(&t_load)/1000.0);
	fprintf(stderr, "%u edges\n", count_edges());

	gui(logfile);

	return 0;
}