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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef FILEOFFPLUGIN_HH
51 #define FILEOFFPLUGIN_HH
52 
53 #include <QObject>
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 #if QT_VERSION >= 0x050000
84  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-FileOFF")
85 #endif
86  signals:
87  void openedFile( int _id );
88  void addEmptyObject( DataType _type, int& _id);
89  void load(QString _filename, DataType _type, int& _id);
90  void save(int _id , QString _filename );
91  void log(Logtype _type, QString _message);
92  void log(QString _message);
93  void updateView();
94  void updatedObject(int _identifier, const UpdateType& _type);
95 
96  void deleteObject( int _id );
97 
98  // StatusbarInterface
99  void showStatusMessage(QString _message, int _timeout = 0);
100  void setStatus( ApplicationStatus::applicationStatus _status);
101 
102  private slots:
103 
104  void fileOpened( int /*_id*/ ){};
105 
106  void noguiSupported( ) {} ;
107 
108  void initializePlugin();
109 
111  void handleTrimeshDialog();
112 
114  void slotLoadDefault();
115 
117  void slotSaveDefault();
118 
119  public :
120 
121  FileOFFPlugin();
122 
123  ~FileOFFPlugin() {};
124 
125  QString name() { return (QString("FileOFF")); };
126  QString description( ) { return (QString(tr("Load/Save OFF-Files"))); };
127 
129 
130  QString getSaveFilters();
131  QString getLoadFilters();
132 
133  QWidget* saveOptionsWidget(QString /*_currentFilter*/);
134  QWidget* loadOptionsWidget(QString /*_currentFilter*/);
135 
136  public slots:
137 
139  int loadObject(QString _filename);
140 
142  int loadObject(QString _filename, DataType _type);
143 
144  bool saveObject(int _id, QString _filename);
145 
146  QString version() { return QString("1.1"); };
147 
148  private:
149 
151  bool readFileOptions(QString _filename, OFFImporter& _importer);
152 
154  bool readOFFFile(QString _filename, OFFImporter& _importer);
155 
157  bool parseASCII(std::istream& _in, OFFImporter& _importer, DataType _type, QString& _objectName);
158 
160  bool parseBinary(std::istream& _in, OFFImporter& _importer, DataType _type, QString& _objectName);
161 
163  int getColorType(std::string& _line, bool _texCoordsAvailable);
164 
167  void updateUserOptions();
168 
170  bool extendedFaceColorTest(std::istream& _in, uint _nV, uint _nF, int _nB) const;
171 
172  // Binary reader and writer helpers
173  void readValue(std::istream& _in, float& _value) const {
174  float tmp;
175 
176  OpenMesh::IO::restore( _in , tmp, false ); //assuming LSB byte order
177  _value = tmp;
178  }
179 
180  void readValue(std::istream& _in, int& _value) const {
182 
183  OpenMesh::IO::restore( _in , tmp, false ); //assuming LSB byte order
184  _value = tmp;
185  }
186 
187  void readValue(std::istream& _in, unsigned int& _value) const {
189 
190  OpenMesh::IO::restore( _in , tmp, false ); //assuming LSB byte order
191  _value = tmp;
192  }
193 
194  void writeValue(std::ostream& _out, int value) const {
195 
196  OpenMesh::IO::uint32_t tmp = value;
197  OpenMesh::IO::store(_out, tmp, false);
198  }
199 
200  void writeValue(std::ostream& _out, unsigned int value) const {
201 
202  OpenMesh::IO::uint32_t tmp = value;
203  OpenMesh::IO::store(_out, tmp, false);
204  }
205 
206  void writeValue(std::ostream& _out, float value) const {
207 
208  float tmp = value;
209  OpenMesh::IO::store(_out, tmp, false);
210  }
211 
212  void trimString( std::string& _string);
213 
221  bool getCleanLine( std::istream& ifs , std::string& _string, bool _skipEmptyLines = true);
222 
224  bool checkDegenerateFace(const std::vector<VertexHandle>& _v);
225 
227  template< class MeshT >
228  bool writeMesh(std::ostream& _out, MeshT& _mesh, BaseObject &_baseObj);
229 
231  template< class MeshT >
232  bool writeBinaryData(std::ostream& _out, MeshT& _mesh );
233 
235  template< class MeshT >
236  bool writeASCIIData(std::ostream& _out, MeshT& _mesh );
237 
239  template <class MeshT>
240  void backupTextureCoordinates(MeshT& _mesh);
241 
242  //Option Widgets
243  QWidget* loadOptions_;
244  QWidget* saveOptions_;
245 
246  QCheckBox* saveBinary_;
247  QCheckBox* saveVertexColor_;
248  QCheckBox* saveFaceColor_;
249  QCheckBox* saveAlpha_;
250  QCheckBox* saveNormals_;
251  QCheckBox* saveTexCoords_;
252  QLabel* savePrecisionLabel_;
253  QSpinBox* savePrecision_;
254  QPushButton* saveDefaultButton_;
255 
256 
257  QComboBox* triMeshHandling_;
258  QCheckBox* loadVertexColor_;
259  QCheckBox* loadFaceColor_;
260  QCheckBox* loadAlpha_;
261  QCheckBox* loadNormals_;
262  QCheckBox* loadTexCoords_;
263  QCheckBox* loadCheckManifold_;
264  QPushButton* loadDefaultButton_;
265 
266  unsigned int userReadOptions_;
267  unsigned int userWriteOptions_;
268 
269  bool forceTriangleMesh_;
270  bool forcePolyMesh_;
271  bool readColorComp_;
272  OFFImporter::ObjectOptionsE trimeshOptions_;
273 };
274 
275 #if defined(INCLUDE_TEMPLATES) && !defined(FILEOFFPLUGIN_C)
276 #define FILEOFFPLUGIN_TEMPLATES
277 #include "FileOFFT.cc"
278 #endif
279 
280 #endif //FILEOFFPLUGIN_HH
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
Definition: FileOFF.cc:1201
void backupTextureCoordinates(MeshT &_mesh)
backup per vertex/face texture coordinates
Definition: FileOFF.cc:1339
Predefined datatypes.
Definition: DataTypes.hh:96
int getColorType(std::string &_line, bool _texCoordsAvailable)
Get color type.
Definition: FileOFF.cc:884
bool writeMesh(std::ostream &_out, MeshT &_mesh, BaseObject &_baseObj)
Writer function.
Definition: FileOFFT.cc:60
bool writeBinaryData(std::ostream &_out, MeshT &_mesh)
Write binary mesh data to file.
Definition: FileOFFT.cc:203
Logtype
Log types for Message Window.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FileOFF.cc:146
QString getSaveFilters()
Definition: FileOFF.cc:140
Control OpenFlippers status bar.
void handleTrimeshDialog()
Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
Definition: FileOFF.cc:571
QWidget * saveOptionsWidget(QString)
Definition: FileOFF.cc:1368
void updateUserOptions()
Definition: FileOFF.cc:204
bool readFileOptions(QString _filename, OFFImporter &_importer)
Before Parsing the actual file, read all features supported.
Definition: FileOFF.cc:263
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
Definition: FileOFF.cc:1482
Interface for all Plugins which provide scriptable Functions.
void noguiSupported()
Definition: FileOFF.hh:106
bool getCleanLine(std::istream &ifs, std::string &_string, bool _skipEmptyLines=true)
Function to retrieve next line.
Definition: FileOFF.cc:167
Interface class from which all plugins have to be created.
void initializePlugin()
Initialize Plugin.
Definition: FileOFF.cc:103
Update type class.
Definition: UpdateType.hh:70
Interface for all Plugins which do logging to the logging window of the framework.
bool checkDegenerateFace(const std::vector< VertexHandle > &_v)
Check for degenerate faces before adding them.
Definition: FileOFF.cc:869
bool parseBinary(std::istream &_in, OFFImporter &_importer, DataType _type, QString &_objectName)
Parse binary OFF file.
Definition: FileOFF.cc:933
bool writeASCIIData(std::ostream &_out, MeshT &_mesh)
Write ASCII mesh data to file.
Definition: FileOFFT.cc:125
bool parseASCII(std::istream &_in, OFFImporter &_importer, DataType _type, QString &_objectName)
Parse ascii OFF file.
Definition: FileOFF.cc:591
Interface class for file handling.
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:1150
applicationStatus
Enum for the statusBar Status Icon.
bool readOFFFile(QString _filename, OFFImporter &_importer)
Read OFF file and parse it.
Definition: FileOFF.cc:478
Interface for all plugins which want to Load or Save files and create Objects.
QString description()
Return a description of what the plugin is doing.
Definition: FileOFF.hh:126
unsigned int uint32_t
Definition: SR_types.hh:90
QString getLoadFilters()
Definition: FileOFF.cc:134
QWidget * loadOptionsWidget(QString)
Definition: FileOFF.cc:1425
FileOFFPlugin()
Constructor.
Definition: FileOFF.cc:72
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
Definition: FileOFF.cc:1495
QString name()
Return a name for the plugin.
Definition: FileOFF.hh:125