Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FileOM.cc
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 #include <ACG/GL/GLState.hh>
50
51 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
52 #include <OpenFlipper/common/GlobalOptions.hh>
53
54 #include <OpenMesh/Core/IO/IOManager.hh>
55
56 #if QT_VERSION >= 0x050000
57 #include <QtWidgets>
58 #else
59 #include <QtGui>
60 #endif
61
62 #include "FileOM.hh"
63
64
65 // Defines for the type handling drop down box
66 #define TYPEAUTODETECT 0
67 #define TYPEASK 1
68 #define TYPEPOLY 2
69 #define TYPETRIANGLE 3
70
72 FileOMPlugin::FileOMPlugin() :
73 loadOptions_(0),
74 saveOptions_(0),
75 saveBinary_(0),
76 saveVertexNormal_(0),
77 saveVertexTexCoord_(0),
78 saveVertexColor_(0),
79 saveFaceColor_(0),
80 saveFaceNormal_(0),
81 saveDefaultButton_(0),
82 triMeshHandling_(0),
83 loadVertexNormal_(0),
84 loadVertexTexCoord_(0),
85 loadVertexColor_(0),
86 loadFaceColor_(0),
87 loadFaceNormal_(0),
88 loadDefaultButton_(0),
89 trimeshOptions_(0)
90
91 {
92 }
93
94 //-----------------------------------------------------------------------------------------------------
95
96 void FileOMPlugin::initializePlugin() {
97 }
98
99 //-----------------------------------------------------------------------------------------------------
100
101 QString FileOMPlugin::getLoadFilters() {
102 return QString( tr("OpenMesh Format files ( *.om )") );
103 };
104
105 //-----------------------------------------------------------------------------------------------------
106
107 QString FileOMPlugin::getSaveFilters() {
108 return QString( tr("OpenMesh Format files ( *.om )") );
109 };
110
111 //-----------------------------------------------------------------------------------------------------
112
113 DataType FileOMPlugin::supportedType() {
114 DataType type = DATA_POLY_MESH | DATA_TRIANGLE_MESH;
115 return type;
116 }
117
118 //-----------------------------------------------------------------------------------------------------
119
120 int FileOMPlugin::loadObject(QString _filename) {
121
122 int triMeshControl = TYPEAUTODETECT; // 0 == Auto-Detect
123
124 if ( OpenFlipper::Options::gui() ){
125 if ( triMeshHandling_ != 0 ){
126 triMeshControl = triMeshHandling_->currentIndex();
127 } else {
128 triMeshControl = TYPEAUTODETECT;
129 }
130 }
131
132 int objectId = -1;
133
134 if(triMeshControl == TYPEAUTODETECT) {
135 // If Auto-Detect is selected (triMeshControl == 0)
136 objectId = loadPolyMeshObject(_filename);
137
138 PolyMeshObject *object = 0;
139 if(!PluginFunctions::getObject(objectId, object))
140 return -1;
141
142 for ( PolyMesh::FaceIter f_it = object->mesh()->faces_begin(); f_it != object->mesh()->faces_end() ; ++f_it) {
143
144 // Count number of vertices for the current face
145 uint count = 0;
146 for ( PolyMesh::FaceVertexIter fv_it( *(object->mesh()),*f_it); fv_it.is_valid(); ++fv_it )
147 ++count;
148
149 // Check if it is a triangle. If not, this is really a poly mesh
150 if ( count != 3 ) {
151
152 PolyMeshObject* object(0);
153 if(PluginFunctions::getObject( objectId, object )) {
154
155 emit updatedObject(objectId, UPDATE_ALL);
156 emit openedFile( objectId );
157 }
158
159 return objectId;
160 }
161 }
162
163 } else if (triMeshControl == TYPEASK ) {
164
165 // If Ask is selected -> show dialog
166 objectId = loadPolyMeshObject(_filename);
167
168 bool triMesh = true;
169
170 PolyMeshObject *object = 0;
171 if(!PluginFunctions::getObject(objectId, object))
172 return -1;
173
174 for ( PolyMesh::FaceIter f_it = object->mesh()->faces_begin(); f_it != object->mesh()->faces_end() ; ++f_it) {
175
176 // Count number of vertices for the current face
177 uint count = 0;
178 for ( PolyMesh::FaceVertexIter fv_it( *(object->mesh()),*f_it); fv_it.is_valid(); ++fv_it )
179 ++count;
180
181 // Check if it is a triangle. If not, this is really a poly mesh
182 if ( count != 3 ) {
183 triMesh = false;
184 break;
185 }
186
187 if(triMesh == false) break;
188 }
189
190 // Note: If in non-gui mode, we will never enter this case branch
191
192 QMetaObject::invokeMethod(this,"handleTrimeshDialog",Qt::BlockingQueuedConnection);
193 if ((trimeshOptions_ == TYPEPOLY) ||
194 (trimeshOptions_ == TYPEASK && !triMesh)) {
195
196 PolyMeshObject* object(0);
197 if(PluginFunctions::getObject( objectId, object )) {
198
199 emit updatedObject(objectId, UPDATE_ALL);
200 emit openedFile( objectId );
201 }
202 return objectId;
203 }
204
205 } else if (triMeshControl == TYPEPOLY) {
206 // If always open as PolyMesh is selected
207
208 objectId = loadPolyMeshObject(_filename);
209
210 PolyMeshObject* object(0);
211 if(PluginFunctions::getObject( objectId, object )) {
212
213 emit updatedObject(objectId, UPDATE_ALL);
214 emit openedFile( objectId );
215 }
216
217 return objectId;
218 } else {
219 // If always open as TriMesh is selected
220
221 objectId = loadTriMeshObject(_filename);
222
223 TriMeshObject* object(0);
224 if(PluginFunctions::getObject( objectId, object )) {
225 emit updatedObject(objectId, UPDATE_ALL);
226 emit openedFile( objectId );
227 }
228
229 return objectId;
230 }
231
232 // Load object as triangle mesh
233 if(objectId != -1) emit deleteObject(objectId);
234
235 objectId = loadTriMeshObject(_filename);
236
237 TriMeshObject* object(0);
238 if(PluginFunctions::getObject( objectId, object )) {
239
240 emit updatedObject(objectId, UPDATE_ALL);
241 emit openedFile( objectId );
242 }
243
244 return objectId;
245 };
246
247 void FileOMPlugin::handleTrimeshDialog()
248 {
249 QMessageBox msgBox;
250 QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
251 QPushButton *triButton = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
252 QPushButton *polyButton = msgBox.addButton(tr("Open as poly mesh"), QMessageBox::ActionRole);
253 msgBox.setWindowTitle( tr("Mesh types in file") );
254 msgBox.setText( tr("You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
255 msgBox.setDefaultButton( detectButton );
256 msgBox.exec();
257
258
259 if (msgBox.clickedButton() == triButton)
260 trimeshOptions_ = TYPETRIANGLE ;
261 else if (msgBox.clickedButton() == polyButton)
262 trimeshOptions_ = TYPEPOLY ;
263 else
264 trimeshOptions_ = TYPEASK;
265 }
266
267 //-----------------------------------------------------------------------------------------------------
268
270 int FileOMPlugin::loadTriMeshObject(QString _filename){
271
272 int id = -1;
273 emit addEmptyObject(DATA_TRIANGLE_MESH, id);
274
275 TriMeshObject* object(0);
276 if(PluginFunctions::getObject( id, object)) {
277
278 if ( PluginFunctions::objectCount() == 1 )
279 object->target(true);
280
281 object->setFromFileName(_filename);
282 object->setName(object->filename());
283
284 std::string filename = std::string( _filename.toUtf8() );
285
286 //set options
287 OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
288
289 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() &&
290 !OpenFlipper::Options::loadingRecentFile() && loadOptions_ != 0){
291
292 if (loadVertexNormal_->isChecked())
293 opt += OpenMesh::IO::Options::VertexNormal;
294
295 if (loadVertexTexCoord_->isChecked())
296 opt += OpenMesh::IO::Options::VertexTexCoord;
297
298 if (loadVertexColor_->isChecked())
299 opt += OpenMesh::IO::Options::VertexColor;
300
301 if (loadFaceColor_->isChecked())
302 opt += OpenMesh::IO::Options::FaceColor;
303
304 if (loadFaceNormal_->isChecked())
305 opt += OpenMesh::IO::Options::FaceNormal;
306
307 } else {
308
309 // Let OpenMesh try to read everything it can
310 opt += OpenMesh::IO::Options::VertexNormal;
311 opt += OpenMesh::IO::Options::VertexTexCoord;
312 opt += OpenMesh::IO::Options::VertexColor;
313 opt += OpenMesh::IO::Options::FaceColor;
314 opt += OpenMesh::IO::Options::FaceNormal;
315
316 }
317
319 object->mesh()->request_vertex_texcoords2D();
320 object->mesh()->request_halfedge_texcoords2D();
321 object->mesh()->request_face_texture_index();
322
323 // load file
324 bool ok = OpenMesh::IO::read_mesh( (*object->mesh()) , filename, opt );
325 if (!ok)
326 {
327 std::cerr << "Plugin FileOM : Read error for Triangle Mesh\n";
328 emit deleteObject( object->id() );
329 return -1;
330 }
331
332 object->mesh()->update_normals();
333
334 backupTextureCoordinates(*(object->mesh()));
335
336 return object->id();
337
338 } else {
339 emit log(LOGERR,"Error : Could not create new triangle mesh object.");
340 return -1;
341 }
342 }
343
344 //-----------------------------------------------------------------------------------------------------
345
347 int FileOMPlugin::loadPolyMeshObject(QString _filename){
348
349 int id = -1;
350 emit addEmptyObject(DATA_POLY_MESH, id);
351
352 PolyMeshObject* object(0);
353 if(PluginFunctions::getObject( id, object)) {
354
355 if (PluginFunctions::objectCount() == 1 )
356 object->target(true);
357
358 object->setFromFileName(_filename);
359 object->setName(object->filename());
360
361 std::string filename = std::string( _filename.toUtf8() );
362
363 //set options
364 OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
365
366 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() &&
367 !OpenFlipper::Options::loadingRecentFile() && loadOptions_ != 0){
368
369 if (loadVertexNormal_->isChecked())
370 opt += OpenMesh::IO::Options::VertexNormal;
371
372 if (loadVertexTexCoord_->isChecked())
373 opt += OpenMesh::IO::Options::VertexTexCoord;
374
375 if (loadVertexColor_->isChecked())
376 opt += OpenMesh::IO::Options::VertexColor;
377
378 if (loadFaceColor_->isChecked())
379 opt += OpenMesh::IO::Options::FaceColor;
380
381 if (loadFaceNormal_->isChecked())
382 opt += OpenMesh::IO::Options::FaceNormal;
383
384 } else {
385
386 // Let openmesh try to read everything it can
387 opt += OpenMesh::IO::Options::VertexNormal;
388 opt += OpenMesh::IO::Options::VertexTexCoord;
389 opt += OpenMesh::IO::Options::VertexColor;
390 opt += OpenMesh::IO::Options::FaceColor;
391 opt += OpenMesh::IO::Options::FaceNormal;
392
393 }
394
396 object->mesh()->request_vertex_texcoords2D();
397 object->mesh()->request_halfedge_texcoords2D();
398 object->mesh()->request_face_texture_index();
399
400 // load file
401 bool ok = OpenMesh::IO::read_mesh( (*object->mesh()) , filename, opt );
402 if (!ok)
403 {
404 std::cerr << "Plugin FileOM : Read error for Poly Mesh\n";
405 emit deleteObject( object->id() );
406 return -1;
407
408 }
409
410
411 if ( ! (opt & OpenMesh::IO::Options::VertexTexCoord) ) {
412 object->mesh()->release_vertex_texcoords2D();
413 }
414
415
416 if ( ! (opt & OpenMesh::IO::Options::FaceTexCoord) ) {
417 object->mesh()->release_halfedge_texcoords2D();
418 }
419
420
421 object->mesh()->update_normals();
422
423 backupTextureCoordinates(*(object->mesh()));
424
425 return object->id();
426
427 } else {
428 emit log(LOGERR,"Error : Could not create new poly mesh object.");
429 return -1;
430 }
431 }
432
433 //-----------------------------------------------------------------------------------------------------
434
435 template <class MeshT>
436 void FileOMPlugin::backupTextureCoordinates(MeshT& _mesh) {
437
438 // Create a backup of the original per Vertex texture Coordinates
439 if (_mesh.has_vertex_texcoords2D()) {
440
441 OpenMesh::VPropHandleT< typename MeshT::TexCoord2D > oldVertexCoords;
442 if (!_mesh.get_property_handle(oldVertexCoords, "Original Per Vertex Texture Coords"))
443 _mesh.add_property(oldVertexCoords, "Original Per Vertex Texture Coords");
444
445 for (typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it)
446 _mesh.property(oldVertexCoords, *v_it) = _mesh.texcoord2D(*v_it);
447
448 }
449
450 // Create a backup of the original per Face texture Coordinates
451 if (_mesh.has_halfedge_texcoords2D()) {
452
453 OpenMesh::HPropHandleT< typename MeshT::TexCoord2D > oldHalfedgeCoords;
454 if (!_mesh.get_property_handle(oldHalfedgeCoords,"Original Per Face Texture Coords"))
455 _mesh.add_property(oldHalfedgeCoords,"Original Per Face Texture Coords");
456
457 for (typename MeshT::HalfedgeIter he_it = _mesh.halfedges_begin(); he_it != _mesh.halfedges_end(); ++he_it)
458 _mesh.property(oldHalfedgeCoords, *he_it) = _mesh.texcoord2D(*he_it);
459
460 }
461 }
462
463 //-----------------------------------------------------------------------------------------------------
464
465 bool FileOMPlugin::saveObject(int _id, QString _filename)
466 {
467 BaseObjectData* object;
468 if ( !PluginFunctions::getObject(_id,object) ) {
469 emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
470 return false;
471 }
472
473 std::string filename = std::string( _filename.toUtf8() );
474
475 if ( object->dataType( DATA_POLY_MESH ) ) {
476
477 PolyMeshObject* polObj = dynamic_cast<PolyMeshObject* >( object );
478
479 OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
480
481 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0){
482
483 PolyMesh* mesh = polObj->mesh();
484
485 if (saveBinary_->isChecked())
486 opt += OpenMesh::IO::Options::Binary;
487
488 if (saveVertexNormal_->isChecked() && mesh->has_vertex_normals())
489 opt += OpenMesh::IO::Options::VertexNormal;
490
491 if (saveVertexTexCoord_->isChecked() && (mesh->has_vertex_texcoords1D() || mesh->has_vertex_texcoords2D() || mesh->has_vertex_texcoords3D())) {
492 std::cerr << "File OM texture write" << std::endl;
493 opt += OpenMesh::IO::Options::VertexTexCoord;
494 }
495
496 if (saveVertexColor_->isChecked() && mesh->has_vertex_colors())
497 opt += OpenMesh::IO::Options::VertexColor;
498
499 if (saveFaceColor_->isChecked() && mesh->has_face_colors())
500 opt += OpenMesh::IO::Options::FaceColor;
501
502 if (saveFaceNormal_->isChecked() && mesh->has_face_normals())
503 opt += OpenMesh::IO::Options::FaceNormal;
504
505 }
506
507 object->setFromFileName(_filename);
508 object->setName(object->filename());
509
510 PolyMeshObject* polyObj = dynamic_cast<PolyMeshObject* >( object );
511
512 if (OpenMesh::IO::write_mesh(*polyObj->mesh(), filename.c_str(),opt) ){
513 emit log(LOGINFO, tr("Saved object to ") + _filename );
514 return true;
515 }else{
516 emit log(LOGERR, tr("Unable to save ") + _filename);
517 return false;
518 }
519 } else if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
520
521 object->setFromFileName(_filename);
522 object->setName(object->filename());
523
524 TriMeshObject* triObj = dynamic_cast<TriMeshObject* >( object );
525
526 OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
527
528 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0){
529
530 TriMesh* mesh = triObj->mesh();
531
532 if (saveBinary_->isChecked())
533 opt += OpenMesh::IO::Options::Binary;
534
535 if (saveVertexNormal_->isChecked() && mesh->has_vertex_normals())
536 opt += OpenMesh::IO::Options::VertexNormal;
537
538 if (saveVertexTexCoord_->isChecked() && (mesh->has_vertex_texcoords1D() || mesh->has_vertex_texcoords2D() || mesh->has_vertex_texcoords3D())) {
539 std::cerr << "File OM texture write" << std::endl;
540 opt += OpenMesh::IO::Options::VertexTexCoord;
541 }
542
543 if (saveVertexColor_->isChecked() && mesh->has_vertex_colors())
544 opt += OpenMesh::IO::Options::VertexColor;
545
546 if (saveFaceColor_->isChecked() && mesh->has_face_colors())
547 opt += OpenMesh::IO::Options::FaceColor;
548
549 if (saveFaceNormal_->isChecked() && mesh->has_face_normals())
550 opt += OpenMesh::IO::Options::FaceNormal;
551
552 }
553
554 if (OpenMesh::IO::write_mesh(*triObj->mesh(), filename.c_str(),opt) ) {
555 emit log(LOGINFO, tr("Saved object to ") + _filename );
556 return true;
557 } else {
558 emit log(LOGERR, tr("Unable to save ") + _filename );
559 return false;
560 }
561 } else {
562 emit log(LOGERR, tr("Unable to save (object is not a compatible mesh type)"));
563 return false;
564 }
565 }
566
567 //-----------------------------------------------------------------------------------------------------
568
569 QWidget* FileOMPlugin::saveOptionsWidget(QString /*_currentFilter*/) {
570
571 if (saveOptions_ == 0){
572 //generate widget
573 saveOptions_ = new QWidget();
574 QVBoxLayout* layout = new QVBoxLayout();
575 layout->setAlignment(Qt::AlignTop);
576
577 saveBinary_ = new QCheckBox("Save Binary");
578 layout->addWidget(saveBinary_);
579
580 saveVertexNormal_ = new QCheckBox("Save Vertex Normals");
581 layout->addWidget(saveVertexNormal_);
582
583 saveVertexTexCoord_ = new QCheckBox("Save Vertex TexCoords");
584 layout->addWidget(saveVertexTexCoord_);
585
586 saveVertexColor_ = new QCheckBox("Save Vertex Colors");
587 layout->addWidget(saveVertexColor_);
588
589 saveFaceColor_ = new QCheckBox("Save Face Colors");
590 layout->addWidget(saveFaceColor_);
591
592 saveFaceNormal_ = new QCheckBox("Save Face Normals");
593 layout->addWidget(saveFaceNormal_);
594
595 saveDefaultButton_ = new QPushButton("Make Default");
596 layout->addWidget(saveDefaultButton_);
597
598 saveOptions_->setLayout(layout);
599
600 connect(saveDefaultButton_, SIGNAL(clicked()), this, SLOT(slotSaveDefault()));
601
602 saveBinary_->setChecked( OpenFlipperSettings().value("FileOM/Save/Binary",true).toBool() );
603 saveVertexNormal_->setChecked( OpenFlipperSettings().value("FileOM/Save/Normals",true).toBool() );
604 saveVertexTexCoord_->setChecked( OpenFlipperSettings().value("FileOM/Save/TexCoords",true).toBool() );
605 saveVertexColor_->setChecked( OpenFlipperSettings().value("FileOM/Save/VertexColor",true).toBool() );
606 saveFaceColor_->setChecked( OpenFlipperSettings().value("FileOM/Save/FaceColor",true).toBool() );
607 saveFaceNormal_->setChecked( OpenFlipperSettings().value("FileOM/Save/FaceNormal",true).toBool() );
608
609 }
610
611 return saveOptions_;
612 }
613
614 //-----------------------------------------------------------------------------------------------------
615
616 QWidget* FileOMPlugin::loadOptionsWidget(QString /*_currentFilter*/) {
617
618 if (loadOptions_ == 0){
619 //generate widget
620 loadOptions_ = new QWidget();
621 QVBoxLayout* layout = new QVBoxLayout();
622 layout->setAlignment(Qt::AlignTop);
623
624 QLabel* label = new QLabel(tr("If PolyMesh is a Triangle Mesh:"));
625
626 layout->addWidget(label);
627
628 triMeshHandling_ = new QComboBox();
629 triMeshHandling_->addItem( tr("Auto-Detect") );
630 triMeshHandling_->addItem( tr("Ask") );
631 triMeshHandling_->addItem( tr("Always open as PolyMesh") );
632 triMeshHandling_->addItem( tr("Always open as TriangleMesh") );
633
634 layout->addWidget(triMeshHandling_);
635
636 loadVertexNormal_ = new QCheckBox("Load Vertex Normals");
637 layout->addWidget(loadVertexNormal_);
638
639 loadVertexTexCoord_ = new QCheckBox("Load Vertex TexCoords");
640 layout->addWidget(loadVertexTexCoord_);
641
642 loadVertexColor_ = new QCheckBox("Load Vertex Colors");
643 layout->addWidget(loadVertexColor_);
644
645 loadFaceColor_ = new QCheckBox("Load Face Colors");
646 layout->addWidget(loadFaceColor_);
647
648 loadFaceNormal_ = new QCheckBox("Load Face Normals");
649 layout->addWidget(loadFaceNormal_);
650
651 loadDefaultButton_ = new QPushButton("Make Default");
652 layout->addWidget(loadDefaultButton_);
653
654 loadOptions_->setLayout(layout);
655
656 connect(loadDefaultButton_, SIGNAL(clicked()), this, SLOT(slotLoadDefault()));
657
658
659 triMeshHandling_->setCurrentIndex(OpenFlipperSettings().value("FileOM/Load/TriMeshHandling",TYPEAUTODETECT).toInt() );
660
661 loadVertexNormal_->setChecked( OpenFlipperSettings().value("FileOM/Load/Normals",true).toBool() );
662 loadVertexTexCoord_->setChecked( OpenFlipperSettings().value("FileOM/Load/TexCoords",true).toBool() );
663 loadVertexColor_->setChecked( OpenFlipperSettings().value("FileOM/Load/VertexColor",true).toBool() );
664 loadFaceColor_->setChecked( OpenFlipperSettings().value("FileOM/Load/FaceColor",true).toBool() );
665 loadFaceColor_->setChecked( OpenFlipperSettings().value("FileOM/Load/FaceNormal",true).toBool() );
666
667 }
668
669 return loadOptions_;
670 }
671
672 void FileOMPlugin::slotLoadDefault() {
673
674 OpenFlipperSettings().setValue( "FileOM/Load/Normals", loadVertexNormal_->isChecked() );
675 OpenFlipperSettings().setValue( "FileOM/Load/TexCoords", loadVertexTexCoord_->isChecked() );
676 OpenFlipperSettings().setValue( "FileOM/Load/VertexColor", loadVertexColor_->isChecked() );
677 OpenFlipperSettings().setValue( "FileOM/Load/FaceColor", loadFaceColor_->isChecked() );
678 OpenFlipperSettings().setValue( "FileOM/Load/FaceNormal", loadFaceNormal_->isChecked() );
679
680 OpenFlipperSettings().setValue( "FileOM/Load/TriMeshHandling", triMeshHandling_->currentIndex() );
681
682 OpenFlipperSettings().setValue( "Core/File/UseLoadDefaults", true );
683 }
684
685
686 void FileOMPlugin::slotSaveDefault() {
687
688 OpenFlipperSettings().setValue( "FileOM/Save/Binary", saveBinary_->isChecked() );
689 OpenFlipperSettings().setValue( "FileOM/Save/Normals", saveVertexNormal_->isChecked() );
690 OpenFlipperSettings().setValue( "FileOM/Save/TexCoords", saveVertexTexCoord_->isChecked() );
691 OpenFlipperSettings().setValue( "FileOM/Save/VertexColor", saveVertexColor_->isChecked() );
692 OpenFlipperSettings().setValue( "FileOM/Save/FaceColor", saveFaceColor_->isChecked() );
693 OpenFlipperSettings().setValue( "FileOM/Save/FaceNormal", saveFaceNormal_->isChecked() );
694 }
695
696 #if QT_VERSION < 0x050000
697 Q_EXPORT_PLUGIN2( fileomplugin , FileOMPlugin );
698 #endif
699
OpenFlipperSettings
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
Definition: GlobalOptions.cc:938
OpenMesh::IO::read_mesh
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:104
FileOMPlugin::loadObject
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
Definition: FileOM.cc:120
OpenMesh::HPropHandleT
Definition: Property.hh:501
MeshObject::mesh
MeshT * mesh()
return a pointer to the mesh
Definition: MeshObjectT.cc:351
PolyMeshObject
Type for a Meshobject containing a poly mesh.
Definition: PolyMesh.hh:70
OpenMesh::IO::Options::Default
No options.
Definition: Options.hh:104
OpenMesh::IO::Options::VertexNormal
Has (r) / store (w) vertex normals.
Definition: Options.hh:109
LOGERR
Definition: LoggingInterface.hh:107
BaseObjectData
Definition: BaseObjectData.hh:105
BaseObject::filename
QString filename() const
return the filename of the object
Definition: BaseObject.cc:717
FileOMPlugin
Definition: FileOM.hh:69
TriMeshObject
Type for a MeshObject containing a triangle mesh.
Definition: TriangleMesh.hh:73
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
PluginFunctions::getObject
bool getObject(int _identifier, BSplineCurveObject *&_object)
Definition: PluginFunctionsBSplineCurve.cc:75
OpenMesh::IO::Options::FaceNormal
Has (r) / store (w) face normals.
Definition: Options.hh:113
FileOMPlugin::loadOptionsWidget
QWidget * loadOptionsWidget(QString)
Definition: FileOM.cc:616
OpenMesh::IO::Options::FaceColor
Has (r) / store (w) face colors.
Definition: Options.hh:114
FileOMPlugin::loadPolyMeshObject
int loadPolyMeshObject(QString _filename)
Always loads mesh as polymesh.
Definition: FileOM.cc:347
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
FileOMPlugin::getSaveFilters
QString getSaveFilters()
Definition: FileOM.cc:107
OpenMesh::IO::Options::VertexTexCoord
Has (r) / store (w) texture coordinates.
Definition: Options.hh:111
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:95
FileOMPlugin::slotSaveDefault
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
Definition: FileOM.cc:686
OpenMesh::VPropHandleT
Definition: Property.hh:487
OpenMesh::IO::Options::FaceTexCoord
Has (r) / store (w) face texture coordinates.
Definition: Options.hh:115
DATA_POLY_MESH
#define DATA_POLY_MESH
Definition: PolyMesh.hh:65
FileOMPlugin::supportedType
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FileOM.cc:113
FileOMPlugin::initializePlugin
void initializePlugin()
Initialize Plugin.
Definition: FileOM.cc:96
GlobalOptions.hh
FileOMPlugin::FileOMPlugin
FileOMPlugin()
Constructor.
Definition: FileOM.cc:72
FileOMPlugin::backupTextureCoordinates
void backupTextureCoordinates(MeshT &_mesh)
creates a backup of the original per vertex/face texture coordinates
Definition: FileOM.cc:436
FileOMPlugin::loadTriMeshObject
int loadTriMeshObject(QString _filename)
Loads a triangle mesh.
Definition: FileOM.cc:270
FileOMPlugin::handleTrimeshDialog
void handleTrimeshDialog()
Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
Definition: FileOM.cc:247
LOGINFO
Definition: LoggingInterface.hh:105
OpenMesh::PolyMeshT::FaceVertexIter
Kernel::FaceVertexIter FaceVertexIter
Circulator.
Definition: PolyMeshT.hh:170
OpenMesh::IO::Options::Binary
Set binary mode for r/w.
Definition: Options.hh:105
PluginFunctions::objectCount
int objectCount()
Get the number of available objects.
Definition: PluginFunctions.cc:1004
OpenMesh::IO::Options::VertexColor
Has (r) / store (w) vertex colors.
Definition: Options.hh:110
FileOMPlugin::slotLoadDefault
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
Definition: FileOM.cc:672
PluginFunctions.hh
DataType
Predefined datatypes.
Definition: DataTypes.hh:96
OpenMesh::IO::write_mesh
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.
Definition: MeshIO.hh:199
OpenFlipperQSettings::setValue
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
Definition: OpenFlipperQSettings.cc:68
FileOMPlugin::getLoadFilters
QString getLoadFilters()
Definition: FileOM.cc:101
DATA_TRIANGLE_MESH
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:66
FileOMPlugin::saveOptionsWidget
QWidget * saveOptionsWidget(QString)
Definition: FileOM.cc:569
BaseObject::id
int id() const
Definition: BaseObject.cc:201