Merged master

This commit is contained in:
Jan Möbius
2023-02-27 15:00:08 +01:00
9 changed files with 84 additions and 57 deletions

View File

@@ -97,7 +97,7 @@ public:
/// Definitions of %Options for reading and writing. The options can be
/// or'ed.
enum Flag {
Default = 0x0000, ///< No options
None = 0x0000, ///< No options
Binary = 0x0001, ///< Set binary mode for r/w
MSB = 0x0002, ///< Assume big endian byte ordering
LSB = 0x0004, ///< Assume little endian byte ordering
@@ -111,9 +111,10 @@ public:
FaceTexCoord = 0x0400, ///< Has (r) / store (w) face texture coordinates
ColorAlpha = 0x0800, ///< Has (r) / store (w) alpha values for colors
ColorFloat = 0x1000, ///< Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files)
Custom = 0x2000, ///< Has (r) custom properties (currently only implemented in PLY Reader ASCII version)
Custom = 0x2000, ///< Has (r) / store (w) custom properties marked persistent (currently PLY only supports reading and only ASCII version. OM supports reading and writing)
Status = 0x4000, ///< Has (r) / store (w) status properties
TexCoordST = 0x8000 ///< Write texture coordinates as ST instead of UV
TexCoordST = 0x8000, ///< Write texture coordinates as ST instead of UV
Default = Custom, ///< By default write persistent custom properties
};
/// Texture filename. This will be written as

View File

@@ -406,7 +406,8 @@ bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi,
{
Chunk::PropertyName property_type;
bytes_ += restore(_is, property_type, _swap);
add_generic_property(property_type, _bi);
if (_opt.check(Options::Custom))
add_generic_property(property_type, _bi);
}
bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_vprop(property_name_), header_.n_vertices_, _swap);
@@ -563,7 +564,8 @@ bool _OMReader_::read_binary_face_chunk(std::istream &_is, BaseImporter &_bi, Op
{
Chunk::PropertyName property_type;
bytes_ += restore(_is, property_type, _swap);
add_generic_property(property_type, _bi);
if (_opt.check(Options::Custom))
add_generic_property(property_type, _bi);
}
bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_fprop(property_name_), header_.n_faces_, _swap);
@@ -604,7 +606,8 @@ bool _OMReader_::read_binary_edge_chunk(std::istream &_is, BaseImporter &_bi, Op
{
Chunk::PropertyName property_type;
bytes_ += restore(_is, property_type, _swap);
add_generic_property(property_type, _bi);
if (_opt.check(Options::Custom))
add_generic_property(property_type, _bi);
}
bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_eprop(property_name_), header_.n_edges_, _swap);
@@ -654,7 +657,8 @@ bool _OMReader_::read_binary_halfedge_chunk(std::istream &_is, BaseImporter &_bi
{
Chunk::PropertyName property_type;
bytes_ += restore(_is, property_type, _swap);
add_generic_property(property_type, _bi);
if (_opt.check(Options::Custom))
add_generic_property(property_type, _bi);
}
bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_hprop(property_name_), 2 * header_.n_edges_, _swap);
@@ -689,7 +693,7 @@ bool _OMReader_::read_binary_halfedge_chunk(std::istream &_is, BaseImporter &_bi
{
int next_id_0 = -1;
int to_vertex_id_0 = -1;
int face_id_0 = -1;
int face_id_0 = -1;
bytes_ += restore( _is, next_id_0, OMFormat::Chunk::Integer_Size(chunk_header_.bits_), _swap );
bytes_ += restore( _is, to_vertex_id_0, OMFormat::Chunk::Integer_Size(chunk_header_.bits_), _swap );
bytes_ += restore( _is, face_id_0, OMFormat::Chunk::Integer_Size(chunk_header_.bits_), _swap );
@@ -745,7 +749,7 @@ bool _OMReader_::read_binary_halfedge_chunk(std::istream &_is, BaseImporter &_bi
//-----------------------------------------------------------------------------
bool _OMReader_::read_binary_mesh_chunk(std::istream &_is, BaseImporter &_bi, Options & /* _opt */, bool _swap) const
bool _OMReader_::read_binary_mesh_chunk(std::istream &_is, BaseImporter &_bi, Options& _opt , bool _swap) const
{
using OMFormat::Chunk;
@@ -760,7 +764,8 @@ bool _OMReader_::read_binary_mesh_chunk(std::istream &_is, BaseImporter &_bi, Op
{
Chunk::PropertyName property_type;
bytes_ += restore(_is, property_type, _swap);
add_generic_property(property_type, _bi);
if (_opt.check(Options::Custom))
add_generic_property(property_type, _bi);
}
bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_mprop(property_name_), 1, _swap);

View File

@@ -562,34 +562,35 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
// -------------------- write custom properties
const auto store_property = [this, &_os, swap, &bytes](
const BaseKernel::const_prop_iterator _it_begin,
const BaseKernel::const_prop_iterator _it_end,
const OMFormat::Chunk::Entity _ent)
if (_opt.check(Options::Custom))
{
for (auto prop = _it_begin; prop != _it_end; ++prop)
const auto store_property = [this, &_os, swap, &bytes](
const BaseKernel::const_prop_iterator _it_begin,
const BaseKernel::const_prop_iterator _it_end,
const OMFormat::Chunk::Entity _ent)
{
if (!*prop || (*prop)->name().empty() ||
((*prop)->name().size() > 1 && (*prop)->name()[1] == ':'))
{ // skip dead and "private" properties (no name or name matches "?:*")
continue;
for (auto prop = _it_begin; prop != _it_end; ++prop)
{
if (!*prop || (*prop)->name().empty() ||
((*prop)->name().size() > 1 && (*prop)->name()[1] == ':'))
{ // skip dead and "private" properties (no name or name matches "?:*")
continue;
}
bytes += store_binary_custom_chunk(_os, **prop, _ent, swap);
}
bytes += store_binary_custom_chunk(_os, **prop, _ent, swap);
}
};
};
store_property(_be.kernel()->vprops_begin(), _be.kernel()->vprops_end(),
OMFormat::Chunk::Entity_Vertex);
store_property(_be.kernel()->fprops_begin(), _be.kernel()->fprops_end(),
OMFormat::Chunk::Entity_Face);
store_property(_be.kernel()->eprops_begin(), _be.kernel()->eprops_end(),
OMFormat::Chunk::Entity_Edge);
store_property(_be.kernel()->hprops_begin(), _be.kernel()->hprops_end(),
OMFormat::Chunk::Entity_Halfedge);
store_property(_be.kernel()->mprops_begin(), _be.kernel()->mprops_end(),
OMFormat::Chunk::Entity_Mesh);
store_property(_be.kernel()->vprops_begin(), _be.kernel()->vprops_end(),
OMFormat::Chunk::Entity_Vertex);
store_property(_be.kernel()->fprops_begin(), _be.kernel()->fprops_end(),
OMFormat::Chunk::Entity_Face);
store_property(_be.kernel()->eprops_begin(), _be.kernel()->eprops_end(),
OMFormat::Chunk::Entity_Edge);
store_property(_be.kernel()->hprops_begin(), _be.kernel()->hprops_end(),
OMFormat::Chunk::Entity_Halfedge);
store_property(_be.kernel()->mprops_begin(), _be.kernel()->mprops_end(),
OMFormat::Chunk::Entity_Mesh);
}
memset(&chunk_header, 0, sizeof(chunk_header));
chunk_header.name_ = false;