43 #include <ACG/GL/GLState.hh> 48 #include <OpenMesh/Core/IO/IOManager.hh> 56 #define TYPEAUTODETECT 0 59 #define TYPETRIANGLE 3 67 saveVertexTexCoord_(0),
71 saveDefaultButton_(0),
74 loadVertexTexCoord_(0),
78 loadDefaultButton_(0),
92 return QString( tr(
"OpenMesh Format files ( *.om )") );
98 return QString( tr(
"OpenMesh Format files ( *.om )") );
112 int triMeshControl = TYPEAUTODETECT;
114 if ( OpenFlipper::Options::gui() ){
115 if ( triMeshHandling_ != 0 ){
116 triMeshControl = triMeshHandling_->currentIndex();
118 triMeshControl = TYPEAUTODETECT;
124 if(triMeshControl == TYPEAUTODETECT) {
132 for ( PolyMesh::FaceIter f_it = object->
mesh()->faces_begin(); f_it !=
object->mesh()->faces_end() ; ++f_it) {
146 emit openedFile( objectId );
153 }
else if (triMeshControl == TYPEASK ) {
164 for ( PolyMesh::FaceIter f_it = object->
mesh()->faces_begin(); f_it !=
object->mesh()->faces_end() ; ++f_it) {
177 if(triMesh ==
false)
break;
182 QMetaObject::invokeMethod(
this,
"handleTrimeshDialog",Qt::BlockingQueuedConnection);
183 if ((trimeshOptions_ == TYPEPOLY) ||
184 (trimeshOptions_ == TYPEASK && !triMesh)) {
190 emit openedFile( objectId );
195 }
else if (triMeshControl == TYPEPOLY) {
204 emit openedFile( objectId );
216 emit openedFile( objectId );
223 if(objectId != -1) emit deleteObject(objectId);
231 emit openedFile( objectId );
240 QPushButton *detectButton = msgBox.addButton(tr(
"Auto-Detect"), QMessageBox::ActionRole);
241 QPushButton *triButton = msgBox.addButton(tr(
"Open as triangle mesh"), QMessageBox::ActionRole);
242 QPushButton *polyButton = msgBox.addButton(tr(
"Open as poly mesh"), QMessageBox::ActionRole);
243 msgBox.setWindowTitle( tr(
"Mesh types in file") );
244 msgBox.setText( tr(
"You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
245 msgBox.setDefaultButton( detectButton );
249 if (msgBox.clickedButton() == triButton)
250 trimeshOptions_ = TYPETRIANGLE ;
251 else if (msgBox.clickedButton() == polyButton)
252 trimeshOptions_ = TYPEPOLY ;
254 trimeshOptions_ = TYPEASK;
269 object->target(
true);
271 object->setFromFileName(_filename);
272 object->setName(object->
filename());
274 std::string filename = std::string( _filename.toUtf8() );
279 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() &&
280 !OpenFlipper::Options::loadingRecentFile() && loadOptions_ != 0){
282 if (loadVertexNormal_->isChecked())
285 if (loadVertexTexCoord_->isChecked())
288 if (loadVertexColor_->isChecked())
291 if (loadFaceColor_->isChecked())
294 if (loadFaceNormal_->isChecked())
309 object->mesh()->request_vertex_texcoords2D();
310 object->mesh()->request_halfedge_texcoords2D();
311 object->mesh()->request_face_texture_index();
317 std::cerr <<
"Plugin FileOM : Read error for Triangle Mesh\n";
318 emit deleteObject( object->
id() );
322 object->mesh()->update_normals();
329 emit log(
LOGERR,
"Error : Could not create new triangle mesh object.");
346 object->target(
true);
348 object->setFromFileName(_filename);
349 object->setName(object->
filename());
351 std::string filename = std::string( _filename.toUtf8() );
356 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() &&
357 !OpenFlipper::Options::loadingRecentFile() && loadOptions_ != 0){
359 if (loadVertexNormal_->isChecked())
362 if (loadVertexTexCoord_->isChecked())
365 if (loadVertexColor_->isChecked())
368 if (loadFaceColor_->isChecked())
371 if (loadFaceNormal_->isChecked())
386 object->mesh()->request_vertex_texcoords2D();
387 object->mesh()->request_halfedge_texcoords2D();
388 object->mesh()->request_face_texture_index();
394 std::cerr <<
"Plugin FileOM : Read error for Poly Mesh\n";
395 emit deleteObject( object->
id() );
402 object->mesh()->release_vertex_texcoords2D();
407 object->mesh()->release_halfedge_texcoords2D();
411 object->mesh()->update_normals();
418 emit log(
LOGERR,
"Error : Could not create new poly mesh object.");
425 template <
class MeshT>
429 if (_mesh.has_vertex_texcoords2D()) {
432 if (!_mesh.get_property_handle(oldVertexCoords,
"Original Per Vertex Texture Coords"))
433 _mesh.add_property(oldVertexCoords,
"Original Per Vertex Texture Coords");
435 for (
typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it)
436 _mesh.property(oldVertexCoords, *v_it) = _mesh.texcoord2D(*v_it);
441 if (_mesh.has_halfedge_texcoords2D()) {
444 if (!_mesh.get_property_handle(oldHalfedgeCoords,
"Original Per Face Texture Coords"))
445 _mesh.add_property(oldHalfedgeCoords,
"Original Per Face Texture Coords");
447 for (
typename MeshT::HalfedgeIter he_it = _mesh.halfedges_begin(); he_it != _mesh.halfedges_end(); ++he_it)
448 _mesh.property(oldHalfedgeCoords, *he_it) = _mesh.texcoord2D(*he_it);
455 bool FileOMPlugin::saveObject(
int _id, QString _filename)
459 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
463 std::string filename = std::string( _filename.toUtf8() );
471 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0){
475 if (saveBinary_->isChecked())
478 if (saveVertexNormal_->isChecked() && mesh->has_vertex_normals())
481 if (saveVertexTexCoord_->isChecked() && (mesh->has_vertex_texcoords1D() || mesh->has_vertex_texcoords2D() || mesh->has_vertex_texcoords3D())) {
482 std::cerr <<
"File OM texture write" << std::endl;
486 if (saveVertexColor_->isChecked() && mesh->has_vertex_colors())
489 if (saveFaceColor_->isChecked() && mesh->has_face_colors())
492 if (saveFaceNormal_->isChecked() && mesh->has_face_normals())
497 object->setFromFileName(_filename);
498 object->setName(object->
filename());
503 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
506 emit log(
LOGERR, tr(
"Unable to save ") + _filename);
511 object->setFromFileName(_filename);
512 object->setName(object->
filename());
518 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0){
522 if (saveBinary_->isChecked())
525 if (saveVertexNormal_->isChecked() && mesh->has_vertex_normals())
528 if (saveVertexTexCoord_->isChecked() && (mesh->has_vertex_texcoords1D() || mesh->has_vertex_texcoords2D() || mesh->has_vertex_texcoords3D())) {
529 std::cerr <<
"File OM texture write" << std::endl;
533 if (saveVertexColor_->isChecked() && mesh->has_vertex_colors())
536 if (saveFaceColor_->isChecked() && mesh->has_face_colors())
539 if (saveFaceNormal_->isChecked() && mesh->has_face_normals())
545 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
548 emit log(
LOGERR, tr(
"Unable to save ") + _filename );
552 emit log(
LOGERR, tr(
"Unable to save (object is not a compatible mesh type)"));
561 if (saveOptions_ == 0){
563 saveOptions_ =
new QWidget();
564 QVBoxLayout* layout =
new QVBoxLayout();
565 layout->setAlignment(Qt::AlignTop);
567 saveBinary_ =
new QCheckBox(
"Save Binary");
568 layout->addWidget(saveBinary_);
570 saveVertexNormal_ =
new QCheckBox(
"Save Vertex Normals");
571 layout->addWidget(saveVertexNormal_);
573 saveVertexTexCoord_ =
new QCheckBox(
"Save Vertex TexCoords");
574 layout->addWidget(saveVertexTexCoord_);
576 saveVertexColor_ =
new QCheckBox(
"Save Vertex Colors");
577 layout->addWidget(saveVertexColor_);
579 saveFaceColor_ =
new QCheckBox(
"Save Face Colors");
580 layout->addWidget(saveFaceColor_);
582 saveFaceNormal_ =
new QCheckBox(
"Save Face Normals");
583 layout->addWidget(saveFaceNormal_);
585 saveDefaultButton_ =
new QPushButton(
"Make Default");
586 layout->addWidget(saveDefaultButton_);
588 saveOptions_->setLayout(layout);
590 connect(saveDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotSaveDefault()));
592 saveBinary_->setChecked(
OpenFlipperSettings().value(
"FileOM/Save/Binary",
true).toBool() );
593 saveVertexNormal_->setChecked(
OpenFlipperSettings().value(
"FileOM/Save/Normals",
true).toBool() );
594 saveVertexTexCoord_->setChecked(
OpenFlipperSettings().value(
"FileOM/Save/TexCoords",
true).toBool() );
595 saveVertexColor_->setChecked(
OpenFlipperSettings().value(
"FileOM/Save/VertexColor",
true).toBool() );
596 saveFaceColor_->setChecked(
OpenFlipperSettings().value(
"FileOM/Save/FaceColor",
true).toBool() );
597 saveFaceNormal_->setChecked(
OpenFlipperSettings().value(
"FileOM/Save/FaceNormal",
true).toBool() );
608 if (loadOptions_ == 0){
610 loadOptions_ =
new QWidget();
611 QVBoxLayout* layout =
new QVBoxLayout();
612 layout->setAlignment(Qt::AlignTop);
614 QLabel* label =
new QLabel(tr(
"If PolyMesh is a Triangle Mesh:"));
616 layout->addWidget(label);
618 triMeshHandling_ =
new QComboBox();
619 triMeshHandling_->addItem( tr(
"Auto-Detect") );
620 triMeshHandling_->addItem( tr(
"Ask") );
621 triMeshHandling_->addItem( tr(
"Always open as PolyMesh") );
622 triMeshHandling_->addItem( tr(
"Always open as TriangleMesh") );
624 layout->addWidget(triMeshHandling_);
626 loadVertexNormal_ =
new QCheckBox(
"Load Vertex Normals");
627 layout->addWidget(loadVertexNormal_);
629 loadVertexTexCoord_ =
new QCheckBox(
"Load Vertex TexCoords");
630 layout->addWidget(loadVertexTexCoord_);
632 loadVertexColor_ =
new QCheckBox(
"Load Vertex Colors");
633 layout->addWidget(loadVertexColor_);
635 loadFaceColor_ =
new QCheckBox(
"Load Face Colors");
636 layout->addWidget(loadFaceColor_);
638 loadFaceNormal_ =
new QCheckBox(
"Load Face Normals");
639 layout->addWidget(loadFaceNormal_);
641 loadDefaultButton_ =
new QPushButton(
"Make Default");
642 layout->addWidget(loadDefaultButton_);
644 loadOptions_->setLayout(layout);
646 connect(loadDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotLoadDefault()));
649 triMeshHandling_->setCurrentIndex(
OpenFlipperSettings().value(
"FileOM/Load/TriMeshHandling",TYPEAUTODETECT).toInt() );
651 loadVertexNormal_->setChecked(
OpenFlipperSettings().value(
"FileOM/Load/Normals",
true).toBool() );
652 loadVertexTexCoord_->setChecked(
OpenFlipperSettings().value(
"FileOM/Load/TexCoords",
true).toBool() );
653 loadVertexColor_->setChecked(
OpenFlipperSettings().value(
"FileOM/Load/VertexColor",
true).toBool() );
654 loadFaceColor_->setChecked(
OpenFlipperSettings().value(
"FileOM/Load/FaceColor",
true).toBool() );
655 loadFaceColor_->setChecked(
OpenFlipperSettings().value(
"FileOM/Load/FaceNormal",
true).toBool() );
void backupTextureCoordinates(MeshT &_mesh)
creates a backup of the original per vertex/face texture coordinates
#define DATA_TRIANGLE_MESH
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
Type for a Meshobject containing a poly mesh.
Has (r) / store (w) vertex colors.
Kernel::FaceVertexIter FaceVertexIter
Circulator.
Has (r) / store (w) face colors.
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.
int objectCount()
Get the number of available objects.
int loadTriMeshObject(QString _filename)
Loads a triangle mesh.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
QString filename() const
return the filename of the object
FileOMPlugin()
Constructor.
MeshT * mesh()
return a pointer to the mesh
bool dataType(DataType _type) const
Has (r) / store (w) face texture coordinates.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
void initializePlugin()
Initialize Plugin.
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
Type for a MeshObject containing a triangle mesh.
int loadPolyMeshObject(QString _filename)
Always loads mesh as polymesh.
Set options for reader/writer modules.
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
Has (r) / store (w) vertex normals.
Has (r) / store (w) face normals.
void handleTrimeshDialog()
Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
QWidget * saveOptionsWidget(QString)
Has (r) / store (w) texture coordinates.
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
QWidget * loadOptionsWidget(QString)