FileManager.hh 7.55 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*===========================================================================*\
 *                                                                           *
 *                            OpenVolumeMesh                                 *
 *        Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen         *
 *                        www.openvolumemesh.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenVolumeMesh.                                     *
 *                                                                           *
 *  OpenVolumeMesh is free software: you can redistribute it and/or modify   *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenVolumeMesh is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenVolumeMesh.  If not,                              *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Date$                    *
 *   $LastChangedBy$                                                *
 *                                                                           *
\*===========================================================================*/

#ifndef FILEMANAGER_HH_
#define FILEMANAGER_HH_

#include <string>
#include <fstream>
48
49
#include <istream>
#include <ostream>
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

namespace OpenVolumeMesh {

namespace IO {

/**
 * \class FileManager
 * \brief Read/Write mesh data from/to files
 *
 * \todo Implement binary file support
 */

class FileManager {
public:

  /// Default constructor
  FileManager();

  /// Default destructor
  ~FileManager();

71
72
73
74
75
76
77

  /**
   * \brief set minimum level for errors that are printed to std::cerr
   * @param _level 0: no output; 1: only errors; 2: warnings/info
   */
  void setVerbosityLevel(int _level) { verbosity_level_ = _level;}

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  /**
    * \brief Read a mesh from an std::istream
    *
    *  Returns true if the file was successfully read. The mesh
    *  is stored in parameter _mesh. If something goes wrong,
    *  this function returns false.
    *
    * @param _istream        The stream to read the mesh from
    * @param _mesh           A reference to an OpenVolumeMesh instance
    * @param _topologyCheck  Pass true if you want to perform a topology check
    *                        each time an entity is added (slower performance)
    * @param _computeBottomUpIncidences Pass true if you want the file manager
    *                                    to directly compute the bottom-up incidences
    *                                    for the mesh. (Note: These are needed for
    *                                    some iterators to work, see documentation)
    */
  template <class MeshT>
  bool readStream(std::istream &_istream, MeshT& _mesh,
      bool _topologyCheck = true,
      bool _computeBottomUpIncidences = true) const;

99
100
101
102
103
104
105
106
107
108
109
  /**
   * \brief Read a mesh from a file
   *
   *  Returns true if the file was successfully read. The mesh
   *  is stored in parameter _mesh. If something goes wrong,
   *  this function returns false.
   *
   * @param _filename       The file that is to be read
   * @param _mesh           A reference to an OpenVolumeMesh instance
   * @param _topologyCheck  Pass true if you want to perform a topology check
   *                        each time an entity is added (slower performance)
110
111
   * @param _computeBottomUpIncidences Pass true if you want the file manager
   *                                    to directly compute the bottom-up incidences
112
113
114
115
116
117
   *                                    for the mesh. (Note: These are needed for
   *                                    some iterators to work, see documentation)
   */
  template <class MeshT>
  bool readFile(const std::string& _filename, MeshT& _mesh,
      bool _topologyCheck = true,
118
      bool _computeBottomUpIncidences = true) const;
119

120
121
122
123
124
125
126
127
128
129

  /**
   * \brief Write a mesh to an std::ostream
   *
   * @param _ostream  The stream to write the mesh to
   * @param _mesh     A const reference to an OpenVolumeMesh instance
   */
  template <class MeshT>
  void writeStream(std::ostream &_ostream, const MeshT& _mesh) const;

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
  /**
   * \brief Write a mesh to a file
   *
   *  Returns true if the file was successfully written. The mesh
   *  is passed as parameter _mesh. If something goes wrong,
   *  this function returns false.
   *
   * @param _filename The file that is to be stored
   * @param _mesh     A const reference to an OpenVolumeMesh instance
   */
  template <class MeshT>
  bool writeFile(const std::string& _filename, const MeshT& _mesh) const;

  /**
   * \brief Test whether given file contains a hexahedral mesh
   */
  bool isHexahedralMesh(const std::string& _filename) const;

148
149
150
151
152
153
154
  /**
   * \brief Test whether given file contains a tetrahedral mesh
   */
  bool isTetrahedralMesh(const std::string& _filename) const;



155
156
private:

157
158
159
160
161
162
163
164
  // Read property
  template <class MeshT>
  void readProperty(std::istream& _iff, MeshT& _mesh) const;

  template <class PropT, class MeshT>
  void generateGenericProperty(const std::string& _entity_t, const std::string& _name,
                               std::istream& _iff, MeshT& _mesh) const;

165
166
167
168
  // Write props
  template<class IteratorT>
  void writeProps(std::ostream& _ostr, const IteratorT& _begin, const IteratorT& _end) const;

169
170
171
172
173
174
175
176
  // Remove leading and trailing whitespaces
  void trimString(std::string& _string) const;

  // Get quoted text out of a string
  void extractQuotedText(std::string& _string) const;

  // Get a whole line from file
  bool getCleanLine(std::istream& ifs, std::string& _string, bool _skipEmptyLines = true) const;
177
178
179


  int verbosity_level_ = 3;
180
181
182
183
184
185
186
187
188
189
190
};

} // Namespace IO

} // Namespace FileManager

#if defined(INCLUDE_TEMPLATES) && !defined(FILEMANAGERT_CC)
#include "FileManagerT.cc"
#endif

#endif /* FILEMANAGER_HH_ */