1
0
mirror of git://projects.qi-hardware.com/ben-scans.git synced 2024-11-21 21:45:55 +02:00

Control inclination of the z0 plane. (Needs more work.)

- solidify/face.h (struct face), solidify/face.c (read_face),
  solidify/level.c (draw_map, draw_image): introduce inclination of the z0
  plane
- solidify/level.c (draw_map): make blue z == z0 display more continuous
- solidify/level.c (scroll_event): moved z0 shift to scroll_z
- solidify/level.c (scroll_event, scroll_xy): added manipulation of the
  z0 plane's inclination
This commit is contained in:
Werner Almesberger 2010-09-22 19:20:29 -03:00
parent ecf993e0f2
commit 6ac06aab7c
3 changed files with 49 additions and 16 deletions

View File

@ -58,6 +58,8 @@ struct face *read_face(const char *name)
h = make_histo(f->a);
f->z_ref = f->a->min_z+median(h);
free_histo(h);
f->fx = f->fy = 0;
fprintf(stderr, "%d-%d / %d-%d / %d-%d\n",
f->a->min_x, f->a->max_x, f->a->min_y, f->a->max_y,
f->a->min_z, f->a->max_z);

View File

@ -6,8 +6,9 @@
struct face {
struct array *a;
int sx, sy;
int sx, sy; /* size */
int z_ref;
double fx, fy; /* inclination factor */
};

View File

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gtk/gtk.h>
#include "array.h"
@ -10,6 +11,7 @@
static void draw_map(GtkWidget *widget, struct face *f)
{
int x, y, z;
double z0;
guchar *rgbbuf, *p;
rgbbuf = p = calloc(f->sx*f->sy, 3);
@ -24,19 +26,20 @@ static void draw_map(GtkWidget *widget, struct face *f)
p += 3;
continue;
}
if (z == f->z_ref) {
*p++ = 0;
*p++ = 0;
z0 = f->z_ref+f->fx*(x-f->sx/2)+f->fy*(y-f->sy/2);
if (fabs(z-z0) < 1) {
*p++ = 255*fabs(z-z0);
*p++ = 255*fabs(z-z0);
*p++ = 255;
continue;
}
if (z < f->z_ref) {
z = 255.0*(z-f->z_ref)/(f->z_ref-f->a->min_z);
if (z < z0) {
z = 255.0*(z-z0)/(z0-f->a->min_z);
*p++ = 255;
*p++ = z;
*p++ = z;
} else {
z = 255.0*(f->z_ref-z)/(f->a->max_z-f->z_ref);
z = 255.0*(z0-z)/(f->a->max_z-z0);
*p++ = z;
*p++ = 255;
*p++ = z;
@ -51,29 +54,56 @@ static void draw_map(GtkWidget *widget, struct face *f)
static void draw_image(GtkWidget *da, struct face *f)
{
fprintf(stderr, "%d\n", f->z_ref);
fprintf(stderr, "%d %g %g\n", f->z_ref, f->fx, f->fy);
draw_map(da, f);
}
static void scroll_z(GtkWidget *da, struct face *f, int up)
{
if (up) {
if (f->z_ref < f->a->max_z)
f->z_ref++;
} else {
if (f->z_ref > f->a->min_z)
f->z_ref--;
}
draw_image(da, f);
}
static void scroll_xy(GtkWidget *da, struct face *f, int dx, int dy, int up)
{
double d;
d = (double) (up ? 1 : -1)/(dx*dx+dy*dy)/2.0;
f->fx += d*dx;
f->fy += d*dy;
draw_image(da, f);
}
static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event,
gpointer data)
{
GtkWidget *da = gtk_bin_get_child(GTK_BIN(widget));
struct face *f = data;
int dx = event->x-f->sx/2;
int dy = event->y-f->sy/2;
int center = hypot(dx, dy)/hypot(f->sx, f->sy) < 0.25;
switch (event->direction) {
case GDK_SCROLL_UP:
if (f->z_ref > f->a->min_z) {
f->z_ref--;
draw_image(da, f);
}
if (center)
scroll_z(da, f, 0);
else
scroll_xy(da, f, dx, dy, 1);
break;
case GDK_SCROLL_DOWN:
if (f->z_ref < f->a->max_z) {
f->z_ref++;
draw_image(da, f);
}
if (center)
scroll_z(da, f, 1);
else
scroll_xy(da, f, dx, dy, 0);
break;
default:
/* ignore */;