Skip to content

Commit

Permalink
allow to save candidate faces into an obj file
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Feb 14, 2024
1 parent dbcef0d commit 9b8db06
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 30 deletions.
83 changes: 68 additions & 15 deletions code/PolyFit/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <QProgressBar>
#include <QMimeData>
#include <QComboBox>
#include <QMenu>

#include "main_window.h"
#include "paint_canvas.h"
Expand Down Expand Up @@ -190,7 +191,36 @@ void MainWindow::dropEvent(QDropEvent *e) {

void MainWindow::createActions() {
connect(actionOpen, SIGNAL(triggered()), this, SLOT(open()));
connect(actionSave, SIGNAL(triggered()), this, SLOT(save()));

// ------------------------------------------------------

// actions for save
QAction* actionSaveReconstruction = new QAction(this);
actionSaveReconstruction->setText("Save reconstruction");
connect(actionSaveReconstruction, SIGNAL(triggered()), this, SLOT(saveReconstruction()));

QAction* actionSaveCandidateFaces = new QAction(this);
actionSaveCandidateFaces->setText("Save candidate faces");
connect(actionSaveCandidateFaces, SIGNAL(triggered()), this, SLOT(saveCandidateFaces()));

QMenu* saveMenu = new QMenu();
saveMenu->addAction(actionSaveReconstruction);
saveMenu->addSeparator();
saveMenu->addAction(actionSaveCandidateFaces);

QToolButton* saveToolButton = new QToolButton();
saveToolButton->setText("Save");
saveToolButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
saveToolButton->setMenu(saveMenu);
saveToolButton->setPopupMode(QToolButton::InstantPopup);
QIcon saveIcon;
saveIcon.addFile(QStringLiteral(":/Resources/filesave.png"), QSize(), QIcon::Normal, QIcon::Off);
saveToolButton->setIcon(saveIcon);

toolBarFile->insertWidget(actionSnapshot, saveToolButton);
toolBarFile->insertSeparator(actionSnapshot);

// ------------------------------------------------------

connect(actionSnapshot, SIGNAL(triggered()), this, SLOT(snapshotScreen()));

Expand Down Expand Up @@ -457,34 +487,57 @@ bool MainWindow::open()
}


bool MainWindow::save()
bool MainWindow::saveReconstruction()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save file"), optimizedMeshFileName_,
tr("Save the reconstruction result into an OBJ file"), optimizedMeshFileName_,
tr("Mesh (*.obj)")
);

if (fileName.isEmpty())
return false;

bool success = false;
std::string ext = FileUtils::extension(fileName.toStdString());
String::to_lowercase(ext);

if (ext == "obj")
success = MapIO::save(fileName.toStdString(), canvas()->optimizedMesh());
else
success = PointSetIO::save(fileName.toStdString(), canvas()->pointSet());

if (success) {
setCurrentFile(fileName);
status_message("File saved", 500);
return true;
if (ext == "obj") {
bool success = MapIO::save(fileName.toStdString(), canvas()->optimizedMesh());
if (success) {
setCurrentFile(fileName);
status_message("File saved", 500);
return true;
}
}
else {
status_message("Saving failed", 500);

status_message("Saving failed", 500);
return false;
}


bool MainWindow::saveCandidateFaces()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save candidate faces into an OBJ file"), optimizedMeshFileName_,
tr("Mesh (*.obj)")
);

if (fileName.isEmpty())
return false;

std::string ext = FileUtils::extension(fileName.toStdString());
String::to_lowercase(ext);

if (ext == "obj") {
bool success = MapIO::save(fileName.toStdString(), canvas()->hypothesisMesh());
if (success) {
setCurrentFile(fileName);
status_message("File saved", 500);
return true;
}
}

status_message("Saving failed", 500);
return false;
}


Expand Down
4 changes: 3 additions & 1 deletion code/PolyFit/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class MainWindow

public Q_SLOTS:
bool open();
bool save();
bool saveReconstruction();
bool saveCandidateFaces();

void updateStatusBar();

void snapshotScreen();
Expand Down
14 changes: 0 additions & 14 deletions code/PolyFit/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,6 @@
<bool>false</bool>
</attribute>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="separator"/>
<addaction name="actionSnapshot"/>
</widget>
<widget class="QToolBar" name="toolBar">
Expand Down Expand Up @@ -601,18 +599,6 @@
<string>Compute Point/Face Confidences</string>
</property>
</action>
<action name="actionSave">
<property name="icon">
<iconset resource="Resources/PolyFit.qrc">
<normaloff>:/Resources/filesave.png</normaloff>:/Resources/filesave.png</iconset>
</property>
<property name="text">
<string>Save</string>
</property>
<property name="iconText">
<string>Save</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>
Expand Down

0 comments on commit 9b8db06

Please sign in to comment.