Ben NanoNote 3D scans
Sign in or create your account | Project List | Help
Ben NanoNote 3D scans Git Source Tree
Root/
Source at commit f6ed3bf762b63b950cf801c9282101a818c0ff8e created 13 years 6 months ago. By Werner Almesberger, solidify now stores the context of sessions in project description files. | |
---|---|
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 | } |
72 |
Branches:
master