summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2015-03-13 06:53:53 (GMT)
committerWerner Almesberger <werner@almesberger.net>2015-03-13 06:53:53 (GMT)
commit55e2604f9cf7145d3aa4456658260ace68bc260c (patch)
treed69e89401dd64a247425821a53a975385bb8f81d /meme
parent6a7b99db7751a7b7bceb2e79d7b11f68a2ad226a (diff)
downloadmisc-55e2604f9cf7145d3aa4456658260ace68bc260c.zip
misc-55e2604f9cf7145d3aa4456658260ace68bc260c.tar.gz
misc-55e2604f9cf7145d3aa4456658260ace68bc260c.tar.bz2
meme/: add overlays (option -o, key O); clean up log file implementation
Diffstat (limited to 'meme')
-rw-r--r--meme/Makefile2
-rw-r--r--meme/README19
-rw-r--r--meme/gui.c55
-rw-r--r--meme/meme.c15
-rw-r--r--meme/overlay.c104
-rw-r--r--meme/overlay.h21
6 files changed, 211 insertions, 5 deletions
diff --git a/meme/Makefile b/meme/Makefile
index cf3b25a..b0e377f 100644
--- a/meme/Makefile
+++ b/meme/Makefile
@@ -13,7 +13,7 @@
include Makefile.c-common
CFLAGS = -Wall -Wshadow -g -O9
-OBJS = meme.o stl.o mesh.o gui.o time.o plane.o text.o gaux.o
+OBJS = meme.o stl.o mesh.o gui.o time.o plane.o text.o gaux.o overlay.o
CFLAGS += $(shell sdl-config --cflags)
LDLIBS = $(shell sdl-config --libs) -lSDL_gfx -lSDL_Pango -lm
diff --git a/meme/README b/meme/README
index b07c467..7d779a7 100644
--- a/meme/README
+++ b/meme/README
@@ -4,7 +4,7 @@ Mesh measurement utility
Usage:
-meme <path-to-STL-file>
+meme [-l logfile] [-o overlay.gp] <path-to-STL-file>
Mouse
@@ -27,6 +27,7 @@ Keyboard
- C: enter contrast enhancement mode, see below
- E: highlight equal height, see below
- G: toggle grid (edges) display
+- O: toggle overlay; see below
- P: toggle profiles display, see below
- Q: quit
- *: center and zoom to extents
@@ -34,6 +35,14 @@ Keyboard
- -: zoom out
+Log file
+--------
+
+When a log file is specified with the -l option, the position of
+measurement markers and of measurements is appended to this file each
+time a marker is set.
+
+
Profiles
--------
@@ -68,6 +77,14 @@ filled. This is similar to contrast enhancement and intended for quick
estimation of where the cursor is located with respect to plateaus.
+Overlay
+-------
+
+A set of lines in gnuplot format can be drawn over the scan data. The
+file containing the lines (in model coordinates) is specified with the
+-o option. The O key toggle overlay display.
+
+
Workflow
--------
diff --git a/meme/gui.c b/meme/gui.c
index d2ac9d6..b615364 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -21,6 +21,7 @@
#include "util.h"
#include "time.h"
#include "mesh.h"
+#include "overlay.h"
#include "plane.h"
#include "gaux.h"
#include "text.h"
@@ -36,6 +37,8 @@
#define MARK_WIDTH 2
#define MARK_LEN 20
+#define OVERLAY_WIDTH 4
+
#define EDGE_RGBA 0x000000ff
#define CURSOR_RGBA 0xff202080
#define PROFILE_RGBA 0x2020ffff
@@ -43,6 +46,7 @@
#define MARK_B_RGBA 0x3030ffff
#define CONTRAST_RGBA 0xffe080ff
#define EQUAL_RGBA 0xf080ffff
+#define OVERLAY_RGBA 0xffc01060
#define DEPTH_RANGE 0xc0
#define DEPTH_OFFSET 0x30
@@ -54,6 +58,7 @@ static int x_min, x_max, y_min, y_max, z_min, z_max;
static int zoom;
static bool show_grid = 0;
static bool show_profiles = 0;
+static bool show_overlay = 0;
static const struct vertex *cursor;
@@ -876,6 +881,51 @@ static void clear_markers(void)
}
+/* ----- Overlay ----------------------------------------------------------- */
+
+
+
+static Sint16 ovl_x, ovl_y;
+static int ovl_ok;
+
+
+static void moveto(void *user, int x, int y)
+{
+ ovl_ok = coord(x, y, &ovl_x, &ovl_y);
+}
+
+
+static void lineto(void *user, int x, int y)
+{
+ SDL_Surface *s = user;
+ Sint16 to_x = 0, to_y = 0; /* @@@ suppress warning */
+ bool ok;
+
+ ok = coord(x, y, &to_x, &to_y);
+ if (ovl_ok >= 0 && ok >= 0 && (ovl_ok || ok))
+ aalineColor(s, ovl_x, ovl_y, to_x, to_y,
+ OVERLAY_RGBA);
+#if 0
+ /*
+ * Something's wrong with thickLineColor. It places the lines with a
+ * substantial offset from the correct position, or even makes them
+ * veer off the screen.
+ */
+ thickLineColor(s, ovl_x, ovl_y, to_x, to_y,
+ OVERLAY_WIDTH, OVERLAY_RGBA);
+#endif
+ ovl_x = to_x;
+ ovl_y = to_y;
+ ovl_ok = ok;
+}
+
+
+static void draw_overlay(SDL_Surface *s)
+{
+ overlay_draw(moveto, lineto, s);
+}
+
+
/* ----- Last mouse position ---------------------------------------------- */
@@ -1185,6 +1235,9 @@ static bool event_loop(SDL_Surface **surf, const char *logfile)
case SDLK_g:
show_grid = !show_grid;
return 0;
+ case SDLK_o:
+ show_overlay = !show_overlay;
+ return 0;
case SDLK_p:
show_profiles = !show_profiles;
return 0;
@@ -1261,6 +1314,8 @@ time_start(&t);
draw(surf);
time_stop(&t);
fprintf(stderr, "%.3f s @ zoom %d\n", time_ms(&t)/1000.0, zoom);
+ if (show_overlay)
+ draw_overlay(surf);
SDL_UnlockSurface(surf);
SDL_UpdateRect(surf, 0, 0, 0, 0);
diff --git a/meme/meme.c b/meme/meme.c
index fcafdb9..411b7ca 100644
--- a/meme/meme.c
+++ b/meme/meme.c
@@ -18,6 +18,7 @@
#include "time.h"
#include "mesh.h"
#include "stl.h"
+#include "overlay.h"
extern void gui(const char *logfile);
@@ -44,7 +45,8 @@ static unsigned count_edges(void)
static void usage(const char *name)
{
- fprintf(stderr, "usage: %s [file.stl]\n", name);
+ fprintf(stderr, "usage: %s [-l logfile] [-o overlap.gp] [file.stl]\n",
+ name);
exit(1);
}
@@ -52,14 +54,18 @@ static void usage(const char *name)
int main(int argc, char **argv)
{
int c;
- const char *logfile = 0;
+ const char *logfile = NULL;
+ const char *overlay = NULL;
struct time t_load;
- while ((c = getopt(argc, argv, "l:")) != EOF)
+ while ((c = getopt(argc, argv, "l:o:")) != EOF)
switch (c) {
case 'l':
logfile = optarg;
break;
+ case 'o':
+ overlay = optarg;
+ break;
default:
usage(*argv);
}
@@ -82,6 +88,9 @@ int main(int argc, char **argv)
fprintf(stderr, "STL loaded in %.3f s\n", time_ms(&t_load)/1000.0);
fprintf(stderr, "%u edges\n", count_edges());
+ if (overlay)
+ overlay_load(overlay);
+
gui(logfile);
return 0;
diff --git a/meme/overlay.c b/meme/overlay.c
new file mode 100644
index 0000000..df3f3cf
--- /dev/null
+++ b/meme/overlay.c
@@ -0,0 +1,104 @@
+/*
+ * overlay.c - Overlay in Gnuplot format
+ *
+ * Written 2015 by Werner Almesberger
+ * Copyright 2015 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 <math.h>
+
+#include "util.h"
+#include "overlay.h"
+
+
+struct point {
+ float x, y;
+ struct point *next;
+};
+
+struct path {
+ struct point *points;
+ struct path *next;
+};
+
+
+static struct path *paths = NULL;
+
+
+void overlay_draw(void (*moveto)(void *user, int x, int y),
+ void (*lineto)(void *user, int x, int y), void *user)
+{
+ const struct path *path;
+ const struct point *p;
+
+ for (path = paths; path; path = path->next) {
+ p = path->points;
+ moveto(user, p->x, p->y);
+ for (p = p->next; p; p = p->next)
+ lineto(user, p->x, p->y);
+ }
+}
+
+
+static void overlay_load_file(FILE *file)
+{
+ struct path *path = NULL;
+ struct point *p;
+ int lineno = 0;
+ char buf[1024];
+ int n;
+ double x, y, z;
+
+ while (fgets(buf, sizeof(buf), file)) {
+ lineno++;
+ if (*buf == '#')
+ continue;
+ n = sscanf(buf, "%lf %lf %lf\n", &x, &y, &z);
+ switch (n) {
+ case -1:
+ path = NULL;
+ continue;
+ case 2:
+ /* fall through */
+ case 3:
+ break;
+ default:
+ fprintf(stderr, "invalid data at line %d\n", lineno);
+ exit(1);
+ }
+
+ if (!path) {
+ path = alloc_type(struct path);
+ path->next = paths;
+ path->points = NULL;
+ paths = path;
+ }
+ p = alloc_type(struct point);
+ p->x = round(x * 1000);
+ p->y = round(y * 1000);
+ p->next = path->points;
+ path->points = p;
+ }
+}
+
+
+void overlay_load(const char *name)
+{
+ FILE *file;
+
+ file = fopen(name, "r");
+ if (!file) {
+ perror(name);
+ exit(1);
+ }
+ overlay_load_file(file);
+ fclose(file);
+}
diff --git a/meme/overlay.h b/meme/overlay.h
new file mode 100644
index 0000000..703d54e
--- /dev/null
+++ b/meme/overlay.h
@@ -0,0 +1,21 @@
+/*
+ * overlay.h - Overlay in Gnuplot format
+ *
+ * Written 2015 by Werner Almesberger
+ * Copyright 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.
+ */
+
+
+#ifndef OVERLAY_H
+#define OVERLAY_H
+
+void overlay_draw(void (*moveto)(void *user, int x, int y),
+ void (*lineto)(void *user, int x, int y), void *user);
+void overlay_load(const char *name);
+
+#endif /* !STL_H */