star-stl

Load STereo Lithography (StL) file format
git clone git://git.meso-star.fr/star-stl.git
Log | Files | Refs | README | LICENSE

commit a4cedc15b54710816bcced567fd6841022256555
parent dec0cb08d536a487f4698a1e26a34d2613c11206
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 21 Feb 2025 16:07:06 +0100

Merge branch 'release_0.5.1'

Diffstat:
MMakefile | 10+++++-----
MREADME.md | 4++++
Mconfig.mk | 2+-
Msrc/sstl.c | 35+++++++++++++++++++++--------------
Msrc/sstl.h | 15+++++++++++----
5 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/Makefile b/Makefile @@ -86,11 +86,11 @@ install: build_library pkg @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-stl" COPYING README.md uninstall: - rm -f $(DESTDIR)$(PREFIX)/lib/$(LIBNAME) - rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/sstl.pc - rm -f $(DESTDIR)$(PREFIX)/share/doc/star-stl/COPYING - rm -f $(DESTDIR)$(PREFIX)/share/doc/star-stl/README.md - rm -f $(DESTDIR)$(PREFIX)/include/star/sstl.h + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/sstl.pc" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-stl/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-stl/README.md" + rm -f "$(DESTDIR)$(PREFIX)/include/star/sstl.h" ################################################################################ # Miscellaneous targets diff --git a/README.md b/README.md @@ -17,6 +17,10 @@ Edit config.mk as needed, then run: ## Release notes +### Version 0.5.1 +- Add the read data type in the descriptor. +- Fix a false error log message (should have been an information message). + ### Version 0.5 - Replace CMake by Makefile as build system. diff --git a/config.mk b/config.mk @@ -1,4 +1,4 @@ -VERSION = 0.5.0 +VERSION = 0.5.1 PREFIX = /usr/local LIB_TYPE = SHARED diff --git a/src/sstl.c b/src/sstl.c @@ -38,13 +38,20 @@ #define OK(Expr) if((res = (Expr)) != RES_OK) goto error; else (void)0 +enum allowed_load_steps { + TRY_READ_ASCII = 1, + TRY_READ_BINARY = 2, + TRY_READ_ALL = 3 +}; + struct solid { char* name; unsigned* indices; float* vertices; float* normals; + enum sstl_read_type read_type; }; -static const struct solid SOLID_NULL = { NULL, NULL, NULL, NULL }; +static const struct solid SOLID_NULL = { NULL, NULL, NULL, NULL, 0 }; struct streamer { FILE* stream; @@ -301,13 +308,15 @@ parse_solid_name char* line, const char* filename, const size_t iline, + int allowed, char** tok_ctx) { res_T res = RES_OK; ASSERT(sstl && solid && !solid->name); if(!line || strcmp(strtok_r(line, " \t", tok_ctx), "solid")) { - print_log(sstl, LOG_ERROR, + enum log_type lt = (allowed & TRY_READ_BINARY) ? LOG_OUTPUT : LOG_ERROR; + print_log(sstl, lt, "%s:%lu: missing the \"solid [NAME]\" directive.\n", filename, (unsigned long)iline); res = RES_BAD_ARG; @@ -433,7 +442,8 @@ static res_T load_ascii_stream (struct sstl* sstl, FILE* stream, - const char* stream_name) + const char* stream_name, + int allowed) { res_T res = RES_OK; struct streamer streamer; @@ -447,7 +457,8 @@ load_ascii_stream clear(sstl); line = streamer_read_line(&streamer, 1); - OK(parse_solid_name(sstl, &solid, line, streamer.name, streamer.iline, &tok_ctx)); + OK(parse_solid_name(sstl, &solid, line, streamer.name, streamer.iline, + allowed, &tok_ctx)); for(;;) { /* Parse the solid facets */ float normal[3]; @@ -525,6 +536,7 @@ load_ascii_stream } /* Register the solid */ + solid.read_type = SSTL_ASCII; sstl->solid = solid; exit: @@ -605,6 +617,7 @@ load_binary_stream } /* Register the solid */ + solid.read_type = SSTL_BINARY; sstl->solid = solid; exit: @@ -624,12 +637,6 @@ error: #error Undefined FTELL macro #endif -enum allowed_load_steps { - TRY_READ_ASCII = 1, - TRY_READ_BINARY = 2, - TRY_READ_ALL = 3 -}; - static res_T load_stream (struct sstl* sstl, @@ -654,7 +661,7 @@ load_stream print_log(sstl, LOG_OUTPUT, "%s: attempt to read as ASCII file.\n", stream_name); } - res = load_ascii_stream(sstl, stream, stream_name); + res = load_ascii_stream(sstl, stream, stream_name, allowed); if(res == RES_OK) { if(log) print_log(sstl, LOG_OUTPUT, "Attempt successful.\n"); goto exit; @@ -706,7 +713,7 @@ get_sstl_triangle_normal float normal[3]) { res_T res = RES_OK; - const struct sstl* sstl = (struct sstl*)data; + struct sstl* sstl = (struct sstl*)data; struct sstl_desc desc; if(!sstl || !normal) { @@ -736,7 +743,7 @@ get_sstl_triangle_vertices float vtx[3][3]) { res_T res = RES_OK; - const struct sstl* sstl = (struct sstl*)data; + struct sstl* sstl = (struct sstl*)data; struct sstl_desc desc; unsigned n; @@ -1004,7 +1011,7 @@ sstl_load_stream(struct sstl* sstl, FILE* stream) } res_T -sstl_get_desc(const struct sstl* sstl, struct sstl_desc* desc) +sstl_get_desc(struct sstl* sstl, struct sstl_desc* desc) { if(!sstl || !desc) return RES_BAD_ARG; desc->solid_name = sstl->solid.name; diff --git a/src/sstl.h b/src/sstl.h @@ -36,14 +36,21 @@ #define SSTL(Func) sstl_ ## Func #endif +/* The type of a read file */ +enum sstl_read_type { + SSTL_ASCII = 1, + SSTL_BINARY = 2 +}; + /* Descriptor of a loaded STL */ struct sstl_desc { const char* solid_name; /* May be NULL <=> no name */ + enum sstl_read_type read_type; /* The type of the file */ /* Front faces are CCW ordered and the normals follow the right handed rule */ - const float* vertices; /* triangles_count * 3 coordinates */ - const unsigned* indices; /* triangles_count * 3 indices */ - const float* normals; /* Per triangle normalized normal */ + float* vertices; /* triangles_count * 3 coordinates */ + unsigned* indices; /* triangles_count * 3 indices */ + float* normals; /* Per triangle normalized normal */ size_t triangles_count; size_t vertices_count; @@ -154,7 +161,7 @@ sstl_write_stream /* The returned descriptor is valid until a new load process */ SSTL_API res_T sstl_get_desc - (const struct sstl* sstl, + (struct sstl* sstl, struct sstl_desc* desc); END_DECLS