geotiff_saver.cpp
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2011, Stefan Kohlbrecher, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Simulation, Systems Optimization and Robotics
13 // group, TU Darmstadt nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #include <cstdio>
30 #include "ros/ros.h"
31 #include "ros/console.h"
32 #include "nav_msgs/GetMap.h"
33 #include "geometry_msgs/Quaternion.h"
34 
35 #include <Eigen/Geometry>
36 
37 #include <QtGui/QApplication>
38 
40 
42 
43 using namespace std;
44 
45 namespace hector_geotiff{
46 
50 class MapGenerator
51 {
52  public:
53  MapGenerator(const std::string& mapname) : mapname_(mapname)
54  {
56  ROS_INFO("Waiting for the map");
57  map_sub_ = n.subscribe("map", 1, &MapGenerator::mapCallback, this);
58  }
59 
60  void mapCallback(const nav_msgs::OccupancyGridConstPtr& map)
61  {
62  ros::Time start_time (ros::Time::now());
63 
64  geotiff_writer.setMapFileName(mapname_);
65  geotiff_writer.setupTransforms(*map);
66  geotiff_writer.drawBackgroundCheckerboard();
67  geotiff_writer.drawMap(*map);
68  geotiff_writer.drawCoords();
69 
70  geotiff_writer.writeGeotiffImage();
71 
72  ros::Duration elapsed_time (ros::Time::now() - start_time);
73  ROS_INFO("GeoTiff created in %f seconds", elapsed_time.toSec());
74  }
75 
77 
78  std::string mapname_;
80 };
81 
82 }
83 
84 #define USAGE "Usage: \n" \
85  " geotiff_saver -h\n"\
86  " geotiff_saver [-f <mapname>] [ROS remapping args]"
87 
88 int main(int argc, char** argv)
89 {
90  ros::init(argc, argv, "map_saver");
91  std::string mapname = "map";
92 
93  for(int i=1; i<argc; i++)
94  {
95  if(!strcmp(argv[i], "-h"))
96  {
97  puts(USAGE);
98  return 0;
99  }
100  else if(!strcmp(argv[i], "-f"))
101  {
102  if(++i < argc)
103  mapname = argv[i];
104  else
105  {
106  puts(USAGE);
107  return 1;
108  }
109  }
110  else
111  {
112  puts(USAGE);
113  return 1;
114  }
115  }
116 
117  //GeotiffWriter geotiff_writer;
118  //geotiff_writer.setMapName("test");
119  hector_geotiff::MapGenerator mg(mapname);
120 
121  ros::spin();
122 
123  return 0;
124 }
125 
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define ROS_INFO(...)
ROSCPP_DECL void spin()
void mapCallback(const nav_msgs::OccupancyGridConstPtr &map)
static Time now()
int main(int argc, char **argv)
MapGenerator(const std::string &mapname)
Map generation node.
#define USAGE


hector_geotiff
Author(s): Stefan Kohlbrecher
autogenerated on Sun Nov 3 2019 03:18:38