Ben NanoNote 3D scans
Sign in or create your account | Project List | Help
Ben NanoNote 3D scans Commit Details
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 | ||
---|---|---|
12 | 12 | |
13 | 13 | SHELL = /bin/bash |
14 | 14 | |
15 | OBJS = array.o face.o histo.o level.o overlap.o solidify.o style.o util.o | |
15 | OBJS = array.o face.o histo.o level.o overlap.o solid.o solidify.o style.o \ | |
16 | util.o | |
16 | 17 | |
17 | 18 | CFLAGS_WARN = -Wall -Wshadow -Wmissing-prototypes \ |
18 | 19 | -Wmissing-declarations -Wno-format-zero-length |
... | ... | |
50 | 51 | spotless: clean |
51 | 52 | rm -f solidify |
52 | 53 | |
54 | # ----- Experimental execution ------------------------------------------------ | |
55 | ||
56 | PRJ=http://projects.qi-hardware.com/index.php/p/ben-scans/source/tree/master | |
57 | DIR=$(PRJ)/data/csv | |
58 | FACE_A=$(DIR)/ben-batcvr-outside-100um.txt.bz2 | |
59 | FACE_B=$(DIR)/ben-batcvr-inside-100um.txt.bz2 | |
60 | D=1.16 | |
61 | ||
62 | .PHONY: run pov disp | |
63 | ||
64 | run: solidify | |
65 | ./solidify $(FACE_A) $(FACE_B) $(D) >batcvr.inc | |
66 | ||
67 | pov: | |
68 | povray +A -W1280 -H1024 main.pov | |
69 | ||
70 | disp: | |
71 | display main.png | |
72 | ||
53 | 73 | # ----- Dependencies ---------------------------------------------------------- |
54 | 74 | |
55 | 75 | # compile and generate dependencies, from fped, based on |
solidify/main.pov | ||
---|---|---|
1 | #include "colors.inc" | |
2 | #include "batcvr.inc" | |
3 | ||
4 | camera { | |
5 | location < 2, 2, 3> | |
6 | look_at < 0, 0, 0> | |
7 | right -4/3*x | |
8 | sky x | |
9 | } | |
10 | ||
11 | background { color White } | |
12 | ||
13 | light_source { | |
14 | < 4, 7, 4> | |
15 | color White | |
16 | } | |
17 | ||
18 | union { | |
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 | ||
22 | static 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 | ||
50 | void 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 | ||
---|---|---|
18 | 18 | double dist; |
19 | 19 | }; |
20 | 20 | |
21 | ||
22 | void povray(const struct solid *s); | |
23 | ||
21 | 24 | #endif /* SOLID_H */ |
solidify/solidify.c | ||
---|---|---|
13 | 13 | |
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <stdio.h> |
16 | #include <unistd.h> | |
16 | 17 | #include <locale.h> |
17 | 18 | #include <gtk/gtk.h> |
18 | 19 | |
... | ... | |
137 | 138 | solid.b = read_face(argv[2]); |
138 | 139 | solid.dist = atof(argv[3])/0.025; /* @@@ hack */ |
139 | 140 | gui(); |
141 | if (!isatty(1)) | |
142 | povray(&solid); | |
140 | 143 | |
141 | 144 | return 0; |
142 | 145 | } |
Branches:
master