32 #include <QtGui/QPainter> 33 #include <QtGui/QImageWriter> 34 #include <QtGui/QApplication> 35 #include <QtCore/QFile> 37 #include <QtCore/QTime> 38 #include <QtCore/QTextStream> 44 : useCheckerboardCache(useCheckerboardCacheIn)
45 , use_utc_time_suffix_(true)
72 QTime now (QTime::currentTime());
73 std::string current_time_string = now.toString(Qt::ISODate).toStdString();
92 resolution =
static_cast<float>(map.info.resolution);
93 origin = Eigen::Vector2f(map.info.origin.position.x, map.info.origin.position.y);
102 maxCoordsMap = Eigen::Vector2i(map.info.width, map.info.height);
105 ROS_INFO(
"Cannot determine map extends!");
148 Eigen::Vector2f p1_w (Eigen::Vector2f::Zero());
149 Eigen::Vector2f p2_w (Eigen::Vector2f(100.0
f, 100.0
f));
173 QPainter qPainter(&
image);
176 QBrush c1 = QBrush(QColor(226, 226, 227));
177 QBrush c2 = QBrush(QColor(237, 237, 238));
178 QRectF background_grid_tile(0.0
f, 0.0
f, pixelsPerGeoTiffMeter, pixelsPerGeoTiffMeter);
181 int xMaxGeo = geoTiffSizePixels[0];
182 int yMaxGeo = geoTiffSizePixels[1];
184 for (
int y = 0; y < yMaxGeo; ++y){
185 for (
int x = 0; x < xMaxGeo; ++x){
188 if ((x + y) % 2 == 0) {
190 qPainter.fillRect(static_cast<float>(x)*pixelsPerGeoTiffMeter,static_cast<float>(y)*pixelsPerGeoTiffMeter,pixelsPerGeoTiffMeter,pixelsPerGeoTiffMeter, c1);
194 qPainter.fillRect(static_cast<float>(x)*pixelsPerGeoTiffMeter,static_cast<float>(y)*pixelsPerGeoTiffMeter,pixelsPerGeoTiffMeter,pixelsPerGeoTiffMeter, c2);
209 bool painter_rotate =
true;
216 image = QImage(yMaxGeo, xMaxGeo, QImage::Format_RGB32);
218 image = QImage(xMaxGeo, yMaxGeo, QImage::Format_RGB32);
221 QPainter qPainter(&
image);
223 QBrush grey = QBrush(QColor(128, 128, 128));
225 qPainter.fillRect(
image.rect(), grey);
235 bool painter_rotate =
true;
239 QPainter qPainter(&
image);
246 QBrush c1 = QBrush(QColor(226, 226, 227));
247 QBrush c2 = QBrush(QColor(237, 237, 238));
252 for (
int y = 0; y < yMaxGeo; ++y){
253 for (
int x = 0; x < xMaxGeo; ++x){
256 if ((x + y) % 2 == 0) {
258 qPainter.fillRect(static_cast<float>(x)*
pixelsPerGeoTiffMeter,static_cast<float>(y)*pixelsPerGeoTiffMeter,pixelsPerGeoTiffMeter,pixelsPerGeoTiffMeter, c1);
262 qPainter.fillRect(static_cast<float>(x)*
pixelsPerGeoTiffMeter,static_cast<float>(y)*pixelsPerGeoTiffMeter,pixelsPerGeoTiffMeter,pixelsPerGeoTiffMeter, c2);
274 QPainter qPainter(&
image);
282 QBrush occupied_brush(QColor(0, 40, 120));
283 QBrush free_brush(QColor(255, 255, 255));
284 QBrush explored_space_grid_brush(QColor(190,190,191));
286 int width = map.info.width;
291 float currYLimit = 0.0f;
299 if(yGeo >= currYLimit ){
303 float currXLimit = 0.0f;
306 for (
int x =
minCoordsMap[0] ; x < maxCoordsMap[0]; ++x){
308 unsigned int i = y*width + x;
310 int8_t data = map.data[i];
312 if (xGeo >= currXLimit){
322 if (draw_explored_space_grid){
332 }
else if(data == 100){
337 currXLimit += explored_space_grid_resolution_pixels;
346 currYLimit += explored_space_grid_resolution_pixels;
355 QPainter qPainter(&
image);
366 qPainter.translate(coords_g[0],coords_g[1]);
370 qPainter.setRenderHint(QPainter::Antialiasing,
true);
374 QRectF ellipse_shape( - radius, - radius, radius*2.0
f, radius*2.0f);
378 QBrush tmpBrush(QColor(color.
r,color.
g,color.
b));
379 QPen tmpPen(Qt::NoPen);
380 qPainter.setBrush(tmpBrush);
381 qPainter.setPen(tmpPen);
383 qPainter.drawEllipse(ellipse_shape);
387 QString tmp (txt.c_str());
390 if (tmp.length() < 2){
395 qPainter.setFont(tmp_font);
400 qPainter.setPen(Qt::white);
401 qPainter.scale(-1.0,1.0);
403 qPainter.drawText(ellipse_shape,Qt::AlignCenter , tmp);
406 void GeotiffWriter::drawPath(
const Eigen::Vector3f& start,
const std::vector<Eigen::Vector2f>& points,
int color_r,
int color_g,
int color_b)
408 QPainter qPainter(&
image);
416 size_t size = points.size();
419 polygon.reserve(size);
421 polygon.push_back(QPointF(start_geo.x(), start_geo.y()));
423 for (
size_t i = 0; i < size; ++i){
425 polygon.push_back(QPointF(vec.x(), vec.y()));
428 QPen pen(qPainter.pen());
429 pen.setColor(QColor(color_r, color_g, color_b));
432 qPainter.setPen(pen);
437 qPainter.drawPolyline(polygon);
440 qPainter.translate(start_geo.x(), start_geo.y());
441 qPainter.rotate(start.z());
442 qPainter.setRenderHint(QPainter::Antialiasing,
true);
461 QImageWriter imageWriter(QString::fromStdString(complete_file_string));
462 imageWriter.setCompression(1);
464 bool success = imageWriter.write(
image);
467 QFile tfwFile(QString::fromStdString(tfw_file_name));
469 tfwFile.open(QIODevice::WriteOnly);
471 QTextStream out(&tfwFile);
475 QString resolution_string;
476 resolution_string.setNum(resolution_geo,
'f',10);
479 out << resolution_string <<
"\n";
482 zero_string.setNum(0.0
f,
'f', 10);
485 out << zero_string <<
"\n" << zero_string <<
"\n";
488 out <<
"-" << resolution_string <<
"\n";
490 QString top_left_string_x;
491 QString top_left_string_y;
497 top_left_string_x.setNum(-zero_geo_w.y(),
'f',10);
498 top_left_string_y.setNum(zero_geo_w.x(),
'f',10);
500 out << top_left_string_x <<
"\n" << top_left_string_y <<
"\n";
505 ROS_INFO(
"Writing image with file %s failed with error %s", complete_file_string.c_str(), imageWriter.errorString().toStdString().c_str());
507 ROS_INFO(
"Successfully wrote geotiff to %s", complete_file_string.c_str());
515 painter.scale(1.0,-1.0);
520 QPainter qPainter(&
image);
526 qPainter.setPen(QColor(0, 50, 140));
528 qPainter.drawLine(pixelsPerGeoTiffMeter * 2 / 5, pixelsPerGeoTiffMeter - 1, pixelsPerGeoTiffMeter * 3 / 5, pixelsPerGeoTiffMeter - 1);
529 qPainter.drawLine(pixelsPerGeoTiffMeter * 2 / 5, 2 * pixelsPerGeoTiffMeter, pixelsPerGeoTiffMeter * 3 / 5, 2 * pixelsPerGeoTiffMeter);
533 qPainter.drawLine(pixelsPerGeoTiffMeter, 2 * pixelsPerGeoTiffMeter, 2 * pixelsPerGeoTiffMeter, 2 * pixelsPerGeoTiffMeter);
534 qPainter.drawLine(pixelsPerGeoTiffMeter, 2 * pixelsPerGeoTiffMeter, pixelsPerGeoTiffMeter + arrowOffset, 2 * pixelsPerGeoTiffMeter - arrowOffset);
535 qPainter.drawLine(pixelsPerGeoTiffMeter, 2 * pixelsPerGeoTiffMeter, pixelsPerGeoTiffMeter + arrowOffset, 2 * pixelsPerGeoTiffMeter + arrowOffset);
537 qPainter.drawLine(2 * pixelsPerGeoTiffMeter, pixelsPerGeoTiffMeter, 2 * pixelsPerGeoTiffMeter, 2 * pixelsPerGeoTiffMeter);
538 qPainter.drawLine(2 * pixelsPerGeoTiffMeter, pixelsPerGeoTiffMeter, 2 * pixelsPerGeoTiffMeter + arrowOffset, pixelsPerGeoTiffMeter + arrowOffset);
539 qPainter.drawLine(2 * pixelsPerGeoTiffMeter, pixelsPerGeoTiffMeter, 2 * pixelsPerGeoTiffMeter - arrowOffset, pixelsPerGeoTiffMeter + arrowOffset);
541 qPainter.drawText(0.6 * pixelsPerGeoTiffMeter, 1.6 * pixelsPerGeoTiffMeter, QString(
"1m"));
543 qPainter.drawText(2.2 * pixelsPerGeoTiffMeter, 1.1 * pixelsPerGeoTiffMeter, QString(
"x"));
544 qPainter.drawText(1.2 * pixelsPerGeoTiffMeter, 1.8 * pixelsPerGeoTiffMeter, QString(
"y"));
546 qPainter.drawText (0.5
f*pixelsPerGeoTiffMeter,0.75
f*pixelsPerGeoTiffMeter, QString((
map_file_name_ +
".tif").c_str()));
551 painter.drawLine(QPointF(coords[0]-1.0
f, coords[1]), QPointF(coords[0]+1.0
f, coords[1]));
552 painter.drawLine(QPointF(coords[0] , coords[1]-1.0
f), QPointF(coords[0], coords[1]+1.0
f));
561 polygon << QPointF(tip_distance, 0.0
f) << QPointF(-tip_distance*0.5
f, -tip_distance*0.5f) << QPointF(0.0f, 0.0f) << QPointF(-tip_distance*0.5f, tip_distance*0.5f);
565 QBrush tmpBrush(QColor(255,200,0));
566 QPen tmpPen(Qt::NoPen);
567 painter.setBrush(tmpBrush);
568 painter.setPen(tmpPen);
570 painter.drawPolygon(polygon);
578 QPointF zero_point (0.0
f, 0.0
f);
582 QPen tmp = painter.pen();
584 tmp.setColor(QColor(255.0,0.0,0.0));
587 painter.drawLine(zero_point,x_point);
589 tmp.setColor(QColor(0,255,0));
591 painter.drawLine(zero_point,y_point);
Eigen::Vector2f rightBottomMarginPixelsf
float pixelsPerGeoTiffMeter
HectorMapTools::CoordinateTransformer< float > world_map_transformer_
bool useCheckerboardCache
void drawMap(const nav_msgs::OccupancyGrid &map, bool draw_explored_space_grid=true)
Eigen::Vector2f mapEndInGeotiff
Eigen::Vector2f leftTopMarginMeters
GeotiffWriter(bool useCheckerboardCacheIn=false)
void setUseUtcTimeSuffix(bool useSuffix)
void drawCross(QPainter &painter, const Eigen::Vector2f &coords)
Eigen::Vector2i rightBottomMarginPixels
virtual void drawPath(const Eigen::Vector3f &start, const std::vector< Eigen::Vector2f > &points)
void drawObjectOfInterest(const Eigen::Vector2f &coords, const std::string &txt, const Color &color)
std::string map_file_name_
Eigen::Vector2f mapOrigInGeotiff
bool setupTransforms(const nav_msgs::OccupancyGrid &map)
Eigen::Vector2f rightBottomMarginMeters
Eigen::Vector2i minCoordsMap
void drawCoordSystem(QPainter &painter)
void setMapFilePath(const std::string &mapFilePath)
std::string getBasePathAndFileName() const
nav_msgs::MapMetaData cached_map_meta_data_
void setMapFileName(const std::string &mapFileName)
void drawArrow(QPainter &painter)
bool use_utc_time_suffix_
std::string map_file_path_
void transformPainterToImgCoords(QPainter &painter)
void drawBackgroundCheckerboard()
Eigen::Vector2i maxCoordsMap
Eigen::Vector2f totalMeters
HectorMapTools::CoordinateTransformer< float > world_geo_transformer_
QImage checkerboard_cache
HectorMapTools::CoordinateTransformer< float > map_geo_transformer_
Eigen::Vector2i geoTiffSizePixels