1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-22 23:04:16 +02:00

slicer/stl.h, stl.c: adapt for use in slicer

This commit is contained in:
Werner Almesberger 2015-01-07 21:26:50 -03:00
parent 632a60f4b7
commit 5f31b94729
2 changed files with 21 additions and 20 deletions

View File

@ -1,8 +1,8 @@
/*
* stl.c - STL file reading
*
* Written 2014 by Werner Almesberger
* Copyright 2014 by Werner Almesberger
* Written 2014-2015 by Werner Almesberger
* Copyright 2014-2015 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,7 +17,6 @@
#include <string.h>
#include <math.h>
#include "mesh.h"
#include "stl.h"
@ -34,18 +33,16 @@ enum state {
};
void stl_load_file(FILE *file)
void stl_load_file(FILE *file, void (*facet)(struct v f[3]))
{
char buf[MAX_LINE+1];
char buf[MAX_LINE + 1];
enum state state = s_init;
const struct vertex *v[3];
struct v f[3];
int num_v = 0;
char *s, *e;
int n = 0;
int end, got;
float x, y, z;
mesh_init();
while (fgets(buf, sizeof(buf), file)) {
n++;
if (!(n & 1023))
@ -75,13 +72,12 @@ void stl_load_file(FILE *file)
num_v = 0;
break;
case s_vertices:
got = sscanf(s, "vertex %f %f %f%n", &x,&y, &z, &end);
got = sscanf(s, "vertex %f %f %f%n",
&f[num_v].x, &f[num_v].y, &f[num_v].z, &end);
if (got < 3)
break;
v[num_v] = vertex_add(
roundf(x*1000), roundf(-y*1000), roundf(z*1000));
if (++num_v == 3) {
facet_add(v[0], v[1], v[2]);
facet(f);
state = s_endloop;
}
break;
@ -94,9 +90,9 @@ void stl_load_file(FILE *file)
state = s_facet;
break;
}
if (end != e-s) {
if (end != e - s) {
fprintf(stderr, "cannot parse line %d (%d %ld)\n",
n, end, e-s);
n, end, e - s);
exit(1);
}
}
@ -106,7 +102,7 @@ void stl_load_file(FILE *file)
}
void stl_load(const char *name)
void stl_load(const char *name, void (*facet)(struct v f[3]))
{
FILE *file;
@ -115,6 +111,6 @@ void stl_load(const char *name)
perror(name);
exit(1);
}
stl_load_file(file);
stl_load_file(file, facet);
fclose(file);
}

View File

@ -1,8 +1,8 @@
/*
* stl.h - STL file reading
*
* Written 2014 by Werner Almesberger
* Copyright 2014 by Werner Almesberger
* Written 2014-2015 by Werner Almesberger
* Copyright 2014-2015 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,7 +17,12 @@
#include <stdio.h>
void stl_load_file(FILE *file);
void stl_load(const char *name);
struct v {
float x, y, z;
};
void stl_load_file(FILE *file, void (*facet)(struct v f[3]));
void stl_load(const char *name, void (*facet)(struct v f[3]));
#endif /* !STL_H */