52 #if QT_VERSION >= 0x050000
60 #define TYPEAUTODETECT 0
63 #define TYPETRIANGLE 3
72 saveVertexTexCoord_(0),
75 savePrecisionLabel_(0),
77 saveDefaultButton_(0),
81 loadVertexTexCoord_(0),
84 loadDefaultButton_(0),
96 return QString( tr(
"Polygon File Format files ( *.ply )") );
102 return QString( tr(
"Polygon File Format files ( *.ply )") );
117 bool gui = OpenFlipper::Options::gui() && (loadVertexNormal_ != 0) ;
119 bool vNormals = ((gui && loadVertexNormal_->isChecked()) ||
121 bool vColors = ((gui && loadVertexColor_->isChecked()) ||
123 bool vTexCoords = ((gui && loadVertexTexCoord_->isChecked()) ||
125 bool fNormals = ((gui && loadFaceNormal_->isChecked()) ||
127 bool fColors = ((gui && loadFaceColor_->isChecked()) ||
150 emit openedFile( objectId );
164 emit openedFile( objectId );
170 emit log(
LOGERR, tr(
"FilePLYPlugin::loadObject(): Tried loading with unknown forced data type"));
180 int triMeshControl = TYPEAUTODETECT;
182 bool gui = OpenFlipper::Options::gui() && (loadVertexNormal_ != 0) ;
184 bool vNormals = ((gui && loadVertexNormal_->isChecked()) ||
186 bool vColors = ((gui && loadVertexColor_->isChecked()) ||
188 bool vTexCoords = ((gui && loadVertexTexCoord_->isChecked()) ||
190 bool fNormals = ((gui && loadFaceNormal_->isChecked()) ||
192 bool fColors = ((gui && loadFaceColor_->isChecked()) ||
208 if ( OpenFlipper::Options::gui() ){
209 if ( triMeshHandling_ != 0 ){
210 triMeshControl = triMeshHandling_->currentIndex();
212 triMeshControl = TYPEAUTODETECT;
219 if(triMeshControl == TYPEAUTODETECT || triMeshControl == TYPEASK) {
227 bool isTriMesh =
true;
228 for ( PolyMesh::FaceIter f_it = object->
mesh()->faces_begin(); f_it !=
object->mesh()->faces_end() && isTriMesh; ++f_it) {
236 isTriMesh = isTriMesh && (count == 3);
239 if (triMeshControl == TYPEAUTODETECT)
245 emit openedFile( objectId );
250 else if (triMeshControl == TYPEASK) {
253 QMetaObject::invokeMethod(
this,
"handleTrimeshDialog",Qt::BlockingQueuedConnection);
254 if ((trimeshOptions_ == TYPEPOLY) ||
255 (trimeshOptions_ == TYPEASK && !isTriMesh)) {
260 emit openedFile( objectId );
267 }
else if (triMeshControl == TYPEPOLY) {
275 emit openedFile( objectId );
287 emit openedFile( objectId );
296 if(objectId != -1) emit deleteObject(objectId);
302 emit openedFile( objectId );
311 QPushButton *detectButton = msgBox.addButton(tr(
"Auto-Detect"), QMessageBox::ActionRole);
312 QPushButton *triButton = msgBox.addButton(tr(
"Open as triangle mesh"), QMessageBox::ActionRole);
313 QPushButton *polyButton = msgBox.addButton(tr(
"Open as poly mesh"), QMessageBox::ActionRole);
314 msgBox.setWindowTitle( tr(
"Mesh types in file") );
315 msgBox.setText( tr(
"You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
316 msgBox.setDefaultButton( detectButton );
320 if (msgBox.clickedButton() == triButton)
321 trimeshOptions_ = TYPETRIANGLE ;
322 else if (msgBox.clickedButton() == polyButton)
323 trimeshOptions_ = TYPEPOLY ;
325 trimeshOptions_ = TYPEASK;
340 object->target(
true);
342 object->setFromFileName(_filename);
343 object->setName(object->
filename());
346 TriMesh* mesh =
object->mesh();
348 bool hadVNormals = mesh->has_vertex_normals();
349 bool hadVColors = mesh->has_vertex_colors();
350 bool hadVTexCoords = mesh->has_vertex_texcoords2D();
351 bool hadFNormals = mesh->has_face_normals();
352 bool hadFColors = mesh->has_face_colors();
354 if(_opt.vertex_has_normal())
355 mesh->request_vertex_normals();
356 if(_opt.vertex_has_color())
357 mesh->request_vertex_colors();
358 if(_opt.vertex_has_texcoord())
359 mesh->request_vertex_texcoords2D();
360 if(_opt.face_has_normal())
361 mesh->request_face_normals();
362 if(_opt.face_has_color())
363 mesh->request_face_colors();
368 emit log(
LOGERR,
"Error while reading PLY file!");
369 emit deleteObject(
id);
374 if (!_opt.vertex_has_normal() || !_opt.face_has_normal())
375 mesh->update_normals();
378 if (!hadVColors && !_opt.vertex_has_color() && mesh->has_vertex_colors())
379 mesh->release_vertex_colors();
380 if (!hadVTexCoords && !_opt.vertex_has_texcoord() && mesh->has_vertex_texcoords2D())
381 mesh->release_vertex_texcoords2D();
382 if (!hadFColors && !_opt.face_has_color() && mesh->has_face_colors())
383 mesh->release_face_colors();
386 if(mesh->n_faces() == 0)
394 emit log(
LOGERR,
"Error : Could not create new triangle mesh object.");
411 object->target(
true);
413 object->setFromFileName(_filename);
414 object->setName(object->
filename());
419 bool hadVNormals = mesh->has_vertex_normals();
420 bool hadVColors = mesh->has_vertex_colors();
421 bool hadVTexCoords = mesh->has_vertex_texcoords2D();
422 bool hadFNormals = mesh->has_face_normals();
423 bool hadFColors = mesh->has_face_colors();
425 if(_opt.vertex_has_normal())
426 mesh->request_vertex_normals();
427 if(_opt.vertex_has_color())
428 mesh->request_vertex_colors();
429 if(_opt.vertex_has_texcoord())
430 mesh->request_vertex_texcoords2D();
431 if(_opt.face_has_normal())
432 mesh->request_face_normals();
433 if(_opt.face_has_color())
434 mesh->request_face_colors();
439 emit log(
LOGERR,
"Error while reading PLY file!");
440 emit deleteObject(
id);
445 if (!_opt.vertex_has_normal() || !_opt.face_has_normal())
449 if (!hadVColors && !_opt.vertex_has_color() && mesh->has_vertex_colors())
450 mesh->release_vertex_colors();
451 if (!hadVTexCoords && !_opt.vertex_has_texcoord() && mesh->has_vertex_texcoords2D())
452 mesh->release_vertex_texcoords2D();
453 if (!hadFColors && !_opt.face_has_color() && mesh->has_face_colors())
454 mesh->release_face_colors();
458 if(mesh->n_faces() == 0)
466 emit log(
LOGERR,
"Error : Could not create new poly mesh object.");
475 bool FilePLYPlugin::saveObject(
int _id, QString _filename)
479 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
483 object->setFromFileName(_filename);
484 object->setName(object->
filename());
488 bool gui = OpenFlipper::Options::gui() && (saveBinary_ != 0) ;
489 bool binary = ((gui && saveBinary_->isChecked()) ||
495 bool vNormals = ((gui && saveVertexNormal_->isChecked())) ||
497 bool vColors = ((gui && saveVertexColor_->isChecked())) ||
499 bool vTexCoords = ((gui && saveVertexTexCoord_->isChecked())) ||
501 bool fNormals = ((gui && saveFaceNormal_->isChecked())) ||
503 bool fColors = ((gui && saveFaceColor_->isChecked())) ||
512 PolyMesh* mesh = polyObj->
mesh();
514 if (vNormals && mesh->has_vertex_normals())
516 if (vColors && mesh->has_vertex_colors())
518 if (vTexCoords && mesh->has_vertex_texcoords2D())
520 if (fNormals && mesh->has_face_normals())
522 if (fColors && mesh->has_face_colors())
530 TriMesh* mesh = triObj->
mesh();
532 if (vNormals && mesh->has_vertex_normals())
534 if (vColors && mesh->has_vertex_colors())
536 if (vTexCoords && mesh->has_vertex_texcoords2D())
538 if (fNormals && mesh->has_face_normals())
540 if (fColors && mesh->has_face_colors())
547 emit log(
LOGERR, tr(
"Unable to save ") + _filename);
551 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
559 if (saveOptions_ == 0){
561 saveOptions_ =
new QWidget();
562 QVBoxLayout* layout =
new QVBoxLayout();
563 layout->setAlignment(Qt::AlignTop);
565 saveBinary_ =
new QCheckBox(
"Save Binary");
566 layout->addWidget(saveBinary_);
568 saveVertexNormal_ =
new QCheckBox(
"Save Vertex Normals");
569 layout->addWidget(saveVertexNormal_);
571 saveVertexColor_ =
new QCheckBox(
"Save Vertex Colors");
572 layout->addWidget(saveVertexColor_);
574 saveVertexTexCoord_ =
new QCheckBox(
"Save Vertex TexCoords");
575 layout->addWidget(saveVertexTexCoord_);
577 saveFaceNormal_ =
new QCheckBox(
"Save Face Normals");
578 layout->addWidget(saveFaceNormal_);
580 saveFaceColor_ =
new QCheckBox(
"Save Face Colors");
581 layout->addWidget(saveFaceColor_);
583 savePrecisionLabel_ =
new QLabel(
"Writer Precision");
584 layout->addWidget(savePrecisionLabel_);
586 savePrecision_ =
new QSpinBox();
587 savePrecision_->setMinimum(1);
588 savePrecision_->setMaximum(12);
589 savePrecision_->setValue(6);
590 layout->addWidget(savePrecision_);
592 saveDefaultButton_ =
new QPushButton(
"Make Default");
593 layout->addWidget(saveDefaultButton_);
595 saveOptions_->setLayout(layout);
597 connect(saveBinary_, SIGNAL(clicked(
bool)), savePrecision_, SLOT(setDisabled(
bool)));
598 connect(saveDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotSaveDefault()));
600 saveBinary_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/Binary",
true).toBool() );
601 savePrecision_->setDisabled(
true);
602 saveVertexNormal_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/Normals",
true).toBool() );
603 saveVertexColor_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/VertexColor",
true).toBool() );
604 saveVertexTexCoord_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/TexCoords",
true).toBool() );
605 saveFaceNormal_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/FaceNormal",
true).toBool() );
606 saveFaceColor_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/FaceColor",
true).toBool() );
616 if (loadOptions_ == 0){
618 loadOptions_ =
new QWidget();
619 QVBoxLayout* layout =
new QVBoxLayout();
620 layout->setAlignment(Qt::AlignTop);
622 QLabel* label =
new QLabel(tr(
"If PolyMesh is a Triangle Mesh:"));
624 layout->addWidget(label);
626 triMeshHandling_ =
new QComboBox();
627 triMeshHandling_->addItem( tr(
"Auto-Detect") );
628 triMeshHandling_->addItem( tr(
"Ask") );
629 triMeshHandling_->addItem( tr(
"Always open as PolyMesh") );
630 triMeshHandling_->addItem( tr(
"Always open as TriangleMesh") );
632 layout->addWidget(triMeshHandling_);
634 loadVertexNormal_ =
new QCheckBox(
"Load Vertex Normals");
635 layout->addWidget(loadVertexNormal_);
637 loadVertexColor_ =
new QCheckBox(
"Load Vertex Colors");
638 layout->addWidget(loadVertexColor_);
640 loadVertexTexCoord_ =
new QCheckBox(
"Load Vertex TexCoords");
641 layout->addWidget(loadVertexTexCoord_);
643 loadFaceNormal_ =
new QCheckBox(
"Load Face Normals");
644 layout->addWidget(loadFaceNormal_);
646 loadFaceColor_ =
new QCheckBox(
"Load Face Colors");
647 layout->addWidget(loadFaceColor_);
649 loadDefaultButton_ =
new QPushButton(
"Make Default");
650 layout->addWidget(loadDefaultButton_);
652 loadOptions_->setLayout(layout);
654 connect(loadDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotLoadDefault()));
657 triMeshHandling_->setCurrentIndex(
OpenFlipperSettings().value(
"FilePLY/Load/TriMeshHandling",TYPEAUTODETECT).toInt() );
659 loadVertexNormal_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Load/Normals",
true).toBool() );
660 loadVertexColor_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Load/VertexColor",
true).toBool() );
661 loadVertexTexCoord_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Load/TexCoords",
true).toBool() );
662 loadFaceNormal_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Load/FaceNormal",
true).toBool() );
663 loadFaceColor_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Load/FaceColor",
true).toBool() );
692 #if QT_VERSION < 0x050000
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
MeshT * mesh()
return a pointer to the mesh
Type for a Meshobject containing a poly mesh.
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
Has (r) / store (w) vertex normals.
QString filename() const
return the filename of the object
Type for a MeshObject containing a triangle mesh.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
Has (r) / store (w) face normals.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
Has (r) / store (w) face colors.
bool dataType(DataType _type) const
Has (r) / store (w) texture coordinates.
Set options for reader/writer modules.
void handleTrimeshDialog()
Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
DrawMode POINTS
draw unlighted points using the default base color
void initializePlugin()
Initialize Plugin.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
int loadTriMeshObject(QString _filename, OpenMesh::IO::Options &_opt)
Loads a triangle mesh.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void update_normals()
Compute normals for all primitives.
Kernel::FaceVertexIter FaceVertexIter
Circulator.
int objectCount()
Get the number of available objects.
Has (r) / store (w) vertex colors.
int loadPolyMeshObject(QString _filename, OpenMesh::IO::Options &_opt)
Always loads mesh as polymesh.
FilePLYPlugin()
Constructor.
QWidget * loadOptionsWidget(QString)
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.
Has (r) custom properties (currently only implemented in PLY Reader ASCII version) ...
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
void backupTextureCoordinates(MeshT &_mesh)
creates a backup of the original per vertex/face texture coordinates
#define DATA_TRIANGLE_MESH
QWidget * saveOptionsWidget(QString)