c-lib: put STL binary reading code in stlb_read.* files
This commit is contained in:
parent
8cbb5a0007
commit
6e513f6d68
@ -26,14 +26,14 @@ HEADERS += \
|
|||||||
../../../src/c/memory.h \
|
../../../src/c/memory.h \
|
||||||
../../../src/c/stream.h \
|
../../../src/c/stream.h \
|
||||||
../../../src/c/task_control.h \
|
../../../src/c/task_control.h \
|
||||||
../../../src/c/libstl/stlb.h \
|
../../../src/c/libstl/stlb_read.h \
|
||||||
../../../src/c/libstl/triangle.h
|
../../../src/c/libstl/triangle.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
../../../src/c/endian.c \
|
../../../src/c/endian.c \
|
||||||
../../../src/c/stream.c \
|
../../../src/c/stream.c \
|
||||||
../../../src/c/task_control.c \
|
../../../src/c/task_control.c \
|
||||||
../../../src/c/libstl/stlb.c
|
../../../src/c/libstl/stlb_read.c
|
||||||
|
|
||||||
*-g++*:QMAKE_CFLAGS += -ansi
|
*-g++*:QMAKE_CFLAGS += -ansi
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "stlb.h"
|
#include "stlb_read.h"
|
||||||
|
|
||||||
#include "../endian.h"
|
#include "../endian.h"
|
||||||
|
|
||||||
@ -30,6 +30,11 @@ void* foug_stlb_geom_get_cookie(const foug_stlb_geom_t* geom)
|
|||||||
static const int stlb_min_file_size = 284;
|
static const int stlb_min_file_size = 284;
|
||||||
static const int stlb_facet_size = (4 * 3) * sizeof(foug_real32_t) + sizeof(uint16_t);
|
static const int stlb_facet_size = (4 * 3) * sizeof(foug_real32_t) + sizeof(uint16_t);
|
||||||
|
|
||||||
|
static foug_bool_t foug_stlb_no_error(int code)
|
||||||
|
{
|
||||||
|
return code == FOUG_STLB_READ_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
int foug_stlb_read(foug_stlb_read_args_t args)
|
int foug_stlb_read(foug_stlb_read_args_t args)
|
||||||
{
|
{
|
||||||
if (args.geom == NULL)
|
if (args.geom == NULL)
|
||||||
@ -64,11 +69,13 @@ int foug_stlb_read(foug_stlb_read_args_t args)
|
|||||||
const size_t buffer_facet_count = 163;
|
const size_t buffer_facet_count = 163;
|
||||||
size_t accum_facet_count_read = 0;
|
size_t accum_facet_count_read = 0;
|
||||||
foug_stl_triangle_t triangle;
|
foug_stl_triangle_t triangle;
|
||||||
foug_bool_t stream_error = 0;
|
int error = FOUG_STLB_READ_NO_ERROR;
|
||||||
while (accum_facet_count_read < total_facet_count && !stream_error) {
|
while (foug_stlb_no_error(error) && accum_facet_count_read < total_facet_count) {
|
||||||
const size_t facet_count_read =
|
const size_t facet_count_read =
|
||||||
foug_stream_read(args.stream, buffer, stlb_facet_size, buffer_facet_count);
|
foug_stream_read(args.stream, buffer, stlb_facet_size, buffer_facet_count);
|
||||||
if (facet_count_read > 0 /* && !foug_stream_has_error(args.stream)*/) {
|
error = foug_stream_error(args.stream) != 0 ? FOUG_STLB_READ_STREAM_ERROR :
|
||||||
|
FOUG_STLB_READ_NO_ERROR;
|
||||||
|
if (foug_stlb_no_error(error)) {
|
||||||
uint32_t buffer_offset = 0;
|
uint32_t buffer_offset = 0;
|
||||||
uint32_t i_facet;
|
uint32_t i_facet;
|
||||||
for (i_facet = 0; i_facet < facet_count_read; ++i_facet) {
|
for (i_facet = 0; i_facet < facet_count_read; ++i_facet) {
|
||||||
@ -103,23 +110,21 @@ int foug_stlb_read(foug_stlb_read_args_t args)
|
|||||||
buffer_offset += stlb_facet_size;
|
buffer_offset += stlb_facet_size;
|
||||||
} /* end for */
|
} /* end for */
|
||||||
|
|
||||||
|
accum_facet_count_read += facet_count_read;
|
||||||
if (foug_task_control_is_stop_requested(args.task_control)) {
|
if (foug_task_control_is_stop_requested(args.task_control)) {
|
||||||
stream_error = 1;
|
error = FOUG_STLB_READ_TASK_STOPPED_ERROR;
|
||||||
foug_task_control_handle_stop(args.task_control);
|
foug_task_control_handle_stop(args.task_control);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
foug_task_control_set_progress(args.task_control, accum_facet_count_read);
|
foug_task_control_set_progress(args.task_control, accum_facet_count_read);
|
||||||
}
|
}
|
||||||
accum_facet_count_read += facet_count_read;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
stream_error = 1;
|
|
||||||
}
|
}
|
||||||
} /* end while */
|
} /* end while */
|
||||||
|
|
||||||
if (!stream_error && args.geom->manip.end_triangles_func != NULL)
|
if (foug_stlb_no_error(error) && args.geom->manip.end_triangles_func != NULL)
|
||||||
(*(args.geom->manip.end_triangles_func))(args.geom);
|
(*(args.geom->manip.end_triangles_func))(args.geom);
|
||||||
|
|
||||||
return FOUG_STLB_READ_NO_ERROR;
|
if (foug_stlb_no_error(error) && accum_facet_count_read != total_facet_count)
|
||||||
|
error = FOUG_STLB_READ_FACET_COUNT_ERROR;
|
||||||
|
return error;
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef FOUG_C_LIBSTL_STLB_H
|
#ifndef FOUG_C_LIBSTL_STLB_READ_H
|
||||||
#define FOUG_C_LIBSTL_STLB_H
|
#define FOUG_C_LIBSTL_STLB_READ_H
|
||||||
|
|
||||||
#include "triangle.h"
|
#include "triangle.h"
|
||||||
#include "../foug_global.h"
|
#include "../foug_global.h"
|
||||||
@ -46,21 +46,7 @@ int foug_stlb_read(foug_stlb_read_args_t args);
|
|||||||
#define FOUG_STLB_READ_INVALID_BUFFER_SIZE_ERROR 3
|
#define FOUG_STLB_READ_INVALID_BUFFER_SIZE_ERROR 3
|
||||||
#define FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR 4
|
#define FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR 4
|
||||||
#define FOUG_STLB_READ_FACET_COUNT_ERROR 5
|
#define FOUG_STLB_READ_FACET_COUNT_ERROR 5
|
||||||
|
#define FOUG_STLB_READ_STREAM_ERROR 6
|
||||||
|
#define FOUG_STLB_READ_TASK_STOPPED_ERROR 7
|
||||||
|
|
||||||
/*class FOUG_STL_EXPORT AbstractGeometryExtraData
|
#endif /* FOUG_C_LIBSTL_STLB_READ_H */
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void getHeader(Header& data) const = 0;
|
|
||||||
virtual UInt16 attributeByteCount(UInt32 triangleIndex) const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class FOUG_STL_EXPORT Io : public IoBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Io(AbstractStream* stream = 0);
|
|
||||||
|
|
||||||
bool read(AbstractGeometryBuilder* builder);
|
|
||||||
bool write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraData* extraData = 0);
|
|
||||||
};*/
|
|
||||||
|
|
||||||
#endif /* FOUG_C_LIBSTL_STLB_H */
|
|
@ -34,10 +34,10 @@ static foug_bool_t foug_stream_stdio_at_end(foug_stream_t* stream)
|
|||||||
return feof((FILE*) stream->cookie);
|
return feof((FILE*) stream->cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static int32_t foug_stream_stdio_seek(foug_stream_t* stream, int64_t pos)
|
static int32_t foug_stream_stdio_error(foug_stream_t* stream)
|
||||||
{
|
{
|
||||||
return fseek((FILE*) stream->cookie, pos, SEEK_SET);
|
return ferror((FILE*) stream->cookie);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
static size_t foug_stream_stdio_read(foug_stream_t* stream,
|
static size_t foug_stream_stdio_read(foug_stream_t* stream,
|
||||||
void* ptr,
|
void* ptr,
|
||||||
@ -59,7 +59,7 @@ foug_stream_manip_t foug_stream_manip_stdio()
|
|||||||
{
|
{
|
||||||
foug_stream_manip_t manip;
|
foug_stream_manip_t manip;
|
||||||
manip.at_end_func = &foug_stream_stdio_at_end;
|
manip.at_end_func = &foug_stream_stdio_at_end;
|
||||||
/* manip.seek_func = &foug_stream_stdio_seek; */
|
manip.error_func = &foug_stream_stdio_error;
|
||||||
manip.read_func = &foug_stream_stdio_read;
|
manip.read_func = &foug_stream_stdio_read;
|
||||||
manip.write_func = &foug_stream_stdio_write;
|
manip.write_func = &foug_stream_stdio_write;
|
||||||
return manip;
|
return manip;
|
||||||
@ -72,12 +72,12 @@ foug_bool_t foug_stream_at_end(foug_stream_t* stream)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*int32_t foug_stream_seek(foug_stream_t* stream, int64_t max_size)
|
int foug_stream_error(foug_stream_t* stream)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->manip.seek_func != NULL)
|
if (stream != NULL && stream->manip.error_func != NULL)
|
||||||
return (*(stream->manip.seek_func))(stream, max_size);
|
return (*(stream->manip.error_func))(stream);
|
||||||
return -1;
|
return 0;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
size_t foug_stream_read(foug_stream_t* stream, void *ptr, size_t item_size, size_t item_count)
|
size_t foug_stream_read(foug_stream_t* stream, void *ptr, size_t item_size, size_t item_count)
|
||||||
{
|
{
|
||||||
|
@ -9,15 +9,13 @@ typedef struct _internal_foug_stream foug_stream_t;
|
|||||||
|
|
||||||
/* foug_stream_manip */
|
/* foug_stream_manip */
|
||||||
typedef foug_bool_t (*foug_stream_at_end_func_t)(foug_stream_t*);
|
typedef foug_bool_t (*foug_stream_at_end_func_t)(foug_stream_t*);
|
||||||
|
typedef int32_t (*foug_stream_error_func_t)(foug_stream_t*);
|
||||||
/* typedef int32_t (*foug_stream_seek_func_t)(foug_stream_t*, int64_t); */
|
|
||||||
typedef size_t (*foug_stream_read_func_t)(foug_stream_t*, void*, size_t, size_t);
|
typedef size_t (*foug_stream_read_func_t)(foug_stream_t*, void*, size_t, size_t);
|
||||||
typedef size_t (*foug_stream_write_func_t)(foug_stream_t*, const void*, size_t, size_t);
|
typedef size_t (*foug_stream_write_func_t)(foug_stream_t*, const void*, size_t, size_t);
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
foug_stream_at_end_func_t at_end_func;
|
foug_stream_at_end_func_t at_end_func;
|
||||||
|
foug_stream_error_func_t error_func;
|
||||||
/* foug_stream_seek_func_t seek_func; */
|
|
||||||
foug_stream_read_func_t read_func;
|
foug_stream_read_func_t read_func;
|
||||||
foug_stream_write_func_t write_func;
|
foug_stream_write_func_t write_func;
|
||||||
} foug_stream_manip_t;
|
} foug_stream_manip_t;
|
||||||
@ -29,7 +27,7 @@ foug_stream_manip_t foug_stream_manip_stdio();
|
|||||||
foug_stream_t* foug_stream_create(foug_malloc_func_t func, void* data, foug_stream_manip_t manip);
|
foug_stream_t* foug_stream_create(foug_malloc_func_t func, void* data, foug_stream_manip_t manip);
|
||||||
|
|
||||||
foug_bool_t foug_stream_at_end(foug_stream_t* stream);
|
foug_bool_t foug_stream_at_end(foug_stream_t* stream);
|
||||||
/*int32_t foug_stream_seek(foug_stream_t* stream, int64_t max_size); */
|
int foug_stream_error(foug_stream_t* stream);
|
||||||
size_t foug_stream_read(foug_stream_t* stream, void* ptr, size_t item_size, size_t item_count);
|
size_t foug_stream_read(foug_stream_t* stream, void* ptr, size_t item_size, size_t item_count);
|
||||||
size_t foug_stream_write(foug_stream_t* stream, const void* ptr, size_t item_size, size_t item_count);
|
size_t foug_stream_write(foug_stream_t* stream, const void* ptr, size_t item_size, size_t item_count);
|
||||||
void* foug_stream_get_cookie(const foug_stream_t* stream);
|
void* foug_stream_get_cookie(const foug_stream_t* stream);
|
||||||
|
Loading…
Reference in New Issue
Block a user