stlb: change namespaces to stlb and stla (were stl::bin / stl::asc)
This commit is contained in:
parent
3fff1fbd28
commit
19b790f61e
@ -1,18 +1,17 @@
|
|||||||
#include "abstract_stream.h"
|
|
||||||
#include "stla.h"
|
#include "stla.h"
|
||||||
|
#include "../abstract_stream.h"
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
namespace foug {
|
namespace foug {
|
||||||
namespace stl {
|
namespace stla {
|
||||||
namespace asc {
|
|
||||||
|
|
||||||
bool Io::read(AbstractGeometryBuilder* builder, Int64 streamSize)
|
bool Io::read(AbstractGeometryBuilder* builder, Int64 streamSize)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Io::write(const AbstractGeometry& geom, const std::string& solidName)
|
bool Io::write(const stl::AbstractGeometry& geom, const std::string& solidName)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -25,6 +24,5 @@ void AbstractGeometryBuilder::endSolid(const std::string& /*name*/)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace asc
|
} // namespace stla
|
||||||
} // namespace stl
|
|
||||||
} // namespace foug
|
} // namespace foug
|
||||||
|
@ -3,18 +3,17 @@
|
|||||||
|
|
||||||
#include "stl_global.h"
|
#include "stl_global.h"
|
||||||
#include "abstract_geometry.h"
|
#include "abstract_geometry.h"
|
||||||
#include "io_base.h"
|
#include "../io_base.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace foug {
|
namespace foug {
|
||||||
namespace stl {
|
namespace stla {
|
||||||
namespace asc {
|
|
||||||
|
|
||||||
class FOUG_STL_EXPORT AbstractGeometryBuilder
|
class FOUG_STL_EXPORT AbstractGeometryBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void beginSolid(const std::string& name);
|
virtual void beginSolid(const std::string& name);
|
||||||
virtual void nextTriangle(const Triangle& triangle) = 0;
|
virtual void nextTriangle(const stl::Triangle& triangle) = 0;
|
||||||
virtual void endSolid(const std::string& name);
|
virtual void endSolid(const std::string& name);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,11 +23,10 @@ public:
|
|||||||
Io(AbstractStream* stream = 0);
|
Io(AbstractStream* stream = 0);
|
||||||
|
|
||||||
bool read(AbstractGeometryBuilder* builder, Int64 streamSize = -1);
|
bool read(AbstractGeometryBuilder* builder, Int64 streamSize = -1);
|
||||||
bool write(const AbstractGeometry& geom, const std::string& solidName);
|
bool write(const stl::AbstractGeometry& geom, const std::string& solidName);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace asc
|
} // namespace stla
|
||||||
} // namespace stl
|
|
||||||
} // namespace foug
|
} // namespace foug
|
||||||
|
|
||||||
#endif // FOUG_STLA_H
|
#endif // FOUG_STLA_H
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "abstract_stream.h"
|
|
||||||
#include "stlb.h"
|
#include "stlb.h"
|
||||||
#include "abstract_task_progress.h"
|
#include "../abstract_task_progress.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@ -56,15 +55,13 @@ void toLittleEndian(NUMERIC n, foug::UInt8* bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace foug {
|
namespace foug {
|
||||||
namespace stl {
|
namespace stlb {
|
||||||
namespace bin {
|
|
||||||
|
|
||||||
static const int stlHeaderSize = 80;
|
|
||||||
static const int stlFacetSize = 50;
|
static const int stlFacetSize = 50;
|
||||||
static const int stlMinFileSize = 284;
|
static const int stlMinFileSize = 284;
|
||||||
static const int stlTriangleDataSize = (4 * 3) * sizeof(foug::Real32) + sizeof(foug::UInt16);
|
static const int stlTriangleDataSize = (4 * 3) * sizeof(foug::Real32) + sizeof(foug::UInt16);
|
||||||
|
|
||||||
void AbstractGeometryBuilder::header(const Header& /*data*/)
|
void AbstractGeometryBuilder::processHeader(const Header& /*data*/)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,32 +73,12 @@ void AbstractGeometryBuilder::endTriangles()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Io::ReadError streamRead(AbstractStream* stream, char* buffer, Int64 size)
|
|
||||||
{
|
|
||||||
const Int64 result = stream->read(buffer, size);
|
|
||||||
if (result == -1)
|
|
||||||
return Io::StreamReadError;
|
|
||||||
else if (result != size)
|
|
||||||
return Io::UnexpectedSizeReadError;
|
|
||||||
return Io::NoReadError;
|
|
||||||
}
|
|
||||||
|
|
||||||
Io::ReadError getReadError(Int64 readResult, Int64 expectedSize)
|
|
||||||
{
|
|
||||||
if (readResult == -1)
|
|
||||||
return Io::StreamReadError;
|
|
||||||
else if (readResult != expectedSize)
|
|
||||||
return Io::UnexpectedSizeReadError;
|
|
||||||
else
|
|
||||||
return Io::NoReadError;
|
|
||||||
}
|
|
||||||
|
|
||||||
Io::Io(AbstractStream *stream)
|
Io::Io(AbstractStream *stream)
|
||||||
: IoBase(stream)
|
: IoBase(stream)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Io::ReadError Io::read(AbstractGeometryBuilder* builder)
|
bool Io::read(AbstractGeometryBuilder* builder)
|
||||||
{
|
{
|
||||||
// // Check file size
|
// // Check file size
|
||||||
// const qint64 fileSize = stream->size();
|
// const qint64 fileSize = stream->size();
|
||||||
@ -115,7 +92,6 @@ Io::ReadError Io::read(AbstractGeometryBuilder* builder)
|
|||||||
|
|
||||||
AbstractStream* istream = this->stream();
|
AbstractStream* istream = this->stream();
|
||||||
AbstractTaskProgress* progress = this->taskProgress();
|
AbstractTaskProgress* progress = this->taskProgress();
|
||||||
// Io::ReadError readErr = Io::NoReadError;
|
|
||||||
const UInt32 chunkSize = stlTriangleDataSize * 163;
|
const UInt32 chunkSize = stlTriangleDataSize * 163;
|
||||||
|
|
||||||
UInt8 buffer[8192];
|
UInt8 buffer[8192];
|
||||||
@ -123,15 +99,13 @@ Io::ReadError Io::read(AbstractGeometryBuilder* builder)
|
|||||||
|
|
||||||
// Read header
|
// Read header
|
||||||
Header headerData;
|
Header headerData;
|
||||||
istream->read(reinterpret_cast<char*>(&headerData), 80);
|
if (istream->read(reinterpret_cast<char*>(&headerData), HeaderSize) != HeaderSize)
|
||||||
// if ((readErr = streamRead(istream, reinterpret_cast<char*>(&headerData), 80)) != NoReadError)
|
return false;
|
||||||
// return readErr;
|
builder->processHeader(headerData);
|
||||||
builder->header(headerData);
|
|
||||||
|
|
||||||
// Read facet count
|
// Read facet count
|
||||||
istream->read(charBuffer, sizeof(UInt32));
|
if (istream->read(charBuffer, sizeof(UInt32)) != sizeof(UInt32))
|
||||||
// if ((readErr = streamRead(istream, charBuffer, sizeof(UInt32))) != NoReadError)
|
return false;
|
||||||
// return readErr;
|
|
||||||
const UInt32 facetCount = ::fromLittleEndian<UInt32>(buffer);
|
const UInt32 facetCount = ::fromLittleEndian<UInt32>(buffer);
|
||||||
builder->beginTriangles(facetCount);
|
builder->beginTriangles(facetCount);
|
||||||
|
|
||||||
@ -143,7 +117,7 @@ Io::ReadError Io::read(AbstractGeometryBuilder* builder)
|
|||||||
// Read triangles
|
// Read triangles
|
||||||
const UInt64 totalFacetSize = stlTriangleDataSize * facetCount;
|
const UInt64 totalFacetSize = stlTriangleDataSize * facetCount;
|
||||||
UInt64 amountReadSize = 0;
|
UInt64 amountReadSize = 0;
|
||||||
Triangle triangle;
|
stl::Triangle triangle;
|
||||||
bool streamError = false;
|
bool streamError = false;
|
||||||
while (amountReadSize < totalFacetSize && !streamError) {
|
while (amountReadSize < totalFacetSize && !streamError) {
|
||||||
const Int64 iReadSize = istream->read(charBuffer, chunkSize);
|
const Int64 iReadSize = istream->read(charBuffer, chunkSize);
|
||||||
@ -176,7 +150,7 @@ Io::ReadError Io::read(AbstractGeometryBuilder* builder)
|
|||||||
::fromLittleEndian<UInt16>(buffer + 12*sizeof(Real32) + bufferOffset);
|
::fromLittleEndian<UInt16>(buffer + 12*sizeof(Real32) + bufferOffset);
|
||||||
|
|
||||||
// Add triangle
|
// Add triangle
|
||||||
builder->nextTriangle(triangle, attributeByteCount);
|
builder->processNextTriangle(triangle, attributeByteCount);
|
||||||
|
|
||||||
bufferOffset += stlTriangleDataSize;
|
bufferOffset += stlTriangleDataSize;
|
||||||
}
|
}
|
||||||
@ -193,10 +167,10 @@ Io::ReadError Io::read(AbstractGeometryBuilder* builder)
|
|||||||
|
|
||||||
builder->endTriangles();
|
builder->endTriangles();
|
||||||
|
|
||||||
return NoReadError;
|
return !streamError;
|
||||||
}
|
}
|
||||||
|
|
||||||
Io::WriteError Io::write(const AbstractGeometry& geom, const AbstractGeometryExtraData* extraData)
|
bool Io::write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraData* extraData)
|
||||||
{
|
{
|
||||||
AbstractStream* ostream = this->stream();
|
AbstractStream* ostream = this->stream();
|
||||||
AbstractTaskProgress* progress = this->taskProgress();
|
AbstractTaskProgress* progress = this->taskProgress();
|
||||||
@ -206,16 +180,18 @@ Io::WriteError Io::write(const AbstractGeometry& geom, const AbstractGeometryExt
|
|||||||
// Write header
|
// Write header
|
||||||
Header headerData;
|
Header headerData;
|
||||||
if (extraData != 0)
|
if (extraData != 0)
|
||||||
extraData->getHeaderData(headerData);
|
extraData->getHeader(headerData);
|
||||||
else
|
else
|
||||||
std::fill(headerData, headerData + 80, 0);
|
std::fill(headerData, headerData + HeaderSize, 0);
|
||||||
|
|
||||||
ostream->write(reinterpret_cast<char*>(&headerData), 80);
|
if (ostream->write(reinterpret_cast<char*>(&headerData), HeaderSize) != HeaderSize)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Write facet count
|
// Write facet count
|
||||||
const UInt32 facetCount = geom.triangleCount();
|
const UInt32 facetCount = geom.triangleCount();
|
||||||
::toLittleEndian<UInt32>(facetCount, buffer);
|
::toLittleEndian<UInt32>(facetCount, buffer);
|
||||||
ostream->write(reinterpret_cast<char*>(&buffer), sizeof(UInt32));
|
if (ostream->write(reinterpret_cast<char*>(&buffer), sizeof(UInt32)) != sizeof(UInt32))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (progress != 0) {
|
if (progress != 0) {
|
||||||
progress->reset();
|
progress->reset();
|
||||||
@ -223,7 +199,7 @@ Io::WriteError Io::write(const AbstractGeometry& geom, const AbstractGeometryExt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write triangles
|
// Write triangles
|
||||||
Triangle triangle;
|
stl::Triangle triangle;
|
||||||
for (UInt32 facet = 0; facet < facetCount; ++facet) {
|
for (UInt32 facet = 0; facet < facetCount; ++facet) {
|
||||||
geom.getTriangle(facet, &triangle);
|
geom.getTriangle(facet, &triangle);
|
||||||
|
|
||||||
@ -252,15 +228,16 @@ Io::WriteError Io::write(const AbstractGeometry& geom, const AbstractGeometryExt
|
|||||||
::toLittleEndian<UInt16>(attrByteCount, buffer + 12*sizeof(Real32));
|
::toLittleEndian<UInt16>(attrByteCount, buffer + 12*sizeof(Real32));
|
||||||
|
|
||||||
// Write to stream
|
// Write to stream
|
||||||
ostream->write(reinterpret_cast<const char*>(buffer), stlTriangleDataSize);
|
if (ostream->write(reinterpret_cast<const char*>(buffer), stlTriangleDataSize)
|
||||||
|
!= stlTriangleDataSize)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (progress != 0)
|
if (progress != 0)
|
||||||
progress->setValue(facet + 1);
|
progress->setValue(facet + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NoWriteError;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace bin
|
} // namespace stlb
|
||||||
} // namespace stl
|
|
||||||
} // namespace foug
|
} // namespace foug
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
#ifndef FOUG_STLB_H
|
#ifndef FOUG_STLB_H
|
||||||
#define FOUG_STLB_H
|
#define FOUG_STLB_H
|
||||||
|
|
||||||
#include "stl_global.h"
|
|
||||||
#include "abstract_geometry.h"
|
#include "abstract_geometry.h"
|
||||||
#include "io_base.h"
|
#include "stl_global.h"
|
||||||
#include <abstract_stream.h>
|
#include "../abstract_stream.h"
|
||||||
|
#include "../io_base.h"
|
||||||
|
|
||||||
namespace foug {
|
namespace foug {
|
||||||
namespace stl {
|
namespace stlb {
|
||||||
namespace bin {
|
|
||||||
|
|
||||||
typedef UInt8 Header[80];
|
enum { HeaderSize = 80 };
|
||||||
|
typedef UInt8 Header[HeaderSize];
|
||||||
|
|
||||||
class FOUG_STL_EXPORT AbstractGeometryBuilder
|
class FOUG_STL_EXPORT AbstractGeometryBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void header(const Header& data);
|
virtual void processHeader(const Header& data);
|
||||||
virtual void beginTriangles(UInt32 count);
|
virtual void beginTriangles(UInt32 count);
|
||||||
virtual void nextTriangle(const stl::Triangle& triangle, UInt16 attributeByteCount) = 0;
|
virtual void processNextTriangle(const stl::Triangle& triangle, UInt16 attributeByteCount) = 0;
|
||||||
virtual void endTriangles();
|
virtual void endTriangles();
|
||||||
};
|
};
|
||||||
|
|
||||||
class FOUG_STL_EXPORT AbstractGeometryExtraData
|
class FOUG_STL_EXPORT AbstractGeometryExtraData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void getHeaderData(Header& data) const = 0;
|
virtual void getHeader(Header& data) const = 0;
|
||||||
virtual UInt16 attributeByteCount(UInt32 triangleIndex) const = 0;
|
virtual UInt16 attributeByteCount(UInt32 triangleIndex) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -33,23 +33,11 @@ class FOUG_STL_EXPORT Io : public IoBase
|
|||||||
public:
|
public:
|
||||||
Io(AbstractStream* stream = 0);
|
Io(AbstractStream* stream = 0);
|
||||||
|
|
||||||
enum ReadError
|
bool read(AbstractGeometryBuilder* builder);
|
||||||
{
|
bool write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraData* extraData = 0);
|
||||||
NoReadError,
|
|
||||||
StreamReadError,
|
|
||||||
UnexpectedSizeReadError
|
|
||||||
};
|
|
||||||
ReadError read(AbstractGeometryBuilder* builder);
|
|
||||||
|
|
||||||
enum WriteError
|
|
||||||
{
|
|
||||||
NoWriteError
|
|
||||||
};
|
|
||||||
WriteError write(const AbstractGeometry& geom, const AbstractGeometryExtraData* extraData = 0);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace bin
|
} // namespace stlb
|
||||||
} // namespace stl
|
|
||||||
} // namespace foug
|
} // namespace foug
|
||||||
|
|
||||||
#endif // FOUG_STLB_H
|
#endif // FOUG_STLB_H
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef FOUG_QT4_STREAM_H
|
#ifndef FOUG_QT4_STREAM_H
|
||||||
#define FOUG_QT4_STREAM_H
|
#define FOUG_QT4_STREAM_H
|
||||||
|
|
||||||
#include "abstract_stream.h"
|
#include "../abstract_stream.h"
|
||||||
class QIODevice;
|
class QIODevice;
|
||||||
|
|
||||||
namespace foug {
|
namespace foug {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef FOUG_STD_IO_STREAM_H
|
#ifndef FOUG_STD_IO_STREAM_H
|
||||||
#define FOUG_STD_IO_STREAM_H
|
#define FOUG_STD_IO_STREAM_H
|
||||||
|
|
||||||
#include "abstract_stream.h"
|
#include "../abstract_stream.h"
|
||||||
|
|
||||||
namespace foug {
|
namespace foug {
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
class DummyGeometryBuilder : public foug::stl::bin::AbstractGeometryBuilder
|
class DummyGeometryBuilder : public foug::stl::bin::AbstractGeometryBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void header(const foug::stl::bin::Header& data)
|
void processHeader(const foug::stl::bin::Header& data)
|
||||||
{
|
{
|
||||||
qDebug() << "HEADER : \n" << QString::fromAscii(reinterpret_cast<const char*>(data), 79);
|
qDebug() << "HEADER : \n" << QString::fromAscii(reinterpret_cast<const char*>(data), 79);
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ public:
|
|||||||
qDebug() << "Triangle count" << count;
|
qDebug() << "Triangle count" << count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nextTriangle(const foug::stl::Triangle& triangle, foug::UInt16 attributeByteCount)
|
void processNextTriangle(const foug::stl::Triangle& triangle, foug::UInt16 attributeByteCount)
|
||||||
{
|
{
|
||||||
// qDebug() << "TRIANGLE " << m_triangleCounter++;
|
// qDebug() << "TRIANGLE " << m_triangleCounter++;
|
||||||
// qDebug() << " normal" << triangle.normal.x << triangle.normal.y << triangle.normal.z;
|
// qDebug() << " normal" << triangle.normal.x << triangle.normal.y << triangle.normal.z;
|
||||||
@ -77,7 +77,7 @@ public:
|
|||||||
|
|
||||||
// -- foug::stl::bin::AbstractGeometryBuilder
|
// -- foug::stl::bin::AbstractGeometryBuilder
|
||||||
|
|
||||||
void header(const foug::stl::bin::Header& data)
|
void processHeader(const foug::stlb::Header& data)
|
||||||
{
|
{
|
||||||
std::memcpy(m_header, data, 80);
|
std::memcpy(m_header, data, 80);
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ public:
|
|||||||
m_triangles.resize(0);
|
m_triangles.resize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nextTriangle(const foug::stl::Triangle& triangle, foug::UInt16 attributeByteCount)
|
void processNextTriangle(const foug::stl::Triangle& triangle, foug::UInt16 attributeByteCount)
|
||||||
{
|
{
|
||||||
TriangleData data;
|
TriangleData data;
|
||||||
data.triangle = triangle;
|
data.triangle = triangle;
|
||||||
@ -106,7 +106,7 @@ public:
|
|||||||
|
|
||||||
foug::UInt16 attributeByteCount(foug::UInt32 triangleIndex) const
|
foug::UInt16 attributeByteCount(foug::UInt32 triangleIndex) const
|
||||||
{
|
{
|
||||||
return m_triangles[triangleIndex].attributeByteCount;
|
return m_triangles.at(triangleIndex).attributeByteCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- foug::stl::AbstractGeometry
|
// -- foug::stl::AbstractGeometry
|
||||||
@ -118,7 +118,7 @@ public:
|
|||||||
|
|
||||||
void getTriangle(foug::UInt32 index, foug::stl::Triangle* triangle) const
|
void getTriangle(foug::UInt32 index, foug::stl::Triangle* triangle) const
|
||||||
{
|
{
|
||||||
*triangle = m_triangles[index].triangle;
|
*triangle = m_triangles.at(index).triangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user