Commit 63dd9974 authored by Max Lyon's avatar Max Lyon

let OMReader and OMWriter read and write double positions and normals

parent 337fb457
......@@ -297,6 +297,7 @@ bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi,
assert( chunk_header_.entity_ == Chunk::Entity_Vertex);
OpenMesh::Vec3f v3f;
OpenMesh::Vec3d v3d;
OpenMesh::Vec2f v2f;
OpenMesh::Vec3uc v3uc; // rgb
OpenMesh::Attributes::StatusInfo status;
......@@ -306,22 +307,53 @@ bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi,
size_t vidx = 0;
switch (chunk_header_.type_) {
case Chunk::Type_Pos:
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
if (chunk_header_.bits_ == OMFormat::bits(0.0f)) // read floats
{
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
bytes_ += vector_restore(_is, v3f, _swap);
_bi.add_vertex(v3f);
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
bytes_ += vector_restore(_is, v3f, _swap);
_bi.add_vertex(v3f);
}
}
else if (chunk_header_.bits_ == OMFormat::bits(0.0)) // read doubles
{
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3d::dim()));
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
bytes_ += vector_restore(_is, v3d, _swap);
_bi.add_vertex(v3d);
}
}
else
{
omerr() << "unknown Vector size" << std::endl;
}
break;
case Chunk::Type_Normal:
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
fileOptions_ += Options::VertexNormal;
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
bytes_ += vector_restore(_is, v3f, _swap);
if (fileOptions_.vertex_has_normal() && _opt.vertex_has_normal())
_bi.set_normal(VertexHandle(int(vidx)), v3f);
if (chunk_header_.bits_ == OMFormat::bits(0.0f)) // read floats
{
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
fileOptions_ += Options::VertexNormal;
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
bytes_ += vector_restore(_is, v3f, _swap);
if (fileOptions_.vertex_has_normal() && _opt.vertex_has_normal())
_bi.set_normal(VertexHandle(int(vidx)), v3f);
}
}
else if (chunk_header_.bits_ == OMFormat::bits(0.0)) // read doubles
{
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3d::dim()));
fileOptions_ += Options::VertexNormal;
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
bytes_ += vector_restore(_is, v3d, _swap);
if (fileOptions_.vertex_has_normal() && _opt.vertex_has_normal())
_bi.set_normal(VertexHandle(int(vidx)), v3d);
}
}
break;
......
......@@ -81,7 +81,7 @@ _OMWriter_& OMWriter() { return __OMWriterInstance; }
const OMFormat::uchar _OMWriter_::magic_[3] = "OM";
const OMFormat::uint8 _OMWriter_::version_ = OMFormat::mk_version(2,0);
const OMFormat::uint8 _OMWriter_::version_ = OMFormat::mk_version(2,1);
_OMWriter_::
......@@ -181,6 +181,7 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
unsigned int i, nV, nF;
Vec3f v;
Vec3d vd;
Vec2f t;
// -------------------- write header
......@@ -211,14 +212,28 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
chunk_header.name_ = false;
chunk_header.entity_ = OMFormat::Chunk::Entity_Vertex;
chunk_header.type_ = OMFormat::Chunk::Type_Pos;
chunk_header.signed_ = OMFormat::is_signed(v[0]);
chunk_header.float_ = OMFormat::is_float(v[0]);
chunk_header.dim_ = OMFormat::dim(v);
chunk_header.bits_ = OMFormat::bits(v[0]);
if (_be.is_point_double())
{
chunk_header.signed_ = OMFormat::is_signed(vd[0]);
chunk_header.float_ = OMFormat::is_float(vd[0]);
chunk_header.dim_ = OMFormat::dim(vd);
chunk_header.bits_ = OMFormat::bits(vd[0]);
}
else
{
chunk_header.signed_ = OMFormat::is_signed(v[0]);
chunk_header.float_ = OMFormat::is_float(v[0]);
chunk_header.dim_ = OMFormat::dim(v);
chunk_header.bits_ = OMFormat::bits(v[0]);
}
bytes += store( _os, chunk_header, swap );
for (i=0, nV=header.n_vertices_; i<nV; ++i)
bytes += vector_store( _os, _be.point(VertexHandle(i)), swap );
if (_be.is_point_double())
for (i=0, nV=header.n_vertices_; i<nV; ++i)
bytes += vector_store( _os, _be.pointd(VertexHandle(i)), swap );
else
for (i=0, nV=header.n_vertices_; i<nV; ++i)
bytes += vector_store( _os, _be.point(VertexHandle(i)), swap );
}
......@@ -226,18 +241,34 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
if (_be.n_vertices() && _opt.check( Options::VertexNormal ))
{
Vec3f n = _be.normal(VertexHandle(0));
Vec3d nd = _be.normald(VertexHandle(0));
chunk_header.name_ = false;
chunk_header.entity_ = OMFormat::Chunk::Entity_Vertex;
chunk_header.type_ = OMFormat::Chunk::Type_Normal;
chunk_header.signed_ = OMFormat::is_signed(n[0]);
chunk_header.float_ = OMFormat::is_float(n[0]);
chunk_header.dim_ = OMFormat::dim(n);
chunk_header.bits_ = OMFormat::bits(n[0]);
if (_be.is_normal_double())
{
chunk_header.signed_ = OMFormat::is_signed(nd[0]);
chunk_header.float_ = OMFormat::is_float(nd[0]);
chunk_header.dim_ = OMFormat::dim(nd);
chunk_header.bits_ = OMFormat::bits(nd[0]);
}
else
{
chunk_header.signed_ = OMFormat::is_signed(n[0]);
chunk_header.float_ = OMFormat::is_float(n[0]);
chunk_header.dim_ = OMFormat::dim(n);
chunk_header.bits_ = OMFormat::bits(n[0]);
}
bytes += store( _os, chunk_header, swap );
for (i=0, nV=header.n_vertices_; i<nV; ++i)
bytes += vector_store( _os, _be.normal(VertexHandle(i)), swap );
if (_be.is_normal_double())
for (i=0, nV=header.n_vertices_; i<nV; ++i)
bytes += vector_store( _os, _be.normald(VertexHandle(i)), swap );
else
for (i=0, nV=header.n_vertices_; i<nV; ++i)
bytes += vector_store( _os, _be.normal(VertexHandle(i)), swap );
}
// ---------- write vertex color
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment