admesh 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/admesh/admesh/AUTHORS +11 -0
- data/ext/admesh/admesh/COPYING +339 -0
- data/ext/admesh/admesh/ChangeLog +143 -0
- data/ext/admesh/admesh/ChangeLog.old +42 -0
- data/ext/admesh/admesh/INSTALL +14 -0
- data/ext/admesh/admesh/Makefile.am +62 -0
- data/ext/admesh/admesh/Makefile.in +1100 -0
- data/ext/admesh/admesh/README.md +115 -0
- data/ext/admesh/admesh/aclocal.m4 +1183 -0
- data/ext/admesh/admesh/admesh-doc.txt +475 -0
- data/ext/admesh/admesh/admesh.1 +173 -0
- data/ext/admesh/admesh/block.stl +86 -0
- data/ext/admesh/admesh/compile +347 -0
- data/ext/admesh/admesh/config.guess +1420 -0
- data/ext/admesh/admesh/config.h.in +65 -0
- data/ext/admesh/admesh/config.sub +1798 -0
- data/ext/admesh/admesh/configure +14671 -0
- data/ext/admesh/admesh/configure.ac +90 -0
- data/ext/admesh/admesh/depcomp +791 -0
- data/ext/admesh/admesh/install-sh +527 -0
- data/ext/admesh/admesh/libadmesh.pc.in +11 -0
- data/ext/admesh/admesh/ltmain.sh +9655 -0
- data/ext/admesh/admesh/m4/libtool.m4 +7992 -0
- data/ext/admesh/admesh/m4/ltoptions.m4 +384 -0
- data/ext/admesh/admesh/m4/ltsugar.m4 +123 -0
- data/ext/admesh/admesh/m4/ltversion.m4 +23 -0
- data/ext/admesh/admesh/m4/lt~obsolete.m4 +98 -0
- data/ext/admesh/admesh/missing +215 -0
- data/ext/admesh/admesh/src/admesh.c +425 -0
- data/ext/admesh/admesh/src/connect.c +971 -0
- data/ext/admesh/admesh/src/normals.c +333 -0
- data/ext/admesh/admesh/src/shared.c +262 -0
- data/ext/admesh/admesh/src/stl.h +201 -0
- data/ext/admesh/admesh/src/stl_io.c +479 -0
- data/ext/admesh/admesh/src/stlinit.c +377 -0
- data/ext/admesh/admesh/src/util.c +557 -0
- data/ext/admesh/extconf.rb +14 -0
- data/lib/admesh.rb +40 -0
- metadata +84 -0
@@ -0,0 +1,201 @@
|
|
1
|
+
/* ADMesh -- process triangulated solid meshes
|
2
|
+
* Copyright (C) 1995, 1996 Anthony D. Martin <amartin@engr.csulb.edu>
|
3
|
+
* Copyright (C) 2013, 2014 several contributors, see AUTHORS
|
4
|
+
*
|
5
|
+
* This program is free software; you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
7
|
+
* the Free Software Foundation; either version 2 of the License, or
|
8
|
+
* (at your option) any later version.
|
9
|
+
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
* GNU General Public License for more details.
|
14
|
+
|
15
|
+
* You should have received a copy of the GNU General Public License along
|
16
|
+
* with this program; if not, write to the Free Software Foundation, Inc.,
|
17
|
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
18
|
+
*
|
19
|
+
* Questions, comments, suggestions, etc to
|
20
|
+
* https://github.com/admesh/admesh/issues
|
21
|
+
*/
|
22
|
+
|
23
|
+
#ifndef __admesh_stl__
|
24
|
+
#define __admesh_stl__
|
25
|
+
|
26
|
+
#include <stdio.h>
|
27
|
+
|
28
|
+
#ifdef __cplusplus
|
29
|
+
extern "C" {
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#define STL_MAX(A,B) ((A)>(B)? (A):(B))
|
33
|
+
#define STL_MIN(A,B) ((A)<(B)? (A):(B))
|
34
|
+
#define ABS(X) ((X) < 0 ? -(X) : (X))
|
35
|
+
|
36
|
+
#define LABEL_SIZE 80
|
37
|
+
#define NUM_FACET_SIZE 4
|
38
|
+
#define HEADER_SIZE 84
|
39
|
+
#define STL_MIN_FILE_SIZE 284
|
40
|
+
#define ASCII_LINES_PER_FACET 7
|
41
|
+
#define SIZEOF_EDGE_SORT 24
|
42
|
+
|
43
|
+
typedef struct {
|
44
|
+
float x;
|
45
|
+
float y;
|
46
|
+
float z;
|
47
|
+
} stl_vertex;
|
48
|
+
|
49
|
+
typedef struct {
|
50
|
+
float x;
|
51
|
+
float y;
|
52
|
+
float z;
|
53
|
+
} stl_normal;
|
54
|
+
|
55
|
+
typedef char stl_extra[2];
|
56
|
+
|
57
|
+
typedef struct {
|
58
|
+
stl_normal normal;
|
59
|
+
stl_vertex vertex[3];
|
60
|
+
stl_extra extra;
|
61
|
+
} stl_facet;
|
62
|
+
#define SIZEOF_STL_FACET 50
|
63
|
+
|
64
|
+
typedef enum {binary, ascii, inmemory} stl_type;
|
65
|
+
|
66
|
+
typedef struct {
|
67
|
+
stl_vertex p1;
|
68
|
+
stl_vertex p2;
|
69
|
+
int facet_number;
|
70
|
+
} stl_edge;
|
71
|
+
|
72
|
+
typedef struct stl_hash_edge {
|
73
|
+
unsigned key[6];
|
74
|
+
int facet_number;
|
75
|
+
int which_edge;
|
76
|
+
struct stl_hash_edge *next;
|
77
|
+
} stl_hash_edge;
|
78
|
+
|
79
|
+
typedef struct {
|
80
|
+
int neighbor[3];
|
81
|
+
char which_vertex_not[3];
|
82
|
+
} stl_neighbors;
|
83
|
+
|
84
|
+
typedef struct {
|
85
|
+
int vertex[3];
|
86
|
+
} v_indices_struct;
|
87
|
+
|
88
|
+
typedef struct {
|
89
|
+
char header[81];
|
90
|
+
stl_type type;
|
91
|
+
int number_of_facets;
|
92
|
+
stl_vertex max;
|
93
|
+
stl_vertex min;
|
94
|
+
stl_vertex size;
|
95
|
+
float bounding_diameter;
|
96
|
+
float shortest_edge;
|
97
|
+
float volume;
|
98
|
+
unsigned number_of_blocks;
|
99
|
+
int connected_edges;
|
100
|
+
int connected_facets_1_edge;
|
101
|
+
int connected_facets_2_edge;
|
102
|
+
int connected_facets_3_edge;
|
103
|
+
int facets_w_1_bad_edge;
|
104
|
+
int facets_w_2_bad_edge;
|
105
|
+
int facets_w_3_bad_edge;
|
106
|
+
int original_num_facets;
|
107
|
+
int edges_fixed;
|
108
|
+
int degenerate_facets;
|
109
|
+
int facets_removed;
|
110
|
+
int facets_added;
|
111
|
+
int facets_reversed;
|
112
|
+
int backwards_edges;
|
113
|
+
int normals_fixed;
|
114
|
+
int number_of_parts;
|
115
|
+
int malloced;
|
116
|
+
int freed;
|
117
|
+
int facets_malloced;
|
118
|
+
int collisions;
|
119
|
+
int shared_vertices;
|
120
|
+
int shared_malloced;
|
121
|
+
} stl_stats;
|
122
|
+
|
123
|
+
typedef struct {
|
124
|
+
FILE *fp;
|
125
|
+
stl_facet *facet_start;
|
126
|
+
stl_edge *edge_start;
|
127
|
+
stl_hash_edge **heads;
|
128
|
+
stl_hash_edge *tail;
|
129
|
+
int M;
|
130
|
+
stl_neighbors *neighbors_start;
|
131
|
+
v_indices_struct *v_indices;
|
132
|
+
stl_vertex *v_shared;
|
133
|
+
stl_stats stats;
|
134
|
+
char error;
|
135
|
+
} stl_file;
|
136
|
+
|
137
|
+
|
138
|
+
extern void stl_open(stl_file *stl, char *file);
|
139
|
+
extern void stl_close(stl_file *stl);
|
140
|
+
extern void stl_stats_out(stl_file *stl, FILE *file, char *input_file);
|
141
|
+
extern void stl_print_edges(stl_file *stl, FILE *file);
|
142
|
+
extern void stl_print_neighbors(stl_file *stl, char *file);
|
143
|
+
extern void stl_put_little_int(FILE *fp, int value_in);
|
144
|
+
extern void stl_put_little_float(FILE *fp, float value_in);
|
145
|
+
extern void stl_write_ascii(stl_file *stl, const char *file, const char *label);
|
146
|
+
extern void stl_write_binary(stl_file *stl, const char *file, const char *label);
|
147
|
+
extern void stl_write_binary_block(stl_file *stl, FILE *fp);
|
148
|
+
extern void stl_check_facets_exact(stl_file *stl);
|
149
|
+
extern void stl_check_facets_nearby(stl_file *stl, float tolerance);
|
150
|
+
extern void stl_remove_unconnected_facets(stl_file *stl);
|
151
|
+
extern void stl_write_vertex(stl_file *stl, int facet, int vertex);
|
152
|
+
extern void stl_write_facet(stl_file *stl, char *label, int facet);
|
153
|
+
extern void stl_write_edge(stl_file *stl, char *label, stl_hash_edge edge);
|
154
|
+
extern void stl_write_neighbor(stl_file *stl, int facet);
|
155
|
+
extern void stl_write_quad_object(stl_file *stl, char *file);
|
156
|
+
extern void stl_verify_neighbors(stl_file *stl);
|
157
|
+
extern void stl_fill_holes(stl_file *stl);
|
158
|
+
extern void stl_fix_normal_directions(stl_file *stl);
|
159
|
+
extern void stl_fix_normal_values(stl_file *stl);
|
160
|
+
extern void stl_reverse_all_facets(stl_file *stl);
|
161
|
+
extern void stl_translate(stl_file *stl, float x, float y, float z);
|
162
|
+
extern void stl_translate_relative(stl_file *stl, float x, float y, float z);
|
163
|
+
extern void stl_scale_versor(stl_file *stl, float versor[3]);
|
164
|
+
extern void stl_scale(stl_file *stl, float factor);
|
165
|
+
extern void stl_rotate_x(stl_file *stl, float angle);
|
166
|
+
extern void stl_rotate_y(stl_file *stl, float angle);
|
167
|
+
extern void stl_rotate_z(stl_file *stl, float angle);
|
168
|
+
extern void stl_mirror_xy(stl_file *stl);
|
169
|
+
extern void stl_mirror_yz(stl_file *stl);
|
170
|
+
extern void stl_mirror_xz(stl_file *stl);
|
171
|
+
extern void stl_open_merge(stl_file *stl, char *file);
|
172
|
+
extern void stl_invalidate_shared_vertices(stl_file *stl);
|
173
|
+
extern void stl_generate_shared_vertices(stl_file *stl);
|
174
|
+
extern void stl_write_obj(stl_file *stl, char *file);
|
175
|
+
extern void stl_write_off(stl_file *stl, char *file);
|
176
|
+
extern void stl_write_dxf(stl_file *stl, char *file, char *label);
|
177
|
+
extern void stl_write_vrml(stl_file *stl, char *file);
|
178
|
+
extern void stl_calculate_normal(float normal[], stl_facet *facet);
|
179
|
+
extern void stl_normalize_vector(float v[]);
|
180
|
+
extern void stl_calculate_volume(stl_file *stl);
|
181
|
+
|
182
|
+
extern void stl_repair(stl_file *stl, int fixall_flag, int exact_flag, int tolerance_flag, float tolerance, int increment_flag, float increment, int nearby_flag, int iterations, int remove_unconnected_flag, int fill_holes_flag, int normal_directions_flag, int normal_values_flag, int reverse_all_flag, int verbose_flag);
|
183
|
+
|
184
|
+
extern void stl_initialize(stl_file *stl);
|
185
|
+
extern void stl_count_facets(stl_file *stl, char *file);
|
186
|
+
extern void stl_allocate(stl_file *stl);
|
187
|
+
extern void stl_read(stl_file *stl, int first_facet, int first);
|
188
|
+
extern void stl_facet_stats(stl_file *stl, stl_facet facet, int first);
|
189
|
+
extern void stl_reallocate(stl_file *stl);
|
190
|
+
extern void stl_add_facet(stl_file *stl, stl_facet *new_facet);
|
191
|
+
extern void stl_get_size(stl_file *stl);
|
192
|
+
|
193
|
+
extern void stl_clear_error(stl_file *stl);
|
194
|
+
extern int stl_get_error(stl_file *stl);
|
195
|
+
extern void stl_exit_on_error(stl_file *stl);
|
196
|
+
|
197
|
+
#ifdef __cplusplus
|
198
|
+
}
|
199
|
+
#endif
|
200
|
+
|
201
|
+
#endif
|
@@ -0,0 +1,479 @@
|
|
1
|
+
/* ADMesh -- process triangulated solid meshes
|
2
|
+
* Copyright (C) 1995, 1996 Anthony D. Martin <amartin@engr.csulb.edu>
|
3
|
+
* Copyright (C) 2013, 2014 several contributors, see AUTHORS
|
4
|
+
*
|
5
|
+
* This program is free software; you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
7
|
+
* the Free Software Foundation; either version 2 of the License, or
|
8
|
+
* (at your option) any later version.
|
9
|
+
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
* GNU General Public License for more details.
|
14
|
+
|
15
|
+
* You should have received a copy of the GNU General Public License along
|
16
|
+
* with this program; if not, write to the Free Software Foundation, Inc.,
|
17
|
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
18
|
+
*
|
19
|
+
* Questions, comments, suggestions, etc to
|
20
|
+
* https://github.com/admesh/admesh/issues
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include <stdlib.h>
|
24
|
+
#include <string.h>
|
25
|
+
#include "stl.h"
|
26
|
+
#include "config.h"
|
27
|
+
|
28
|
+
#if !defined(SEEK_SET)
|
29
|
+
#define SEEK_SET 0
|
30
|
+
#define SEEK_CUR 1
|
31
|
+
#define SEEK_END 2
|
32
|
+
#endif
|
33
|
+
|
34
|
+
void
|
35
|
+
stl_print_edges(stl_file *stl, FILE *file) {
|
36
|
+
int i;
|
37
|
+
int edges_allocated;
|
38
|
+
|
39
|
+
if (stl->error) return;
|
40
|
+
|
41
|
+
edges_allocated = stl->stats.number_of_facets * 3;
|
42
|
+
for(i = 0; i < edges_allocated; i++) {
|
43
|
+
fprintf(file, "%d, %f, %f, %f, %f, %f, %f\n",
|
44
|
+
stl->edge_start[i].facet_number,
|
45
|
+
stl->edge_start[i].p1.x, stl->edge_start[i].p1.y,
|
46
|
+
stl->edge_start[i].p1.z, stl->edge_start[i].p2.x,
|
47
|
+
stl->edge_start[i].p2.y, stl->edge_start[i].p2.z);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
void
|
53
|
+
stl_stats_out(stl_file *stl, FILE *file, char *input_file) {
|
54
|
+
if (stl->error) return;
|
55
|
+
|
56
|
+
/* this is here for Slic3r, without our config.h
|
57
|
+
it won't use this part of the code anyway */
|
58
|
+
#ifndef VERSION
|
59
|
+
#define VERSION "unknown"
|
60
|
+
#endif
|
61
|
+
fprintf(file, "\n\
|
62
|
+
================= Results produced by ADMesh version " VERSION " ================\n");
|
63
|
+
fprintf(file, "\
|
64
|
+
Input file : %s\n", input_file);
|
65
|
+
if(stl->stats.type == binary) {
|
66
|
+
fprintf(file, "\
|
67
|
+
File type : Binary STL file\n");
|
68
|
+
} else {
|
69
|
+
fprintf(file, "\
|
70
|
+
File type : ASCII STL file\n");
|
71
|
+
}
|
72
|
+
fprintf(file, "\
|
73
|
+
Header : %s\n", stl->stats.header);
|
74
|
+
fprintf(file, "============== Size ==============\n");
|
75
|
+
fprintf(file, "Min X = % f, Max X = % f\n",
|
76
|
+
stl->stats.min.x, stl->stats.max.x);
|
77
|
+
fprintf(file, "Min Y = % f, Max Y = % f\n",
|
78
|
+
stl->stats.min.y, stl->stats.max.y);
|
79
|
+
fprintf(file, "Min Z = % f, Max Z = % f\n",
|
80
|
+
stl->stats.min.z, stl->stats.max.z);
|
81
|
+
|
82
|
+
fprintf(file, "\
|
83
|
+
========= Facet Status ========== Original ============ Final ====\n");
|
84
|
+
fprintf(file, "\
|
85
|
+
Number of facets : %5d %5d\n",
|
86
|
+
stl->stats.original_num_facets, stl->stats.number_of_facets);
|
87
|
+
fprintf(file, "\
|
88
|
+
Facets with 1 disconnected edge : %5d %5d\n",
|
89
|
+
stl->stats.facets_w_1_bad_edge, stl->stats.connected_facets_2_edge -
|
90
|
+
stl->stats.connected_facets_3_edge);
|
91
|
+
fprintf(file, "\
|
92
|
+
Facets with 2 disconnected edges : %5d %5d\n",
|
93
|
+
stl->stats.facets_w_2_bad_edge, stl->stats.connected_facets_1_edge -
|
94
|
+
stl->stats.connected_facets_2_edge);
|
95
|
+
fprintf(file, "\
|
96
|
+
Facets with 3 disconnected edges : %5d %5d\n",
|
97
|
+
stl->stats.facets_w_3_bad_edge, stl->stats.number_of_facets -
|
98
|
+
stl->stats.connected_facets_1_edge);
|
99
|
+
fprintf(file, "\
|
100
|
+
Total disconnected facets : %5d %5d\n",
|
101
|
+
stl->stats.facets_w_1_bad_edge + stl->stats.facets_w_2_bad_edge +
|
102
|
+
stl->stats.facets_w_3_bad_edge, stl->stats.number_of_facets -
|
103
|
+
stl->stats.connected_facets_3_edge);
|
104
|
+
|
105
|
+
fprintf(file,
|
106
|
+
"=== Processing Statistics === ===== Other Statistics =====\n");
|
107
|
+
fprintf(file, "\
|
108
|
+
Number of parts : %5d Volume : % f\n",
|
109
|
+
stl->stats.number_of_parts, stl->stats.volume);
|
110
|
+
fprintf(file, "\
|
111
|
+
Degenerate facets : %5d\n", stl->stats.degenerate_facets);
|
112
|
+
fprintf(file, "\
|
113
|
+
Edges fixed : %5d\n", stl->stats.edges_fixed);
|
114
|
+
fprintf(file, "\
|
115
|
+
Facets removed : %5d\n", stl->stats.facets_removed);
|
116
|
+
fprintf(file, "\
|
117
|
+
Facets added : %5d\n", stl->stats.facets_added);
|
118
|
+
fprintf(file, "\
|
119
|
+
Facets reversed : %5d\n", stl->stats.facets_reversed);
|
120
|
+
fprintf(file, "\
|
121
|
+
Backwards edges : %5d\n", stl->stats.backwards_edges);
|
122
|
+
fprintf(file, "\
|
123
|
+
Normals fixed : %5d\n", stl->stats.normals_fixed);
|
124
|
+
}
|
125
|
+
|
126
|
+
void
|
127
|
+
stl_write_ascii(stl_file *stl, const char *file, const char *label) {
|
128
|
+
int i;
|
129
|
+
FILE *fp;
|
130
|
+
char *error_msg;
|
131
|
+
|
132
|
+
if (stl->error) return;
|
133
|
+
|
134
|
+
/* Open the file */
|
135
|
+
fp = fopen(file, "w");
|
136
|
+
if(fp == NULL) {
|
137
|
+
error_msg = (char*)
|
138
|
+
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
|
139
|
+
sprintf(error_msg, "stl_write_ascii: Couldn't open %s for writing",
|
140
|
+
file);
|
141
|
+
perror(error_msg);
|
142
|
+
free(error_msg);
|
143
|
+
stl->error = 1;
|
144
|
+
return;
|
145
|
+
}
|
146
|
+
|
147
|
+
fprintf(fp, "solid %s\n", label);
|
148
|
+
|
149
|
+
for(i = 0; i < stl->stats.number_of_facets; i++) {
|
150
|
+
fprintf(fp, " facet normal % .8E % .8E % .8E\n",
|
151
|
+
stl->facet_start[i].normal.x, stl->facet_start[i].normal.y,
|
152
|
+
stl->facet_start[i].normal.z);
|
153
|
+
fprintf(fp, " outer loop\n");
|
154
|
+
fprintf(fp, " vertex % .8E % .8E % .8E\n",
|
155
|
+
stl->facet_start[i].vertex[0].x, stl->facet_start[i].vertex[0].y,
|
156
|
+
stl->facet_start[i].vertex[0].z);
|
157
|
+
fprintf(fp, " vertex % .8E % .8E % .8E\n",
|
158
|
+
stl->facet_start[i].vertex[1].x, stl->facet_start[i].vertex[1].y,
|
159
|
+
stl->facet_start[i].vertex[1].z);
|
160
|
+
fprintf(fp, " vertex % .8E % .8E % .8E\n",
|
161
|
+
stl->facet_start[i].vertex[2].x, stl->facet_start[i].vertex[2].y,
|
162
|
+
stl->facet_start[i].vertex[2].z);
|
163
|
+
fprintf(fp, " endloop\n");
|
164
|
+
fprintf(fp, " endfacet\n");
|
165
|
+
}
|
166
|
+
|
167
|
+
fprintf(fp, "endsolid %s\n", label);
|
168
|
+
|
169
|
+
fclose(fp);
|
170
|
+
}
|
171
|
+
|
172
|
+
void
|
173
|
+
stl_print_neighbors(stl_file *stl, char *file) {
|
174
|
+
int i;
|
175
|
+
FILE *fp;
|
176
|
+
char *error_msg;
|
177
|
+
|
178
|
+
if (stl->error) return;
|
179
|
+
|
180
|
+
/* Open the file */
|
181
|
+
fp = fopen(file, "w");
|
182
|
+
if(fp == NULL) {
|
183
|
+
error_msg = (char*)
|
184
|
+
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
|
185
|
+
sprintf(error_msg, "stl_print_neighbors: Couldn't open %s for writing",
|
186
|
+
file);
|
187
|
+
perror(error_msg);
|
188
|
+
free(error_msg);
|
189
|
+
stl->error = 1;
|
190
|
+
return;
|
191
|
+
}
|
192
|
+
|
193
|
+
for(i = 0; i < stl->stats.number_of_facets; i++) {
|
194
|
+
fprintf(fp, "%d, %d,%d, %d,%d, %d,%d\n",
|
195
|
+
i,
|
196
|
+
stl->neighbors_start[i].neighbor[0],
|
197
|
+
(int)stl->neighbors_start[i].which_vertex_not[0],
|
198
|
+
stl->neighbors_start[i].neighbor[1],
|
199
|
+
(int)stl->neighbors_start[i].which_vertex_not[1],
|
200
|
+
stl->neighbors_start[i].neighbor[2],
|
201
|
+
(int)stl->neighbors_start[i].which_vertex_not[2]);
|
202
|
+
}
|
203
|
+
fclose(fp);
|
204
|
+
}
|
205
|
+
|
206
|
+
void
|
207
|
+
stl_put_little_int(FILE *fp, int value_in) {
|
208
|
+
int new_value;
|
209
|
+
union {
|
210
|
+
int int_value;
|
211
|
+
char char_value[4];
|
212
|
+
} value;
|
213
|
+
|
214
|
+
value.int_value = value_in;
|
215
|
+
|
216
|
+
new_value = value.char_value[0] & 0xFF;
|
217
|
+
new_value |= (value.char_value[1] & 0xFF) << 0x08;
|
218
|
+
new_value |= (value.char_value[2] & 0xFF) << 0x10;
|
219
|
+
new_value |= (value.char_value[3] & 0xFF) << 0x18;
|
220
|
+
fwrite(&new_value, sizeof(int), 1, fp);
|
221
|
+
}
|
222
|
+
|
223
|
+
void
|
224
|
+
stl_put_little_float(FILE *fp, float value_in) {
|
225
|
+
int new_value;
|
226
|
+
union {
|
227
|
+
float float_value;
|
228
|
+
char char_value[4];
|
229
|
+
} value;
|
230
|
+
|
231
|
+
value.float_value = value_in;
|
232
|
+
|
233
|
+
new_value = value.char_value[0] & 0xFF;
|
234
|
+
new_value |= (value.char_value[1] & 0xFF) << 0x08;
|
235
|
+
new_value |= (value.char_value[2] & 0xFF) << 0x10;
|
236
|
+
new_value |= (value.char_value[3] & 0xFF) << 0x18;
|
237
|
+
fwrite(&new_value, sizeof(int), 1, fp);
|
238
|
+
}
|
239
|
+
|
240
|
+
void
|
241
|
+
stl_write_binary_block(stl_file *stl, FILE *fp)
|
242
|
+
{
|
243
|
+
int i;
|
244
|
+
for(i = 0; i < stl->stats.number_of_facets; i++)
|
245
|
+
{
|
246
|
+
stl_put_little_float(fp, stl->facet_start[i].normal.x);
|
247
|
+
stl_put_little_float(fp, stl->facet_start[i].normal.y);
|
248
|
+
stl_put_little_float(fp, stl->facet_start[i].normal.z);
|
249
|
+
stl_put_little_float(fp, stl->facet_start[i].vertex[0].x);
|
250
|
+
stl_put_little_float(fp, stl->facet_start[i].vertex[0].y);
|
251
|
+
stl_put_little_float(fp, stl->facet_start[i].vertex[0].z);
|
252
|
+
stl_put_little_float(fp, stl->facet_start[i].vertex[1].x);
|
253
|
+
stl_put_little_float(fp, stl->facet_start[i].vertex[1].y);
|
254
|
+
stl_put_little_float(fp, stl->facet_start[i].vertex[1].z);
|
255
|
+
stl_put_little_float(fp, stl->facet_start[i].vertex[2].x);
|
256
|
+
stl_put_little_float(fp, stl->facet_start[i].vertex[2].y);
|
257
|
+
stl_put_little_float(fp, stl->facet_start[i].vertex[2].z);
|
258
|
+
fputc(stl->facet_start[i].extra[0], fp);
|
259
|
+
fputc(stl->facet_start[i].extra[1], fp);
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
void
|
264
|
+
stl_write_binary(stl_file *stl, const char *file, const char *label) {
|
265
|
+
FILE *fp;
|
266
|
+
int i;
|
267
|
+
char *error_msg;
|
268
|
+
|
269
|
+
if (stl->error) return;
|
270
|
+
|
271
|
+
/* Open the file */
|
272
|
+
fp = fopen(file, "w");
|
273
|
+
if(fp == NULL) {
|
274
|
+
error_msg = (char*)
|
275
|
+
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
|
276
|
+
sprintf(error_msg, "stl_write_binary: Couldn't open %s for writing",
|
277
|
+
file);
|
278
|
+
perror(error_msg);
|
279
|
+
free(error_msg);
|
280
|
+
stl->error = 1;
|
281
|
+
return;
|
282
|
+
}
|
283
|
+
|
284
|
+
fprintf(fp, "%s", label);
|
285
|
+
for(i = strlen(label); i < LABEL_SIZE; i++) putc(0, fp);
|
286
|
+
|
287
|
+
fseek(fp, LABEL_SIZE, SEEK_SET);
|
288
|
+
|
289
|
+
stl_put_little_int(fp, stl->stats.number_of_facets);
|
290
|
+
|
291
|
+
stl_write_binary_block(stl, fp);
|
292
|
+
|
293
|
+
fclose(fp);
|
294
|
+
}
|
295
|
+
|
296
|
+
void
|
297
|
+
stl_write_vertex(stl_file *stl, int facet, int vertex) {
|
298
|
+
if (stl->error) return;
|
299
|
+
printf(" vertex %d/%d % .8E % .8E % .8E\n", vertex, facet,
|
300
|
+
stl->facet_start[facet].vertex[vertex].x,
|
301
|
+
stl->facet_start[facet].vertex[vertex].y,
|
302
|
+
stl->facet_start[facet].vertex[vertex].z);
|
303
|
+
}
|
304
|
+
|
305
|
+
void
|
306
|
+
stl_write_facet(stl_file *stl, char *label, int facet) {
|
307
|
+
if (stl->error) return;
|
308
|
+
printf("facet (%d)/ %s\n", facet, label);
|
309
|
+
stl_write_vertex(stl, facet, 0);
|
310
|
+
stl_write_vertex(stl, facet, 1);
|
311
|
+
stl_write_vertex(stl, facet, 2);
|
312
|
+
}
|
313
|
+
|
314
|
+
void
|
315
|
+
stl_write_edge(stl_file *stl, char *label, stl_hash_edge edge) {
|
316
|
+
if (stl->error) return;
|
317
|
+
printf("edge (%d)/(%d) %s\n", edge.facet_number, edge.which_edge, label);
|
318
|
+
if(edge.which_edge < 3) {
|
319
|
+
stl_write_vertex(stl, edge.facet_number, edge.which_edge % 3);
|
320
|
+
stl_write_vertex(stl, edge.facet_number, (edge.which_edge + 1) % 3);
|
321
|
+
} else {
|
322
|
+
stl_write_vertex(stl, edge.facet_number, (edge.which_edge + 1) % 3);
|
323
|
+
stl_write_vertex(stl, edge.facet_number, edge.which_edge % 3);
|
324
|
+
}
|
325
|
+
}
|
326
|
+
|
327
|
+
void
|
328
|
+
stl_write_neighbor(stl_file *stl, int facet) {
|
329
|
+
if (stl->error) return;
|
330
|
+
printf("Neighbors %d: %d, %d, %d ; %d, %d, %d\n", facet,
|
331
|
+
stl->neighbors_start[facet].neighbor[0],
|
332
|
+
stl->neighbors_start[facet].neighbor[1],
|
333
|
+
stl->neighbors_start[facet].neighbor[2],
|
334
|
+
stl->neighbors_start[facet].which_vertex_not[0],
|
335
|
+
stl->neighbors_start[facet].which_vertex_not[1],
|
336
|
+
stl->neighbors_start[facet].which_vertex_not[2]);
|
337
|
+
}
|
338
|
+
|
339
|
+
void
|
340
|
+
stl_write_quad_object(stl_file *stl, char *file) {
|
341
|
+
FILE *fp;
|
342
|
+
int i;
|
343
|
+
int j;
|
344
|
+
char *error_msg;
|
345
|
+
stl_vertex connect_color;
|
346
|
+
stl_vertex uncon_1_color;
|
347
|
+
stl_vertex uncon_2_color;
|
348
|
+
stl_vertex uncon_3_color;
|
349
|
+
stl_vertex color;
|
350
|
+
|
351
|
+
if (stl->error) return;
|
352
|
+
|
353
|
+
/* Open the file */
|
354
|
+
fp = fopen(file, "w");
|
355
|
+
if(fp == NULL) {
|
356
|
+
error_msg = (char*)
|
357
|
+
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
|
358
|
+
sprintf(error_msg, "stl_write_quad_object: Couldn't open %s for writing",
|
359
|
+
file);
|
360
|
+
perror(error_msg);
|
361
|
+
free(error_msg);
|
362
|
+
stl->error = 1;
|
363
|
+
return;
|
364
|
+
}
|
365
|
+
|
366
|
+
connect_color.x = 0.0;
|
367
|
+
connect_color.y = 0.0;
|
368
|
+
connect_color.z = 1.0;
|
369
|
+
uncon_1_color.x = 0.0;
|
370
|
+
uncon_1_color.y = 1.0;
|
371
|
+
uncon_1_color.z = 0.0;
|
372
|
+
uncon_2_color.x = 1.0;
|
373
|
+
uncon_2_color.y = 1.0;
|
374
|
+
uncon_2_color.z = 1.0;
|
375
|
+
uncon_3_color.x = 1.0;
|
376
|
+
uncon_3_color.y = 0.0;
|
377
|
+
uncon_3_color.z = 0.0;
|
378
|
+
|
379
|
+
fprintf(fp, "CQUAD\n");
|
380
|
+
for(i = 0; i < stl->stats.number_of_facets; i++) {
|
381
|
+
j = ((stl->neighbors_start[i].neighbor[0] == -1) +
|
382
|
+
(stl->neighbors_start[i].neighbor[1] == -1) +
|
383
|
+
(stl->neighbors_start[i].neighbor[2] == -1));
|
384
|
+
if(j == 0) {
|
385
|
+
color = connect_color;
|
386
|
+
} else if(j == 1) {
|
387
|
+
color = uncon_1_color;
|
388
|
+
} else if(j == 2) {
|
389
|
+
color = uncon_2_color;
|
390
|
+
} else {
|
391
|
+
color = uncon_3_color;
|
392
|
+
}
|
393
|
+
fprintf(fp, "%f %f %f %1.1f %1.1f %1.1f 1\n",
|
394
|
+
stl->facet_start[i].vertex[0].x,
|
395
|
+
stl->facet_start[i].vertex[0].y,
|
396
|
+
stl->facet_start[i].vertex[0].z, color.x, color.y, color.z);
|
397
|
+
fprintf(fp, "%f %f %f %1.1f %1.1f %1.1f 1\n",
|
398
|
+
stl->facet_start[i].vertex[1].x,
|
399
|
+
stl->facet_start[i].vertex[1].y,
|
400
|
+
stl->facet_start[i].vertex[1].z, color.x, color.y, color.z);
|
401
|
+
fprintf(fp, "%f %f %f %1.1f %1.1f %1.1f 1\n",
|
402
|
+
stl->facet_start[i].vertex[2].x,
|
403
|
+
stl->facet_start[i].vertex[2].y,
|
404
|
+
stl->facet_start[i].vertex[2].z, color.x, color.y, color.z);
|
405
|
+
fprintf(fp, "%f %f %f %1.1f %1.1f %1.1f 1\n",
|
406
|
+
stl->facet_start[i].vertex[2].x,
|
407
|
+
stl->facet_start[i].vertex[2].y,
|
408
|
+
stl->facet_start[i].vertex[2].z, color.x, color.y, color.z);
|
409
|
+
}
|
410
|
+
fclose(fp);
|
411
|
+
}
|
412
|
+
|
413
|
+
void
|
414
|
+
stl_write_dxf(stl_file *stl, char *file, char *label) {
|
415
|
+
int i;
|
416
|
+
FILE *fp;
|
417
|
+
char *error_msg;
|
418
|
+
|
419
|
+
if (stl->error) return;
|
420
|
+
|
421
|
+
/* Open the file */
|
422
|
+
fp = fopen(file, "w");
|
423
|
+
if(fp == NULL) {
|
424
|
+
error_msg = (char*)
|
425
|
+
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
|
426
|
+
sprintf(error_msg, "stl_write_ascii: Couldn't open %s for writing",
|
427
|
+
file);
|
428
|
+
perror(error_msg);
|
429
|
+
free(error_msg);
|
430
|
+
stl->error = 1;
|
431
|
+
return;
|
432
|
+
}
|
433
|
+
|
434
|
+
fprintf(fp, "999\n%s\n", label);
|
435
|
+
fprintf(fp, "0\nSECTION\n2\nHEADER\n0\nENDSEC\n");
|
436
|
+
fprintf(fp, "0\nSECTION\n2\nTABLES\n0\nTABLE\n2\nLAYER\n70\n1\n\
|
437
|
+
0\nLAYER\n2\n0\n70\n0\n62\n7\n6\nCONTINUOUS\n0\nENDTAB\n0\nENDSEC\n");
|
438
|
+
fprintf(fp, "0\nSECTION\n2\nBLOCKS\n0\nENDSEC\n");
|
439
|
+
|
440
|
+
fprintf(fp, "0\nSECTION\n2\nENTITIES\n");
|
441
|
+
|
442
|
+
for(i = 0; i < stl->stats.number_of_facets; i++) {
|
443
|
+
fprintf(fp, "0\n3DFACE\n8\n0\n");
|
444
|
+
fprintf(fp, "10\n%f\n20\n%f\n30\n%f\n",
|
445
|
+
stl->facet_start[i].vertex[0].x, stl->facet_start[i].vertex[0].y,
|
446
|
+
stl->facet_start[i].vertex[0].z);
|
447
|
+
fprintf(fp, "11\n%f\n21\n%f\n31\n%f\n",
|
448
|
+
stl->facet_start[i].vertex[1].x, stl->facet_start[i].vertex[1].y,
|
449
|
+
stl->facet_start[i].vertex[1].z);
|
450
|
+
fprintf(fp, "12\n%f\n22\n%f\n32\n%f\n",
|
451
|
+
stl->facet_start[i].vertex[2].x, stl->facet_start[i].vertex[2].y,
|
452
|
+
stl->facet_start[i].vertex[2].z);
|
453
|
+
fprintf(fp, "13\n%f\n23\n%f\n33\n%f\n",
|
454
|
+
stl->facet_start[i].vertex[2].x, stl->facet_start[i].vertex[2].y,
|
455
|
+
stl->facet_start[i].vertex[2].z);
|
456
|
+
}
|
457
|
+
|
458
|
+
fprintf(fp, "0\nENDSEC\n0\nEOF\n");
|
459
|
+
|
460
|
+
fclose(fp);
|
461
|
+
}
|
462
|
+
|
463
|
+
void
|
464
|
+
stl_clear_error(stl_file *stl) {
|
465
|
+
stl->error = 0;
|
466
|
+
}
|
467
|
+
|
468
|
+
void
|
469
|
+
stl_exit_on_error(stl_file *stl) {
|
470
|
+
if (!stl->error) return;
|
471
|
+
stl->error = 0;
|
472
|
+
stl_close(stl);
|
473
|
+
exit(1);
|
474
|
+
}
|
475
|
+
|
476
|
+
int
|
477
|
+
stl_get_error(stl_file *stl) {
|
478
|
+
return stl->error;
|
479
|
+
}
|