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
64
67
68// Binary file support
69#include <OpenMesh/Core/IO/SR_store.hh>
70#include <limits>
71
72#include "OFFImporter.hh"
73
76{
77 Q_OBJECT
78 Q_INTERFACES(FileInterface)
79 Q_INTERFACES(LoadSaveInterface)
80 Q_INTERFACES(LoggingInterface)
81 Q_INTERFACES(BaseInterface)
82 Q_INTERFACES(ScriptInterface)
83 Q_INTERFACES(StatusbarInterface)
84 Q_INTERFACES(PythonInterface)
85
86 Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-FileOFF")
87
88 signals:
89 void openedFile( int _id );
90 void addEmptyObject( DataType _type, int& _id);
91 void load(QString _filename, DataType _type, int& _id);
92 void save(int _id , QString _filename );
93 void log(Logtype _type, QString _message);
94 void log(QString _message);
95 void updateView();
96 void updatedObject(int _identifier, const UpdateType& _type);
97
98 void deleteObject( int _id );
99
100 // StatusbarInterface
101 void showStatusMessage(QString _message, int _timeout = 0);
102 void setStatus( ApplicationStatus::applicationStatus _status);
103
104 private slots:
105
106 void fileOpened( int /*_id*/ ){};
107
108 void noguiSupported( ) {} ;
109
110 void initializePlugin();
111
113 void handleTrimeshDialog();
114
116 void slotLoadDefault();
117
119 void slotSaveDefault();
120
121 public :
122
124
125 ~FileOFFPlugin() {};
126
127 QString name() { return (QString("FileOFF")); };
128 QString description( ) { return (QString(tr("Load/Save OFF-Files"))); };
129
131
132 QString getSaveFilters();
133 QString getLoadFilters();
134
135 QWidget* saveOptionsWidget(QString /*_currentFilter*/);
136 QWidget* loadOptionsWidget(QString /*_currentFilter*/);
137
138 public slots:
139
141 int loadObject(QString _filename);
142
144 int loadObject(QString _filename, DataType _type);
145
146 bool saveObject(int _id, QString _filename);
147
148 QString version() { return QString("1.1"); };
149
150 private:
151
153 bool readFileOptions(QString _filename, OFFImporter& _importer);
154
156 bool readOFFFile(QString _filename, OFFImporter& _importer);
157
159 bool parseASCII(std::istream& _in, OFFImporter& _importer, DataType _type, QString& _objectName);
160
162 bool parseBinary(std::istream& _in, OFFImporter& _importer, DataType _type, QString& _objectName);
163
165 int getColorType(std::string& _line, bool _texCoordsAvailable);
166
169 void updateUserOptions();
170
172 bool extendedFaceColorTest(std::istream& _in, uint _nV, uint _nF, int _nB) const;
173
174 // Binary reader and writer helpers
175 void readValue(std::istream& _in, float& _value) const {
176 float tmp;
177
178 OpenMesh::IO::restore( _in , tmp, false ); //assuming LSB byte order
179 _value = tmp;
180 }
181
182 void readValue(std::istream& _in, int& _value) const {
184
185 OpenMesh::IO::restore( _in , tmp, false ); //assuming LSB byte order
186 _value = tmp;
187 }
188
189 void readValue(std::istream& _in, unsigned int& _value) const {
191
192 OpenMesh::IO::restore( _in , tmp, false ); //assuming LSB byte order
193 _value = tmp;
194 }
195
196 void writeValue(std::ostream& _out, int value) const {
197
198 OpenMesh::IO::uint32_t tmp = value;
199 OpenMesh::IO::store(_out, tmp, false);
200 }
201
202 void writeValue(std::ostream& _out, unsigned int value) const {
203
204 OpenMesh::IO::uint32_t tmp = value;
205 OpenMesh::IO::store(_out, tmp, false);
206 }
207
208 void writeValue(std::ostream& _out, float value) const {
209
210 float tmp = value;
211 OpenMesh::IO::store(_out, tmp, false);
212 }
213
214 void trimString( std::string& _string);
215
223 bool getCleanLine( std::istream& ifs , std::string& _string, bool _skipEmptyLines = true);
224
226 bool checkDegenerateFace(const std::vector<VertexHandle>& _v);
227
229 template< class MeshT >
230 bool writeMesh(std::ostream& _out, MeshT& _mesh, BaseObject &_baseObj);
231
233 template< class MeshT >
234 bool writeBinaryData(std::ostream& _out, MeshT& _mesh );
235
237 template< class MeshT >
238 bool writeASCIIData(std::ostream& _out, MeshT& _mesh );
239
241 template <class MeshT>
242 void backupTextureCoordinates(MeshT& _mesh);
243
244 //Option Widgets
245 QWidget* loadOptions_;
246 QWidget* saveOptions_;
247
248 QCheckBox* saveBinary_;
249 QCheckBox* saveVertexColor_;
250 QCheckBox* saveFaceColor_;
251 QCheckBox* saveAlpha_;
252 QCheckBox* saveNormals_;
253 QCheckBox* saveTexCoords_;
254 QLabel* savePrecisionLabel_;
255 QSpinBox* savePrecision_;
256 QPushButton* saveDefaultButton_;
257
258
259 QComboBox* triMeshHandling_;
260 QCheckBox* loadVertexColor_;
261 QCheckBox* loadFaceColor_;
262 QCheckBox* loadAlpha_;
263 QCheckBox* loadNormals_;
264 QCheckBox* loadTexCoords_;
265 QCheckBox* loadCheckManifold_;
266 QPushButton* loadDefaultButton_;
267
268 unsigned int userReadOptions_;
269 unsigned int userWriteOptions_;
270
271 bool forceTriangleMesh_;
272 bool forcePolyMesh_;
273 bool readColorComp_;
274 OFFImporter::ObjectOptionsE trimeshOptions_;
275};
276
277#if defined(INCLUDE_TEMPLATES) && !defined(FILEOFFPLUGIN_C)
278#define FILEOFFPLUGIN_TEMPLATES
279#include "FileOFFT_impl.hh"
280#endif
281
282#endif //FILEOFFPLUGIN_HH
Logtype
Log types for Message Window.
Interface class from which all plugins have to be created.
Predefined datatypes.
Definition: DataTypes.hh:83
Interface class for file handling.
bool parseBinary(std::istream &_in, OFFImporter &_importer, DataType _type, QString &_objectName)
Parse binary OFF file.
Definition: FileOFF.cc:927
void handleTrimeshDialog()
Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
Definition: FileOFF.cc:565
bool readFileOptions(QString _filename, OFFImporter &_importer)
Before Parsing the actual file, read all features supported.
Definition: FileOFF.cc:256
bool writeASCIIData(std::ostream &_out, MeshT &_mesh)
Write ASCII mesh data to file.
void initializePlugin()
Initialize Plugin.
Definition: FileOFF.cc:96
bool writeBinaryData(std::ostream &_out, MeshT &_mesh)
Write binary mesh data to file.
void noguiSupported()
Definition: FileOFF.hh:108
bool writeMesh(std::ostream &_out, MeshT &_mesh, BaseObject &_baseObj)
Writer function.
QString getSaveFilters()
Definition: FileOFF.cc:133
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
Definition: FileOFF.cc:1482
QWidget * loadOptionsWidget(QString)
Definition: FileOFF.cc:1425
QString getLoadFilters()
Definition: FileOFF.cc:127
QString name()
Return a name for the plugin.
Definition: FileOFF.hh:127
int getColorType(std::string &_line, bool _texCoordsAvailable)
Get color type.
Definition: FileOFF.cc:878
QString description()
Return a description of what the plugin is doing.
Definition: FileOFF.hh:128
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FileOFF.cc:139
QWidget * saveOptionsWidget(QString)
Definition: FileOFF.cc:1368
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
Definition: FileOFF.cc:1495
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:1144
void updateUserOptions()
Definition: FileOFF.cc:197
void backupTextureCoordinates(MeshT &_mesh)
backup per vertex/face texture coordinates
Definition: FileOFF.cc:1339
FileOFFPlugin()
Constructor.
Definition: FileOFF.cc:65
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
Definition: FileOFF.cc:1195
bool parseASCII(std::istream &_in, OFFImporter &_importer, DataType _type, QString &_objectName)
Parse ascii OFF file.
Definition: FileOFF.cc:585
bool checkDegenerateFace(const std::vector< VertexHandle > &_v)
Check for degenerate faces before adding them.
Definition: FileOFF.cc:863
bool readOFFFile(QString _filename, OFFImporter &_importer)
Read OFF file and parse it.
Definition: FileOFF.cc:472
bool getCleanLine(std::istream &ifs, std::string &_string, bool _skipEmptyLines=true)
Function to retrieve next line.
Definition: FileOFF.cc:160
Interface for all plugins which want to Load or Save files and create Objects.
Interface for all Plugins which do logging to the logging window of the framework.
Interface class for exporting functions to python.
Interface for all Plugins which provide scriptable Functions.
Control OpenFlippers status bar.
Update type class.
Definition: UpdateType.hh:59
applicationStatus
Enum for the statusBar Status Icon.
unsigned int uint32_t
Definition: SR_types.hh:85