Remove out-dated C++ stuff
This commit is contained in:
parent
a539d38315
commit
3e7b8546eb
@ -1,2 +0,0 @@
|
||||
TEMPLATE = subdirs
|
||||
SUBDIRS += libstl
|
@ -1,56 +0,0 @@
|
||||
isEmpty(PREFIX_DIR) {
|
||||
PREFIX_DIR = ../../..
|
||||
}
|
||||
|
||||
include(../../config.pri)
|
||||
|
||||
message($$PREFIX_DIR)
|
||||
|
||||
TEMPLATE = lib
|
||||
TARGET = fougstl-c++$$TARGET_SUFFIX
|
||||
DESTDIR = $$PREFIX_DIR/lib
|
||||
|
||||
DEFINES *= FOUG_USE_STDINT_H
|
||||
|
||||
dll {
|
||||
DEFINES *= FOUG_STL_DLL FOUG_STL_MAKE_DLL
|
||||
}
|
||||
|
||||
#*g++*:QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
#*g++*:QMAKE_CXXFLAGS_RELEASE += -O3
|
||||
|
||||
INCLUDEPATH += ../../../src
|
||||
|
||||
HEADERS += \
|
||||
../../../src/c++/io_base.h \
|
||||
../../../src/c++/foug_global.h \
|
||||
../../../src/c++/abstract_task_progress.h \
|
||||
../../../src/c++/abstract_stream.h \
|
||||
../../../src/c++/streams/std_io_stream.h \
|
||||
../../../src/c++/streams/qt4_stream.h \
|
||||
../../../src/c++/libstl/abstract_geometry.h \
|
||||
../../../src/c++/libstl/stlb.h \
|
||||
../../../src/c++/libstl/stla.h \
|
||||
../../../src/c++/libstl/stl_global.h
|
||||
|
||||
SOURCES += \
|
||||
../../../src/c++/io_base.cpp \
|
||||
../../../src/c++/abstract_task_progress.cpp \
|
||||
# ../../src/streams/std_io_stream.cpp \
|
||||
../../../src/c++/streams/qt4_stream.cpp \
|
||||
../../../src/c++/libstl/stlb.cpp \
|
||||
../../../src/c++/libstl/stla.cpp
|
||||
|
||||
global_inc.path = $$PREFIX_DIR/include/datax
|
||||
global_inc.files = ../../../src/*.h
|
||||
cpp_global_inc.path = $$PREFIX_DIR/include/datax/c++
|
||||
cpp_global_inc.files = ../../../src/c++/*.h
|
||||
cpp_streams_inc.path = $$PREFIX_DIR/include/datax/c++/streams
|
||||
cpp_streams_inc.files = ../../../src/c++/streams/*.h
|
||||
cpp_libstl_inc.path = $$PREFIX_DIR/include/datax/c++/libstl
|
||||
cpp_libstl_inc.files = ../../../src/c++/libstl/*.h
|
||||
INSTALLS += global_inc cpp_global_inc cpp_streams_inc cpp_libstl_inc
|
||||
|
||||
VER_MAJ = 0
|
||||
VER_MIN = 1
|
||||
VER_PAT = 0
|
@ -1,24 +0,0 @@
|
||||
#ifndef FOUG_CPP_ABSTRACT_STREAM_H
|
||||
#define FOUG_CPP_ABSTRACT_STREAM_H
|
||||
|
||||
#include "foug_global.h"
|
||||
|
||||
namespace foug {
|
||||
|
||||
class AbstractStream
|
||||
{
|
||||
public:
|
||||
virtual bool atEnd() const = 0;
|
||||
|
||||
virtual bool isWritable() const = 0;
|
||||
virtual bool isReadable() const = 0;
|
||||
virtual bool isSequential() const = 0;
|
||||
|
||||
virtual bool seek(int64_t pos) = 0;
|
||||
virtual int64_t read(char* data, int64_t maxSize) = 0;
|
||||
virtual int64_t write(const char* data, int64_t maxSize) = 0;
|
||||
};
|
||||
|
||||
} // namespace foug
|
||||
|
||||
#endif // FOUG_CPP_ABSTRACT_STREAM_H
|
@ -1,125 +0,0 @@
|
||||
#include "abstract_task_progress.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace foug {
|
||||
|
||||
namespace internal {
|
||||
|
||||
class AbstractTaskProgressPrivate
|
||||
{
|
||||
public:
|
||||
AbstractTaskProgressPrivate()
|
||||
: m_stepId(-1),
|
||||
m_value(-1.),
|
||||
m_rangeMin(-1.),
|
||||
m_rangeMax(-2.),
|
||||
m_rangeLength(0.),
|
||||
m_progressThreshold(0.01), // Notifies each percent only
|
||||
m_isTaskStopRequested(false)
|
||||
{
|
||||
}
|
||||
|
||||
int m_stepId;
|
||||
double m_value;
|
||||
double m_rangeMin;
|
||||
double m_rangeMax;
|
||||
double m_rangeLength;
|
||||
double m_progressThreshold;
|
||||
bool m_isTaskStopRequested;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
AbstractTaskProgress::AbstractTaskProgress()
|
||||
: d(new internal::AbstractTaskProgressPrivate)
|
||||
{
|
||||
}
|
||||
|
||||
AbstractTaskProgress::~AbstractTaskProgress()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
double AbstractTaskProgress::rangeMin() const
|
||||
{
|
||||
return d->m_rangeMin;
|
||||
}
|
||||
|
||||
double AbstractTaskProgress::rangeMax() const
|
||||
{
|
||||
return d->m_rangeMax;
|
||||
}
|
||||
|
||||
void AbstractTaskProgress::setRange(double min, double max)
|
||||
{
|
||||
d->m_rangeMin = min;
|
||||
d->m_rangeMax = max;
|
||||
d->m_rangeLength = max - min;
|
||||
}
|
||||
|
||||
int AbstractTaskProgress::stepId() const
|
||||
{
|
||||
return d->m_stepId;
|
||||
}
|
||||
|
||||
void AbstractTaskProgress::setStepId(int id)
|
||||
{
|
||||
d->m_stepId = id;
|
||||
}
|
||||
|
||||
double AbstractTaskProgress::progress() const
|
||||
{
|
||||
const double result = (d->m_value - d->m_rangeMin) / d->m_rangeLength;
|
||||
return std::fabs(result);
|
||||
}
|
||||
|
||||
double AbstractTaskProgress::value() const
|
||||
{
|
||||
return d->m_value;
|
||||
}
|
||||
|
||||
void AbstractTaskProgress::setValue(double v)
|
||||
{
|
||||
if (std::fabs(v - d->m_value) > std::fabs(d->m_progressThreshold * d->m_rangeLength)) {
|
||||
d->m_value = v;
|
||||
this->progressUpdateEvent();
|
||||
}
|
||||
}
|
||||
|
||||
double AbstractTaskProgress::progressUpdateThreshold() const
|
||||
{
|
||||
return d->m_progressThreshold;
|
||||
}
|
||||
|
||||
void AbstractTaskProgress::setProgressUpdateThreshold(double v)
|
||||
{
|
||||
d->m_progressThreshold = v;
|
||||
}
|
||||
|
||||
void AbstractTaskProgress::asyncTaskStop()
|
||||
{
|
||||
d->m_isTaskStopRequested = true;
|
||||
}
|
||||
|
||||
bool AbstractTaskProgress::isTaskStopRequested() const
|
||||
{
|
||||
return d->m_isTaskStopRequested;
|
||||
}
|
||||
|
||||
void AbstractTaskProgress::taskStoppedEvent()
|
||||
{
|
||||
d->m_isTaskStopRequested = false;
|
||||
}
|
||||
|
||||
void AbstractTaskProgress::reset()
|
||||
{
|
||||
d->m_stepId = -1;
|
||||
d->m_value = -1.;
|
||||
d->m_rangeMin = -1.;
|
||||
d->m_rangeMax = -2.;
|
||||
d->m_isTaskStopRequested = false;
|
||||
}
|
||||
|
||||
} // namespace foug
|
@ -1,42 +0,0 @@
|
||||
#ifndef FOUG_CPP_ABSTRACT_TASK_PROGRESS_H
|
||||
#define FOUG_CPP_ABSTRACT_TASK_PROGRESS_H
|
||||
|
||||
namespace foug {
|
||||
|
||||
namespace internal { class AbstractTaskProgressPrivate; }
|
||||
|
||||
class AbstractTaskProgress
|
||||
{
|
||||
public:
|
||||
AbstractTaskProgress();
|
||||
virtual ~AbstractTaskProgress();
|
||||
|
||||
double rangeMin() const;
|
||||
double rangeMax() const;
|
||||
void setRange(double min, double max);
|
||||
|
||||
int stepId() const;
|
||||
void setStepId(int id);
|
||||
|
||||
double progress() const;
|
||||
double value() const;
|
||||
void setValue(double v);
|
||||
|
||||
double progressUpdateThreshold() const;
|
||||
void setProgressUpdateThreshold(double v);
|
||||
|
||||
virtual void reset();
|
||||
|
||||
void asyncTaskStop();
|
||||
bool isTaskStopRequested() const;
|
||||
virtual void taskStoppedEvent();
|
||||
|
||||
virtual void progressUpdateEvent() = 0;
|
||||
|
||||
private:
|
||||
internal::AbstractTaskProgressPrivate* const d;
|
||||
};
|
||||
|
||||
} // namespace foug
|
||||
|
||||
#endif // FOUG_CPP_ABSTRACT_TASK_PROGRESS_H
|
@ -1,13 +0,0 @@
|
||||
#ifndef FOUG_CPP_GLOBAL_H
|
||||
#define FOUG_CPP_GLOBAL_H
|
||||
|
||||
#include "../c/global.h"
|
||||
|
||||
namespace foug {
|
||||
|
||||
typedef foug_real32_t Real32;
|
||||
typedef foug_real64_t Real64;
|
||||
|
||||
} // namespace foug
|
||||
|
||||
#endif // FOUG_CPP_GLOBAL_H
|
@ -1,90 +0,0 @@
|
||||
#include "io_base.h"
|
||||
|
||||
#include "abstract_stream.h"
|
||||
#include "abstract_task_progress.h"
|
||||
|
||||
namespace foug {
|
||||
|
||||
namespace internal {
|
||||
|
||||
class IoBasePrivate
|
||||
{
|
||||
public:
|
||||
IoBasePrivate()
|
||||
: m_stream(0),
|
||||
m_taskProgress(0),
|
||||
m_autoDeleteStream(true),
|
||||
m_autoDeleteTaskProgress(true)
|
||||
{
|
||||
}
|
||||
|
||||
AbstractStream* m_stream;
|
||||
AbstractTaskProgress* m_taskProgress;
|
||||
bool m_autoDeleteStream;
|
||||
bool m_autoDeleteTaskProgress;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
IoBase::IoBase(AbstractStream *stream)
|
||||
: d(new internal::IoBasePrivate)
|
||||
{
|
||||
d->m_stream = stream;
|
||||
}
|
||||
|
||||
IoBase::~IoBase()
|
||||
{
|
||||
if (this->autoDeleteStream() && d->m_stream != 0)
|
||||
delete d->m_stream;
|
||||
|
||||
if (this->autoDeleteTaskProgress() && d->m_taskProgress != 0)
|
||||
delete d->m_taskProgress;
|
||||
|
||||
delete d;
|
||||
}
|
||||
|
||||
AbstractStream* IoBase::stream() const
|
||||
{
|
||||
return d->m_stream;
|
||||
}
|
||||
|
||||
void IoBase::setStream(AbstractStream* stream)
|
||||
{
|
||||
if (this->autoDeleteStream() && d->m_stream != 0 && d->m_stream != stream)
|
||||
delete d->m_stream;
|
||||
d->m_stream = stream;
|
||||
}
|
||||
|
||||
AbstractTaskProgress* IoBase::taskProgress() const
|
||||
{
|
||||
return d->m_taskProgress;
|
||||
}
|
||||
|
||||
void IoBase::setTaskProgress(AbstractTaskProgress* progress)
|
||||
{
|
||||
if (this->autoDeleteTaskProgress() && d->m_taskProgress != 0 && d->m_taskProgress != progress)
|
||||
delete d->m_taskProgress;
|
||||
d->m_taskProgress = progress;
|
||||
}
|
||||
|
||||
bool IoBase::autoDeleteStream() const
|
||||
{
|
||||
return d->m_autoDeleteStream;
|
||||
}
|
||||
|
||||
void IoBase::setAutoDeleteStream(bool on)
|
||||
{
|
||||
d->m_autoDeleteStream = on;
|
||||
}
|
||||
|
||||
bool IoBase::autoDeleteTaskProgress() const
|
||||
{
|
||||
return d->m_autoDeleteTaskProgress;
|
||||
}
|
||||
|
||||
void IoBase::setAutoDeleteTaskProgress(bool on) const
|
||||
{
|
||||
d->m_autoDeleteTaskProgress = on;
|
||||
}
|
||||
|
||||
} // namespace foug
|
@ -1,35 +0,0 @@
|
||||
#ifndef FOUG_CPP_IO_BASE_H
|
||||
#define FOUG_CPP_IO_BASE_H
|
||||
|
||||
namespace foug {
|
||||
|
||||
class AbstractStream;
|
||||
class AbstractTaskProgress;
|
||||
|
||||
namespace internal { class IoBasePrivate; }
|
||||
|
||||
class IoBase
|
||||
{
|
||||
public:
|
||||
IoBase(AbstractStream* stream = 0);
|
||||
virtual ~IoBase();
|
||||
|
||||
AbstractStream* stream() const;
|
||||
void setStream(AbstractStream* stream);
|
||||
|
||||
AbstractTaskProgress* taskProgress() const;
|
||||
void setTaskProgress(AbstractTaskProgress* progress);
|
||||
|
||||
bool autoDeleteStream() const;
|
||||
void setAutoDeleteStream(bool on);
|
||||
|
||||
bool autoDeleteTaskProgress() const;
|
||||
void setAutoDeleteTaskProgress(bool on) const;
|
||||
|
||||
private:
|
||||
internal::IoBasePrivate* const d;
|
||||
};
|
||||
|
||||
} // namespace foug
|
||||
|
||||
#endif // FOUG_CPP_IO_BASE_H
|
@ -1,40 +0,0 @@
|
||||
#ifndef FOUG_CPP_LIBSTL_ABSTRACT_GEOMETRY_H
|
||||
#define FOUG_CPP_LIBSTL_ABSTRACT_GEOMETRY_H
|
||||
|
||||
#include "stl_global.h"
|
||||
|
||||
namespace foug {
|
||||
|
||||
template <typename NUMERIC>
|
||||
struct Coords3d
|
||||
{
|
||||
NUMERIC x;
|
||||
NUMERIC y;
|
||||
NUMERIC z;
|
||||
};
|
||||
|
||||
template <typename COORDS>
|
||||
struct Triangle
|
||||
{
|
||||
COORDS normal;
|
||||
COORDS v1;
|
||||
COORDS v2;
|
||||
COORDS v3;
|
||||
};
|
||||
|
||||
namespace stl {
|
||||
|
||||
typedef Coords3d<Real32> Coords;
|
||||
typedef Triangle<Coords> Triangle;
|
||||
|
||||
class FOUG_STL_EXPORT AbstractGeometry
|
||||
{
|
||||
public:
|
||||
virtual uint32_t triangleCount() const = 0;
|
||||
virtual void getTriangle(uint32_t index, Triangle* triangle) const = 0;
|
||||
};
|
||||
|
||||
} // namespace stl
|
||||
} // namespace foug
|
||||
|
||||
#endif // FOUG_CPP_LIBSTL_ABSTRACT_GEOMETRY_H
|
@ -1,16 +0,0 @@
|
||||
#ifndef FOUG_CPP_LIBSTL_GLOBAL_H
|
||||
#define FOUG_CPP_LIBSTL_GLOBAL_H
|
||||
|
||||
#include "../foug_global.h"
|
||||
|
||||
#ifdef FOUG_STL_DLL
|
||||
# ifdef FOUG_STL_MAKE_DLL
|
||||
# define FOUG_STL_EXPORT FOUG_DECL_EXPORT
|
||||
# else
|
||||
# define FOUG_STL_EXPORT FOUG_DECL_IMPORT
|
||||
# endif // FOUG_STL_MAKE_DLL
|
||||
#else
|
||||
# define FOUG_STL_EXPORT
|
||||
#endif // FOUG_STL_DLL
|
||||
|
||||
#endif // FOUG_CPP_LIBSTL_GLOBAL_H
|
@ -1,28 +0,0 @@
|
||||
#include "stla.h"
|
||||
#include "../abstract_stream.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace foug {
|
||||
namespace stla {
|
||||
|
||||
bool Io::read(AbstractGeometryBuilder* builder, int64_t streamSize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Io::write(const stl::AbstractGeometry& geom, const std::string& solidName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AbstractGeometryBuilder::beginSolid(const std::string& /*name*/)
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractGeometryBuilder::endSolid(const std::string& /*name*/)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace stla
|
||||
} // namespace foug
|
@ -1,32 +0,0 @@
|
||||
#ifndef FOUG_CPP_LIBSTL_STLA_H
|
||||
#define FOUG_CPP_LIBSTL_STLA_H
|
||||
|
||||
#include "stl_global.h"
|
||||
#include "abstract_geometry.h"
|
||||
#include "../io_base.h"
|
||||
#include <string>
|
||||
|
||||
namespace foug {
|
||||
namespace stla {
|
||||
|
||||
class FOUG_STL_EXPORT AbstractGeometryBuilder
|
||||
{
|
||||
public:
|
||||
virtual void beginSolid(const std::string& name);
|
||||
virtual void nextTriangle(const stl::Triangle& triangle) = 0;
|
||||
virtual void endSolid(const std::string& name);
|
||||
};
|
||||
|
||||
class FOUG_STL_EXPORT Io : public IoBase
|
||||
{
|
||||
public:
|
||||
Io(AbstractStream* stream = 0);
|
||||
|
||||
bool read(AbstractGeometryBuilder* builder, int64_t streamSize = -1);
|
||||
bool write(const stl::AbstractGeometry& geom, const std::string& solidName);
|
||||
};
|
||||
|
||||
} // namespace stla
|
||||
} // namespace foug
|
||||
|
||||
#endif // FOUG_CPP_LIBSTL_STLA_H
|
@ -1,264 +0,0 @@
|
||||
#include "stlb.h"
|
||||
#include "../abstract_task_progress.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
// Read tools
|
||||
|
||||
template<typename NUMERIC>
|
||||
NUMERIC fromLittleEndian(const uint8_t* bytes)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
uint16_t fromLittleEndian<uint16_t>(const uint8_t* bytes)
|
||||
{
|
||||
// |BB|AA| -> 0xAABB
|
||||
return (bytes[1] << 8) | bytes[0];
|
||||
}
|
||||
|
||||
template<>
|
||||
uint32_t fromLittleEndian<uint32_t>(const uint8_t* bytes)
|
||||
{
|
||||
// |DD|CC|BB|AA| -> 0xAABBCCDD
|
||||
return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
|
||||
}
|
||||
|
||||
template<>
|
||||
foug::Real32 fromLittleEndian<foug::Real32>(const uint8_t* bytes)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32_t asInteger;
|
||||
foug::Real32 asFloat;
|
||||
} helper;
|
||||
|
||||
helper.asInteger = fromLittleEndian<uint32_t>(bytes);
|
||||
return helper.asFloat;
|
||||
}
|
||||
|
||||
// Write tools
|
||||
|
||||
template<typename NUMERIC>
|
||||
void toLittleEndian(NUMERIC n, uint8_t* bytes)
|
||||
{
|
||||
union {
|
||||
NUMERIC asNumeric;
|
||||
uint8_t 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(uint16_t);
|
||||
|
||||
void AbstractGeometryBuilder::processHeader(const Header& /*data*/)
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractGeometryBuilder::beginTriangles(uint32_t /*count*/)
|
||||
{
|
||||
}
|
||||
|
||||
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_t chunkSize = stlTriangleDataSize * 163;
|
||||
|
||||
uint8_t 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_t)) != sizeof(uint32_t))
|
||||
return false;
|
||||
const uint32_t facetCount = ::fromLittleEndian<uint32_t>(buffer);
|
||||
builder->beginTriangles(facetCount);
|
||||
|
||||
if (progress != 0) {
|
||||
progress->reset();
|
||||
progress->setRange(0., facetCount);
|
||||
}
|
||||
|
||||
// Read triangles
|
||||
const uint64_t totalFacetSize = stlTriangleDataSize * facetCount;
|
||||
uint64_t amountReadSize = 0;
|
||||
stl::Triangle triangle;
|
||||
bool streamError = false;
|
||||
while (amountReadSize < totalFacetSize && !streamError) {
|
||||
const int64_t iReadSize = istream->read(charBuffer, chunkSize);
|
||||
if (iReadSize > 0 && (iReadSize % stlTriangleDataSize == 0)) {
|
||||
const uint32_t iFacetCount = iReadSize / stlTriangleDataSize;
|
||||
uint32_t bufferOffset = 0;
|
||||
for (uint32_t 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_t attributeByteCount =
|
||||
::fromLittleEndian<uint16_t>(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)
|
||||
{
|
||||
if (this->stream() == 0)
|
||||
return false;
|
||||
|
||||
AbstractStream* ostream = this->stream();
|
||||
AbstractTaskProgress* progress = this->taskProgress();
|
||||
|
||||
uint8_t buffer[128];
|
||||
|
||||
// Write header
|
||||
Header headerData;
|
||||
if (extraData != 0)
|
||||
extraData->getHeader(headerData);
|
||||
else
|
||||
std::fill(headerData, headerData + HeaderSize, 0);
|
||||
|
||||
if (ostream->write(reinterpret_cast<char*>(&headerData), HeaderSize) != HeaderSize)
|
||||
return false;
|
||||
|
||||
// Write facet count
|
||||
const uint32_t facetCount = geom.triangleCount();
|
||||
::toLittleEndian<uint32_t>(facetCount, buffer);
|
||||
if (ostream->write(reinterpret_cast<char*>(&buffer), sizeof(uint32_t)) != sizeof(uint32_t))
|
||||
return false;
|
||||
|
||||
if (progress != 0) {
|
||||
progress->reset();
|
||||
progress->setRange(0., facetCount);
|
||||
}
|
||||
|
||||
// Write triangles
|
||||
stl::Triangle triangle;
|
||||
for (uint32_t facet = 0; facet < facetCount; ++facet) {
|
||||
geom.getTriangle(facet, &triangle);
|
||||
|
||||
// Write normal
|
||||
::toLittleEndian<Real32>(triangle.normal.x, buffer);
|
||||
::toLittleEndian<Real32>(triangle.normal.y, buffer + 1*sizeof(Real32));
|
||||
::toLittleEndian<Real32>(triangle.normal.z, buffer + 2*sizeof(Real32));
|
||||
|
||||
// Write vertex1
|
||||
::toLittleEndian<Real32>(triangle.v1.x, buffer + 3*sizeof(Real32));
|
||||
::toLittleEndian<Real32>(triangle.v1.y, buffer + 4*sizeof(Real32));
|
||||
::toLittleEndian<Real32>(triangle.v1.z, buffer + 5*sizeof(Real32));
|
||||
|
||||
// Write vertex2
|
||||
::toLittleEndian<Real32>(triangle.v2.x, buffer + 6*sizeof(Real32));
|
||||
::toLittleEndian<Real32>(triangle.v2.y, buffer + 7*sizeof(Real32));
|
||||
::toLittleEndian<Real32>(triangle.v2.z, buffer + 8*sizeof(Real32));
|
||||
|
||||
// Write vertex3
|
||||
::toLittleEndian<Real32>(triangle.v3.x, buffer + 9*sizeof(Real32));
|
||||
::toLittleEndian<Real32>(triangle.v3.y, buffer + 10*sizeof(Real32));
|
||||
::toLittleEndian<Real32>(triangle.v3.z, buffer + 11*sizeof(Real32));
|
||||
|
||||
// Attribute byte count
|
||||
const uint16_t attrByteCount = extraData != 0 ? extraData->attributeByteCount(facet) : 0;
|
||||
::toLittleEndian<uint16_t>(attrByteCount, buffer + 12*sizeof(Real32));
|
||||
|
||||
// Write to stream
|
||||
if (ostream->write(reinterpret_cast<const char*>(buffer), stlTriangleDataSize)
|
||||
!= stlTriangleDataSize)
|
||||
return false;
|
||||
|
||||
if (progress != 0) {
|
||||
if (progress->isTaskStopRequested()) {
|
||||
progress->taskStoppedEvent();
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
progress->setValue(facet + 1);
|
||||
}
|
||||
}
|
||||
} // end for
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace stlb
|
||||
} // namespace foug
|
@ -1,43 +0,0 @@
|
||||
#ifndef FOUG_CPP_LIBSTL_STLB_H
|
||||
#define FOUG_CPP_LIBSTL_STLB_H
|
||||
|
||||
#include "abstract_geometry.h"
|
||||
#include "stl_global.h"
|
||||
#include "../abstract_stream.h"
|
||||
#include "../io_base.h"
|
||||
|
||||
namespace foug {
|
||||
namespace stlb {
|
||||
|
||||
enum { HeaderSize = 80 };
|
||||
typedef uint8_t Header[HeaderSize];
|
||||
|
||||
class FOUG_STL_EXPORT AbstractGeometryBuilder
|
||||
{
|
||||
public:
|
||||
virtual void processHeader(const Header& data);
|
||||
virtual void beginTriangles(uint32_t count);
|
||||
virtual void processNextTriangle(const stl::Triangle& triangle, uint16_t attributeByteCount) = 0;
|
||||
virtual void endTriangles();
|
||||
};
|
||||
|
||||
class FOUG_STL_EXPORT AbstractGeometryExtraData
|
||||
{
|
||||
public:
|
||||
virtual void getHeader(Header& data) const = 0;
|
||||
virtual uint16_t attributeByteCount(uint32_t 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);
|
||||
};
|
||||
|
||||
} // namespace stlb
|
||||
} // namespace foug
|
||||
|
||||
#endif // FOUG_CPP_LIBSTL_STLB_H
|
@ -1,48 +0,0 @@
|
||||
#include "qt4_stream.h"
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtCore/QtDebug>
|
||||
|
||||
namespace foug {
|
||||
|
||||
Qt4Stream::Qt4Stream(QIODevice *device)
|
||||
: m_device(device)
|
||||
{
|
||||
}
|
||||
|
||||
bool Qt4Stream::atEnd() const
|
||||
{
|
||||
return m_device->atEnd();
|
||||
}
|
||||
|
||||
bool Qt4Stream::isWritable() const
|
||||
{
|
||||
return m_device != 0 ? m_device->isWritable() : false;
|
||||
}
|
||||
|
||||
bool Qt4Stream::isReadable() const
|
||||
{
|
||||
return m_device != 0 ? m_device->isReadable() : false;
|
||||
}
|
||||
|
||||
bool Qt4Stream::isSequential() const
|
||||
{
|
||||
return m_device != 0 ? m_device->isSequential() : false;
|
||||
}
|
||||
|
||||
bool Qt4Stream::seek(int64_t pos)
|
||||
{
|
||||
return m_device->seek(pos);
|
||||
}
|
||||
|
||||
int64_t Qt4Stream::read(char *data, int64_t maxSize)
|
||||
{
|
||||
return m_device->read(data, maxSize);
|
||||
}
|
||||
|
||||
int64_t Qt4Stream::write(const char *data, int64_t maxSize)
|
||||
{
|
||||
return m_device->write(data, maxSize);
|
||||
}
|
||||
|
||||
} // namespace foug
|
@ -1,30 +0,0 @@
|
||||
#ifndef FOUG_CPP_STREAMS_QT4_STREAM_H
|
||||
#define FOUG_CPP_STREAMS_QT4_STREAM_H
|
||||
|
||||
#include "../abstract_stream.h"
|
||||
class QIODevice;
|
||||
|
||||
namespace foug {
|
||||
|
||||
class Qt4Stream : public AbstractStream
|
||||
{
|
||||
public:
|
||||
Qt4Stream(QIODevice* device);
|
||||
|
||||
bool atEnd() const;
|
||||
|
||||
bool isWritable() const;
|
||||
bool isReadable() const;
|
||||
bool isSequential() const;
|
||||
|
||||
bool seek(int64_t pos);
|
||||
int64_t read(char* data, int64_t maxSize);
|
||||
int64_t write(const char* data, int64_t maxSize);
|
||||
|
||||
private:
|
||||
QIODevice* m_device;
|
||||
};
|
||||
|
||||
} // namespace foug
|
||||
|
||||
#endif // FOUG_CPP_STREAMS_QT4_STREAM_H
|
@ -1,29 +0,0 @@
|
||||
#include "std_io_stream.h"
|
||||
|
||||
namespace foug {
|
||||
|
||||
StdIoStream::StdIoStream(std::iostream* iostr)
|
||||
: m_iostr(iostr)
|
||||
{
|
||||
}
|
||||
|
||||
Int64 StdIoStream::read(char* data, Int64 maxSize)
|
||||
{
|
||||
if (!m_iostr->eof())
|
||||
return 0;
|
||||
|
||||
m_iostr->read(data, maxSize);
|
||||
if (!m_iostr->good())
|
||||
return -1;
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
Int64 StdIoStream::write(const char* data, Int64 maxSize)
|
||||
{
|
||||
m_iostr->write(data, maxSize);
|
||||
if (!m_iostr->good())
|
||||
return -1;
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
} // namespace foug
|
@ -1,119 +0,0 @@
|
||||
#ifndef FOUG_CPP_STREAMS_STD_IO_STREAM_H
|
||||
#define FOUG_CPP_STREAMS_STD_IO_STREAM_H
|
||||
|
||||
#include "../abstract_stream.h"
|
||||
|
||||
namespace foug {
|
||||
|
||||
template<typename STD_STREAM>
|
||||
class StdInputStream : public AbstractStream
|
||||
{
|
||||
public:
|
||||
StdInputStream(STD_STREAM* istr)
|
||||
: m_istr(istr)
|
||||
{
|
||||
}
|
||||
|
||||
bool atEnd() const
|
||||
{
|
||||
return m_istr->eof();
|
||||
}
|
||||
|
||||
bool isWritable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isReadable() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isSequential() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool seek(foug::Int64 pos)
|
||||
{
|
||||
m_istr->seekg(pos);
|
||||
return m_istr->good();
|
||||
}
|
||||
|
||||
Int64 read(char* data, Int64 maxSize)
|
||||
{
|
||||
m_istr->read(data, maxSize);
|
||||
if (!m_istr->eof() && m_istr->fail()) {
|
||||
m_istr->clear();
|
||||
return -1;
|
||||
}
|
||||
const Int64 bytesCount = m_istr->gcount();
|
||||
if (m_istr->fail()) // TODO preserve eof() flag
|
||||
m_istr->clear();
|
||||
return bytesCount;
|
||||
}
|
||||
|
||||
Int64 write(const char* /*data*/, Int64 /*maxSize*/)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
private:
|
||||
STD_STREAM* m_istr;
|
||||
};
|
||||
|
||||
template<typename STD_STREAM>
|
||||
class StdOutputStream : public AbstractStream
|
||||
{
|
||||
public:
|
||||
StdOutputStream(STD_STREAM* ostr)
|
||||
: m_ostr(ostr)
|
||||
{
|
||||
}
|
||||
|
||||
bool atEnd() const
|
||||
{
|
||||
return m_ostr->eof();
|
||||
}
|
||||
|
||||
bool isWritable() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isReadable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isSequential() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool seek(foug::Int64 pos)
|
||||
{
|
||||
m_ostr->seekp(pos);
|
||||
return m_ostr->good();
|
||||
}
|
||||
|
||||
Int64 read(char* /*data*/, Int64 /*maxSize*/)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
Int64 write(const char* data, Int64 maxSize)
|
||||
{
|
||||
m_ostr->write(data, maxSize);
|
||||
if (!m_ostr->good())
|
||||
return -1;
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
private:
|
||||
STD_STREAM* m_ostr;
|
||||
};
|
||||
|
||||
} // namespace foug
|
||||
|
||||
#endif // FOUG_CPP_STREAMS_STD_IO_STREAM_H
|
Loading…
Reference in New Issue
Block a user