Loading...
Searching...
No Matches
IOManager.hh
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2025, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* 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. *
* *
* ========================================================================= */
//=============================================================================
//
// Implements the OpenMesh IOManager singleton
//
//=============================================================================
#ifndef __IOMANAGER_HH__
#define __IOMANAGER_HH__
//=== INCLUDES ================================================================
// STL
#include <iosfwd>
#include <sstream>
#include <string>
#include <set>
// OpenMesh
#include <OpenMesh/Core/System/config.h>
#include <OpenMesh/Core/IO/Options.hh>
#include <OpenMesh/Core/IO/reader/BaseReader.hh>
#include <OpenMesh/Core/IO/writer/BaseWriter.hh>
#include <OpenMesh/Core/IO/importer/BaseImporter.hh>
#include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
#include <OpenMesh/Core/Utils/SingletonT.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace IO {
//=== IMPLEMENTATION ==========================================================
class OPENMESHDLLEXPORT _IOManager_
{
private:
_IOManager_() {}
~_IOManager_() {};
friend OPENMESHDLLEXPORT _IOManager_& IOManager();
public:
bool read(const std::string& _filename,
BaseImporter& _bi,
Options& _opt);
bool read(std::istream& _filename,
const std::string& _ext,
BaseImporter& _bi,
Options& _opt);
bool write(const std::string& _filename,
BaseExporter& _be,
Options _opt=Options::Default,
std::streamsize _precision = 6);
bool write(std::ostream& _filename,
const std::string& _ext,
BaseExporter& _be,
Options _opt=Options::Default,
std::streamsize _precision = 6);
bool can_read( const std::string& _format ) const;
bool can_write( const std::string& _format ) const;
size_t binary_size(const std::string& _format,
BaseExporter& _be,
Options _opt = Options::Default)
{
const BaseWriter *bw = find_writer(_format);
return bw ? bw->binary_size(_be,_opt) : 0;
}
public: //-- QT convenience function ------------------------------------------
const std::string& qt_read_filters() const { return read_filters_; }
const std::string& qt_write_filters() const { return write_filters_; }
private:
// collect all readable file extensions
void update_read_filters();
// collect all writeable file extensions
void update_write_filters();
public: //-- SYSTEM PART------------------------------------------------------
bool register_module(BaseReader* _bl)
{
reader_modules_.insert(_bl);
update_read_filters();
return true;
}
bool register_module(BaseWriter* _bw)
{
writer_modules_.insert(_bw);
update_write_filters();
return true;
}
private:
const BaseWriter *find_writer(const std::string& _format);
// stores registered reader modules
std::set<BaseReader*> reader_modules_;
// stores registered writer modules
std::set<BaseWriter*> writer_modules_;
// input filters (e.g. for Qt file dialog)
std::string read_filters_;
// output filters (e.g. for Qt file dialog)
std::string write_filters_;
};
//=============================================================================
//_IOManager_* __IOManager_instance; Causes memory leak, as destructor is never called
OPENMESHDLLEXPORT _IOManager_& IOManager();
//=============================================================================
} // namespace IO
} // namespace OpenMesh
//=============================================================================
#endif
//=============================================================================
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:59
OpenMesh::IO
This namespace contains functions for reading and writing polygonal meshes and a list of supported fi...
OpenMesh::IO::BaseExporter
Base class for exporter modules.
Definition BaseExporter.hh:85
OpenMesh::IO::BaseImporter
Base class for importer modules.
Definition BaseImporter.hh:84
OpenMesh::IO::_IOManager_::qt_read_filters
const std::string & qt_read_filters() const
Returns all readable file extension + descriptions in one string.
Definition IOManager.hh:189
OpenMesh::IO::_IOManager_::can_write
bool can_write(const std::string &_format) const
Returns true if the format is supported by one of the writer modules.
Definition IOManager.cc:220
OpenMesh::IO::_IOManager_::register_module
bool register_module(BaseWriter *_bw)
Registers a new writer module.
Definition IOManager.hh:229
OpenMesh::IO::_IOManager_::write
bool write(const std::string &_filename, BaseExporter &_be, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to file _filename.
Definition IOManager.cc:143
OpenMesh::IO::_IOManager_::qt_write_filters
const std::string & qt_write_filters() const
Returns all writeable file extension + descriptions in one string.
Definition IOManager.hh:196
OpenMesh::IO::_IOManager_::read
bool read(const std::string &_filename, BaseImporter &_bi, Options &_opt)
Read a mesh from file _filename.
Definition IOManager.cc:87
OpenMesh::IO::_IOManager_::IOManager
friend _IOManager_ & IOManager()
Declare the singleton getter function as friend to access the private constructor and destructor.
Definition IOManager.cc:72
OpenMesh::IO::_IOManager_::can_read
bool can_read(const std::string &_format) const
Returns true if the format is supported by one of the reader modules.
Definition IOManager.cc:201
OpenMesh::IO::_IOManager_::register_module
bool register_module(BaseReader *_bl)
Registers a new reader module.
Definition IOManager.hh:217
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition Options.hh:92
OpenMesh::IO::Options::Default
@ Default
By default write persistent custom properties.
Definition Options.hh:117
OpenMesh::IO::BaseReader
Base class for reader modules.
Definition BaseReader.hh:87
OpenMesh::IO::BaseWriter
Base class for all writer modules.
Definition BaseWriter.hh:84
OpenMesh::IO::BaseWriter::binary_size
virtual size_t binary_size(BaseExporter &, const Options &) const
Returns expected size of file if binary format is supported else 0.
Definition BaseWriter.hh:128