2015-04-28 11:54:17 +00:00
|
|
|
/* ========================================================================= *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
|
|
|
|
* OpenMesh *
|
2015-04-28 11:33:32 +00:00
|
|
|
* Copyright (c) 2001-2015, RWTH-Aachen University *
|
2015-04-28 13:07:46 +00:00
|
|
|
* Department of Computer Graphics and Multimedia *
|
2015-04-28 11:33:32 +00:00
|
|
|
* All rights reserved. *
|
|
|
|
|
* www.openmesh.org *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2012-10-15 10:28:14 +00:00
|
|
|
*---------------------------------------------------------------------------*
|
2015-04-28 11:33:32 +00:00
|
|
|
* This file is part of OpenMesh. *
|
|
|
|
|
*---------------------------------------------------------------------------*
|
|
|
|
|
* *
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without *
|
|
|
|
|
* modification, are permitted provided that the following conditions *
|
|
|
|
|
* are met: *
|
|
|
|
|
* *
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, *
|
|
|
|
|
* this list of conditions and the following disclaimer. *
|
|
|
|
|
* *
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright *
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the *
|
|
|
|
|
* documentation and/or other materials provided with the distribution. *
|
|
|
|
|
* *
|
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its *
|
|
|
|
|
* contributors may be used to endorse or promote products derived from *
|
|
|
|
|
* this software without specific prior written permission. *
|
|
|
|
|
* *
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
|
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
|
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
|
|
|
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
|
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
|
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
|
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
|
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
|
2015-04-28 11:54:17 +00:00
|
|
|
* *
|
|
|
|
|
* ========================================================================= */
|
2009-06-04 08:46:29 +00:00
|
|
|
|
|
|
|
|
/*===========================================================================*\
|
2012-10-15 10:28:14 +00:00
|
|
|
* *
|
2009-06-04 08:46:29 +00:00
|
|
|
* $Revision$ *
|
|
|
|
|
* $Date$ *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
|
|
|
|
\*===========================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== INCLUDES =================================================================
|
|
|
|
|
|
|
|
|
|
#include <OpenMesh/Core/System/config.h>
|
|
|
|
|
// -------------------- STL
|
|
|
|
|
#if defined( OM_CC_MIPS )
|
2012-01-12 12:13:08 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
#include <string.h>
|
2009-02-06 13:37:46 +00:00
|
|
|
#else
|
2012-01-12 12:13:08 +00:00
|
|
|
#include <ctime>
|
|
|
|
|
#include <cstring>
|
2009-02-06 13:37:46 +00:00
|
|
|
#endif
|
2012-01-12 12:13:08 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
#include <fstream>
|
2015-06-09 08:58:41 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
// -------------------- OpenMesh
|
|
|
|
|
#include <OpenMesh/Core/IO/OMFormat.hh>
|
|
|
|
|
#include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
|
|
|
|
|
#include <OpenMesh/Core/IO/writer/OMWriter.hh>
|
|
|
|
|
|
|
|
|
|
//=== NAMESPACES ==============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenMesh {
|
|
|
|
|
namespace IO {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=== INSTANCIATE =============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// register the OMLoader singleton with MeshLoader
|
|
|
|
|
_OMWriter_ __OMWriterInstance;
|
|
|
|
|
_OMWriter_& OMWriter() { return __OMWriterInstance; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=== IMPLEMENTATION ==========================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const OMFormat::uchar _OMWriter_::magic_[3] = "OM";
|
|
|
|
|
const OMFormat::uint8 _OMWriter_::version_ = OMFormat::mk_version(1,2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_OMWriter_::
|
2012-10-15 10:28:14 +00:00
|
|
|
_OMWriter_()
|
|
|
|
|
{
|
|
|
|
|
IOManager().register_module(this);
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
_OMWriter_::write(const std::string& _filename, BaseExporter& _be,
|
2012-10-15 14:46:52 +00:00
|
|
|
Options _opt, std::streamsize /*_precision*/) const
|
2009-02-06 13:37:46 +00:00
|
|
|
{
|
|
|
|
|
// check whether exporter can give us an OpenMesh BaseKernel
|
|
|
|
|
if (!_be.kernel()) return false;
|
|
|
|
|
|
|
|
|
|
|
2012-10-15 10:28:14 +00:00
|
|
|
// check for om extension in filename, we can only handle OM
|
|
|
|
|
if (_filename.rfind(".om") == std::string::npos)
|
2009-02-06 13:37:46 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
_opt += Options::Binary; // only binary format supported
|
|
|
|
|
|
|
|
|
|
std::ofstream ofs(_filename.c_str(), std::ios::binary);
|
|
|
|
|
|
|
|
|
|
// check if file is open
|
|
|
|
|
if (!ofs.is_open())
|
|
|
|
|
{
|
|
|
|
|
omerr() << "[OMWriter] : cannot open file " << _filename << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// call stream save method
|
|
|
|
|
bool rc = write(ofs, _be, _opt);
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
// close filestream
|
|
|
|
|
ofs.close();
|
|
|
|
|
|
|
|
|
|
// return success/failure notice
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool
|
2012-10-15 14:46:52 +00:00
|
|
|
_OMWriter_::write(std::ostream& _os, BaseExporter& _be, Options _opt, std::streamsize /*_precision*/) const
|
2009-02-06 13:37:46 +00:00
|
|
|
{
|
|
|
|
|
// std::clog << "[OMWriter]::write( stream )\n";
|
|
|
|
|
|
|
|
|
|
// check exporter features
|
|
|
|
|
if ( !check( _be, _opt ) )
|
|
|
|
|
{
|
|
|
|
|
omerr() << "[OMWriter]: exporter does not support wanted feature!\n";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Maybe an ascii version will be implemented in the future.
|
|
|
|
|
// For now, support only a binary format
|
|
|
|
|
if ( !_opt.check( Options::Binary ) )
|
|
|
|
|
_opt += Options::Binary;
|
|
|
|
|
|
|
|
|
|
// Ignore LSB/MSB bit. Always store in LSB (little endian)
|
|
|
|
|
_opt += Options::LSB;
|
|
|
|
|
_opt -= Options::MSB;
|
|
|
|
|
|
|
|
|
|
return write_binary(_os, _be, _opt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef DOXY_IGNORE_THIS
|
|
|
|
|
template <typename T> struct Enabler
|
|
|
|
|
{
|
|
|
|
|
Enabler( T& obj ) : obj_(obj)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
~Enabler() { obj_.enable(); }
|
|
|
|
|
|
|
|
|
|
T& obj_;
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
|
|
|
|
|
Options _opt) const
|
|
|
|
|
{
|
2012-01-12 12:13:08 +00:00
|
|
|
#ifndef DOXY_IGNORE_THIS
|
|
|
|
|
Enabler<mostream> enabler(omlog());
|
|
|
|
|
#endif
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
size_t bytes = 0;
|
|
|
|
|
|
|
|
|
|
bool swap = _opt.check(Options::Swap) || (Endian::local() == Endian::MSB);
|
|
|
|
|
|
|
|
|
|
unsigned int i, nV, nF;
|
|
|
|
|
Vec3f v;
|
|
|
|
|
Vec2f t;
|
|
|
|
|
std::vector<VertexHandle> vhandles;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------- write header
|
|
|
|
|
OMFormat::Header header;
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
header.magic_[0] = 'O';
|
|
|
|
|
header.magic_[1] = 'M';
|
|
|
|
|
header.mesh_ = _be.is_triangle_mesh() ? 'T' : 'P';
|
|
|
|
|
header.version_ = version_;
|
2013-07-24 06:52:14 +00:00
|
|
|
header.n_vertices_ = int(_be.n_vertices());
|
|
|
|
|
header.n_faces_ = int(_be.n_faces());
|
|
|
|
|
header.n_edges_ = int(_be.n_edges());
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
bytes += store( _os, header, swap );
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
// ---------------------------------------- write chunks
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
OMFormat::Chunk::Header chunk_header;
|
2012-10-15 10:28:14 +00:00
|
|
|
|
|
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
// -------------------- write vertex data
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
// ---------- write vertex position
|
|
|
|
|
if (_be.n_vertices())
|
|
|
|
|
{
|
|
|
|
|
v = _be.point(VertexHandle(0));
|
|
|
|
|
chunk_header.reserved_ = 0;
|
|
|
|
|
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]);
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
bytes += store( _os, chunk_header, swap );
|
2013-07-24 06:52:14 +00:00
|
|
|
for (i=0, nV=header.n_vertices_; i<nV; ++i)
|
2009-02-06 13:37:46 +00:00
|
|
|
bytes += vector_store( _os, _be.point(VertexHandle(i)), swap );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- write vertex normal
|
|
|
|
|
if (_be.n_vertices() && _opt.check( Options::VertexNormal ))
|
|
|
|
|
{
|
|
|
|
|
Vec3f n = _be.normal(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]);
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
bytes += store( _os, chunk_header, swap );
|
2013-07-24 06:52:14 +00:00
|
|
|
for (i=0, nV=header.n_vertices_; i<nV; ++i)
|
2009-02-06 13:37:46 +00:00
|
|
|
bytes += vector_store( _os, _be.normal(VertexHandle(i)), swap );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------- write vertex color
|
2015-12-14 11:55:28 +01:00
|
|
|
if (_be.n_vertices() && _opt.check( Options::VertexColor ) && _be.has_vertex_colors() )
|
2012-10-15 10:28:14 +00:00
|
|
|
{
|
2009-02-06 13:37:46 +00:00
|
|
|
Vec3uc c = _be.color(VertexHandle(0));
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
chunk_header.name_ = false;
|
|
|
|
|
chunk_header.entity_ = OMFormat::Chunk::Entity_Vertex;
|
|
|
|
|
chunk_header.type_ = OMFormat::Chunk::Type_Color;
|
2013-08-21 15:00:59 +00:00
|
|
|
chunk_header.signed_ = OMFormat::is_signed( c[0] );
|
|
|
|
|
chunk_header.float_ = OMFormat::is_float( c[0] );
|
2009-02-06 13:37:46 +00:00
|
|
|
chunk_header.dim_ = OMFormat::dim( c );
|
2013-08-21 15:00:59 +00:00
|
|
|
chunk_header.bits_ = OMFormat::bits( c[0] );
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
bytes += store( _os, chunk_header, swap );
|
2013-07-24 06:52:14 +00:00
|
|
|
for (i=0, nV=header.n_vertices_; i<nV; ++i)
|
2009-02-06 13:37:46 +00:00
|
|
|
bytes += vector_store( _os, _be.color(VertexHandle(i)), swap );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------- write vertex texture coords
|
2013-02-18 17:17:01 +00:00
|
|
|
if (_be.n_vertices() && _opt.check(Options::VertexTexCoord)) {
|
|
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
t = _be.texcoord(VertexHandle(0));
|
|
|
|
|
|
2013-02-18 17:17:01 +00:00
|
|
|
chunk_header.name_ = false;
|
|
|
|
|
chunk_header.entity_ = OMFormat::Chunk::Entity_Vertex;
|
|
|
|
|
chunk_header.type_ = OMFormat::Chunk::Type_Texcoord;
|
|
|
|
|
chunk_header.signed_ = OMFormat::is_signed(t[0]);
|
|
|
|
|
chunk_header.float_ = OMFormat::is_float(t[0]);
|
|
|
|
|
chunk_header.dim_ = OMFormat::dim(t);
|
|
|
|
|
chunk_header.bits_ = OMFormat::bits(t[0]);
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
// std::clog << chunk_header << std::endl;
|
2013-02-18 17:17:01 +00:00
|
|
|
bytes += store(_os, chunk_header, swap);
|
|
|
|
|
|
2013-07-24 06:52:14 +00:00
|
|
|
for (i = 0, nV = header.n_vertices_; i < nV; ++i)
|
2013-02-18 17:17:01 +00:00
|
|
|
bytes += vector_store(_os, _be.texcoord(VertexHandle(i)), swap);
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -------------------- write face data
|
|
|
|
|
|
|
|
|
|
// ---------- write topology
|
|
|
|
|
{
|
|
|
|
|
chunk_header.name_ = false;
|
|
|
|
|
chunk_header.entity_ = OMFormat::Chunk::Entity_Face;
|
|
|
|
|
chunk_header.type_ = OMFormat::Chunk::Type_Topology;
|
|
|
|
|
chunk_header.signed_ = 0;
|
|
|
|
|
chunk_header.float_ = 0;
|
|
|
|
|
chunk_header.dim_ = OMFormat::Chunk::Dim_1D; // ignored
|
2012-10-15 10:28:14 +00:00
|
|
|
chunk_header.bits_ = OMFormat::needed_bits(_be.n_vertices());
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
bytes += store( _os, chunk_header, swap );
|
|
|
|
|
|
2013-07-24 06:52:14 +00:00
|
|
|
for (i=0, nF=header.n_faces_; i<nF; ++i)
|
2009-02-06 13:37:46 +00:00
|
|
|
{
|
2013-08-21 08:01:44 +00:00
|
|
|
nV = _be.get_vhandles(FaceHandle(i), vhandles);
|
2009-02-06 13:37:46 +00:00
|
|
|
if ( header.mesh_ == 'P' )
|
2013-08-21 11:34:24 +00:00
|
|
|
bytes += store( _os, vhandles.size(), OMFormat::Chunk::Integer_16, swap );
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
for (size_t j=0; j < vhandles.size(); ++j)
|
|
|
|
|
{
|
2013-08-21 11:34:24 +00:00
|
|
|
using namespace OMFormat;
|
|
|
|
|
using namespace GenProg;
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2013-08-21 11:34:24 +00:00
|
|
|
bytes += store( _os, vhandles[j].idx(), Chunk::Integer_Size(chunk_header.bits_), swap );
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------- write face normals
|
|
|
|
|
|
2016-12-19 13:24:23 +01:00
|
|
|
if (_be.n_faces() && _be.has_face_normals() && _opt.check(Options::FaceNormal) )
|
2009-02-06 13:37:46 +00:00
|
|
|
{
|
|
|
|
|
#define NEW_STYLE 0
|
|
|
|
|
#if NEW_STYLE
|
|
|
|
|
const BaseProperty *bp = _be.kernel()._get_fprop("f:normals");
|
|
|
|
|
|
|
|
|
|
if (bp)
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
Vec3f n = _be.normal(FaceHandle(0));
|
|
|
|
|
|
|
|
|
|
chunk_header.name_ = false;
|
|
|
|
|
chunk_header.entity_ = OMFormat::Chunk::Entity_Face;
|
|
|
|
|
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]);
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
bytes += store( _os, chunk_header, swap );
|
|
|
|
|
#if !NEW_STYLE
|
2013-07-24 06:52:14 +00:00
|
|
|
for (i=0, nF=header.n_faces_; i<nF; ++i)
|
2009-02-06 13:37:46 +00:00
|
|
|
bytes += vector_store( _os, _be.normal(FaceHandle(i)), swap );
|
|
|
|
|
#else
|
|
|
|
|
bytes += bp->store(_os, swap );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
|
|
|
|
#undef NEW_STYLE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- write face color
|
|
|
|
|
|
2016-12-19 13:24:23 +01:00
|
|
|
if (_be.n_faces() && _be.has_face_colors() && _opt.check( Options::FaceColor ))
|
2012-10-15 10:28:14 +00:00
|
|
|
{
|
2009-02-06 13:37:46 +00:00
|
|
|
#define NEW_STYLE 0
|
|
|
|
|
#if NEW_STYLE
|
|
|
|
|
const BaseProperty *bp = _be.kernel()._get_fprop("f:colors");
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
if (bp)
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
Vec3uc c;
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
chunk_header.name_ = false;
|
|
|
|
|
chunk_header.entity_ = OMFormat::Chunk::Entity_Face;
|
|
|
|
|
chunk_header.type_ = OMFormat::Chunk::Type_Color;
|
|
|
|
|
chunk_header.signed_ = OMFormat::is_signed( c[0] );
|
|
|
|
|
chunk_header.float_ = OMFormat::is_float( c[0] );
|
|
|
|
|
chunk_header.dim_ = OMFormat::dim( c );
|
|
|
|
|
chunk_header.bits_ = OMFormat::bits( c[0] );
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
bytes += store( _os, chunk_header, swap );
|
|
|
|
|
#if !NEW_STYLE
|
2013-07-24 06:52:14 +00:00
|
|
|
for (i=0, nF=header.n_faces_; i<nF; ++i)
|
2012-10-15 10:28:14 +00:00
|
|
|
bytes += vector_store( _os, _be.color(FaceHandle(i)), swap );
|
2009-02-06 13:37:46 +00:00
|
|
|
#else
|
|
|
|
|
bytes += bp->store(_os, swap);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -------------------- write custom properties
|
|
|
|
|
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
BaseKernel::const_prop_iterator prop;
|
2012-10-15 10:28:14 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
for (prop = _be.kernel()->vprops_begin();
|
|
|
|
|
prop != _be.kernel()->vprops_end(); ++prop)
|
|
|
|
|
{
|
|
|
|
|
if ( !*prop ) continue;
|
|
|
|
|
if ( (*prop)->name()[1]==':') continue;
|
2012-10-15 10:28:14 +00:00
|
|
|
bytes += store_binary_custom_chunk(_os, **prop,
|
2009-02-06 13:37:46 +00:00
|
|
|
OMFormat::Chunk::Entity_Vertex, swap );
|
|
|
|
|
}
|
|
|
|
|
for (prop = _be.kernel()->fprops_begin();
|
|
|
|
|
prop != _be.kernel()->fprops_end(); ++prop)
|
|
|
|
|
{
|
|
|
|
|
if ( !*prop ) continue;
|
|
|
|
|
if ( (*prop)->name()[1]==':') continue;
|
2012-10-15 10:28:14 +00:00
|
|
|
bytes += store_binary_custom_chunk(_os, **prop,
|
2009-02-06 13:37:46 +00:00
|
|
|
OMFormat::Chunk::Entity_Face, swap );
|
|
|
|
|
}
|
|
|
|
|
for (prop = _be.kernel()->eprops_begin();
|
|
|
|
|
prop != _be.kernel()->eprops_end(); ++prop)
|
|
|
|
|
{
|
|
|
|
|
if ( !*prop ) continue;
|
|
|
|
|
if ( (*prop)->name()[1]==':') continue;
|
2012-10-15 10:28:14 +00:00
|
|
|
bytes += store_binary_custom_chunk(_os, **prop,
|
2009-02-06 13:37:46 +00:00
|
|
|
OMFormat::Chunk::Entity_Edge, swap );
|
|
|
|
|
}
|
|
|
|
|
for (prop = _be.kernel()->hprops_begin();
|
|
|
|
|
prop != _be.kernel()->hprops_end(); ++prop)
|
|
|
|
|
{
|
|
|
|
|
if ( !*prop ) continue;
|
|
|
|
|
if ( (*prop)->name()[1]==':') continue;
|
2012-10-15 10:28:14 +00:00
|
|
|
bytes += store_binary_custom_chunk(_os, **prop,
|
2009-02-06 13:37:46 +00:00
|
|
|
OMFormat::Chunk::Entity_Halfedge, swap );
|
|
|
|
|
}
|
|
|
|
|
for (prop = _be.kernel()->mprops_begin();
|
|
|
|
|
prop != _be.kernel()->mprops_end(); ++prop)
|
|
|
|
|
{
|
|
|
|
|
if ( !*prop ) continue;
|
|
|
|
|
if ( (*prop)->name()[1]==':') continue;
|
2012-10-15 10:28:14 +00:00
|
|
|
bytes += store_binary_custom_chunk(_os, **prop,
|
2009-02-06 13:37:46 +00:00
|
|
|
OMFormat::Chunk::Entity_Mesh, swap );
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-27 08:10:10 +01:00
|
|
|
memset(&chunk_header, 0, sizeof(chunk_header));
|
|
|
|
|
chunk_header.name_ = false;
|
|
|
|
|
chunk_header.entity_ = OMFormat::Chunk::Entity_Sentinel;
|
|
|
|
|
bytes += store(_os, chunk_header, swap);
|
|
|
|
|
|
2014-05-09 13:11:11 +00:00
|
|
|
std::clog << "#bytes written: " << bytes << std::endl;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2012-10-15 10:28:14 +00:00
|
|
|
size_t _OMWriter_::store_binary_custom_chunk(std::ostream& _os,
|
2009-02-06 13:37:46 +00:00
|
|
|
const BaseProperty& _bp,
|
|
|
|
|
OMFormat::Chunk::Entity _entity,
|
|
|
|
|
bool _swap) const
|
|
|
|
|
{
|
2014-05-09 12:44:18 +00:00
|
|
|
//omlog() << "Custom Property " << OMFormat::as_string(_entity) << " property ["
|
|
|
|
|
// << _bp.name() << "]" << std::endl;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2012-10-15 10:28:14 +00:00
|
|
|
// Don't store if
|
2009-02-06 13:37:46 +00:00
|
|
|
// 1. it is not persistent
|
|
|
|
|
// 2. it's name is empty
|
|
|
|
|
if ( !_bp.persistent() || _bp.name().empty() )
|
|
|
|
|
{
|
2014-05-09 12:44:18 +00:00
|
|
|
//omlog() << " skipped\n";
|
2009-02-06 13:37:46 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t bytes = 0;
|
|
|
|
|
|
2013-07-24 06:52:14 +00:00
|
|
|
OMFormat::Chunk::esize_t element_size = OMFormat::Chunk::esize_t(_bp.element_size());
|
2009-02-06 13:37:46 +00:00
|
|
|
OMFormat::Chunk::Header chdr;
|
|
|
|
|
|
|
|
|
|
// set header
|
|
|
|
|
chdr.name_ = true;
|
|
|
|
|
chdr.entity_ = _entity;
|
|
|
|
|
chdr.type_ = OMFormat::Chunk::Type_Custom;
|
|
|
|
|
chdr.signed_ = 0;
|
|
|
|
|
chdr.float_ = 0;
|
|
|
|
|
chdr.dim_ = OMFormat::Chunk::Dim_1D; // ignored
|
|
|
|
|
chdr.bits_ = element_size;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// write custom chunk
|
|
|
|
|
|
2012-10-15 10:28:14 +00:00
|
|
|
// 1. chunk header
|
2009-02-06 13:37:46 +00:00
|
|
|
bytes += store( _os, chdr, _swap );
|
|
|
|
|
|
|
|
|
|
// 2. property name
|
|
|
|
|
bytes += store( _os, OMFormat::Chunk::PropertyName(_bp.name()), _swap );
|
|
|
|
|
|
|
|
|
|
// 3. block size
|
2012-07-17 10:13:27 +00:00
|
|
|
bytes += store( _os, _bp.size_of(), OMFormat::Chunk::Integer_32, _swap );
|
2014-05-09 12:44:18 +00:00
|
|
|
//omlog() << " n_bytes = " << _bp.size_of() << std::endl;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
// 4. data
|
|
|
|
|
{
|
|
|
|
|
size_t b;
|
|
|
|
|
bytes += ( b=_bp.store( _os, _swap ) );
|
2014-05-09 12:44:18 +00:00
|
|
|
//omlog() << " b = " << b << std::endl;
|
2009-02-06 13:37:46 +00:00
|
|
|
assert( b == _bp.size_of() );
|
|
|
|
|
}
|
|
|
|
|
return bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
size_t _OMWriter_::binary_size(BaseExporter& /* _be */, Options /* _opt */) const
|
|
|
|
|
{
|
|
|
|
|
// std::clog << "[OMWriter]: binary_size()" << std::endl;
|
|
|
|
|
size_t bytes = sizeof( OMFormat::Header );
|
|
|
|
|
|
|
|
|
|
// !!!TODO!!!
|
|
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
} // namespace IO
|
|
|
|
|
} // namespace OpenMesh
|
|
|
|
|
//=============================================================================
|