2009-02-06 13:37:46 +00:00
|
|
|
/*===========================================================================*\
|
|
|
|
|
* *
|
|
|
|
|
* OpenMesh *
|
2015-04-28 11:33:32 +00:00
|
|
|
* Copyright (c) 2001-2015, RWTH-Aachen University *
|
|
|
|
|
* Department for 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. *
|
|
|
|
|
* *
|
|
|
|
|
/*===========================================================================*\
|
2009-06-04 08:46:29 +00:00
|
|
|
|
|
|
|
|
/*===========================================================================*\
|
|
|
|
|
* *
|
|
|
|
|
* $Revision$ *
|
|
|
|
|
* $Date$ *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
|
|
|
|
\*===========================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
//
|
|
|
|
|
// Implements the baseclass for IOManager file access modules
|
|
|
|
|
//
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __BASEREADER_HH__
|
|
|
|
|
#define __BASEREADER_HH__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=== INCLUDES ================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STD C++
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
2011-11-28 11:46:16 +00:00
|
|
|
#include <cctype>
|
2013-01-30 15:22:31 +00:00
|
|
|
#include <functional>
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
// OpenMesh
|
|
|
|
|
#include <OpenMesh/Core/System/config.h>
|
|
|
|
|
#include <OpenMesh/Core/IO/Options.hh>
|
|
|
|
|
#include <OpenMesh/Core/IO/importer/BaseImporter.hh>
|
|
|
|
|
#include <OpenMesh/Core/Utils/SingletonT.hh>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== NAMESPACES ===============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenMesh {
|
|
|
|
|
namespace IO {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=== IMPLEMENTATION ==========================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Base class for reader modules.
|
|
|
|
|
Reader modules access persistent data and pass them to the desired
|
|
|
|
|
data structure by the means of a BaseImporter derivative.
|
|
|
|
|
All reader modules must be derived from this class.
|
|
|
|
|
*/
|
2012-09-23 14:49:46 +00:00
|
|
|
class OPENMESHDLLEXPORT BaseReader
|
2009-02-06 13:37:46 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2009-03-12 07:38:04 +00:00
|
|
|
/// Destructor
|
|
|
|
|
virtual ~BaseReader() {};
|
|
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
/// Returns a brief description of the file type that can be parsed.
|
|
|
|
|
virtual std::string get_description() const = 0;
|
|
|
|
|
|
|
|
|
|
/** Returns a string with the accepted file extensions separated by a
|
|
|
|
|
whitespace and in small caps.
|
|
|
|
|
*/
|
|
|
|
|
virtual std::string get_extensions() const = 0;
|
|
|
|
|
|
|
|
|
|
/// Return magic bits used to determine file format
|
|
|
|
|
virtual std::string get_magic() const { return std::string(""); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Reads a mesh given by a filename. Usually this method opens a stream
|
|
|
|
|
and passes it to stream read method. Acceptance checks by filename
|
|
|
|
|
extension can be placed here.
|
|
|
|
|
|
|
|
|
|
Options can be passed via _opt. After execution _opt contains the Options
|
|
|
|
|
that were available
|
|
|
|
|
*/
|
|
|
|
|
virtual bool read(const std::string& _filename,
|
|
|
|
|
BaseImporter& _bi,
|
|
|
|
|
Options& _opt) = 0;
|
2009-11-17 13:54:16 +00:00
|
|
|
|
|
|
|
|
/** Reads a mesh given by a std::stream. This method usually uses the same stream reading method
|
|
|
|
|
that read uses. Options can be passed via _opt. After execution _opt contains the Options
|
2012-10-18 11:09:34 +00:00
|
|
|
that were available.
|
|
|
|
|
|
|
|
|
|
Please make sure that if _is is std::ifstream, the correct std::ios_base::openmode flags are set.
|
2009-11-17 13:54:16 +00:00
|
|
|
*/
|
|
|
|
|
virtual bool read(std::istream& _is,
|
|
|
|
|
BaseImporter& _bi,
|
|
|
|
|
Options& _opt) = 0;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns true if reader can parse _filename (checks extension)
|
|
|
|
|
virtual bool can_u_read(const std::string& _filename) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
// case insensitive search for _ext in _fname.
|
|
|
|
|
bool check_extension(const std::string& _fname,
|
|
|
|
|
const std::string& _ext) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2011-11-28 11:46:16 +00:00
|
|
|
/** \brief Trim left whitespace
|
|
|
|
|
*
|
|
|
|
|
* Removes whitespace at the beginning of the string
|
|
|
|
|
*
|
|
|
|
|
* @param _string input string
|
|
|
|
|
* @return trimmed string
|
|
|
|
|
*/
|
|
|
|
|
static inline std::string &left_trim(std::string &_string) {
|
|
|
|
|
_string.erase(_string.begin(), std::find_if(_string.begin(), _string.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
|
|
|
|
|
return _string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief Trim right whitespace
|
|
|
|
|
*
|
|
|
|
|
* Removes whitespace at the end of the string
|
|
|
|
|
*
|
|
|
|
|
* @param _string input string
|
|
|
|
|
* @return trimmed string
|
|
|
|
|
*/
|
|
|
|
|
static inline std::string &right_trim(std::string &_string) {
|
|
|
|
|
_string.erase(std::find_if(_string.rbegin(), _string.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _string.end());
|
|
|
|
|
return _string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief Trim whitespace
|
|
|
|
|
*
|
|
|
|
|
* Removes whitespace at the beginning and end of the string
|
|
|
|
|
*
|
|
|
|
|
* @param _string input string
|
|
|
|
|
* @return trimmed string
|
|
|
|
|
*/
|
|
|
|
|
static inline std::string &trim(std::string &_string) {
|
|
|
|
|
return left_trim(right_trim(_string));
|
|
|
|
|
}
|
2011-11-28 10:38:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
//=============================================================================
|
|
|
|
|
} // namespace IO
|
|
|
|
|
} // namespace OpenMesh
|
|
|
|
|
//=============================================================================
|
|
|
|
|
#endif
|
|
|
|
|
//=============================================================================
|