50 #define TYPEAUTODETECT 0 53 #define TYPETRIANGLE 3 62 saveVertexTexCoord_(0),
65 savePrecisionLabel_(0),
67 saveDefaultButton_(0),
71 loadVertexTexCoord_(0),
74 loadDefaultButton_(0),
86 return QString( tr(
"Polygon File Format files ( *.ply )") );
92 return QString( tr(
"Polygon File Format files ( *.ply )") );
107 bool gui = OpenFlipper::Options::gui() && (loadVertexNormal_ != 0) ;
109 bool vNormals = ((gui && loadVertexNormal_->isChecked()) ||
111 bool vColors = ((gui && loadVertexColor_->isChecked()) ||
113 bool vTexCoords = ((gui && loadVertexTexCoord_->isChecked()) ||
115 bool fNormals = ((gui && loadFaceNormal_->isChecked()) ||
117 bool fColors = ((gui && loadFaceColor_->isChecked()) ||
140 emit openedFile( objectId );
154 emit openedFile( objectId );
160 emit log(
LOGERR, tr(
"FilePLYPlugin::loadObject(): Tried loading with unknown forced data type"));
170 int triMeshControl = TYPEAUTODETECT;
172 bool gui = OpenFlipper::Options::gui() && (loadVertexNormal_ != 0) ;
174 bool vNormals = ((gui && loadVertexNormal_->isChecked()) ||
176 bool vColors = ((gui && loadVertexColor_->isChecked()) ||
178 bool vTexCoords = ((gui && loadVertexTexCoord_->isChecked()) ||
180 bool fNormals = ((gui && loadFaceNormal_->isChecked()) ||
182 bool fColors = ((gui && loadFaceColor_->isChecked()) ||
198 if ( OpenFlipper::Options::gui() ){
199 if ( triMeshHandling_ != 0 ){
200 triMeshControl = triMeshHandling_->currentIndex();
202 triMeshControl = TYPEAUTODETECT;
209 if(triMeshControl == TYPEAUTODETECT || triMeshControl == TYPEASK) {
217 bool isTriMesh =
true;
218 for ( PolyMesh::FaceIter f_it = object->
mesh()->faces_begin(); f_it !=
object->mesh()->faces_end() && isTriMesh; ++f_it) {
226 isTriMesh = isTriMesh && (count == 3);
229 if (triMeshControl == TYPEAUTODETECT)
235 emit openedFile( objectId );
240 else if (triMeshControl == TYPEASK) {
243 QMetaObject::invokeMethod(
this,
"handleTrimeshDialog",Qt::BlockingQueuedConnection);
244 if ((trimeshOptions_ == TYPEPOLY) ||
245 (trimeshOptions_ == TYPEASK && !isTriMesh)) {
250 emit openedFile( objectId );
257 }
else if (triMeshControl == TYPEPOLY) {
265 emit openedFile( objectId );
277 emit openedFile( objectId );
286 if(objectId != -1) emit deleteObject(objectId);
292 emit openedFile( objectId );
301 QPushButton *detectButton = msgBox.addButton(tr(
"Auto-Detect"), QMessageBox::ActionRole);
302 QPushButton *triButton = msgBox.addButton(tr(
"Open as triangle mesh"), QMessageBox::ActionRole);
303 QPushButton *polyButton = msgBox.addButton(tr(
"Open as poly mesh"), QMessageBox::ActionRole);
304 msgBox.setWindowTitle( tr(
"Mesh types in file") );
305 msgBox.setText( tr(
"You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
306 msgBox.setDefaultButton( detectButton );
310 if (msgBox.clickedButton() == triButton)
311 trimeshOptions_ = TYPETRIANGLE ;
312 else if (msgBox.clickedButton() == polyButton)
313 trimeshOptions_ = TYPEPOLY ;
315 trimeshOptions_ = TYPEASK;
330 object->target(
true);
332 object->setFromFileName(_filename);
333 object->setName(object->
filename());
336 TriMesh* mesh =
object->mesh();
338 bool hadVNormals = mesh->has_vertex_normals();
339 bool hadVColors = mesh->has_vertex_colors();
340 bool hadVTexCoords = mesh->has_vertex_texcoords2D();
341 bool hadFNormals = mesh->has_face_normals();
342 bool hadFColors = mesh->has_face_colors();
344 if(_opt.vertex_has_normal())
345 mesh->request_vertex_normals();
346 if(_opt.vertex_has_color())
347 mesh->request_vertex_colors();
348 if(_opt.vertex_has_texcoord())
349 mesh->request_vertex_texcoords2D();
350 if(_opt.face_has_normal())
351 mesh->request_face_normals();
352 if(_opt.face_has_color())
353 mesh->request_face_colors();
358 emit log(
LOGERR,
"Error while reading PLY file!");
359 emit deleteObject(
id);
364 if (!_opt.vertex_has_normal() || !_opt.face_has_normal()) {
367 if (_opt.vertex_has_normal() ) {
369 emit log(
LOGINFO,
"Vertex normals loaded from file. Computing Face normals.");
371 std::cerr <<
"Update face normals" << std::endl;
374 emit log(
LOGINFO,
"File did not contain normals. Computing automatically.");
382 if (!hadVColors && !_opt.vertex_has_color() && mesh->has_vertex_colors())
383 mesh->release_vertex_colors();
384 if (!hadVTexCoords && !_opt.vertex_has_texcoord() && mesh->has_vertex_texcoords2D())
385 mesh->release_vertex_texcoords2D();
386 if (!hadFColors && !_opt.face_has_color() && mesh->has_face_colors())
387 mesh->release_face_colors();
390 if(mesh->n_faces() == 0)
398 emit log(
LOGERR,
"Error : Could not create new triangle mesh object.");
415 object->target(
true);
417 object->setFromFileName(_filename);
418 object->setName(object->
filename());
423 bool hadVNormals = mesh->has_vertex_normals();
424 bool hadVColors = mesh->has_vertex_colors();
425 bool hadVTexCoords = mesh->has_vertex_texcoords2D();
426 bool hadFNormals = mesh->has_face_normals();
427 bool hadFColors = mesh->has_face_colors();
429 if(_opt.vertex_has_normal())
430 mesh->request_vertex_normals();
431 if(_opt.vertex_has_color())
432 mesh->request_vertex_colors();
433 if(_opt.vertex_has_texcoord())
434 mesh->request_vertex_texcoords2D();
435 if(_opt.face_has_normal())
436 mesh->request_face_normals();
437 if(_opt.face_has_color())
438 mesh->request_face_colors();
443 emit log(
LOGERR,
"Error while reading PLY file!");
444 emit deleteObject(
id);
450 if (!_opt.vertex_has_normal() || !_opt.face_has_normal()) {
453 if (_opt.vertex_has_normal() ) {
455 emit log(
LOGINFO,
"Vertex normals loaded from file. Computing Face normals.");
457 std::cerr <<
"Update face normals" << std::endl;
460 emit log(
LOGINFO,
"File did not contain normals. Computing automatically.");
468 if (!hadVColors && !_opt.vertex_has_color() && mesh->has_vertex_colors())
469 mesh->release_vertex_colors();
470 if (!hadVTexCoords && !_opt.vertex_has_texcoord() && mesh->has_vertex_texcoords2D())
471 mesh->release_vertex_texcoords2D();
472 if (!hadFColors && !_opt.face_has_color() && mesh->has_face_colors())
473 mesh->release_face_colors();
477 if(mesh->n_faces() == 0)
485 emit log(
LOGERR,
"Error : Could not create new poly mesh object.");
494 bool FilePLYPlugin::saveObject(
int _id, QString _filename)
498 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
502 object->setFromFileName(_filename);
503 object->setName(object->
filename());
507 bool gui = OpenFlipper::Options::gui() && (saveBinary_ != 0) ;
508 bool binary = ((gui && saveBinary_->isChecked()) ||
514 bool vNormals = ((gui && saveVertexNormal_->isChecked())) ||
516 bool vColors = ((gui && saveVertexColor_->isChecked())) ||
518 bool vTexCoords = ((gui && saveVertexTexCoord_->isChecked())) ||
520 bool fNormals = ((gui && saveFaceNormal_->isChecked())) ||
522 bool fColors = ((gui && saveFaceColor_->isChecked())) ||
533 if (vNormals && mesh->has_vertex_normals())
535 if (vColors && mesh->has_vertex_colors())
537 if (vTexCoords && mesh->has_vertex_texcoords2D())
539 if (fNormals && mesh->has_face_normals())
541 if (fColors && mesh->has_face_colors())
551 if (vNormals && mesh->has_vertex_normals())
553 if (vColors && mesh->has_vertex_colors())
555 if (vTexCoords && mesh->has_vertex_texcoords2D())
557 if (fNormals && mesh->has_face_normals())
559 if (fColors && mesh->has_face_colors())
566 emit log(
LOGERR, tr(
"Unable to save ") + _filename);
570 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
578 if (saveOptions_ == 0){
580 saveOptions_ =
new QWidget();
581 QVBoxLayout* layout =
new QVBoxLayout();
582 layout->setAlignment(Qt::AlignTop);
584 saveBinary_ =
new QCheckBox(
"Save Binary");
585 layout->addWidget(saveBinary_);
587 saveVertexNormal_ =
new QCheckBox(
"Save Vertex Normals");
588 layout->addWidget(saveVertexNormal_);
590 saveVertexColor_ =
new QCheckBox(
"Save Vertex Colors");
591 layout->addWidget(saveVertexColor_);
593 saveVertexTexCoord_ =
new QCheckBox(
"Save Vertex TexCoords");
594 layout->addWidget(saveVertexTexCoord_);
596 saveFaceNormal_ =
new QCheckBox(
"Save Face Normals");
597 layout->addWidget(saveFaceNormal_);
599 saveFaceColor_ =
new QCheckBox(
"Save Face Colors");
600 layout->addWidget(saveFaceColor_);
602 savePrecisionLabel_ =
new QLabel(
"Writer Precision");
603 layout->addWidget(savePrecisionLabel_);
605 savePrecision_ =
new QSpinBox();
606 savePrecision_->setMinimum(1);
607 savePrecision_->setMaximum(12);
608 savePrecision_->setValue(6);
609 layout->addWidget(savePrecision_);
611 saveDefaultButton_ =
new QPushButton(
"Make Default");
612 layout->addWidget(saveDefaultButton_);
614 saveOptions_->setLayout(layout);
616 connect(saveBinary_, SIGNAL(clicked(
bool)), savePrecision_, SLOT(setDisabled(
bool)));
617 connect(saveDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotSaveDefault()));
619 saveBinary_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/Binary",
true).toBool() );
620 savePrecision_->setDisabled(
true);
621 saveVertexNormal_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/Normals",
true).toBool() );
622 saveVertexColor_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/VertexColor",
true).toBool() );
623 saveVertexTexCoord_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/TexCoords",
true).toBool() );
624 saveFaceNormal_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/FaceNormal",
true).toBool() );
625 saveFaceColor_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Save/FaceColor",
true).toBool() );
635 if (loadOptions_ == 0){
637 loadOptions_ =
new QWidget();
638 QVBoxLayout* layout =
new QVBoxLayout();
639 layout->setAlignment(Qt::AlignTop);
641 QLabel* label =
new QLabel(tr(
"If PolyMesh is a Triangle Mesh:"));
643 layout->addWidget(label);
645 triMeshHandling_ =
new QComboBox();
646 triMeshHandling_->addItem( tr(
"Auto-Detect") );
647 triMeshHandling_->addItem( tr(
"Ask") );
648 triMeshHandling_->addItem( tr(
"Always open as PolyMesh") );
649 triMeshHandling_->addItem( tr(
"Always open as TriangleMesh") );
651 layout->addWidget(triMeshHandling_);
653 loadVertexNormal_ =
new QCheckBox(
"Load Vertex Normals");
654 layout->addWidget(loadVertexNormal_);
656 loadVertexColor_ =
new QCheckBox(
"Load Vertex Colors");
657 layout->addWidget(loadVertexColor_);
659 loadVertexTexCoord_ =
new QCheckBox(
"Load Vertex TexCoords");
660 layout->addWidget(loadVertexTexCoord_);
662 loadFaceNormal_ =
new QCheckBox(
"Load Face Normals");
663 layout->addWidget(loadFaceNormal_);
665 loadFaceColor_ =
new QCheckBox(
"Load Face Colors");
666 layout->addWidget(loadFaceColor_);
668 loadDefaultButton_ =
new QPushButton(
"Make Default");
669 layout->addWidget(loadDefaultButton_);
671 loadOptions_->setLayout(layout);
673 connect(loadDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotLoadDefault()));
676 triMeshHandling_->setCurrentIndex(
OpenFlipperSettings().value(
"FilePLY/Load/TriMeshHandling",TYPEAUTODETECT).toInt() );
678 loadVertexNormal_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Load/Normals",
true).toBool() );
679 loadVertexColor_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Load/VertexColor",
true).toBool() );
680 loadVertexTexCoord_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Load/TexCoords",
true).toBool() );
681 loadFaceNormal_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Load/FaceNormal",
true).toBool() );
682 loadFaceColor_->setChecked(
OpenFlipperSettings().value(
"FilePLY/Load/FaceColor",
true).toBool() );
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
QWidget * loadOptionsWidget(QString)
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
#define DATA_TRIANGLE_MESH
int loadTriMeshObject(QString _filename, OpenMesh::IO::Options &_opt)
Loads a triangle mesh.
DataType supportedType()
Return your supported object type( e.g. 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.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
int loadPolyMeshObject(QString _filename, OpenMesh::IO::Options &_opt)
Always loads mesh as polymesh.
QString filename() const
return the filename of the object
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
MeshT * mesh()
return a pointer to the mesh
bool dataType(DataType _type) const
void handleTrimeshDialog()
Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
void initializePlugin()
Initialize Plugin.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Has (r) custom properties (currently only implemented in PLY Reader ASCII version) ...
Type for a MeshObject containing a triangle mesh.
DrawMode POINTS
draw unlighted points using the default base color
void update_normals()
Compute normals for all primitives.
QWidget * saveOptionsWidget(QString)
Set options for reader/writer modules.
void update_face_normals()
Update normal vectors for all faces.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
Has (r) / store (w) vertex normals.
Has (r) / store (w) face normals.
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.
FilePLYPlugin()
Constructor.
void backupTextureCoordinates(MeshT &_mesh)
creates a backup of the original per vertex/face texture coordinates
Has (r) / store (w) texture coordinates.