PrusaSlicer-NonPlainar/xs/xsp/TriangleMesh.xsp

85 lines
2.9 KiB
Plaintext
Raw Normal View History

2013-06-23 13:33:07 +00:00
%module{Slic3r::XS};
2013-06-22 15:16:45 +00:00
%package{Slic3r::TriangleMesh::XS};
%{
PROTOTYPES: DISABLE
2013-06-23 16:18:38 +00:00
#include <myinit.h>
2013-06-22 15:16:45 +00:00
std::string
hello_world()
CODE:
RETVAL = "Hello world!";
OUTPUT:
RETVAL
2013-06-23 19:11:46 +00:00
void
stl_repair(input_file, output_file)
char* input_file;
char* output_file;
2013-06-23 16:18:38 +00:00
CODE:
2013-06-23 19:11:46 +00:00
int i;
2013-06-23 16:18:38 +00:00
stl_file stl_in;
2013-06-23 19:11:46 +00:00
stl_open(&stl_in, input_file);
2013-06-23 16:18:38 +00:00
2013-06-23 19:11:46 +00:00
// checking exact
2013-06-23 16:18:38 +00:00
stl_check_facets_exact(&stl_in);
stl_in.stats.facets_w_1_bad_edge = (stl_in.stats.connected_facets_2_edge - stl_in.stats.connected_facets_3_edge);
stl_in.stats.facets_w_2_bad_edge = (stl_in.stats.connected_facets_1_edge - stl_in.stats.connected_facets_2_edge);
stl_in.stats.facets_w_3_bad_edge = (stl_in.stats.number_of_facets - stl_in.stats.connected_facets_1_edge);
2013-06-23 19:11:46 +00:00
// checking nearby
int last_edges_fixed = 0;
float tolerance = stl_in.stats.shortest_edge;
float increment = stl_in.stats.bounding_diameter / 10000.0;
int iterations = 2;
if (stl_in.stats.connected_facets_3_edge < stl_in.stats.number_of_facets) {
for (i = 0; i < iterations; i++) {
if (stl_in.stats.connected_facets_3_edge < stl_in.stats.number_of_facets) {
printf("Checking nearby. Tolerance= %f Iteration=%d of %d...", tolerance, i + 1, iterations);
stl_check_facets_nearby(&stl_in, tolerance);
printf(" Fixed %d edges.\n", stl_in.stats.edges_fixed - last_edges_fixed);
last_edges_fixed = stl_in.stats.edges_fixed;
tolerance += increment;
} else {
printf("All facets connected. No further nearby check necessary.\n");
break;
}
}
} else {
printf("All facets connected. No nearby check necessary.\n");
}
// remove_unconnected
if (stl_in.stats.connected_facets_3_edge < stl_in.stats.number_of_facets) {
printf("Removing unconnected facets...\n");
stl_remove_unconnected_facets(&stl_in);
} else
printf("No unconnected need to be removed.\n");
// fill_holes
if (stl_in.stats.connected_facets_3_edge < stl_in.stats.number_of_facets) {
printf("Filling holes...\n");
stl_fill_holes(&stl_in);
} else
printf("No holes need to be filled.\n");
// normal_directions
printf("Checking normal directions...\n");
2013-06-23 16:18:38 +00:00
stl_fix_normal_directions(&stl_in);
2013-06-23 19:11:46 +00:00
// normal_values
printf("Checking normal values...\n");
2013-06-23 16:18:38 +00:00
stl_fix_normal_values(&stl_in);
2013-06-23 19:11:46 +00:00
// write STL
//stl_write_ascii(&stl_in, output_file, (char*)"Repaired by Slic3r + ADMesh");
stl_generate_shared_vertices(&stl_in);
stl_write_obj(&stl_in, output_file);
2013-06-23 16:18:38 +00:00
stl_close(&stl_in);
2013-06-22 15:16:45 +00:00
%}