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 13:52:32 +00:00
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
2015-04-28 11:33:32 +00:00
* This file is part of OpenMesh . *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
2009-02-06 13:37:46 +00:00
* *
2015-04-28 11:33:32 +00:00
* Redistribution and use in source and binary forms , with or without *
* modification , are permitted provided that the following conditions *
* are met : *
2009-02-06 13:37:46 +00:00
* *
2015-04-28 11:33:32 +00:00
* 1. Redistributions of source code must retain the above copyright notice , *
* this list of conditions and the following disclaimer . *
2009-02-06 13:37:46 +00:00
* *
2015-04-28 11:33:32 +00:00
* 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 . *
2009-02-06 13:37:46 +00:00
* *
2015-04-28 11:33:32 +00:00
* 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 . *
2009-06-04 08:46:29 +00:00
* *
2015-04-28 11:33:32 +00:00
* 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 13:52:32 +00:00
* *
2009-06-04 08:46:29 +00:00
* $ Revision $ *
* $ Date $ *
2009-02-06 13:37:46 +00:00
* *
\ * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
# ifndef OM_MESHIO_HH
# define OM_MESHIO_HH
//=== INCLUDES ================================================================
// -------------------- system settings
# include <OpenMesh/Core/System/config.h>
2018-04-05 14:09:47 +02:00
2009-02-06 13:37:46 +00:00
// -------------------- check include order
# if defined (OPENMESH_TRIMESH_ARRAY_KERNEL_HH) || \
defined ( OPENMESH_POLYMESH_ARRAY_KERNEL_HH )
2018-04-05 14:09:47 +02:00
// Issue warning if MeshIO was not included before Mesh Type
// Nobody knows why this order was enforced.
// If somebody encounters an error resulting from a wrong order, please report it to the OpenMesh developers.
// If we don't here about any errors, this check will be removed
// @TODO: Remove after reasonable time
# ifdef WIN32
# pragma message("MeshIO.hh was included after Mesh Type. You may ignore this warning. Please report errors resulting ifrom this order to the developers!")
# else
# warning "MeshIO.hh was included after Mesh Type. You may ignore this warning. Please report errors resulting from this order to the developers!"
# endif
2009-02-06 13:37:46 +00:00
# endif
2018-04-05 14:09:47 +02:00
2009-02-06 13:37:46 +00:00
// -------------------- OpenMesh
# include <OpenMesh/Core/IO/SR_store.hh>
# include <OpenMesh/Core/IO/IOManager.hh>
# include <OpenMesh/Core/IO/importer/ImporterT.hh>
# include <OpenMesh/Core/IO/exporter/ExporterT.hh>
//== NAMESPACES ==============================================================
namespace OpenMesh {
namespace IO {
//=== IMPLEMENTATION ==========================================================
/** \name Mesh Reading / Writing
Convenience functions the map to IOManager functions .
\ see OpenMesh : : IO : : _IOManager_
*/
//@{
//-----------------------------------------------------------------------------
2012-10-15 13:52:32 +00:00
/** \brief Read a mesh from file _filename.
2011-10-10 09:59:18 +00:00
2012-10-15 13:52:32 +00:00
The file format is determined by the file extension .
2011-10-10 09:59:18 +00:00
2012-10-15 13:52:32 +00:00
\ note If you link statically against OpenMesh , you have to add
the define OM_STATIC_BUILD to your application . This will
2011-10-10 12:31:03 +00:00
ensure that readers and writers get initialized correctly .
2011-10-10 09:59:18 +00:00
@ param _mesh The target mesh that will be filled with the read data
@ param _filename fill to load
@ return Successful ?
*/
2009-02-06 13:37:46 +00:00
template < class Mesh >
2012-10-15 13:52:32 +00:00
bool
2011-10-10 09:59:18 +00:00
read_mesh ( Mesh & _mesh ,
2013-02-25 13:30:56 +00:00
const std : : string & _filename )
2009-02-06 13:37:46 +00:00
{
Options opt ;
2013-02-25 13:30:56 +00:00
return read_mesh ( _mesh , _filename , opt , true ) ;
2009-02-06 13:37:46 +00:00
}
2012-10-15 13:52:32 +00:00
/** \brief Read a mesh from file _filename.
2011-10-10 09:59:18 +00:00
2012-10-15 13:52:32 +00:00
The file format is determined by the file extension .
2011-10-10 09:59:18 +00:00
2012-10-15 13:52:32 +00:00
\ note If you link statically against OpenMesh , you have to add
the define OM_STATIC_BUILD to your application . This will
2011-10-10 12:31:03 +00:00
ensure that readers and writers get initialized correctly .
2011-10-10 09:59:18 +00:00
@ param _mesh The target mesh that will be filled with the read data
@ param _filename fill to load
@ param _opt Reader options ( e . g . skip loading of normals . . . depends
2013-02-25 13:30:56 +00:00
on the reader capabilities ) . Note that simply passing an
Options : : Flag enum is not sufficient .
2011-10-10 09:59:18 +00:00
@ param _clear Clear the target data before filling it ( allows to
2013-02-25 13:30:56 +00:00
load multiple files into one Mesh ) . If you only want to read a mesh
without clearing set _clear to false . Providing a default Options
object is sufficient in this case .
2011-10-10 09:59:18 +00:00
@ return Successful ?
*/
2009-02-06 13:37:46 +00:00
template < class Mesh >
2012-10-15 13:52:32 +00:00
bool
2011-10-10 09:59:18 +00:00
read_mesh ( Mesh & _mesh ,
2012-10-15 13:52:32 +00:00
const std : : string & _filename ,
Options & _opt ,
bool _clear = true )
2009-02-06 13:37:46 +00:00
{
if ( _clear ) _mesh . clear ( ) ;
ImporterT < Mesh > importer ( _mesh ) ;
2012-10-15 13:52:32 +00:00
return IOManager ( ) . read ( _filename , importer , _opt ) ;
2009-02-06 13:37:46 +00:00
}
2012-10-15 13:52:32 +00:00
/** \brief Read a mesh from file open std::istream.
2011-10-10 09:59:18 +00:00
2012-10-15 13:52:32 +00:00
The file format is determined by parameter _ext . _ext has to include
2011-10-10 09:59:18 +00:00
" .[format] " in order to work properly ( e . g . " .OFF " )
2012-10-15 13:52:32 +00:00
\ note If you link statically against OpenMesh , you have to add
the define OM_STATIC_BUILD to your application . This will
2011-10-10 12:31:03 +00:00
ensure that readers and writers get initialized correctly .
2011-10-10 09:59:18 +00:00
@ param _mesh The target mesh that will be filled with the read data
@ param _is stream to load the data from
@ param _ext The file format that is written to the stream
@ param _opt Reader options ( e . g . skip loading of normals . . . depends
on the reader capabilities )
@ param _clear Clear the target data before filling it ( allows to
load multiple files into one Mesh )
@ return Successful ?
*/
2009-11-17 13:54:16 +00:00
template < class Mesh >
2012-10-15 13:52:32 +00:00
bool
2011-10-10 09:59:18 +00:00
read_mesh ( Mesh & _mesh ,
std : : istream & _is ,
const std : : string & _ext ,
2012-10-15 13:52:32 +00:00
Options & _opt ,
bool _clear = true )
2009-11-17 13:54:16 +00:00
{
if ( _clear ) _mesh . clear ( ) ;
ImporterT < Mesh > importer ( _mesh ) ;
2012-10-15 13:52:32 +00:00
return IOManager ( ) . read ( _is , _ext , importer , _opt ) ;
2009-11-17 13:54:16 +00:00
}
2009-02-06 13:37:46 +00:00
//-----------------------------------------------------------------------------
2012-10-15 13:52:32 +00:00
/** \brief Write a mesh to the file _filename.
2011-10-10 09:59:18 +00:00
2012-10-15 13:52:32 +00:00
The file format is determined by _filename ' s extension .
2011-10-10 09:59:18 +00:00
2012-10-15 13:52:32 +00:00
\ note If you link statically against OpenMesh , you have to add
the define OM_STATIC_BUILD to your application . This will
2011-10-10 12:31:03 +00:00
ensure that readers and writers get initialized correctly .
2011-10-10 09:59:18 +00:00
@ param _mesh The mesh that will be written to file
@ param _filename output filename
@ param _opt Writer options ( e . g . writing of normals . . . depends
on the writer capabilities )
2012-10-15 15:01:06 +00:00
@ param _precision specifies stream precision for ascii files
2011-10-10 09:59:18 +00:00
@ return Successful ?
*/
2009-02-06 13:37:46 +00:00
template < class Mesh >
2012-10-15 13:52:32 +00:00
bool write_mesh ( const Mesh & _mesh ,
2011-10-10 09:59:18 +00:00
const std : : string & _filename ,
2012-10-15 13:52:32 +00:00
Options _opt = Options : : Default ,
std : : streamsize _precision = 6 )
{
2009-02-06 13:37:46 +00:00
ExporterT < Mesh > exporter ( _mesh ) ;
2012-10-15 13:52:32 +00:00
return IOManager ( ) . write ( _filename , exporter , _opt , _precision ) ;
2009-02-06 13:37:46 +00:00
}
//-----------------------------------------------------------------------------
2012-10-15 13:52:32 +00:00
/** Write a mesh to an open std::ostream.
2011-10-10 09:59:18 +00:00
2012-10-15 13:52:32 +00:00
The file format is determined by parameter _ext . _ext has to include
2011-10-10 09:59:18 +00:00
" .[format] " in order to work properly ( e . g . " .OFF " )
2012-10-15 13:52:32 +00:00
\ note If you link statically against OpenMesh , you have to add
the define OM_STATIC_BUILD to your application . This will
2011-10-10 12:31:03 +00:00
ensure that readers and writers get initialized correctly .
2011-10-10 09:59:18 +00:00
@ param _mesh The mesh that will be written to file
@ param _os output stream to write into
@ param _ext extension defining the type of output
@ param _opt Writer options ( e . g . writing of normals . . . depends
on the writer capabilities )
2012-10-15 15:01:06 +00:00
@ param _precision specifies stream precision for ascii files
2011-10-10 09:59:18 +00:00
@ return Successful ?
*/
2009-11-17 13:54:16 +00:00
template < class Mesh >
2012-10-15 13:52:32 +00:00
bool write_mesh ( const Mesh & _mesh ,
std : : ostream & _os ,
const std : : string & _ext ,
Options _opt = Options : : Default ,
std : : streamsize _precision = 6 )
{
2009-11-17 13:54:16 +00:00
ExporterT < Mesh > exporter ( _mesh ) ;
2012-10-15 13:52:32 +00:00
return IOManager ( ) . write ( _os , _ext , exporter , _opt , _precision ) ;
2009-11-17 13:54:16 +00:00
}
//-----------------------------------------------------------------------------
2011-10-10 09:59:18 +00:00
/** \brief Get binary size of data
This function calls the corresponding writer which calculates the size
of the data that would be written to a binary file
2009-11-17 13:54:16 +00:00
2011-10-10 09:59:18 +00:00
The file format is determined by parameter _ext . _ext has to include
" .[format] " in order to work properly ( e . g . " .OFF " )
@ param _mesh Mesh to write
@ param _ext extension of the file ( used to determine the writing module )
@ param _opt Writer options ( e . g . writing of normals . . . depends
on the writer capabilities )
@ return Binary size in bytes used when writing the data
*/
2009-02-06 13:37:46 +00:00
template < class Mesh >
2012-10-15 13:52:32 +00:00
size_t binary_size ( const Mesh & _mesh ,
2011-10-10 09:59:18 +00:00
const std : : string & _ext ,
Options _opt = Options : : Default )
2009-02-06 13:37:46 +00:00
{
ExporterT < Mesh > exporter ( _mesh ) ;
2011-10-10 09:59:18 +00:00
return IOManager ( ) . binary_size ( _ext , exporter , _opt ) ;
2009-02-06 13:37:46 +00:00
}
//-----------------------------------------------------------------------------
//@}
//=============================================================================
} // namespace IO
} // namespace OpenMesh
//=============================================================================
# if defined(OM_STATIC_BUILD) || defined(ARCH_DARWIN)
# include <OpenMesh / Core / IO / IOInstances.hh>
# endif
//=============================================================================
# endif
//=============================================================================