c-lib: workable reading of binary STL files
This commit is contained in:
parent
5f4ed36e9f
commit
8cbb5a0007
@ -21,6 +21,7 @@ dll {
|
|||||||
INCLUDEPATH += ../../../src
|
INCLUDEPATH += ../../../src
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
../../../src/c/endian.h \
|
||||||
../../../src/c/foug_global.h \
|
../../../src/c/foug_global.h \
|
||||||
../../../src/c/memory.h \
|
../../../src/c/memory.h \
|
||||||
../../../src/c/stream.h \
|
../../../src/c/stream.h \
|
||||||
@ -29,19 +30,20 @@ HEADERS += \
|
|||||||
../../../src/c/libstl/triangle.h
|
../../../src/c/libstl/triangle.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
../../../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.c
|
||||||
|
|
||||||
*-g++*:QMAKE_CFLAGS += -ansi
|
*-g++*:QMAKE_CFLAGS += -ansi
|
||||||
|
|
||||||
global_inc.path = $$PREFIX_DIR/include
|
global_inc.path = $$PREFIX_DIR/include/dataex
|
||||||
global_inc.files = ../../../src/*.h
|
global_inc.files = ../../../src/*.h
|
||||||
c_global_inc.path = $$PREFIX_DIR/include/c
|
c_global_inc.path = $$PREFIX_DIR/include/dataex/c
|
||||||
c_global_inc.files = ../../../src/c/*.h
|
c_global_inc.files = ../../../src/c/*.h
|
||||||
c_streams_inc.path = $$PREFIX_DIR/include/c/streams
|
c_streams_inc.path = $$PREFIX_DIR/include/dataex/c/streams
|
||||||
c_streams_inc.files = ../../../src/c/streams/*.h
|
c_streams_inc.files = ../../../src/c/streams/*.h
|
||||||
c_libstl_inc.path = $$PREFIX_DIR/include/c/libstl
|
c_libstl_inc.path = $$PREFIX_DIR/include/dataex/c/libstl
|
||||||
c_libstl_inc.files = ../../../src/c/libstl/*.h
|
c_libstl_inc.files = ../../../src/c/libstl/*.h
|
||||||
INSTALLS += global_inc c_global_inc c_streams_inc c_libstl_inc
|
INSTALLS += global_inc c_global_inc c_streams_inc c_libstl_inc
|
||||||
|
|
||||||
|
102
src/c/endian.c
Normal file
102
src/c/endian.c
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
#include "endian.h"
|
||||||
|
|
||||||
|
foug_endianness_t foug_host_endianness()
|
||||||
|
{
|
||||||
|
union {
|
||||||
|
uint32_t integer;
|
||||||
|
uint8_t bytes[4];
|
||||||
|
} u;
|
||||||
|
|
||||||
|
u.integer = 0x01020408;
|
||||||
|
if (u.bytes[0] == 0x08 && u.bytes[3] == 0x01)
|
||||||
|
return FOUG_LITTLE_ENDIAN;
|
||||||
|
else if (u.bytes[0] == 0x01 && u.bytes[3] == 0x08)
|
||||||
|
return FOUG_BIG_ENDIAN;
|
||||||
|
else if (u.bytes[1] == 0x08 && u.bytes[2] == 0x01)
|
||||||
|
return FOUG_MIDDLE_ENDIAN;
|
||||||
|
else
|
||||||
|
return FOUG_OTHER_ENDIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t foug_uint16_swap(uint16_t val)
|
||||||
|
{
|
||||||
|
return ((val & 0x00FF) << 8) | ((val >> 8) & 0x00FF);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t foug_uint16_noswap(uint16_t val)
|
||||||
|
{
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t foug_decode_uint16_le(const uint8_t* bytes)
|
||||||
|
{
|
||||||
|
/* |0 |1 | */
|
||||||
|
/* |BB|AA| -> 0xAABB */
|
||||||
|
return (bytes[1] << 8) | bytes[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t foug_decode_uint16_be(const uint8_t* bytes)
|
||||||
|
{
|
||||||
|
/* |0 |1 | */
|
||||||
|
/* |AA|BB| -> 0xAABB */
|
||||||
|
return (bytes[0] << 8) | bytes[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t foug_uint32_swap(uint32_t val)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
((val & 0x000000FF) << 24)
|
||||||
|
| ((val & 0x0000FF00) << 8)
|
||||||
|
| ((val >> 8) & 0x0000FF00)
|
||||||
|
| ((val >> 24) & 0x000000FF);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t foug_uint32_noswap(uint32_t val)
|
||||||
|
{
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t foug_decode_uint32_le(const uint8_t* bytes)
|
||||||
|
{
|
||||||
|
/* |DD|CC|BB|AA| -> 0xAABBCCDD */
|
||||||
|
return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t foug_decode_uint32_me(const uint8_t* bytes)
|
||||||
|
{
|
||||||
|
/* |DD|CC|BB|AA| -> 0xCCDDAABB */
|
||||||
|
return (bytes[0] >> 8) | (bytes[2] << 8) | (bytes[3] << 8) | (bytes[8] << 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t foug_decode_uint32_be(const uint8_t* bytes)
|
||||||
|
{
|
||||||
|
/* |DD|CC|BB|AA| -> 0xDDCCBBAA */
|
||||||
|
return bytes[3] | (bytes[2] << 8) | (bytes[1] << 16) | (bytes[0] << 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
static foug_real32_t convert_real32(uint32_t val)
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
uint32_t as_integer;
|
||||||
|
foug_real32_t as_float;
|
||||||
|
} u;
|
||||||
|
|
||||||
|
u.as_integer = val;
|
||||||
|
return u.as_float;
|
||||||
|
}
|
||||||
|
|
||||||
|
foug_real32_t foug_decode_real32_le(const uint8_t* bytes)
|
||||||
|
{
|
||||||
|
return convert_real32(foug_decode_uint32_le(bytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
foug_real32_t foug_decode_real32_me(const uint8_t* bytes)
|
||||||
|
{
|
||||||
|
return convert_real32(foug_decode_uint32_me(bytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
foug_real32_t foug_decode_real32_be(const uint8_t* bytes)
|
||||||
|
{
|
||||||
|
return convert_real32(foug_decode_uint32_be(bytes));
|
||||||
|
}
|
31
src/c/endian.h
Normal file
31
src/c/endian.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef FOUG_ENDIAN_H
|
||||||
|
#define FOUG_ENDIAN_H
|
||||||
|
|
||||||
|
#include "foug_global.h"
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
FOUG_LITTLE_ENDIAN,
|
||||||
|
FOUG_BIG_ENDIAN,
|
||||||
|
FOUG_MIDDLE_ENDIAN,
|
||||||
|
FOUG_OTHER_ENDIAN
|
||||||
|
} foug_endianness_t;
|
||||||
|
|
||||||
|
foug_endianness_t foug_host_endianness();
|
||||||
|
|
||||||
|
uint16_t foug_uint16_swap(uint16_t val);
|
||||||
|
uint16_t foug_uint16_noswap(uint16_t val);
|
||||||
|
uint16_t foug_decode_uint16_le(const uint8_t* bytes);
|
||||||
|
uint16_t foug_decode_uint16_be(const uint8_t* bytes);
|
||||||
|
|
||||||
|
uint32_t foug_uint32_swap(uint32_t val);
|
||||||
|
uint32_t foug_uint32_noswap(uint32_t val);
|
||||||
|
uint32_t foug_decode_uint32_le(const uint8_t* bytes);
|
||||||
|
uint32_t foug_decode_uint32_me(const uint8_t* bytes);
|
||||||
|
uint32_t foug_decode_uint32_be(const uint8_t* bytes);
|
||||||
|
|
||||||
|
foug_real32_t foug_decode_real32_le(const uint8_t* bytes);
|
||||||
|
foug_real32_t foug_decode_real32_me(const uint8_t* bytes);
|
||||||
|
foug_real32_t foug_decode_real32_be(const uint8_t* bytes);
|
||||||
|
|
||||||
|
#endif /* FOUG_ENDIAN_H */
|
@ -10,26 +10,30 @@
|
|||||||
# define FOUG_DECL_IMPORT
|
# define FOUG_DECL_IMPORT
|
||||||
#endif /* WIN */
|
#endif /* WIN */
|
||||||
|
|
||||||
typedef char foug_int8;
|
#ifdef FOUG_USE_STDINT_H
|
||||||
typedef unsigned char foug_uint8;
|
# include <stdint.h>
|
||||||
|
|
||||||
typedef foug_int8 foug_bool;
|
|
||||||
|
|
||||||
typedef short foug_int16;
|
|
||||||
typedef unsigned short foug_uint16;
|
|
||||||
|
|
||||||
typedef int foug_int32;
|
|
||||||
typedef unsigned int foug_uint32;
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
typedef __int64 foug_int64;
|
|
||||||
typedef unsigned __int64 foug_uint64;
|
|
||||||
#else
|
#else
|
||||||
typedef long long foug_int64;
|
typedef char int8_t;
|
||||||
typedef unsigned long long foug_uint64;
|
typedef unsigned char uint8_t;
|
||||||
#endif /* _MSC_VER */
|
|
||||||
|
|
||||||
typedef float foug_real32;
|
typedef short int16_t;
|
||||||
typedef double foug_real64;
|
typedef unsigned short uint16_t;
|
||||||
|
|
||||||
|
typedef int int32_t;
|
||||||
|
typedef unsigned int uint32_t;
|
||||||
|
|
||||||
|
# ifdef _MSC_VER
|
||||||
|
typedef __int64 int64_t;
|
||||||
|
typedef unsigned __int64 uint64_t;
|
||||||
|
# else
|
||||||
|
typedef long long int64_t;
|
||||||
|
typedef unsigned long long uint64_t;
|
||||||
|
# endif /* _MSC_VER */
|
||||||
|
|
||||||
|
#endif /* FOUG_USE_STDINT_H */
|
||||||
|
|
||||||
|
typedef int8_t foug_bool_t;
|
||||||
|
typedef float foug_real32_t;
|
||||||
|
typedef double foug_real64_t;
|
||||||
|
|
||||||
#endif /* FOUG_C_GLOBAL_H */
|
#endif /* FOUG_C_GLOBAL_H */
|
||||||
|
@ -1,261 +1,125 @@
|
|||||||
#include "stlb.h"
|
#include "stlb.h"
|
||||||
|
|
||||||
/*
|
#include "../endian.h"
|
||||||
#include "../abstract_task_progress.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
struct _internal_foug_stlb_geom
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
// Read tools
|
|
||||||
|
|
||||||
template<typename NUMERIC>
|
|
||||||
NUMERIC fromLittleEndian(const foug::UInt8* bytes)
|
|
||||||
{
|
{
|
||||||
return 0;
|
void* cookie;
|
||||||
}
|
foug_stlb_geom_input_manip_t manip;
|
||||||
|
};
|
||||||
|
|
||||||
template<>
|
foug_stlb_geom_t* foug_stlb_geom_create(foug_malloc_func_t func,
|
||||||
foug::UInt16 fromLittleEndian<foug::UInt16>(const foug::UInt8* bytes)
|
void* data,
|
||||||
|
foug_stlb_geom_input_manip_t manip)
|
||||||
{
|
{
|
||||||
// |BB|AA| -> 0xAABB
|
if (func == NULL)
|
||||||
return (bytes[1] << 8) | bytes[0];
|
return NULL;
|
||||||
}
|
foug_stlb_geom_t* geom = (*func)(sizeof(struct _internal_foug_stlb_geom));
|
||||||
|
if (geom != NULL) {
|
||||||
template<>
|
geom->cookie = data;
|
||||||
foug::UInt32 fromLittleEndian<foug::UInt32>(const foug::UInt8* bytes)
|
geom->manip = manip;
|
||||||
{
|
|
||||||
// |DD|CC|BB|AA| -> 0xAABBCCDD
|
|
||||||
return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
foug::Real32 fromLittleEndian<foug::Real32>(const foug::UInt8* bytes)
|
|
||||||
{
|
|
||||||
union
|
|
||||||
{
|
|
||||||
foug::UInt32 asInteger;
|
|
||||||
foug::Real32 asFloat;
|
|
||||||
} helper;
|
|
||||||
|
|
||||||
helper.asInteger = fromLittleEndian<foug::UInt32>(bytes);
|
|
||||||
return helper.asFloat;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write tools
|
|
||||||
|
|
||||||
template<typename NUMERIC>
|
|
||||||
void toLittleEndian(NUMERIC n, foug::UInt8* bytes)
|
|
||||||
{
|
|
||||||
union {
|
|
||||||
NUMERIC asNumeric;
|
|
||||||
foug::UInt8 asBytes[sizeof(NUMERIC)];
|
|
||||||
} helper;
|
|
||||||
helper.asNumeric = n;
|
|
||||||
// std::copy(helper.asBytes, helper.asBytes + sizeof(NUMERIC), bytes);
|
|
||||||
for (unsigned i = 0; i < sizeof(NUMERIC); ++i)
|
|
||||||
bytes[i] = helper.asBytes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace foug {
|
|
||||||
namespace stlb {
|
|
||||||
|
|
||||||
static const int stlFacetSize = 50;
|
|
||||||
static const int stlMinFileSize = 284;
|
|
||||||
static const int stlTriangleDataSize = (4 * 3) * sizeof(foug::Real32) + sizeof(foug::UInt16);
|
|
||||||
|
|
||||||
|
|
||||||
void AbstractGeometryBuilder::endTriangles()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Io::Io(AbstractStream *stream)
|
|
||||||
: IoBase(stream)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Io::read(AbstractGeometryBuilder* builder)
|
|
||||||
{
|
|
||||||
// // Check file size
|
|
||||||
// const qint64 fileSize = stream->size();
|
|
||||||
// if (((fileSize - stlHeaderSize - stlFacetCountSize) % stlFacetSize != 0)
|
|
||||||
// || fileSize < stlMinFileSize) {
|
|
||||||
// cpp::checkedAssign(err, WrongFileSizeBinaryStlLoadError);
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const int facetCount = (fileSize - stlHeaderSize - stlFacetCountSize) / stlFacetSize;
|
|
||||||
|
|
||||||
if (this->stream() == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
AbstractStream* istream = this->stream();
|
|
||||||
AbstractTaskProgress* progress = this->taskProgress();
|
|
||||||
const UInt32 chunkSize = stlTriangleDataSize * 163;
|
|
||||||
|
|
||||||
UInt8 buffer[8192];
|
|
||||||
char* charBuffer = reinterpret_cast<char*>(buffer);
|
|
||||||
|
|
||||||
// Read header
|
|
||||||
Header headerData;
|
|
||||||
if (istream->read(reinterpret_cast<char*>(&headerData), HeaderSize) != HeaderSize)
|
|
||||||
return false;
|
|
||||||
builder->processHeader(headerData);
|
|
||||||
|
|
||||||
// Read facet count
|
|
||||||
if (istream->read(charBuffer, sizeof(UInt32)) != sizeof(UInt32))
|
|
||||||
return false;
|
|
||||||
const UInt32 facetCount = ::fromLittleEndian<UInt32>(buffer);
|
|
||||||
builder->beginTriangles(facetCount);
|
|
||||||
|
|
||||||
if (progress != 0) {
|
|
||||||
progress->reset();
|
|
||||||
progress->setRange(0., facetCount);
|
|
||||||
}
|
}
|
||||||
|
return geom;
|
||||||
// Read triangles
|
|
||||||
const UInt64 totalFacetSize = stlTriangleDataSize * facetCount;
|
|
||||||
UInt64 amountReadSize = 0;
|
|
||||||
stl::Triangle triangle;
|
|
||||||
bool streamError = false;
|
|
||||||
while (amountReadSize < totalFacetSize && !streamError) {
|
|
||||||
const Int64 iReadSize = istream->read(charBuffer, chunkSize);
|
|
||||||
if (iReadSize > 0 && (iReadSize % stlTriangleDataSize == 0)) {
|
|
||||||
const UInt32 iFacetCount = iReadSize / stlTriangleDataSize;
|
|
||||||
UInt32 bufferOffset = 0;
|
|
||||||
for (UInt32 i = 0; i < iFacetCount; ++i) {
|
|
||||||
// Read normal
|
|
||||||
triangle.normal.x = ::fromLittleEndian<Real32>(buffer + bufferOffset);
|
|
||||||
triangle.normal.y = ::fromLittleEndian<Real32>(buffer + 1*sizeof(Real32) + bufferOffset);
|
|
||||||
triangle.normal.z = ::fromLittleEndian<Real32>(buffer + 2*sizeof(Real32) + bufferOffset);
|
|
||||||
|
|
||||||
// Read vertex1
|
|
||||||
triangle.v1.x = ::fromLittleEndian<Real32>(buffer + 3*sizeof(Real32) + bufferOffset);
|
|
||||||
triangle.v1.y = ::fromLittleEndian<Real32>(buffer + 4*sizeof(Real32) + bufferOffset);
|
|
||||||
triangle.v1.z = ::fromLittleEndian<Real32>(buffer + 5*sizeof(Real32) + bufferOffset);
|
|
||||||
|
|
||||||
// Read vertex2
|
|
||||||
triangle.v2.x = ::fromLittleEndian<Real32>(buffer + 6*sizeof(Real32) + bufferOffset);
|
|
||||||
triangle.v2.y = ::fromLittleEndian<Real32>(buffer + 7*sizeof(Real32) + bufferOffset);
|
|
||||||
triangle.v2.z = ::fromLittleEndian<Real32>(buffer + 8*sizeof(Real32) + bufferOffset);
|
|
||||||
|
|
||||||
// Read vertex3
|
|
||||||
triangle.v3.x = ::fromLittleEndian<Real32>(buffer + 9*sizeof(Real32) + bufferOffset);
|
|
||||||
triangle.v3.y = ::fromLittleEndian<Real32>(buffer + 10*sizeof(Real32) + bufferOffset);
|
|
||||||
triangle.v3.z = ::fromLittleEndian<Real32>(buffer + 11*sizeof(Real32) + bufferOffset);
|
|
||||||
|
|
||||||
// Attribute byte count
|
|
||||||
const UInt16 attributeByteCount =
|
|
||||||
::fromLittleEndian<UInt16>(buffer + 12*sizeof(Real32) + bufferOffset);
|
|
||||||
|
|
||||||
// Add triangle
|
|
||||||
builder->processNextTriangle(triangle, attributeByteCount);
|
|
||||||
|
|
||||||
bufferOffset += stlTriangleDataSize;
|
|
||||||
} // end for
|
|
||||||
|
|
||||||
if (progress != 0) {
|
|
||||||
if (progress->isTaskStopRequested()) {
|
|
||||||
streamError = true;
|
|
||||||
progress->taskStoppedEvent();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
progress->setValue(amountReadSize / stlTriangleDataSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
amountReadSize += iReadSize;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
streamError = true;
|
|
||||||
}
|
|
||||||
} // end while
|
|
||||||
|
|
||||||
if (!streamError)
|
|
||||||
builder->endTriangles();
|
|
||||||
|
|
||||||
return !streamError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Io::write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraData* extraData)
|
void* foug_stlb_geom_get_cookie(const foug_stlb_geom_t* geom)
|
||||||
{
|
{
|
||||||
if (this->stream() == 0)
|
return geom != NULL ? geom->cookie : NULL;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
AbstractStream* ostream = this->stream();
|
static const int stlb_min_file_size = 284;
|
||||||
AbstractTaskProgress* progress = this->taskProgress();
|
static const int stlb_facet_size = (4 * 3) * sizeof(foug_real32_t) + sizeof(uint16_t);
|
||||||
|
|
||||||
UInt8 buffer[128];
|
int foug_stlb_read(foug_stlb_read_args_t args)
|
||||||
|
{
|
||||||
|
if (args.geom == NULL)
|
||||||
|
return FOUG_STLB_READ_NULL_GEOM_ERROR;
|
||||||
|
if (args.stream == NULL)
|
||||||
|
return FOUG_STLB_READ_NULL_STREAM_ERROR;
|
||||||
|
if (args.buffer_size == 0)
|
||||||
|
return FOUG_STLB_READ_INVALID_BUFFER_SIZE_ERROR;
|
||||||
|
|
||||||
// Write header
|
uint8_t buffer[8192];
|
||||||
Header headerData;
|
|
||||||
if (extraData != 0)
|
|
||||||
extraData->getHeader(headerData);
|
|
||||||
else
|
|
||||||
std::fill(headerData, headerData + HeaderSize, 0);
|
|
||||||
|
|
||||||
if (ostream->write(reinterpret_cast<char*>(&headerData), HeaderSize) != HeaderSize)
|
/* Read header */
|
||||||
return false;
|
uint8_t header_data[foug_stlb_header_size];
|
||||||
|
if (foug_stream_read(args.stream, header_data, 1, foug_stlb_header_size) != foug_stlb_header_size)
|
||||||
|
return FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR;
|
||||||
|
|
||||||
// Write facet count
|
if (args.geom->manip.process_header_func != NULL)
|
||||||
const UInt32 facetCount = geom.triangleCount();
|
(*(args.geom->manip.process_header_func))(args.geom, header_data);
|
||||||
::toLittleEndian<UInt32>(facetCount, buffer);
|
|
||||||
if (ostream->write(reinterpret_cast<char*>(&buffer), sizeof(UInt32)) != sizeof(UInt32))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (progress != 0) {
|
/* Read facet count */
|
||||||
progress->reset();
|
if (foug_stream_read(args.stream, buffer, sizeof(uint32_t), 1) != 1)
|
||||||
progress->setRange(0., facetCount);
|
return FOUG_STLB_READ_FACET_COUNT_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
// Write triangles
|
const uint32_t total_facet_count = foug_decode_uint32_le(buffer);
|
||||||
stl::Triangle triangle;
|
if (args.geom->manip.begin_triangles_func != NULL)
|
||||||
for (UInt32 facet = 0; facet < facetCount; ++facet) {
|
(*(args.geom->manip.begin_triangles_func))(args.geom, total_facet_count);
|
||||||
geom.getTriangle(facet, &triangle);
|
|
||||||
|
|
||||||
// Write normal
|
foug_task_control_reset(args.task_control);
|
||||||
::toLittleEndian<Real32>(triangle.normal.x, buffer);
|
foug_task_control_set_range(args.task_control, 0., (foug_real32_t)total_facet_count);
|
||||||
::toLittleEndian<Real32>(triangle.normal.y, buffer + 1*sizeof(Real32));
|
|
||||||
::toLittleEndian<Real32>(triangle.normal.z, buffer + 2*sizeof(Real32));
|
|
||||||
|
|
||||||
// Write vertex1
|
/* Read triangles */
|
||||||
::toLittleEndian<Real32>(triangle.v1.x, buffer + 3*sizeof(Real32));
|
const size_t buffer_facet_count = 163;
|
||||||
::toLittleEndian<Real32>(triangle.v1.y, buffer + 4*sizeof(Real32));
|
size_t accum_facet_count_read = 0;
|
||||||
::toLittleEndian<Real32>(triangle.v1.z, buffer + 5*sizeof(Real32));
|
foug_stl_triangle_t triangle;
|
||||||
|
foug_bool_t stream_error = 0;
|
||||||
|
while (accum_facet_count_read < total_facet_count && !stream_error) {
|
||||||
|
const size_t facet_count_read =
|
||||||
|
foug_stream_read(args.stream, buffer, stlb_facet_size, buffer_facet_count);
|
||||||
|
if (facet_count_read > 0 /* && !foug_stream_has_error(args.stream)*/) {
|
||||||
|
uint32_t buffer_offset = 0;
|
||||||
|
uint32_t i_facet;
|
||||||
|
for (i_facet = 0; i_facet < facet_count_read; ++i_facet) {
|
||||||
|
/* Read normal */
|
||||||
|
triangle.normal.x = foug_decode_real32_le(buffer + buffer_offset);
|
||||||
|
triangle.normal.y = foug_decode_real32_le(buffer + 1*sizeof(foug_real32_t) + buffer_offset);
|
||||||
|
triangle.normal.z = foug_decode_real32_le(buffer + 2*sizeof(foug_real32_t) + buffer_offset);
|
||||||
|
|
||||||
// Write vertex2
|
/* Read vertex1 */
|
||||||
::toLittleEndian<Real32>(triangle.v2.x, buffer + 6*sizeof(Real32));
|
triangle.v1.x = foug_decode_real32_le(buffer + 3*sizeof(foug_real32_t) + buffer_offset);
|
||||||
::toLittleEndian<Real32>(triangle.v2.y, buffer + 7*sizeof(Real32));
|
triangle.v1.y = foug_decode_real32_le(buffer + 4*sizeof(foug_real32_t) + buffer_offset);
|
||||||
::toLittleEndian<Real32>(triangle.v2.z, buffer + 8*sizeof(Real32));
|
triangle.v1.z = foug_decode_real32_le(buffer + 5*sizeof(foug_real32_t) + buffer_offset);
|
||||||
|
|
||||||
// Write vertex3
|
/* Read vertex2 */
|
||||||
::toLittleEndian<Real32>(triangle.v3.x, buffer + 9*sizeof(Real32));
|
triangle.v2.x = foug_decode_real32_le(buffer + 6*sizeof(foug_real32_t) + buffer_offset);
|
||||||
::toLittleEndian<Real32>(triangle.v3.y, buffer + 10*sizeof(Real32));
|
triangle.v2.y = foug_decode_real32_le(buffer + 7*sizeof(foug_real32_t) + buffer_offset);
|
||||||
::toLittleEndian<Real32>(triangle.v3.z, buffer + 11*sizeof(Real32));
|
triangle.v2.z = foug_decode_real32_le(buffer + 8*sizeof(foug_real32_t) + buffer_offset);
|
||||||
|
|
||||||
// Attribute byte count
|
/* Read vertex3 */
|
||||||
const UInt16 attrByteCount = extraData != 0 ? extraData->attributeByteCount(facet) : 0;
|
triangle.v3.x = foug_decode_real32_le(buffer + 9*sizeof(foug_real32_t) + buffer_offset);
|
||||||
::toLittleEndian<UInt16>(attrByteCount, buffer + 12*sizeof(Real32));
|
triangle.v3.y = foug_decode_real32_le(buffer + 10*sizeof(foug_real32_t) + buffer_offset);
|
||||||
|
triangle.v3.z = foug_decode_real32_le(buffer + 11*sizeof(foug_real32_t) + buffer_offset);
|
||||||
|
|
||||||
// Write to stream
|
/* Attribute byte count */
|
||||||
if (ostream->write(reinterpret_cast<const char*>(buffer), stlTriangleDataSize)
|
const uint16_t attribute_byte_count =
|
||||||
!= stlTriangleDataSize)
|
foug_decode_uint16_le(buffer + 12*sizeof(foug_real32_t) + buffer_offset);
|
||||||
return false;
|
|
||||||
|
|
||||||
if (progress != 0) {
|
/* Add triangle */
|
||||||
if (progress->isTaskStopRequested()) {
|
if (args.geom->manip.process_next_triangle_func != NULL)
|
||||||
progress->taskStoppedEvent();
|
(*(args.geom->manip.process_next_triangle_func))(args.geom, &triangle, attribute_byte_count);
|
||||||
return false;
|
|
||||||
|
buffer_offset += stlb_facet_size;
|
||||||
|
} /* end for */
|
||||||
|
|
||||||
|
if (foug_task_control_is_stop_requested(args.task_control)) {
|
||||||
|
stream_error = 1;
|
||||||
|
foug_task_control_handle_stop(args.task_control);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
progress->setValue(facet + 1);
|
foug_task_control_set_progress(args.task_control, accum_facet_count_read);
|
||||||
}
|
}
|
||||||
|
accum_facet_count_read += facet_count_read;
|
||||||
}
|
}
|
||||||
} // end for
|
|
||||||
|
|
||||||
return true;
|
else {
|
||||||
|
stream_error = 1;
|
||||||
|
}
|
||||||
|
} /* end while */
|
||||||
|
|
||||||
|
if (!stream_error && args.geom->manip.end_triangles_func != NULL)
|
||||||
|
(*(args.geom->manip.end_triangles_func))(args.geom);
|
||||||
|
|
||||||
|
return FOUG_STLB_READ_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace stlb
|
|
||||||
} // namespace foug
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
@ -7,19 +7,17 @@
|
|||||||
#include "../task_control.h"
|
#include "../task_control.h"
|
||||||
|
|
||||||
enum { foug_stlb_header_size = 80 };
|
enum { foug_stlb_header_size = 80 };
|
||||||
typedef foug_uint8 foug_stlb_header_t[foug_stlb_header_size];
|
|
||||||
|
|
||||||
/* foug_stlb_geom : opaque structure */
|
/* foug_stlb_geom : opaque structure */
|
||||||
typedef struct _internal_foug_stlb_geom foug_stlb_geom_t;
|
typedef struct _internal_foug_stlb_geom foug_stlb_geom_t;
|
||||||
typedef void (*foug_stlb_geom_input_process_header_func_t)(foug_stlb_geom_t,
|
typedef void (*foug_stlb_geom_input_process_header_func_t)(foug_stlb_geom_t*, const uint8_t*);
|
||||||
const foug_stlb_header_t);
|
typedef void (*foug_stlb_geom_input_begin_triangles_func_t)(foug_stlb_geom_t*, uint32_t);
|
||||||
typedef void (*foug_stlb_geom_input_begin_triangles_func_t)(foug_stlb_geom_t, foug_uint32);
|
typedef void (*foug_stlb_geom_input_process_next_triangle_func_t)(foug_stlb_geom_t*,
|
||||||
typedef void (*foug_stlb_geom_input_process_next_triangle_func_t)(foug_stlb_geom_t,
|
|
||||||
const foug_stl_triangle_t*,
|
const foug_stl_triangle_t*,
|
||||||
foug_uint16);
|
uint16_t);
|
||||||
typedef void (*foug_stlb_geom_input_end_triangles_func_t)(foug_stlb_geom_t);
|
typedef void (*foug_stlb_geom_input_end_triangles_func_t)(foug_stlb_geom_t*);
|
||||||
|
|
||||||
typedef struct foug_stlb_geom_input_manip
|
typedef struct
|
||||||
{
|
{
|
||||||
foug_stlb_geom_input_process_header_func_t process_header_func;
|
foug_stlb_geom_input_process_header_func_t process_header_func;
|
||||||
foug_stlb_geom_input_begin_triangles_func_t begin_triangles_func;
|
foug_stlb_geom_input_begin_triangles_func_t begin_triangles_func;
|
||||||
@ -27,18 +25,27 @@ typedef struct foug_stlb_geom_input_manip
|
|||||||
foug_stlb_geom_input_end_triangles_func_t end_triangles_func;
|
foug_stlb_geom_input_end_triangles_func_t end_triangles_func;
|
||||||
} foug_stlb_geom_input_manip_t;
|
} foug_stlb_geom_input_manip_t;
|
||||||
|
|
||||||
/*
|
foug_stlb_geom_t* foug_stlb_geom_create(foug_malloc_func_t func,
|
||||||
typedef struct foug_stlb_read_args
|
void* data,
|
||||||
|
foug_stlb_geom_input_manip_t manip);
|
||||||
|
|
||||||
|
void* foug_stlb_geom_get_cookie(const foug_stlb_geom_t* geom);
|
||||||
|
|
||||||
|
typedef struct
|
||||||
{
|
{
|
||||||
void* stream;
|
foug_stlb_geom_t* geom;
|
||||||
foug_stream_manip_t stream_manip;
|
foug_stream_t* stream;
|
||||||
|
foug_task_control_t* task_control;
|
||||||
foug_stlb_geom_t geom;
|
uint32_t buffer_size;
|
||||||
foug_stlb_geom_input_manip_t geom_manip;
|
|
||||||
} foug_stlb_read_args_t;
|
} foug_stlb_read_args_t;
|
||||||
|
int foug_stlb_read(foug_stlb_read_args_t args);
|
||||||
|
|
||||||
int foug_stlb_read(foug_stlb_geom_t geom, foug_stlb_read_args_t args);
|
#define FOUG_STLB_READ_NO_ERROR 0;
|
||||||
*/
|
#define FOUG_STLB_READ_NULL_GEOM_ERROR 1;
|
||||||
|
#define FOUG_STLB_READ_NULL_STREAM_ERROR 2;
|
||||||
|
#define FOUG_STLB_READ_INVALID_BUFFER_SIZE_ERROR 3
|
||||||
|
#define FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR 4
|
||||||
|
#define FOUG_STLB_READ_FACET_COUNT_ERROR 5
|
||||||
|
|
||||||
/*class FOUG_STL_EXPORT AbstractGeometryExtraData
|
/*class FOUG_STL_EXPORT AbstractGeometryExtraData
|
||||||
{
|
{
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
|
|
||||||
#include "../foug_global.h"
|
#include "../foug_global.h"
|
||||||
|
|
||||||
typedef struct foug_stl_coords
|
typedef struct
|
||||||
{
|
{
|
||||||
foug_real32 x;
|
foug_real32_t x;
|
||||||
foug_real32 y;
|
foug_real32_t y;
|
||||||
foug_real32 z;
|
foug_real32_t z;
|
||||||
} foug_stl_coords_t;
|
} foug_stl_coords_t;
|
||||||
|
|
||||||
typedef struct foug_stl_triangle
|
typedef struct
|
||||||
{
|
{
|
||||||
foug_stl_coords_t normal;
|
foug_stl_coords_t normal;
|
||||||
foug_stl_coords_t v1;
|
foug_stl_coords_t v1;
|
||||||
|
@ -29,63 +29,67 @@ foug_stream_manip_t foug_stream_manip_null()
|
|||||||
return manip;
|
return manip;
|
||||||
}
|
}
|
||||||
|
|
||||||
static foug_bool foug_stream_stdio_at_end(foug_stream_t* stream)
|
static foug_bool_t foug_stream_stdio_at_end(foug_stream_t* stream)
|
||||||
{
|
{
|
||||||
return feof((FILE*) stream->cookie);
|
return feof((FILE*) stream->cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
static foug_int32 foug_stream_stdio_seek(foug_stream_t* stream, foug_int64 pos)
|
/*static int32_t foug_stream_stdio_seek(foug_stream_t* stream, int64_t pos)
|
||||||
{
|
{
|
||||||
return fseek((FILE*) stream->cookie, pos, SEEK_SET);
|
return fseek((FILE*) stream->cookie, pos, SEEK_SET);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
static size_t foug_stream_stdio_read(foug_stream_t* stream,
|
||||||
|
void* ptr,
|
||||||
|
size_t item_size,
|
||||||
|
size_t item_count)
|
||||||
|
{
|
||||||
|
return fread(ptr, item_size, item_count, (FILE*) stream->cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
static foug_uint64 foug_stream_stdio_read(foug_stream_t* stream, char* s, foug_uint64 max_size)
|
static size_t foug_stream_stdio_write(foug_stream_t* stream,
|
||||||
|
const void* ptr,
|
||||||
|
size_t item_size,
|
||||||
|
size_t item_count)
|
||||||
{
|
{
|
||||||
return fread(s, sizeof(char), max_size, (FILE*) stream->cookie);
|
return fwrite(ptr, item_size, item_count, (FILE*) stream->cookie);
|
||||||
}
|
|
||||||
|
|
||||||
static foug_uint64 foug_stream_stdio_write(foug_stream_t* stream,
|
|
||||||
const char* s,
|
|
||||||
foug_uint64 max_size)
|
|
||||||
{
|
|
||||||
return fwrite(s, sizeof(char), max_size, (FILE*) stream->cookie);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foug_stream_manip_t foug_stream_manip_stdio()
|
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.seek_func = &foug_stream_stdio_seek; */
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
foug_bool foug_stream_at_end(foug_stream_t* stream)
|
foug_bool_t foug_stream_at_end(foug_stream_t* stream)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->manip.at_end_func != NULL)
|
if (stream != NULL && stream->manip.at_end_func != NULL)
|
||||||
return (*(stream->manip.at_end_func))(stream);
|
return (*(stream->manip.at_end_func))(stream);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
foug_int32 foug_stream_seek(foug_stream_t* stream, foug_int64 max_size)
|
/*int32_t foug_stream_seek(foug_stream_t* stream, int64_t max_size)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->manip.seek_func != NULL)
|
if (stream != NULL && stream->manip.seek_func != NULL)
|
||||||
return (*(stream->manip.seek_func))(stream, max_size);
|
return (*(stream->manip.seek_func))(stream, max_size);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
foug_uint64 foug_stream_read(foug_stream_t* stream, char* s, foug_uint64 max_size)
|
size_t foug_stream_read(foug_stream_t* stream, void *ptr, size_t item_size, size_t item_count)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->manip.read_func != NULL)
|
if (stream != NULL && stream->manip.read_func != NULL)
|
||||||
return (*(stream->manip.read_func))(stream, s, max_size);
|
return (*(stream->manip.read_func))(stream, ptr, item_size, item_count);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
foug_uint64 foug_stream_write(foug_stream_t* stream, const char* s, foug_uint64 max_size)
|
size_t foug_stream_write(foug_stream_t* stream, const void *ptr, size_t item_size, size_t item_count)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->manip.write_func != NULL)
|
if (stream != NULL && stream->manip.write_func != NULL)
|
||||||
return (*(stream->manip.write_func))(stream, s, max_size);
|
return (*(stream->manip.write_func))(stream, ptr, item_size, item_count);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,14 +8,16 @@
|
|||||||
typedef struct _internal_foug_stream foug_stream_t;
|
typedef struct _internal_foug_stream foug_stream_t;
|
||||||
|
|
||||||
/* foug_stream_manip */
|
/* foug_stream_manip */
|
||||||
typedef foug_bool (*foug_stream_at_end_func_t)(foug_stream_t*);
|
typedef foug_bool_t (*foug_stream_at_end_func_t)(foug_stream_t*);
|
||||||
typedef foug_int32 (*foug_stream_seek_func_t)(foug_stream_t*, foug_int64);
|
|
||||||
typedef foug_uint64 (*foug_stream_read_func_t)(foug_stream_t*, char*, foug_uint64);
|
/* typedef int32_t (*foug_stream_seek_func_t)(foug_stream_t*, int64_t); */
|
||||||
typedef foug_uint64 (*foug_stream_write_func_t)(foug_stream_t*, const char*, foug_uint64);
|
typedef size_t (*foug_stream_read_func_t)(foug_stream_t*, void*, size_t, size_t);
|
||||||
typedef struct foug_stream_manip
|
typedef size_t (*foug_stream_write_func_t)(foug_stream_t*, const void*, size_t, size_t);
|
||||||
|
typedef struct
|
||||||
{
|
{
|
||||||
foug_stream_at_end_func_t at_end_func;
|
foug_stream_at_end_func_t at_end_func;
|
||||||
foug_stream_seek_func_t seek_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;
|
||||||
@ -26,10 +28,10 @@ foug_stream_manip_t foug_stream_manip_stdio();
|
|||||||
/* Services */
|
/* Services */
|
||||||
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 foug_stream_at_end(foug_stream_t* stream);
|
foug_bool_t foug_stream_at_end(foug_stream_t* stream);
|
||||||
foug_int32 foug_stream_seek(foug_stream_t* stream, foug_int64 max_size);
|
/*int32_t foug_stream_seek(foug_stream_t* stream, int64_t max_size); */
|
||||||
foug_uint64 foug_stream_read(foug_stream_t* stream, char* s, foug_uint64 max_size);
|
size_t foug_stream_read(foug_stream_t* stream, void* ptr, size_t item_size, size_t item_count);
|
||||||
foug_uint64 foug_stream_write(foug_stream_t* stream, const char* s, foug_uint64 max_size);
|
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);
|
||||||
|
|
||||||
#endif /* FOUG_C_STREAM_H */
|
#endif /* FOUG_C_STREAM_H */
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
struct _internal_foug_task_control
|
struct _internal_foug_task_control
|
||||||
{
|
{
|
||||||
foug_real32 range_min;
|
foug_real32_t range_min;
|
||||||
foug_real32 range_max;
|
foug_real32_t range_max;
|
||||||
foug_real32 range_length;
|
foug_real32_t range_length;
|
||||||
foug_int32 step_id;
|
int32_t step_id;
|
||||||
foug_real32 progress_value;
|
foug_real32_t progress_value;
|
||||||
foug_real32 progress_threshold;
|
foug_real32_t progress_threshold;
|
||||||
foug_bool is_stop_requested;
|
foug_bool_t is_stop_requested;
|
||||||
void* cookie;
|
void* cookie;
|
||||||
foug_task_control_manip_t manip;
|
foug_task_control_manip_t manip;
|
||||||
};
|
};
|
||||||
@ -49,17 +49,17 @@ void foug_task_control_manip_init(foug_task_control_manip_t* manip)
|
|||||||
|
|
||||||
/* Range */
|
/* Range */
|
||||||
|
|
||||||
foug_real32 foug_task_control_get_range_min(const foug_task_control_t* ctrl)
|
foug_real32_t foug_task_control_get_range_min(const foug_task_control_t* ctrl)
|
||||||
{
|
{
|
||||||
return ctrl != NULL ? ctrl->range_min : -1.;
|
return ctrl != NULL ? ctrl->range_min : -1.;
|
||||||
}
|
}
|
||||||
|
|
||||||
foug_real32 foug_task_control_get_range_max(const foug_task_control_t* ctrl)
|
foug_real32_t foug_task_control_get_range_max(const foug_task_control_t* ctrl)
|
||||||
{
|
{
|
||||||
return ctrl != NULL ? ctrl->range_max : -2.;
|
return ctrl != NULL ? ctrl->range_max : -2.;
|
||||||
}
|
}
|
||||||
|
|
||||||
void foug_task_control_set_range(foug_task_control_t* ctrl, foug_real32 min, foug_real32 max)
|
void foug_task_control_set_range(foug_task_control_t* ctrl, foug_real32_t min, foug_real32_t max)
|
||||||
{
|
{
|
||||||
if (ctrl != NULL) {
|
if (ctrl != NULL) {
|
||||||
ctrl->range_min = min;
|
ctrl->range_min = min;
|
||||||
@ -70,32 +70,32 @@ void foug_task_control_set_range(foug_task_control_t* ctrl, foug_real32 min, fou
|
|||||||
|
|
||||||
/* Step id */
|
/* Step id */
|
||||||
|
|
||||||
foug_int32 foug_task_control_get_step_id(const foug_task_control_t* ctrl)
|
int32_t foug_task_control_get_step_id(const foug_task_control_t* ctrl)
|
||||||
{
|
{
|
||||||
return ctrl != NULL ? ctrl->step_id : -1;
|
return ctrl != NULL ? ctrl->step_id : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void foug_task_control_set_step_id(foug_task_control_t* ctrl, foug_int32 step_id)
|
void foug_task_control_set_step_id(foug_task_control_t* ctrl, int32_t step_id)
|
||||||
{
|
{
|
||||||
if (ctrl != NULL)
|
if (ctrl != NULL)
|
||||||
ctrl->step_id = step_id;
|
ctrl->step_id = step_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Progress */
|
/* Progress */
|
||||||
foug_real32 foug_task_control_get_progress_as_pc(const foug_task_control_t* ctrl)
|
foug_real32_t foug_task_control_get_progress_as_pc(const foug_task_control_t* ctrl)
|
||||||
{
|
{
|
||||||
if (ctrl == NULL)
|
if (ctrl == NULL)
|
||||||
return 0.;
|
return 0.;
|
||||||
const foug_real32 result = (ctrl->progress_value - ctrl->range_min) / ctrl->range_length;
|
const foug_real32_t result = (ctrl->progress_value - ctrl->range_min) / ctrl->range_length;
|
||||||
return fabs(result);
|
return fabs(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
foug_real32 foug_task_control_get_progress(const foug_task_control_t* ctrl)
|
foug_real32_t foug_task_control_get_progress(const foug_task_control_t* ctrl)
|
||||||
{
|
{
|
||||||
return ctrl != NULL ? ctrl->progress_value : 0.;
|
return ctrl != NULL ? ctrl->progress_value : 0.;
|
||||||
}
|
}
|
||||||
|
|
||||||
void foug_task_control_set_progress(foug_task_control_t* ctrl, foug_real32 v)
|
void foug_task_control_set_progress(foug_task_control_t* ctrl, foug_real32_t v)
|
||||||
{
|
{
|
||||||
if (ctrl == NULL)
|
if (ctrl == NULL)
|
||||||
return;
|
return;
|
||||||
@ -107,12 +107,12 @@ void foug_task_control_set_progress(foug_task_control_t* ctrl, foug_real32 v)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foug_real32 foug_task_control_get_progress_update_threshold(const foug_task_control_t* ctrl)
|
foug_real32_t foug_task_control_get_progress_update_threshold(const foug_task_control_t* ctrl)
|
||||||
{
|
{
|
||||||
return ctrl != NULL ? ctrl->progress_threshold : 0.01;
|
return ctrl != NULL ? ctrl->progress_threshold : 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
void foug_task_control_set_progress_update_threshold(foug_task_control_t* ctrl, foug_real32 v)
|
void foug_task_control_set_progress_update_threshold(foug_task_control_t* ctrl, foug_real32_t v)
|
||||||
{
|
{
|
||||||
if (ctrl != NULL)
|
if (ctrl != NULL)
|
||||||
ctrl->progress_threshold = v;
|
ctrl->progress_threshold = v;
|
||||||
@ -148,7 +148,7 @@ void foug_task_control_handle_stop(foug_task_control_t* ctrl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foug_bool foug_task_control_is_stop_requested(const foug_task_control_t* ctrl)
|
foug_bool_t foug_task_control_is_stop_requested(const foug_task_control_t* ctrl)
|
||||||
{
|
{
|
||||||
return ctrl != NULL ? ctrl->is_stop_requested : 0;
|
return ctrl != NULL ? ctrl->is_stop_requested : 0;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ typedef struct _internal_foug_task_control foug_task_control_t;
|
|||||||
/* foug_task_control_manip */
|
/* foug_task_control_manip */
|
||||||
typedef void (*foug_task_control_handle_stop_func)(foug_task_control_t*);
|
typedef void (*foug_task_control_handle_stop_func)(foug_task_control_t*);
|
||||||
typedef void (*foug_task_control_handle_progress_update_func)(foug_task_control_t*);
|
typedef void (*foug_task_control_handle_progress_update_func)(foug_task_control_t*);
|
||||||
typedef struct foug_task_control_manip
|
typedef struct
|
||||||
{
|
{
|
||||||
foug_task_control_handle_stop_func handle_stop_func;
|
foug_task_control_handle_stop_func handle_stop_func;
|
||||||
foug_task_control_handle_progress_update_func handle_progress_update_func;
|
foug_task_control_handle_progress_update_func handle_progress_update_func;
|
||||||
@ -22,21 +22,21 @@ foug_task_control_t* foug_task_control_create(foug_malloc_func_t func,
|
|||||||
void* data, foug_task_control_manip_t manip);
|
void* data, foug_task_control_manip_t manip);
|
||||||
|
|
||||||
/* Range */
|
/* Range */
|
||||||
foug_real32 foug_task_control_get_range_min(const foug_task_control_t* ctrl);
|
foug_real32_t foug_task_control_get_range_min(const foug_task_control_t* ctrl);
|
||||||
foug_real32 foug_task_control_get_range_max(const foug_task_control_t* ctrl);
|
foug_real32_t foug_task_control_get_range_max(const foug_task_control_t* ctrl);
|
||||||
void foug_task_control_set_range(foug_task_control_t* ctrl, foug_real32 min, foug_real32 max);
|
void foug_task_control_set_range(foug_task_control_t* ctrl, foug_real32_t min, foug_real32_t max);
|
||||||
|
|
||||||
/* Step id */
|
/* Step id */
|
||||||
foug_int32 foug_task_control_get_step_id(const foug_task_control_t* ctrl);
|
int32_t foug_task_control_get_step_id(const foug_task_control_t* ctrl);
|
||||||
void foug_task_control_set_step_id(foug_task_control_t* ctrl, foug_int32 step_id);
|
void foug_task_control_set_step_id(foug_task_control_t* ctrl, int32_t step_id);
|
||||||
|
|
||||||
/* Progress */
|
/* Progress */
|
||||||
foug_real32 foug_task_control_get_progress_as_pc(const foug_task_control_t* ctrl);
|
foug_real32_t foug_task_control_get_progress_as_pc(const foug_task_control_t* ctrl);
|
||||||
foug_real32 foug_task_control_get_progress(const foug_task_control_t* ctrl);
|
foug_real32_t foug_task_control_get_progress(const foug_task_control_t* ctrl);
|
||||||
void foug_task_control_set_progress(foug_task_control_t* ctrl, foug_real32 v);
|
void foug_task_control_set_progress(foug_task_control_t* ctrl, foug_real32_t v);
|
||||||
|
|
||||||
foug_real32 foug_task_control_get_progress_update_threshold(const foug_task_control_t* ctrl);
|
foug_real32_t foug_task_control_get_progress_update_threshold(const foug_task_control_t* ctrl);
|
||||||
void foug_task_control_set_progress_update_threshold(foug_task_control_t* ctrl, foug_real32 v);
|
void foug_task_control_set_progress_update_threshold(foug_task_control_t* ctrl, foug_real32_t v);
|
||||||
|
|
||||||
/* Reset */
|
/* Reset */
|
||||||
void foug_task_control_reset(foug_task_control_t* ctrl);
|
void foug_task_control_reset(foug_task_control_t* ctrl);
|
||||||
@ -44,7 +44,7 @@ void foug_task_control_reset(foug_task_control_t* ctrl);
|
|||||||
/* Task stop */
|
/* Task stop */
|
||||||
void foug_task_control_async_stop(foug_task_control_t* ctrl);
|
void foug_task_control_async_stop(foug_task_control_t* ctrl);
|
||||||
void foug_task_control_handle_stop(foug_task_control_t* ctrl);
|
void foug_task_control_handle_stop(foug_task_control_t* ctrl);
|
||||||
foug_bool foug_task_control_is_stop_requested(const foug_task_control_t* ctrl);
|
foug_bool_t foug_task_control_is_stop_requested(const foug_task_control_t* ctrl);
|
||||||
|
|
||||||
/* Cookie */
|
/* Cookie */
|
||||||
void* foug_task_control_get_cookie(const foug_task_control_t* ctrl);
|
void* foug_task_control_get_cookie(const foug_task_control_t* ctrl);
|
||||||
|
Loading…
Reference in New Issue
Block a user