let OMReader and OMWriter read and write double positions and normals

This commit is contained in:
Max Lyon
2020-02-05 22:13:36 +01:00
parent 337fb4571d
commit 63dd997489
2 changed files with 86 additions and 23 deletions

View File

@@ -297,6 +297,7 @@ bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi,
assert( chunk_header_.entity_ == Chunk::Entity_Vertex); assert( chunk_header_.entity_ == Chunk::Entity_Vertex);
OpenMesh::Vec3f v3f; OpenMesh::Vec3f v3f;
OpenMesh::Vec3d v3d;
OpenMesh::Vec2f v2f; OpenMesh::Vec2f v2f;
OpenMesh::Vec3uc v3uc; // rgb OpenMesh::Vec3uc v3uc; // rgb
OpenMesh::Attributes::StatusInfo status; OpenMesh::Attributes::StatusInfo status;
@@ -306,22 +307,53 @@ bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi,
size_t vidx = 0; size_t vidx = 0;
switch (chunk_header_.type_) { switch (chunk_header_.type_) {
case Chunk::Type_Pos: 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) { for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
bytes_ += vector_restore(_is, v3f, _swap); bytes_ += vector_restore(_is, v3f, _swap);
_bi.add_vertex(v3f); _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; break;
case Chunk::Type_Normal: case Chunk::Type_Normal:
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
fileOptions_ += Options::VertexNormal; if (chunk_header_.bits_ == OMFormat::bits(0.0f)) // read floats
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) { {
bytes_ += vector_restore(_is, v3f, _swap); assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
if (fileOptions_.vertex_has_normal() && _opt.vertex_has_normal())
_bi.set_normal(VertexHandle(int(vidx)), v3f); 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; break;

View File

@@ -81,7 +81,7 @@ _OMWriter_& OMWriter() { return __OMWriterInstance; }
const OMFormat::uchar _OMWriter_::magic_[3] = "OM"; 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_:: _OMWriter_::
@@ -181,6 +181,7 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
unsigned int i, nV, nF; unsigned int i, nV, nF;
Vec3f v; Vec3f v;
Vec3d vd;
Vec2f t; Vec2f t;
// -------------------- write header // -------------------- write header
@@ -211,14 +212,28 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
chunk_header.name_ = false; chunk_header.name_ = false;
chunk_header.entity_ = OMFormat::Chunk::Entity_Vertex; chunk_header.entity_ = OMFormat::Chunk::Entity_Vertex;
chunk_header.type_ = OMFormat::Chunk::Type_Pos; chunk_header.type_ = OMFormat::Chunk::Type_Pos;
chunk_header.signed_ = OMFormat::is_signed(v[0]); if (_be.is_point_double())
chunk_header.float_ = OMFormat::is_float(v[0]); {
chunk_header.dim_ = OMFormat::dim(v); chunk_header.signed_ = OMFormat::is_signed(vd[0]);
chunk_header.bits_ = OMFormat::bits(v[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 ); bytes += store( _os, chunk_header, swap );
for (i=0, nV=header.n_vertices_; i<nV; ++i) if (_be.is_point_double())
bytes += vector_store( _os, _be.point(VertexHandle(i)), swap ); 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 )) if (_be.n_vertices() && _opt.check( Options::VertexNormal ))
{ {
Vec3f n = _be.normal(VertexHandle(0)); Vec3f n = _be.normal(VertexHandle(0));
Vec3d nd = _be.normald(VertexHandle(0));
chunk_header.name_ = false; chunk_header.name_ = false;
chunk_header.entity_ = OMFormat::Chunk::Entity_Vertex; chunk_header.entity_ = OMFormat::Chunk::Entity_Vertex;
chunk_header.type_ = OMFormat::Chunk::Type_Normal; chunk_header.type_ = OMFormat::Chunk::Type_Normal;
chunk_header.signed_ = OMFormat::is_signed(n[0]); if (_be.is_normal_double())
chunk_header.float_ = OMFormat::is_float(n[0]); {
chunk_header.dim_ = OMFormat::dim(n); chunk_header.signed_ = OMFormat::is_signed(nd[0]);
chunk_header.bits_ = OMFormat::bits(n[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 ); bytes += store( _os, chunk_header, swap );
for (i=0, nV=header.n_vertices_; i<nV; ++i) if (_be.is_normal_double())
bytes += vector_store( _os, _be.normal(VertexHandle(i)), swap ); 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 // ---------- write vertex color