Developer Documentation
FileOFF.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 #ifndef FILEOFFPLUGIN_HH
45 #define FILEOFFPLUGIN_HH
46 
47 #include <QObject>
48 #include <QCheckBox>
49 #include <QLabel>
50 #include <QSpinBox>
51 #include <QPushButton>
52 #include <QComboBox>
53 
54 
63 
66 
67 // Binary file support
68 #include <OpenMesh/Core/IO/SR_store.hh>
69 #include <limits>
70 
71 #include "OFFImporter.hh"
72 
75 {
76  Q_OBJECT
77  Q_INTERFACES(FileInterface)
78  Q_INTERFACES(LoadSaveInterface)
79  Q_INTERFACES(LoggingInterface)
80  Q_INTERFACES(BaseInterface)
81  Q_INTERFACES(ScriptInterface)
82  Q_INTERFACES(StatusbarInterface)
83  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-FileOFF")
84  signals:
85  void openedFile( int _id );
86  void addEmptyObject( DataType _type, int& _id);
87  void load(QString _filename, DataType _type, int& _id);
88  void save(int _id , QString _filename );
89  void log(Logtype _type, QString _message);
90  void log(QString _message);
91  void updateView();
92  void updatedObject(int _identifier, const UpdateType& _type);
93 
94  void deleteObject( int _id );
95 
96  // StatusbarInterface
97  void showStatusMessage(QString _message, int _timeout = 0);
98  void setStatus( ApplicationStatus::applicationStatus _status);
99 
100  private slots:
101 
102  void fileOpened( int /*_id*/ ){};
103 
104  void noguiSupported( ) {} ;
105 
106  void initializePlugin();
107 
109  void handleTrimeshDialog();
110 
112  void slotLoadDefault();
113 
115  void slotSaveDefault();
116 
117  public :
118 
119  FileOFFPlugin();
120 
121  ~FileOFFPlugin() {};
122 
123  QString name() { return (QString("FileOFF")); };
124  QString description( ) { return (QString(tr("Load/Save OFF-Files"))); };
125 
127 
128  QString getSaveFilters();
129  QString getLoadFilters();
130 
131  QWidget* saveOptionsWidget(QString /*_currentFilter*/);
132  QWidget* loadOptionsWidget(QString /*_currentFilter*/);
133 
134  public slots:
135 
137  int loadObject(QString _filename);
138 
140  int loadObject(QString _filename, DataType _type);
141 
142  bool saveObject(int _id, QString _filename);
143 
144  QString version() { return QString("1.1"); };
145 
146  private:
147 
149  bool readFileOptions(QString _filename, OFFImporter& _importer);
150 
152  bool readOFFFile(QString _filename, OFFImporter& _importer);
153 
155  bool parseASCII(std::istream& _in, OFFImporter& _importer, DataType _type, QString& _objectName);
156 
158  bool parseBinary(std::istream& _in, OFFImporter& _importer, DataType _type, QString& _objectName);
159 
161  int getColorType(std::string& _line, bool _texCoordsAvailable);
162 
165  void updateUserOptions();
166 
168  bool extendedFaceColorTest(std::istream& _in, uint _nV, uint _nF, int _nB) const;
169 
170  // Binary reader and writer helpers
171  void readValue(std::istream& _in, float& _value) const {
172  float tmp;
173 
174  OpenMesh::IO::restore( _in , tmp, false ); //assuming LSB byte order
175  _value = tmp;
176  }
177 
178  void readValue(std::istream& _in, int& _value) const {
180 
181  OpenMesh::IO::restore( _in , tmp, false ); //assuming LSB byte order
182  _value = tmp;
183  }
184 
185  void readValue(std::istream& _in, unsigned int& _value) const {
187 
188  OpenMesh::IO::restore( _in , tmp, false ); //assuming LSB byte order
189  _value = tmp;
190  }
191 
192  void writeValue(std::ostream& _out, int value) const {
193 
194  OpenMesh::IO::uint32_t tmp = value;
195  OpenMesh::IO::store(_out, tmp, false);
196  }
197 
198  void writeValue(std::ostream& _out, unsigned int value) const {
199 
200  OpenMesh::IO::uint32_t tmp = value;
201  OpenMesh::IO::store(_out, tmp, false);
202  }
203 
204  void writeValue(std::ostream& _out, float value) const {
205 
206  float tmp = value;
207  OpenMesh::IO::store(_out, tmp, false);
208  }
209 
210  void trimString( std::string& _string);
211 
219  bool getCleanLine( std::istream& ifs , std::string& _string, bool _skipEmptyLines = true);
220 
222  bool checkDegenerateFace(const std::vector<VertexHandle>& _v);
223 
225  template< class MeshT >
226  bool writeMesh(std::ostream& _out, MeshT& _mesh, BaseObject &_baseObj);
227 
229  template< class MeshT >
230  bool writeBinaryData(std::ostream& _out, MeshT& _mesh );
231 
233  template< class MeshT >
234  bool writeASCIIData(std::ostream& _out, MeshT& _mesh );
235 
237  template <class MeshT>
238  void backupTextureCoordinates(MeshT& _mesh);
239 
240  //Option Widgets
241  QWidget* loadOptions_;
242  QWidget* saveOptions_;
243 
244  QCheckBox* saveBinary_;
245  QCheckBox* saveVertexColor_;
246  QCheckBox* saveFaceColor_;
247  QCheckBox* saveAlpha_;
248  QCheckBox* saveNormals_;
249  QCheckBox* saveTexCoords_;
250  QLabel* savePrecisionLabel_;
251  QSpinBox* savePrecision_;
252  QPushButton* saveDefaultButton_;
253 
254 
255  QComboBox* triMeshHandling_;
256  QCheckBox* loadVertexColor_;
257  QCheckBox* loadFaceColor_;
258  QCheckBox* loadAlpha_;
259  QCheckBox* loadNormals_;
260  QCheckBox* loadTexCoords_;
261  QCheckBox* loadCheckManifold_;
262  QPushButton* loadDefaultButton_;
263 
264  unsigned int userReadOptions_;
265  unsigned int userWriteOptions_;
266 
267  bool forceTriangleMesh_;
268  bool forcePolyMesh_;
269  bool readColorComp_;
270  OFFImporter::ObjectOptionsE trimeshOptions_;
271 };
272 
273 #if defined(INCLUDE_TEMPLATES) && !defined(FILEOFFPLUGIN_C)
274 #define FILEOFFPLUGIN_TEMPLATES
275 #include "FileOFFT_impl.hh"
276 #endif
277 
278 #endif //FILEOFFPLUGIN_HH
Update type class.
Definition: UpdateType.hh:60
bool getCleanLine(std::istream &ifs, std::string &_string, bool _skipEmptyLines=true)
Function to retrieve next line.
Definition: FileOFF.cc:160
QString getSaveFilters()
Definition: FileOFF.cc:133
Logtype
Log types for Message Window.
Interface for all plugins which want to Load or Save files and create Objects.
Control OpenFlippers status bar.
Interface for all Plugins which provide scriptable Functions.
unsigned int uint32_t
Definition: SR_types.hh:85
bool writeBinaryData(std::ostream &_out, MeshT &_mesh)
Write binary mesh data to file.
QString name()
Return a name for the plugin.
Definition: FileOFF.hh:123
bool writeASCIIData(std::ostream &_out, MeshT &_mesh)
Write ASCII mesh data to file.
bool parseASCII(std::istream &_in, OFFImporter &_importer, DataType _type, QString &_objectName)
Parse ascii OFF file.
Definition: FileOFF.cc:584
Interface for all Plugins which do logging to the logging window of the framework.
void noguiSupported()
Definition: FileOFF.hh:104
bool readOFFFile(QString _filename, OFFImporter &_importer)
Read OFF file and parse it.
Definition: FileOFF.cc:471
bool readFileOptions(QString _filename, OFFImporter &_importer)
Before Parsing the actual file, read all features supported.
Definition: FileOFF.cc:256
QWidget * saveOptionsWidget(QString)
Definition: FileOFF.cc:1367
applicationStatus
Enum for the statusBar Status Icon.
QWidget * loadOptionsWidget(QString)
Definition: FileOFF.cc:1424
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
Definition: FileOFF.cc:1194
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
Definition: FileOFF.cc:1494
bool checkDegenerateFace(const std::vector< VertexHandle > &_v)
Check for degenerate faces before adding them.
Definition: FileOFF.cc:862
void handleTrimeshDialog()
Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
Definition: FileOFF.cc:564
FileOFFPlugin()
Constructor.
Definition: FileOFF.cc:65
void backupTextureCoordinates(MeshT &_mesh)
backup per vertex/face texture coordinates
Definition: FileOFF.cc:1338
Interface class from which all plugins have to be created.
bool extendedFaceColorTest(std::istream &_in, uint _nV, uint _nF, int _nB) const
Test if there are face color components (_nV is the initial face valence)
Definition: FileOFF.cc:1143
bool writeMesh(std::ostream &_out, MeshT &_mesh, BaseObject &_baseObj)
Writer function.
void initializePlugin()
Initialize Plugin.
Definition: FileOFF.cc:96
QString getLoadFilters()
Definition: FileOFF.cc:127
bool parseBinary(std::istream &_in, OFFImporter &_importer, DataType _type, QString &_objectName)
Parse binary OFF file.
Definition: FileOFF.cc:926
Predefined datatypes.
Definition: DataTypes.hh:83
Interface class for file handling.
QString description()
Return a description of what the plugin is doing.
Definition: FileOFF.hh:124
void updateUserOptions()
Definition: FileOFF.cc:197
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
Definition: FileOFF.cc:1481
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FileOFF.cc:139
int getColorType(std::string &_line, bool _texCoordsAvailable)
Get color type.
Definition: FileOFF.cc:877