From 2640ee03b67c83c94edb3e786942bf406b0f8d98 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 28 May 2024 09:31:25 +0000 Subject: [PATCH] style(pre-commit): autofix --- .../CMakeLists.txt | 10 +- .../demo/demo.launch.xml | 10 +- .../demo/publish_demo_data | 8 +- .../package.xml | 2 +- .../src/include/minimap.hpp | 6 +- .../src/include/overlay_utils.hpp | 33 ++-- .../src/include/tile.hpp | 18 +- .../src/include/tile_field.hpp | 13 +- .../src/overlay_utils.cpp | 177 ++++++++++-------- .../src/tile.cpp | 2 +- .../src/tile_field.cpp | 94 +++++----- 11 files changed, 200 insertions(+), 173 deletions(-) diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/CMakeLists.txt b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/CMakeLists.txt index f3161082925b5..410b3280d1cd0 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/CMakeLists.txt +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/CMakeLists.txt @@ -31,7 +31,7 @@ set( src/include/minimap.hpp src/include/tile.hpp src/include/tile_field.hpp - src/include/overlay_utils.hpp + src/include/overlay_utils.hpp ) foreach(header "${headers_to_moc}") @@ -59,7 +59,7 @@ target_compile_options( "-DVEHICLEMAP_VERSION=\"${vehicle_map_VERSION}\"" ) -target_include_directories(${PROJECT_NAME} +target_include_directories(${PROJECT_NAME} PRIVATE src PRIVATE /usr/include/x86_64-linux-gnu/qt5 PRIVATE ${OGRE_INCLUDE_DIRS} @@ -67,9 +67,9 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${rviz_default_plugins_INCLUDE_DIRS} ) -target_link_libraries(${PROJECT_NAME} - Qt5::Network - Qt5::Widgets +target_link_libraries(${PROJECT_NAME} + Qt5::Network + Qt5::Widgets ${OGRE_LIBRARIES} ${rviz_common_LIBRARIES} ${rviz_default_plugins_LIBRARIES} diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/demo/demo.launch.xml b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/demo/demo.launch.xml index c069726394c74..fefdc4569a256 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/demo/demo.launch.xml +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/demo/demo.launch.xml @@ -1,12 +1,10 @@ - - - - + - - + + + diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/demo/publish_demo_data b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/demo/publish_demo_data index de4aa43d86f4a..57188ae2f0618 100755 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/demo/publish_demo_data +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/demo/publish_demo_data @@ -2,12 +2,14 @@ """ Periodically publish gps positions in a circle around a given origin as NavSatFix messages. """ -import rclpy +from argparse import ArgumentParser import math + import numpy as np -from argparse import ArgumentParser +import rclpy from rclpy.time import CONVERSION_CONSTANT -from sensor_msgs.msg import NavSatFix, NavSatStatus +from sensor_msgs.msg import NavSatFix +from sensor_msgs.msg import NavSatStatus class CircularTranslate: diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/package.xml b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/package.xml index 59b667189f57f..a625f6a3c4a15 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/package.xml +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/package.xml @@ -7,13 +7,13 @@ khalil TODO: License declaration + angles rclcpp rcpputils rviz_common rviz_default_plugins sensor_msgs tf2_ros - angles qtbase5-dev ament_cmake_auto diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/minimap.hpp b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/minimap.hpp index 90196c8508a8e..93cc3a2a0a0de 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/minimap.hpp +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/minimap.hpp @@ -1,5 +1,5 @@ -#ifndef MINIMAP_H -#define MINIMAP_H +#ifndef MINIMAP_HPP_ +#define MINIMAP_HPP_ #include "overlay_utils.hpp" #include "rviz_common/properties/color_property.hpp" @@ -92,4 +92,4 @@ protected Q_SLOTS: } // namespace autoware_minimap_overlay_rviz_plugin -#endif // MINIMAP_H +#endif // MINIMAP_HPP_ diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/overlay_utils.hpp b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/overlay_utils.hpp index 90aa61d1c6cd4..9e28d989ee2ee 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/overlay_utils.hpp +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/overlay_utils.hpp @@ -68,19 +68,20 @@ #include #include -namespace rviz_satellite { +namespace rviz_satellite +{ class OverlayObject; -class ScopedPixelBuffer { +class ScopedPixelBuffer +{ public: explicit ScopedPixelBuffer(Ogre::HardwarePixelBufferSharedPtr pixel_buffer); virtual ~ScopedPixelBuffer(); virtual Ogre::HardwarePixelBufferSharedPtr getPixelBuffer(); virtual QImage getQImage(unsigned int width, unsigned int height); - virtual QImage getQImage(OverlayObject &overlay); - virtual QImage getQImage(unsigned int width, unsigned int height, - QColor &bg_color); - virtual QImage getQImage(OverlayObject &overlay, QColor &bg_color); + virtual QImage getQImage(OverlayObject & overlay); + virtual QImage getQImage(unsigned int width, unsigned int height, QColor & bg_color); + virtual QImage getQImage(OverlayObject & overlay, QColor & bg_color); protected: Ogre::HardwarePixelBufferSharedPtr pixel_buffer_; @@ -96,11 +97,12 @@ enum class HorizontalAlignment : uint8_t { LEFT, RIGHT, CENTER }; * This class is supposed to be instantiated in the onInitialize method of the * rviz_common::Display class. */ -class OverlayObject { +class OverlayObject +{ public: using SharedPtr = std::shared_ptr; - explicit OverlayObject(const std::string &name); + explicit OverlayObject(const std::string & name); virtual ~OverlayObject(); virtual std::string getName() const; @@ -109,10 +111,9 @@ class OverlayObject { virtual bool isTextureReady() const; virtual void updateTextureSize(unsigned int width, unsigned int height); virtual ScopedPixelBuffer getBuffer(); - virtual void - setPosition(double hor_dist, double ver_dist, - HorizontalAlignment hor_alignment = HorizontalAlignment::LEFT, - VerticalAlignment ver_alignment = VerticalAlignment::TOP); + virtual void setPosition( + double hor_dist, double ver_dist, HorizontalAlignment hor_alignment = HorizontalAlignment::LEFT, + VerticalAlignment ver_alignment = VerticalAlignment::TOP); virtual void setDimensions(double width, double height); virtual bool isVisible() const; virtual unsigned int getTextureWidth() const; @@ -120,11 +121,11 @@ class OverlayObject { protected: const std::string name_; - Ogre::Overlay *overlay_; - Ogre::PanelOverlayElement *panel_; + Ogre::Overlay * overlay_; + Ogre::PanelOverlayElement * panel_; Ogre::MaterialPtr panel_material_; Ogre::TexturePtr texture_; }; -} // namespace rviz_satellite +} // namespace rviz_satellite -#endif // OVERLAY_UTILS_HPP_ +#endif // OVERLAY_UTILS_HPP_ diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/tile.hpp b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/tile.hpp index 18b261b73c562..db7265a7be521 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/tile.hpp +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/tile.hpp @@ -1,21 +1,23 @@ -#ifndef TILE_HPP -#define TILE_HPP +#ifndef TILE_HPP_ +#define TILE_HPP_ #include #include #include #include + #include -class Tile : public QObject { +class Tile : public QObject +{ Q_OBJECT public: - Tile(int zoom, int x, int y, QObject *parent = nullptr); + Tile(int zoom, int x, int y, QObject * parent = nullptr); ~Tile(); void fetch(); QImage getImage() const; - bool isValidUrl(const std::string &url) const; + bool isValidUrl(const std::string & url) const; int getZoom() const { return zoom_; } int getX() const { return x_; } @@ -25,7 +27,7 @@ class Tile : public QObject { void tileFetched(); private Q_SLOTS: - void onTileFetched(QNetworkReply *reply); + void onTileFetched(QNetworkReply * reply); private: int zoom_; @@ -33,11 +35,11 @@ private Q_SLOTS: int y_; std::string last_url_; QImage image_; - QNetworkAccessManager *network_manager_; + QNetworkAccessManager * network_manager_; std::promise tile_promise_; std::future requestRemote(); }; -#endif // TILE_HPP \ No newline at end of file +#endif // TILE_HPP_ diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/tile_field.hpp b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/tile_field.hpp index cc8c8a0adc5c2..e3bf35a0fa2a5 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/tile_field.hpp +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/include/tile_field.hpp @@ -1,20 +1,23 @@ -#ifndef TILE_FIELD_HPP -#define TILE_FIELD_HPP +#ifndef TILE_FIELD_HPP_ +#define TILE_FIELD_HPP_ #include "tile.hpp" + #include #include + #include #include #include #include #include -class TileField : public QObject { +class TileField : public QObject +{ Q_OBJECT public: - TileField(QObject *parent = nullptr); + TileField(QObject * parent = nullptr); ~TileField(); void initializeTiles(int center_x_tile, int center_y_tile); @@ -44,4 +47,4 @@ private Q_SLOTS: std::mutex tile_mutex_; }; -#endif // TILE_FIELD_HPP +#endif // TILE_FIELD_HPP_ diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/overlay_utils.cpp b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/overlay_utils.cpp index 3d8b246ee273d..15249872c9442 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/overlay_utils.cpp +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/overlay_utils.cpp @@ -52,28 +52,34 @@ #include -namespace rviz_satellite { -ScopedPixelBuffer::ScopedPixelBuffer( - Ogre::HardwarePixelBufferSharedPtr pixel_buffer) - : pixel_buffer_(pixel_buffer) { +namespace rviz_satellite +{ +ScopedPixelBuffer::ScopedPixelBuffer(Ogre::HardwarePixelBufferSharedPtr pixel_buffer) +: pixel_buffer_(pixel_buffer) +{ pixel_buffer_->lock(Ogre::HardwareBuffer::HBL_NORMAL); } -ScopedPixelBuffer::~ScopedPixelBuffer() { pixel_buffer_->unlock(); } +ScopedPixelBuffer::~ScopedPixelBuffer() +{ + pixel_buffer_->unlock(); +} -Ogre::HardwarePixelBufferSharedPtr ScopedPixelBuffer::getPixelBuffer() { +Ogre::HardwarePixelBufferSharedPtr ScopedPixelBuffer::getPixelBuffer() +{ return pixel_buffer_; } -QImage ScopedPixelBuffer::getQImage(unsigned int width, unsigned int height) { - const Ogre::PixelBox &pixelBox = pixel_buffer_->getCurrentLock(); - Ogre::uint8 *pDest = static_cast(pixelBox.data); +QImage ScopedPixelBuffer::getQImage(unsigned int width, unsigned int height) +{ + const Ogre::PixelBox & pixelBox = pixel_buffer_->getCurrentLock(); + Ogre::uint8 * pDest = static_cast(pixelBox.data); memset(pDest, 0, width * height); return QImage(pDest, width, height, QImage::Format_ARGB32); } -QImage ScopedPixelBuffer::getQImage(unsigned int width, unsigned int height, - QColor &bg_color) { +QImage ScopedPixelBuffer::getQImage(unsigned int width, unsigned int height, QColor & bg_color) +{ QImage Hud = getQImage(width, height); for (unsigned int i = 0; i < width; i++) { for (unsigned int j = 0; j < height; j++) { @@ -83,31 +89,34 @@ QImage ScopedPixelBuffer::getQImage(unsigned int width, unsigned int height, return Hud; } -QImage ScopedPixelBuffer::getQImage(OverlayObject &overlay) { +QImage ScopedPixelBuffer::getQImage(OverlayObject & overlay) +{ return getQImage(overlay.getTextureWidth(), overlay.getTextureHeight()); } -QImage ScopedPixelBuffer::getQImage(OverlayObject &overlay, QColor &bg_color) { - return getQImage(overlay.getTextureWidth(), overlay.getTextureHeight(), - bg_color); +QImage ScopedPixelBuffer::getQImage(OverlayObject & overlay, QColor & bg_color) +{ + return getQImage(overlay.getTextureWidth(), overlay.getTextureHeight(), bg_color); } -OverlayObject::OverlayObject(const std::string &name) : name_(name) { +OverlayObject::OverlayObject(const std::string & name) : name_(name) +{ std::string material_name = name_ + "Material"; - Ogre::OverlayManager *mOverlayMgr = Ogre::OverlayManager::getSingletonPtr(); + Ogre::OverlayManager * mOverlayMgr = Ogre::OverlayManager::getSingletonPtr(); overlay_ = mOverlayMgr->create(name_); panel_ = static_cast( - mOverlayMgr->createOverlayElement("Panel", name_ + "Panel")); + mOverlayMgr->createOverlayElement("Panel", name_ + "Panel")); panel_->setMetricsMode(Ogre::GMM_PIXELS); panel_material_ = Ogre::MaterialManager::getSingleton().create( - material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); + material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); panel_->setMaterialName(panel_material_->getName()); overlay_->add2D(panel_); } -OverlayObject::~OverlayObject() { - Ogre::OverlayManager *mOverlayMgr = Ogre::OverlayManager::getSingletonPtr(); +OverlayObject::~OverlayObject() +{ + Ogre::OverlayManager * mOverlayMgr = Ogre::OverlayManager::getSingletonPtr(); if (mOverlayMgr) { mOverlayMgr->destroyOverlayElement(panel_); mOverlayMgr->destroy(overlay_); @@ -118,63 +127,66 @@ OverlayObject::~OverlayObject() { } } -std::string OverlayObject::getName() const { return name_; } +std::string OverlayObject::getName() const +{ + return name_; +} -void OverlayObject::hide() { +void OverlayObject::hide() +{ if (overlay_->isVisible()) { overlay_->hide(); } } -void OverlayObject::show() { +void OverlayObject::show() +{ if (!overlay_->isVisible()) { overlay_->show(); } } -bool OverlayObject::isTextureReady() const { return texture_ != nullptr; } +bool OverlayObject::isTextureReady() const +{ + return texture_ != nullptr; +} -void OverlayObject::updateTextureSize(unsigned int width, unsigned int height) { +void OverlayObject::updateTextureSize(unsigned int width, unsigned int height) +{ const std::string texture_name = name_ + "Texture"; if (width == 0) { - RVIZ_COMMON_LOG_WARNING_STREAM( - "[OverlayObject] width=0 is specified as texture size"); + RVIZ_COMMON_LOG_WARNING_STREAM("[OverlayObject] width=0 is specified as texture size"); width = 1; } if (height == 0) { - RVIZ_COMMON_LOG_WARNING_STREAM( - "[OverlayObject] height=0 is specified as texture size"); + RVIZ_COMMON_LOG_WARNING_STREAM("[OverlayObject] height=0 is specified as texture size"); height = 1; } - if (!isTextureReady() || - ((width != texture_->getWidth()) || (height != texture_->getHeight()))) { + if (!isTextureReady() || ((width != texture_->getWidth()) || (height != texture_->getHeight()))) { if (isTextureReady()) { Ogre::TextureManager::getSingleton().remove(texture_name); - panel_material_->getTechnique(0) - ->getPass(0) - ->removeAllTextureUnitStates(); + panel_material_->getTechnique(0)->getPass(0)->removeAllTextureUnitStates(); } texture_ = Ogre::TextureManager::getSingleton().createManual( - texture_name, // name - Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - Ogre::TEX_TYPE_2D, // type - width, height, // width & height of the render window - 0, // number of mipmaps - Ogre::PF_A8R8G8B8, // pixel format chosen to match a format Qt can use - Ogre::TU_DEFAULT // usage + texture_name, // name + Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, + Ogre::TEX_TYPE_2D, // type + width, height, // width & height of the render window + 0, // number of mipmaps + Ogre::PF_A8R8G8B8, // pixel format chosen to match a format Qt can use + Ogre::TU_DEFAULT // usage ); - panel_material_->getTechnique(0)->getPass(0)->createTextureUnitState( - texture_name); + panel_material_->getTechnique(0)->getPass(0)->createTextureUnitState(texture_name); - panel_material_->getTechnique(0)->getPass(0)->setSceneBlending( - Ogre::SBT_TRANSPARENT_ALPHA); + panel_material_->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); } } -ScopedPixelBuffer OverlayObject::getBuffer() { +ScopedPixelBuffer OverlayObject::getBuffer() +{ if (isTextureReady()) { return ScopedPixelBuffer(texture_->getBuffer()); } else { @@ -182,9 +194,10 @@ ScopedPixelBuffer OverlayObject::getBuffer() { } } -void OverlayObject::setPosition(double hor_dist, double ver_dist, - HorizontalAlignment hor_alignment, - VerticalAlignment ver_alignment) { +void OverlayObject::setPosition( + double hor_dist, double ver_dist, HorizontalAlignment hor_alignment, + VerticalAlignment ver_alignment) +{ // ogre position is always based on the top left corner of the panel, while // our position input depends on the chosen alignment, i.e. if the horizontal // alignment is right, increasing the horizontal dist moves the panel to the @@ -193,45 +206,50 @@ void OverlayObject::setPosition(double hor_dist, double ver_dist, double top = 0; switch (hor_alignment) { - case HorizontalAlignment::LEFT: - panel_->setHorizontalAlignment(Ogre::GuiHorizontalAlignment::GHA_LEFT); - left = hor_dist; - break; - case HorizontalAlignment::CENTER: - panel_->setHorizontalAlignment(Ogre::GuiHorizontalAlignment::GHA_CENTER); - left = hor_dist - panel_->getWidth() / 2; - break; - case HorizontalAlignment::RIGHT: - panel_->setHorizontalAlignment(Ogre::GuiHorizontalAlignment::GHA_RIGHT); - left = -hor_dist - panel_->getWidth(); - break; + case HorizontalAlignment::LEFT: + panel_->setHorizontalAlignment(Ogre::GuiHorizontalAlignment::GHA_LEFT); + left = hor_dist; + break; + case HorizontalAlignment::CENTER: + panel_->setHorizontalAlignment(Ogre::GuiHorizontalAlignment::GHA_CENTER); + left = hor_dist - panel_->getWidth() / 2; + break; + case HorizontalAlignment::RIGHT: + panel_->setHorizontalAlignment(Ogre::GuiHorizontalAlignment::GHA_RIGHT); + left = -hor_dist - panel_->getWidth(); + break; } switch (ver_alignment) { - case VerticalAlignment::BOTTOM: - panel_->setVerticalAlignment(Ogre::GuiVerticalAlignment::GVA_BOTTOM); - top = -ver_dist - panel_->getHeight(); - break; - case VerticalAlignment::CENTER: - panel_->setVerticalAlignment(Ogre::GuiVerticalAlignment::GVA_CENTER); - top = ver_dist - panel_->getHeight() / 2; - break; - case VerticalAlignment::TOP: - panel_->setVerticalAlignment(Ogre::GuiVerticalAlignment::GVA_TOP); - top = ver_dist; - break; + case VerticalAlignment::BOTTOM: + panel_->setVerticalAlignment(Ogre::GuiVerticalAlignment::GVA_BOTTOM); + top = -ver_dist - panel_->getHeight(); + break; + case VerticalAlignment::CENTER: + panel_->setVerticalAlignment(Ogre::GuiVerticalAlignment::GVA_CENTER); + top = ver_dist - panel_->getHeight() / 2; + break; + case VerticalAlignment::TOP: + panel_->setVerticalAlignment(Ogre::GuiVerticalAlignment::GVA_TOP); + top = ver_dist; + break; } panel_->setPosition(left, top); } -void OverlayObject::setDimensions(double width, double height) { +void OverlayObject::setDimensions(double width, double height) +{ panel_->setDimensions(width, height); } -bool OverlayObject::isVisible() const { return overlay_->isVisible(); } +bool OverlayObject::isVisible() const +{ + return overlay_->isVisible(); +} -unsigned int OverlayObject::getTextureWidth() const { +unsigned int OverlayObject::getTextureWidth() const +{ if (isTextureReady()) { return texture_->getWidth(); } else { @@ -239,11 +257,12 @@ unsigned int OverlayObject::getTextureWidth() const { } } -unsigned int OverlayObject::getTextureHeight() const { +unsigned int OverlayObject::getTextureHeight() const +{ if (isTextureReady()) { return texture_->getHeight(); } else { return 0; } } -} // namespace rviz_satellite +} // namespace rviz_satellite diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/tile.cpp b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/tile.cpp index 6ec2e6f83e559..2cf17d258f27f 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/tile.cpp +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/tile.cpp @@ -74,4 +74,4 @@ void Tile::onTileFetched(QNetworkReply * reply) tile_promise_.set_value(QImage()); } reply->deleteLater(); -} \ No newline at end of file +} diff --git a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/tile_field.cpp b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/tile_field.cpp index 6d02bf15757a9..97f788c358340 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/tile_field.cpp +++ b/common/autoware_overlay_rviz_plugin/autoware_minimap_overlay_rviz_plugin/src/tile_field.cpp @@ -1,19 +1,24 @@ #include "include/tile_field.hpp" + #include #include + #include -TileField::TileField(QObject *parent) - : QObject(parent), center_x_tile_(0), center_y_tile_(0) {} +TileField::TileField(QObject * parent) : QObject(parent), center_x_tile_(0), center_y_tile_(0) +{ +} -TileField::~TileField() { +TileField::~TileField() +{ std::lock_guard lock(tile_mutex_); - for (auto &tile : tiles_) { + for (auto & tile : tiles_) { delete tile.second; } } -void TileField::fetchTiles(int zoom, int center_x_tile, int center_y_tile) { +void TileField::fetchTiles(int zoom, int center_x_tile, int center_y_tile) +{ std::lock_guard lock(tile_mutex_); zoom_ = zoom != 0 ? zoom : zoom_; center_x_tile_ = center_x_tile; @@ -23,12 +28,11 @@ void TileField::fetchTiles(int zoom, int center_x_tile, int center_y_tile) { for (int dy = -1; dy <= 1; ++dy) { int x_tile = center_x_tile_ + dx; int y_tile = center_y_tile_ + dy; - std::string tile_key = std::to_string(zoom) + "/" + - std::to_string(x_tile) + "/" + - std::to_string(y_tile) + ".png"; + std::string tile_key = + std::to_string(zoom) + "/" + std::to_string(x_tile) + "/" + std::to_string(y_tile) + ".png"; if (tiles_.find(tile_key) == tiles_.end()) { - Tile *tile = new Tile(zoom, x_tile, y_tile); + Tile * tile = new Tile(zoom, x_tile, y_tile); tiles_[tile_key] = tile; connect(tile, &Tile::tileFetched, this, &TileField::onTileFetched); tile->fetch(); @@ -37,17 +41,18 @@ void TileField::fetchTiles(int zoom, int center_x_tile, int center_y_tile) { } } -void TileField::initializeTiles(int center_x_tile, int center_y_tile) { +void TileField::initializeTiles(int center_x_tile, int center_y_tile) +{ std::lock_guard lock(tile_mutex_); center_x_tile_ = center_x_tile; center_y_tile_ = center_y_tile; updateTiles(center_x_tile_, center_y_tile_); } -void TileField::updateTiles(int new_center_x_tile, int new_center_y_tile) { +void TileField::updateTiles(int new_center_x_tile, int new_center_y_tile) +{ std::lock_guard lock(tile_mutex_); - if (new_center_x_tile == center_x_tile_ && - new_center_y_tile == center_y_tile_) { + if (new_center_x_tile == center_x_tile_ && new_center_y_tile == center_y_tile_) { return; } @@ -59,14 +64,10 @@ void TileField::updateTiles(int new_center_x_tile, int new_center_y_tile) { int x_tile = center_x_tile_ + dx; int y_tile = center_y_tile_ + dy; - auto tile_key = QString("%1/%2/%3.png") - .arg(zoom_) - .arg(x_tile) - .arg(y_tile) - .toStdString(); + auto tile_key = QString("%1/%2/%3.png").arg(zoom_).arg(x_tile).arg(y_tile).toStdString(); if (tiles_.find(tile_key) == tiles_.end()) { - Tile *tile = new Tile(zoom_, x_tile, y_tile); + Tile * tile = new Tile(zoom_, x_tile, y_tile); tiles_[tile_key] = tile; connect(tile, &Tile::tileFetched, this, &TileField::onTileFetched); tile->fetch(); @@ -75,12 +76,12 @@ void TileField::updateTiles(int new_center_x_tile, int new_center_y_tile) { } } -QImage TileField::getTileFieldImage() { +QImage TileField::getTileFieldImage() +{ std::lock_guard lock(tile_mutex_); if (tile_field_image_.isNull()) { - int tile_size = 256; // Assuming tile size is 256x256 pixels - tile_field_image_ = - QImage(tile_size * 3, tile_size * 3, QImage::Format_ARGB32); + int tile_size = 256; // Assuming tile size is 256x256 pixels + tile_field_image_ = QImage(tile_size * 3, tile_size * 3, QImage::Format_ARGB32); } QPainter painter(&tile_field_image_); @@ -91,11 +92,7 @@ QImage TileField::getTileFieldImage() { int x_tile = center_x_tile_ + dx; int y_tile = center_y_tile_ + dy; - auto tile_key = QString("%1/%2/%3.png") - .arg(zoom_) - .arg(x_tile) - .arg(y_tile) - .toStdString(); + auto tile_key = QString("%1/%2/%3.png").arg(zoom_).arg(x_tile).arg(y_tile).toStdString(); auto tile_it = tiles_.find(tile_key); if (tile_it != tiles_.end() && !tile_it->second->getImage().isNull()) { @@ -103,8 +100,7 @@ QImage TileField::getTileFieldImage() { QRectF source(0, 0, 256, 256); painter.drawImage(target, tile_it->second->getImage(), source); // Draw the tile key as text for debugging - painter.drawText(target, Qt::AlignCenter, - QString::fromStdString(tile_key)); + painter.drawText(target, Qt::AlignCenter, QString::fromStdString(tile_key)); } } } @@ -112,32 +108,39 @@ QImage TileField::getTileFieldImage() { return tile_field_image_; } -void TileField::onTileFetched() { Q_EMIT tilesUpdated(); } +void TileField::onTileFetched() +{ + Q_EMIT tilesUpdated(); +} -int TileField::long2tilex(double lon, int z) { +int TileField::long2tilex(double lon, int z) +{ return (int)(floor((lon + 180.0) / 360.0 * (1 << z))); } -int TileField::lat2tiley(double lat, int z) { +int TileField::lat2tiley(double lat, int z) +{ double latrad = lat * M_PI / 180.0; return (int)(floor((1.0 - asinh(tan(latrad)) / M_PI) / 2.0 * (1 << z))); } -double TileField::tilex2long(int x, int z) { +double TileField::tilex2long(int x, int z) +{ return x / (double)(1 << z) * 360.0 - 180; } -double TileField::tiley2lat(int y, int z) { +double TileField::tiley2lat(int y, int z) +{ double n = M_PI - 2.0 * M_PI * y / (double)(1 << z); return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); } -std::pair TileField::getTileOffsets(double lat, double lon) { +std::pair TileField::getTileOffsets(double lat, double lon) +{ double x = (lon + 180.0) / 360.0 * std::pow(2.0, zoom_); - double y = (1.0 - std::log(std::tan(lat * M_PI / 180.0) + - 1.0 / std::cos(lat * M_PI / 180.0)) / - M_PI) / - 2.0 * std::pow(2.0, zoom_); + double y = + (1.0 - std::log(std::tan(lat * M_PI / 180.0) + 1.0 / std::cos(lat * M_PI / 180.0)) / M_PI) / + 2.0 * std::pow(2.0, zoom_); int x_tile = static_cast(std::floor(x)); int y_tile = static_cast(std::floor(y)); @@ -148,13 +151,12 @@ std::pair TileField::getTileOffsets(double lat, double lon) { return {x_offset, y_offset}; } -std::pair TileField::latLonToTile(double lat, double lon, - int zoom) { +std::pair TileField::latLonToTile(double lat, double lon, int zoom) +{ double x = (lon + 180.0) / 360.0 * std::pow(2.0, zoom); - double y = (1.0 - std::log(std::tan(lat * M_PI / 180.0) + - 1.0 / std::cos(lat * M_PI / 180.0)) / - M_PI) / - 2.0 * std::pow(2.0, zoom); + double y = + (1.0 - std::log(std::tan(lat * M_PI / 180.0) + 1.0 / std::cos(lat * M_PI / 180.0)) / M_PI) / + 2.0 * std::pow(2.0, zoom); return {x, y}; }