49 #include <ACG/GL/GLState.hh> 54 #include <OpenMesh/Core/IO/IOManager.hh> 56 #if QT_VERSION >= 0x050000 66 #define TYPEAUTODETECT 0 69 #define TYPETRIANGLE 3 77 saveVertexTexCoord_(0),
81 saveDefaultButton_(0),
84 loadVertexTexCoord_(0),
88 loadDefaultButton_(0),
102 return QString( tr(
"OpenMesh Format files ( *.om )") );
108 return QString( tr(
"OpenMesh Format files ( *.om )") );
122 int triMeshControl = TYPEAUTODETECT;
124 if ( OpenFlipper::Options::gui() ){
125 if ( triMeshHandling_ != 0 ){
126 triMeshControl = triMeshHandling_->currentIndex();
128 triMeshControl = TYPEAUTODETECT;
134 if(triMeshControl == TYPEAUTODETECT) {
142 for ( PolyMesh::FaceIter f_it = object->
mesh()->faces_begin(); f_it !=
object->mesh()->faces_end() ; ++f_it) {
156 emit openedFile( objectId );
163 }
else if (triMeshControl == TYPEASK ) {
174 for ( PolyMesh::FaceIter f_it = object->
mesh()->faces_begin(); f_it !=
object->mesh()->faces_end() ; ++f_it) {
187 if(triMesh ==
false)
break;
192 QMetaObject::invokeMethod(
this,
"handleTrimeshDialog",Qt::BlockingQueuedConnection);
193 if ((trimeshOptions_ == TYPEPOLY) ||
194 (trimeshOptions_ == TYPEASK && !triMesh)) {
200 emit openedFile( objectId );
205 }
else if (triMeshControl == TYPEPOLY) {
214 emit openedFile( objectId );
226 emit openedFile( objectId );
233 if(objectId != -1) emit deleteObject(objectId);
241 emit openedFile( objectId );
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 );
259 if (msgBox.clickedButton() == triButton)
260 trimeshOptions_ = TYPETRIANGLE ;
261 else if (msgBox.clickedButton() == polyButton)
262 trimeshOptions_ = TYPEPOLY ;
264 trimeshOptions_ = TYPEASK;
279 object->target(
true);
281 object->setFromFileName(_filename);
282 object->setName(object->
filename());
284 std::string filename = std::string( _filename.toUtf8() );
289 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() &&
290 !OpenFlipper::Options::loadingRecentFile() && loadOptions_ != 0){
292 if (loadVertexNormal_->isChecked())
295 if (loadVertexTexCoord_->isChecked())
298 if (loadVertexColor_->isChecked())
301 if (loadFaceColor_->isChecked())
304 if (loadFaceNormal_->isChecked())
319 object->mesh()->request_vertex_texcoords2D();
320 object->mesh()->request_halfedge_texcoords2D();
321 object->mesh()->request_face_texture_index();
327 std::cerr <<
"Plugin FileOM : Read error for Triangle Mesh\n";
328 emit deleteObject( object->
id() );
332 object->mesh()->update_normals();
339 emit log(
LOGERR,
"Error : Could not create new triangle mesh object.");
356 object->target(
true);
358 object->setFromFileName(_filename);
359 object->setName(object->
filename());
361 std::string filename = std::string( _filename.toUtf8() );
366 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() &&
367 !OpenFlipper::Options::loadingRecentFile() && loadOptions_ != 0){
369 if (loadVertexNormal_->isChecked())
372 if (loadVertexTexCoord_->isChecked())
375 if (loadVertexColor_->isChecked())
378 if (loadFaceColor_->isChecked())
381 if (loadFaceNormal_->isChecked())
396 object->mesh()->request_vertex_texcoords2D();
397 object->mesh()->request_halfedge_texcoords2D();
398 object->mesh()->request_face_texture_index();
404 std::cerr <<
"Plugin FileOM : Read error for Poly Mesh\n";
405 emit deleteObject( object->
id() );
412 object->mesh()->release_vertex_texcoords2D();
417 object->mesh()->release_halfedge_texcoords2D();
421 object->mesh()->update_normals();
428 emit log(
LOGERR,
"Error : Could not create new poly mesh object.");
435 template <
class MeshT>
439 if (_mesh.has_vertex_texcoords2D()) {
442 if (!_mesh.get_property_handle(oldVertexCoords,
"Original Per Vertex Texture Coords"))
443 _mesh.add_property(oldVertexCoords,
"Original Per Vertex Texture Coords");
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);
451 if (_mesh.has_halfedge_texcoords2D()) {
454 if (!_mesh.get_property_handle(oldHalfedgeCoords,
"Original Per Face Texture Coords"))
455 _mesh.add_property(oldHalfedgeCoords,
"Original Per Face Texture Coords");
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);
465 bool FileOMPlugin::saveObject(
int _id, QString _filename)
469 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
473 std::string filename = std::string( _filename.toUtf8() );
481 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0){
485 if (saveBinary_->isChecked())
488 if (saveVertexNormal_->isChecked() && mesh->has_vertex_normals())
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;
496 if (saveVertexColor_->isChecked() && mesh->has_vertex_colors())
499 if (saveFaceColor_->isChecked() && mesh->has_face_colors())
502 if (saveFaceNormal_->isChecked() && mesh->has_face_normals())
507 object->setFromFileName(_filename);
508 object->setName(object->
filename());
513 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
516 emit log(
LOGERR, tr(
"Unable to save ") + _filename);
521 object->setFromFileName(_filename);
522 object->setName(object->
filename());
528 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0){
532 if (saveBinary_->isChecked())
535 if (saveVertexNormal_->isChecked() && mesh->has_vertex_normals())
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;
543 if (saveVertexColor_->isChecked() && mesh->has_vertex_colors())
546 if (saveFaceColor_->isChecked() && mesh->has_face_colors())
549 if (saveFaceNormal_->isChecked() && mesh->has_face_normals())
555 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
558 emit log(
LOGERR, tr(
"Unable to save ") + _filename );
562 emit log(
LOGERR, tr(
"Unable to save (object is not a compatible mesh type)"));
571 if (saveOptions_ == 0){
573 saveOptions_ =
new QWidget();
574 QVBoxLayout* layout =
new QVBoxLayout();
575 layout->setAlignment(Qt::AlignTop);
577 saveBinary_ =
new QCheckBox(
"Save Binary");
578 layout->addWidget(saveBinary_);
580 saveVertexNormal_ =
new QCheckBox(
"Save Vertex Normals");
581 layout->addWidget(saveVertexNormal_);
583 saveVertexTexCoord_ =
new QCheckBox(
"Save Vertex TexCoords");
584 layout->addWidget(saveVertexTexCoord_);
586 saveVertexColor_ =
new QCheckBox(
"Save Vertex Colors");
587 layout->addWidget(saveVertexColor_);
589 saveFaceColor_ =
new QCheckBox(
"Save Face Colors");
590 layout->addWidget(saveFaceColor_);
592 saveFaceNormal_ =
new QCheckBox(
"Save Face Normals");
593 layout->addWidget(saveFaceNormal_);
595 saveDefaultButton_ =
new QPushButton(
"Make Default");
596 layout->addWidget(saveDefaultButton_);
598 saveOptions_->setLayout(layout);
600 connect(saveDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotSaveDefault()));
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() );
618 if (loadOptions_ == 0){
620 loadOptions_ =
new QWidget();
621 QVBoxLayout* layout =
new QVBoxLayout();
622 layout->setAlignment(Qt::AlignTop);
624 QLabel* label =
new QLabel(tr(
"If PolyMesh is a Triangle Mesh:"));
626 layout->addWidget(label);
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") );
634 layout->addWidget(triMeshHandling_);
636 loadVertexNormal_ =
new QCheckBox(
"Load Vertex Normals");
637 layout->addWidget(loadVertexNormal_);
639 loadVertexTexCoord_ =
new QCheckBox(
"Load Vertex TexCoords");
640 layout->addWidget(loadVertexTexCoord_);
642 loadVertexColor_ =
new QCheckBox(
"Load Vertex Colors");
643 layout->addWidget(loadVertexColor_);
645 loadFaceColor_ =
new QCheckBox(
"Load Face Colors");
646 layout->addWidget(loadFaceColor_);
648 loadFaceNormal_ =
new QCheckBox(
"Load Face Normals");
649 layout->addWidget(loadFaceNormal_);
651 loadDefaultButton_ =
new QPushButton(
"Make Default");
652 layout->addWidget(loadDefaultButton_);
654 loadOptions_->setLayout(layout);
656 connect(loadDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotLoadDefault()));
659 triMeshHandling_->setCurrentIndex(
OpenFlipperSettings().value(
"FileOM/Load/TriMeshHandling",TYPEAUTODETECT).toInt() );
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() );
696 #if QT_VERSION < 0x050000 void backupTextureCoordinates(MeshT &_mesh)
creates a backup of the original per vertex/face texture coordinates
Has (r) / store (w) texture coordinates.
Type for a MeshObject containing a triangle mesh.
QString filename() const
return the filename of the object
Has (r) / store (w) vertex normals.
bool getObject(int _identifier, BSplineCurveObject *&_object)
bool dataType(DataType _type) const
FileOMPlugin()
Constructor.
void handleTrimeshDialog()
Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
Has (r) / store (w) face normals.
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
QWidget * saveOptionsWidget(QString)
MeshT * mesh()
return a pointer to the mesh
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
Kernel::FaceVertexIter FaceVertexIter
Circulator.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
int objectCount()
Get the number of available objects.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Set options for reader/writer modules.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Type for a Meshobject containing a poly mesh.
Has (r) / store (w) face texture coordinates.
Has (r) / store (w) face colors.
void initializePlugin()
Initialize Plugin.
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
int loadTriMeshObject(QString _filename)
Loads a triangle mesh.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
Has (r) / store (w) vertex colors.
QWidget * loadOptionsWidget(QString)
#define DATA_TRIANGLE_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.
int loadPolyMeshObject(QString _filename)
Always loads mesh as polymesh.