Skip to content

Commit

Permalink
add new app ros-map-yaml2mrpt
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Jul 7, 2022
1 parent 84f00ee commit 61420a1
Show file tree
Hide file tree
Showing 52 changed files with 288 additions and 44 deletions.
16 changes: 16 additions & 0 deletions apps/ros-map-yaml2mrpt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

project(ros-map-yaml2mrpt)

# Define the executable target:
add_executable(${PROJECT_NAME}
ros-map-yaml2mrpt.cpp
${MRPT_VERSION_RC_FILE})

# Add the required libraries for linking:

# Dependencies on MRPT libraries:
# Just mention the top-level dependency, the rest will be detected automatically,
# and all the needed #include<> dirs added (see the script DeclareAppDependencies.cmake for further details)
DeclareAppDependencies(${PROJECT_NAME} mrpt::maps mrpt::tclap)

DeclareAppForInstall(${PROJECT_NAME})
134 changes: 134 additions & 0 deletions apps/ros-map-yaml2mrpt/ros-map-yaml2mrpt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| https://www.mrpt.org/ |
| |
| Copyright (c) 2005-2022, Individual contributors, see AUTHORS file |
| See: https://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See: https://www.mrpt.org/License |
+------------------------------------------------------------------------+ */

#include <mrpt/3rdparty/tclap/CmdLine.h>
#include <mrpt/io/CFileGZInputStream.h>
#include <mrpt/io/CFileGZOutputStream.h>
#include <mrpt/maps/COccupancyGridMap2D.h>
#include <mrpt/opengl/COpenGLScene.h>
#include <mrpt/serialization/CArchive.h>
#include <mrpt/system/filesystem.h>
#include <mrpt/system/os.h>

int main(int argc, char** argv)
{
try
{
// Declare the supported command line switches ===========
TCLAP::CmdLine cmd(
"ros-map-yaml2mrpt", ' ', mrpt::system::MRPT_getVersion().c_str());

TCLAP::ValueArg<std::string> argInputFile(
"i", "input", "Input map yaml file (required) (*.yaml)", true,
"<map.yaml>", "map.yaml", cmd);

TCLAP::ValueArg<std::string> argOutputDirectory(
"d", "output-directory",
"If provided, output files will be written to the specified "
"directory, instead of the same directory of the input file, which "
"is the default behavior. The output directory must exist, it will "
"not be created.",
false, "", ".", cmd);

TCLAP::SwitchArg argOverwrite(
"w", "overwrite", "Force overwrite target file without prompting.",
cmd, false);

TCLAP::SwitchArg argQuiet(
"q", "quiet",
"Do not print info messages to cout, only errors to cerr", cmd,
false);

TCLAP::SwitchArg argGenerate3D(
"", "generate-3d",
"Create a .3Dscene view of the gridmap, suitable for quick "
"visualization in the SceneViewer3D program.",
cmd, false);

if (!argQuiet.isSet())
{
printf( //
" ros-map-yaml2mrpt - Part of %s\n"
"------------------------------------------------------------"
"\n",
mrpt::system::MRPT_getVersion().c_str());
}

// Parse arguments:
if (!cmd.parse(argc, argv))
throw std::runtime_error(""); // should exit.

const std::string inputFile = argInputFile.getValue();

const auto grid =
mrpt::maps::COccupancyGridMap2D::FromROSMapServerYAML(inputFile);

const std::string outDir = argOutputDirectory.isSet()
? argOutputDirectory.getValue()
: mrpt::system::extractFileDirectory(inputFile);

const std::string outGridFil = mrpt::system::pathJoin(
{outDir,
mrpt::system::fileNameChangeExtension(inputFile, "gridmap.gz")});

std::string out3D;
if (argGenerate3D.isSet())
{
out3D = mrpt::system::pathJoin(
{outDir,
mrpt::system::fileNameChangeExtension(inputFile, "3Dscene")});
}

if (!argQuiet.isSet())
{
std::cout << "Input file : " << inputFile << "\n";
std::cout << "Output gridmap : " << outGridFil << std::endl;
if (!out3D.empty())
std::cout << "Output 3D view : " << out3D << std::endl;
}

if (mrpt::system::fileExists(outGridFil) && !argOverwrite.isSet())
{
std::cerr << "Output gridmap file already exists, aborting. Use "
"`-w` flag "
"to overwrite."
<< std::endl;
return 1;
}
if (mrpt::system::fileExists(out3D) && !argOverwrite.isSet())
{
std::cerr
<< "Output 3D file already exists, aborting. Use `-w` flag "
"to overwrite."
<< std::endl;
return 1;
}

{
mrpt::io::CFileGZOutputStream f(outGridFil);
mrpt::serialization::archiveFrom(f) << grid;
}

if (!out3D.empty())
{
mrpt::opengl ::COpenGLScene scene;
scene.insert(grid.getVisualization());
scene.saveToFile(out3D);
}

std::cout << "All done.\n";

return 0;
}
catch (const std::exception& e)
{
std::cerr << mrpt::exception_to_str(e) << std::endl;
return 1;
}
}
1 change: 1 addition & 0 deletions doc/man-pages/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ if (PROG_GZIP AND PROG_POD2MAN)
CREATE_MANPAGE_PROJECT(rosbag2rawlog)
CREATE_MANPAGE_PROJECT(mrpt-performance)
CREATE_MANPAGE_PROJECT(3d-rotation-converter)
CREATE_MANPAGE_PROJECT(ros-map-yaml2mrpt)

endif()
2 changes: 1 addition & 1 deletion doc/man-pages/pod/2d-slam-demo.pod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/3d-rotation-converter.pod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/DifOdometry-Camera.pod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/DifOdometry-Datasets.pod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/GridmapNavSimul.pod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/RawLogViewer.pod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/ReactiveNav3D-Demo.pod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/ReactiveNavigationDemo.pod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/SceneViewer3D.pod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/benchmarking-image-features.pod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/benchmarkingImageFeatures_GUI.pod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/camera-calib.pod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/carmen2rawlog.pod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/carmen2simplemap.pod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/features-matching.pod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/grid-matching.pod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/hmt-slam-gui.pod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/hmt-slam.pod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/hmtMapViewer.pod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/holonomic-navigator-demo.pod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/icp-slam-live.pod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/icp-slam.pod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/image2gridmap.pod
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/ini2yaml.pod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/kf-slam.pod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
2 changes: 1 addition & 1 deletion doc/man-pages/pod/map-partition.pod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Please report bugs at https://github.com/MRPT/mrpt/issues

=head1 SEE ALSO

The application wiki page at https://www.mrpt.org/Applications
The application list and their documentation: https://docs.mrpt.org/reference/latest/applications.html

=head1 AUTHORS

Expand Down
Loading

0 comments on commit 61420a1

Please sign in to comment.