Commit 75389846 authored by Christian Mattes's avatar Christian Mattes

Extended OM2Format to also save the dimension of texcoords.

parent 7f30ebcc
Pipeline #7375 failed with stage
in 81 minutes and 1 second
......@@ -99,14 +99,14 @@ void writePreamble(std::ostream &os, const OpenMesh::BaseKernel &mesh,
}
}
OpenMesh::IO::Options readPreamble(std::istream &is,
ExtendedOptions readPreamble(std::istream &is,
OpenMesh::BaseKernel &mesh) {
PreambleHeader header;
is.read(reinterpret_cast<char *>(&header), sizeof(header));
if (header.magic[0] != 'O' || header.magic[1] != 'M' ||
header.magic[2] != '2' || header.magic[3] != '\0') {
std::cerr << "File is missing magic number!" << std::endl;
return 0;
return {0};
}
const auto props_total =
......@@ -118,7 +118,7 @@ OpenMesh::IO::Options readPreamble(std::istream &is,
PropertyDeclaration decl;
if (!decl.restore(is)) {
std::cerr << "Could not read property declaration!" << std::endl;
return 0;
return {0};
}
auto type = get(decl.typeName);
......@@ -143,7 +143,7 @@ OpenMesh::IO::Options readPreamble(std::istream &is,
continue;
}
}
return header.options;
return {header.options};
}
std::vector<std::unique_ptr<BasePropertyType>> sTypes;
......
......@@ -106,7 +106,6 @@ namespace OM2Format
// is not recommended because of inconsistencies
// in case of cross writing and reading.
struct BasePropertyType {
BasePropertyType(std::string const &_name) : name(_name) {}
virtual ~BasePropertyType();
......@@ -175,7 +174,7 @@ namespace TypeInfo {
extern std::vector<std::unique_ptr<BasePropertyType>> sTypes;
template <class T> void registerType(std::string const &identifier) {
sTypes.push_back({new PropertyTypeT<T>(identifier)});
sTypes.push_back(std::unique_ptr<BasePropertyType>{new PropertyTypeT<T>(identifier)});
}
template <class T> BasePropertyType *get() {
......@@ -210,6 +209,28 @@ namespace TypeInfo {
void writePreamble(std::ostream &os, OpenMesh::BaseKernel const &mesh,
OpenMesh::IO::Options opts = 0);
struct ExtendedOptions {
int32_t value;
OpenMesh::IO::Options om() const { return {value & 0xffff}; }
bool has_vertex_texcoords1D() const { return om().vertex_has_texcoord() && (value & 0x10000); }
bool has_vertex_texcoords2D() const { return om().vertex_has_texcoord() && (value & 0x20000); }
bool has_vertex_texcoords3D() const { return om().vertex_has_texcoord() && (value & 0x40000); }
bool has_halfedge_texcoords1D() const { return om().face_has_texcoord() && (value & 0x100000); }
bool has_halfedge_texcoords2D() const { return om().face_has_texcoord() && (value & 0x200000); }
bool has_halfedge_texcoords3D() const { return om().face_has_texcoord() && (value & 0x400000); }
void add_vertex_texcoords1D() { value |= OpenMesh::IO::Options::VertexTexCoord | 0x10000; }
void add_vertex_texcoords2D() { value |= OpenMesh::IO::Options::VertexTexCoord | 0x20000; }
void add_vertex_texcoords3D() { value |= OpenMesh::IO::Options::VertexTexCoord | 0x40000; }
void add_halfedge_texcoords1D() { value |= OpenMesh::IO::Options::FaceTexCoord | 0x100000; }
void add_halfedge_texcoords2D() { value |= OpenMesh::IO::Options::FaceTexCoord | 0x200000; }
void add_halfedge_texcoords3D() { value |= OpenMesh::IO::Options::FaceTexCoord | 0x400000; }
};
/// Read the preamble and request the included properties on the mesh.
/// Use the returned OpenMesh::IO::Options for the actual mesh import
template <class MeshItems, class Connectivity>
......@@ -217,7 +238,7 @@ namespace TypeInfo {
std::istream &is,
OpenMesh::AttribKernelT<MeshItems, Connectivity> &mesh);
OpenMesh::IO::Options readPreamble(std::istream &is,
ExtendedOptions readPreamble(std::istream &is,
OpenMesh::BaseKernel &mesh);
bool checkMagic(char const * first4Bytes);
......
......@@ -203,6 +203,9 @@ public:
virtual void request_edge_colors() = 0;
virtual void request_face_normals() = 0;
virtual void request_face_colors() = 0;
virtual void request_halfedge_texcoords1D() = 0;
virtual void request_halfedge_texcoords2D() = 0;
virtual void request_halfedge_texcoords3D() = 0;
};
......
......@@ -396,6 +396,9 @@ public:
void request_vertex_texcoords1D() { mesh_.request_vertex_texcoords1D(); }
void request_vertex_texcoords2D() { mesh_.request_vertex_texcoords2D(); }
void request_vertex_texcoords3D() { mesh_.request_vertex_texcoords3D(); }
void request_halfedge_texcoords1D() { mesh_.request_halfedge_texcoords1D(); }
void request_halfedge_texcoords2D() { mesh_.request_halfedge_texcoords2D(); }
void request_halfedge_texcoords3D() { mesh_.request_halfedge_texcoords3D(); }
void request_edge_colors() { mesh_.request_edge_colors(); }
void request_face_normals() { mesh_.request_face_normals(); }
void request_face_colors() { mesh_.request_face_colors(); }
......
......@@ -56,6 +56,7 @@
// OpenMesh
#include <OpenMesh/Core/IO/OM2Format.hh>
#include <OpenMesh/Core/IO/OMFormat.hh>
#include <OpenMesh/Core/IO/reader/OMReader.hh>
#include <OpenMesh/Core/IO/reader/OM2Reader.hh>
#include <OpenMesh/Core/System/config.h>
#include <OpenMesh/Core/System/omstream.hh>
......@@ -142,12 +143,27 @@ bool _OM2Reader_::read_ascii(std::istream & /* _is */, BaseImporter & /* _bi */,
bool _OM2Reader_::read_binary(std::istream &_is, BaseImporter &_bi,
Options &_opt) const {
bool swap = _opt.check(Options::Swap) || (Endian::local() == Endian::MSB);
using Opts = OpenMesh::IO::Options;
throw std::logic_error("not implementable right now.");
OM2Format::TypeInfo::ExtendedOptions eopts = OM2Format::TypeInfo::readPreamble(_is, *_bi.kernel());
// File was successfully parsed.
return true;
if (eopts.has_halfedge_texcoords1D()) _bi.request_halfedge_texcoords1D();
if (eopts.has_halfedge_texcoords2D()) _bi.request_halfedge_texcoords2D();
if (eopts.has_halfedge_texcoords3D()) _bi.request_halfedge_texcoords3D();
if (eopts.has_vertex_texcoords1D()) _bi.request_vertex_texcoords1D();
if (eopts.has_vertex_texcoords2D()) _bi.request_vertex_texcoords2D();
if (eopts.has_vertex_texcoords3D()) _bi.request_vertex_texcoords3D();
_opt = eopts.om();
if (_opt.vertex_has_normal() ) _bi.request_vertex_normals();
if (_opt.vertex_has_color() ) _bi.request_vertex_colors();
if (_opt.edge_has_color() ) _bi.request_edge_colors();
if (_opt.face_has_normal() ) _bi.request_face_normals();
if (_opt.face_has_color() ) _bi.request_face_colors();
return __OMReaderInstance.read(_is, _bi, _opt);
}
//-----------------------------------------------------------------------------
......@@ -165,14 +181,12 @@ bool _OM2Reader_::can_u_read(const std::string &_filename) const {
//-----------------------------------------------------------------------------
bool _OM2Reader_::can_u_read(std::istream &_is) const {
std::vector<char> evt;
evt.reserve(20);
char tip[4];
_is.read(tip, 4);
// read first 4 characters into a buffer
while (evt.size() < 4)
evt.push_back(static_cast<char>(_is.get()));
for (char c : tip) _is.putback(c);
return OM2Format::TypeInfo::checkMagic(evt.data());
return OM2Format::TypeInfo::checkMagic(tip);
}
//-----------------------------------------------------------------------------
......
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