Skip to content

Commit

Permalink
GraphView: added right-click option to export 2d grid map directly fr…
Browse files Browse the repository at this point in the history
…om the view
  • Loading branch information
matlabbe committed Sep 7, 2023
1 parent e31eec2 commit 9e86faa
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions guilib/src/GraphViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,8 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event)
{
QMenu menu;
QAction * aScreenShot = menu.addAction(tr("Take a screenshot..."));
QAction * aExportGridMap = menu.addAction(tr("Export grid map..."));
aExportGridMap->setEnabled(!_gridMap->pixmap().isNull());
menu.addSeparator();

QAction * aChangeNodeColor = menu.addAction(createIcon(_nodeColor), tr("Set node color..."));
Expand Down Expand Up @@ -2095,6 +2097,48 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event)
}
return; // without emitting configChanged
}
else if(r == aExportGridMap)
{
float xMin, yMin, cellSize;

cellSize = _gridCellSize;
xMin = -_gridMap->y()/100.0f;
yMin = -_gridMap->x()/100.0f;

QString path = QFileDialog::getSaveFileName(
this,
tr("Save File"),
"map.pgm",
tr("Map (*.pgm)"));

if(!path.isEmpty())
{
if(QFileInfo(path).suffix() == "")
{
path += ".pgm";
}
_gridMap->pixmap().save(path);

QFileInfo info(path);
QString yaml = info.absolutePath() + "/" + info.baseName() + ".yaml";

float occupancyThr = Parameters::defaultGridGlobalOccupancyThr();

std::ofstream file;
file.open (yaml.toStdString());
file << "image: " << info.baseName().toStdString() << ".pgm" << std::endl;
file << "resolution: " << cellSize << std::endl;
file << "origin: [" << xMin << ", " << yMin << ", 0.0]" << std::endl;
file << "negate: 0" << std::endl;
file << "occupied_thresh: " << occupancyThr << std::endl;
file << "free_thresh: 0.196" << std::endl;
file << std::endl;
file.close();


QMessageBox::information(this, tr("Export 2D map"), tr("Exported %1 and %2!").arg(path).arg(yaml));
}
}
else if(r == aSetIntraInterSessionColors)
{
setIntraInterSessionColorsEnabled(aSetIntraInterSessionColors->isChecked());
Expand Down

0 comments on commit 9e86faa

Please sign in to comment.