Date:2010-09-24 11:22:48 (13 years 6 months ago)
Author:Werner Almesberger
Commit:37e840fa775f031529053578668512b1c430548f
Message:Infrastructure for generating POV-Ray output (not useful yet)

- solidify/Makefile: added solid.o
- solidify/solid.h, solidify.c (height_field, povray): output the part as
the intersection of two height fields
- solidify/solidify.c (main): generate POV-Ray output if stdout is
redirected
- solidify/Makefile (run, pov, disp): targets to run a test setup, render
it, and display the result
- solidify/main.pov: simple scene showing the test part
Files: solidify/Makefile (2 diffs)
solidify/main.pov (1 diff)
solidify/solid.c (1 diff)
solidify/solid.h (1 diff)
solidify/solidify.c (2 diffs)

Change Details

solidify/Makefile
1212
1313SHELL = /bin/bash
1414
15OBJS = array.o face.o histo.o level.o overlap.o solidify.o style.o util.o
15OBJS = array.o face.o histo.o level.o overlap.o solid.o solidify.o style.o \
16       util.o
1617
1718CFLAGS_WARN = -Wall -Wshadow -Wmissing-prototypes \
1819          -Wmissing-declarations -Wno-format-zero-length
...... 
5051spotless: clean
5152        rm -f solidify
5253
54# ----- Experimental execution ------------------------------------------------
55
56PRJ=http://projects.qi-hardware.com/index.php/p/ben-scans/source/tree/master
57DIR=$(PRJ)/data/csv
58FACE_A=$(DIR)/ben-batcvr-outside-100um.txt.bz2
59FACE_B=$(DIR)/ben-batcvr-inside-100um.txt.bz2
60D=1.16
61
62.PHONY: run pov disp
63
64run: solidify
65        ./solidify $(FACE_A) $(FACE_B) $(D) >batcvr.inc
66
67pov:
68        povray +A -W1280 -H1024 main.pov
69
70disp:
71        display main.png
72
5373# ----- Dependencies ----------------------------------------------------------
5474
5575# compile and generate dependencies, from fped, based on
solidify/main.pov
1#include "colors.inc"
2#include "batcvr.inc"
3
4camera {
5    location < 2, 2, 3>
6    look_at < 0, 0, 0>
7    right -4/3*x
8    sky x
9}
10
11background { color White }
12
13light_source {
14    < 4, 7, 4>
15    color White
16}
17
18union {
19    Part
20    pigment { rgb <0.9, 0.9, 0.9> }
21    finish {
22        brilliance 2
23        phong 0.8
24        phong_size 100
25        metallic
26    }
27}
solidify/solid.c
1/*
2 * solid.c - Data structure and handling of a solid made of two opposing faces
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 by Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdint.h>
15#include <stdlib.h>
16#include <stdio.h>
17
18#include "face.h"
19#include "solid.h"
20
21
22static void height_field(const char *name, const struct face *f,
23    const struct matrix *m)
24{
25    FILE *file;
26    int x, y;
27    int z;
28    uint16_t g;
29    uint8_t v[2];
30
31    file = fopen(name, "w");
32    if (!file) {
33        perror(name);
34        exit(1);
35    }
36    fprintf(file, "P5\n%d %d\n65535\n", f->sx, f->sy);
37    for (y = 0; y != f->sy; y++)
38        for (x = 0; x != f->sx; x++) {
39            z = get(f->a, x+f->a->min_x, y+f->a->min_y);
40            g = z == UNDEF ? 0 :
41                65535*(z-f->a->min_z)/(f->a->max_z-f->a->min_z);
42            v[0] = g >> 8;
43            v[1] = g;
44            fwrite(v, 2, 1, file);
45        }
46    fclose(file);
47}
48
49
50void povray(const struct solid *s)
51{
52    struct matrix m;
53
54    m.a[0][0] = m.a[1][1] = 1;
55    m.a[0][1] = m.a[1][0] = 0;
56    m.b[0] = m.b[1] = 0;
57
58    height_field("top.pgm", s->a, &m);
59    height_field("bot.pgm", s->b, &m);
60
61    /*
62     * 1/65535 = 0.000015..., so we set the water level a bit lower, e.g.,
63     * to 0.0001
64     */
65    printf(
66"#declare Part =\n"
67" intersection {\n"
68" height_field { pgm \"top.pgm\" water_level 0.00001 smooth }\n"
69" height_field { pgm \"bot.pgm\" water_level 0.00001 smooth }\n"
70" }\n");
71}
solidify/solid.h
1818    double dist;
1919};
2020
21
22void povray(const struct solid *s);
23
2124#endif /* SOLID_H */
solidify/solidify.c
1313
1414#include <stdlib.h>
1515#include <stdio.h>
16#include <unistd.h>
1617#include <locale.h>
1718#include <gtk/gtk.h>
1819
...... 
137138    solid.b = read_face(argv[2]);
138139    solid.dist = atof(argv[3])/0.025; /* @@@ hack */
139140    gui();
141    if (!isatty(1))
142        povray(&solid);
140143
141144    return 0;
142145}

Archive Download the corresponding diff file

Branches:
master



interactive