-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: added DigitalElevationMapMs_CVMat adapter.
- Loading branch information
1 parent
41e7c2e
commit bee5584
Showing
5 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Copyright 2023 Patrick Roncagliolo, Antonino Bongiovanni | ||
*/ | ||
|
||
#ifndef NATIVE_ADAPTERS__SENSORMSGIMAGE_CVMAT_HPP_ | ||
#define NATIVE_ADAPTERS__SENSORMSGIMAGE_CVMAT_HPP_ | ||
#include <rclcpp/type_adapter.hpp> | ||
#include <dem_msgs/msg/digital_elevation_map.hpp> | ||
#include <opencv2/core/mat.hpp> | ||
#include <native_adapters/PointerDefinesMacro.hpp> | ||
|
||
|
||
struct StampedDigitalElevationMap_CV | ||
{ | ||
std_msgs::msg::Header header; | ||
nav_msgs::msg::MapMetaData info; | ||
cv::Mat mat; | ||
|
||
StampedDigitalElevationMap_CV() = default; | ||
StampedDigitalElevationMap_CV(const StampedDigitalElevationMap_CV & other); | ||
StampedDigitalElevationMap_CV(StampedDigitalElevationMap_CV && other); | ||
StampedDigitalElevationMap_CV & operator=(const StampedDigitalElevationMap_CV & other); | ||
|
||
DEFINE_MSG_POINTERS(StampedDigitalElevationMap_CV) | ||
}; | ||
|
||
template<> | ||
struct rclcpp::TypeAdapter<StampedDigitalElevationMap_CV, dem_msgs::msg::DigitalElevationMap> | ||
{ | ||
using is_specialized = std::true_type; | ||
using custom_type = StampedDigitalElevationMap_CV; | ||
using ros_message_type = dem_msgs::msg::DigitalElevationMap; | ||
static void convert_to_ros_message(const custom_type & source, ros_message_type & destination); | ||
static void convert_to_custom(const ros_message_type & source, custom_type & destination); | ||
}; | ||
|
||
|
||
#endif // NATIVE_ADAPTERS__DIGITALELEVATIONMAP_CVMAT_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright 2023 Patrick Roncagliolo, Antonino Bongiovanni | ||
*/ | ||
|
||
#include <native_adapters/DigitalElevationMapMsg_CvMat.hpp> | ||
// #include <sensor_msgs/image_encodings.hpp> | ||
#include <rclcpp/logging.hpp> | ||
|
||
StampedDigitalElevationMap_CV::StampedDigitalElevationMap_CV( | ||
const StampedDigitalElevationMap_CV & other) | ||
{ | ||
//RCLCPP_WARN(rclcpp::get_logger("DEM Adapter"), "Copy constructor called"); | ||
this->header = other.header; | ||
this->info = other.info; | ||
this->mat = other.mat.clone(); | ||
} | ||
|
||
StampedDigitalElevationMap_CV::StampedDigitalElevationMap_CV(StampedDigitalElevationMap_CV && other) | ||
{ | ||
//RCLCPP_WARN(rclcpp::get_logger("DEM Adapter"), "Move constructor called"); | ||
this->header = std::move(other.header); | ||
this->info = std::move(other.info); | ||
this->mat = std::move(other.mat); | ||
} | ||
|
||
StampedDigitalElevationMap_CV & StampedDigitalElevationMap_CV::operator=( | ||
const StampedDigitalElevationMap_CV & other) | ||
{ | ||
//RCLCPP_WARN(rclcpp::get_logger("DEM Adapter"), "Assignment operator called"); | ||
if (this == &other) {return *this;} | ||
this->header = other.header; | ||
this->info = other.info; | ||
this->mat = other.mat.clone(); | ||
return *this; | ||
} | ||
|
||
void rclcpp::TypeAdapter<StampedDigitalElevationMap_CV, | ||
dem_msgs::msg::DigitalElevationMap>::convert_to_ros_message( | ||
const custom_type & source, ros_message_type & destination) | ||
{ | ||
//RCLCPP_WARN(rclcpp::get_logger("DEM Adapter"), "Conversion to message"); | ||
|
||
destination.data.resize(source.mat.rows * source.mat.cols); | ||
for (int y = 0; y < source.mat.rows; ++y) { | ||
for (int x = 0; x < source.mat.cols; ++x) { | ||
destination.data[y * source.mat.cols + x] = source.mat.at<float>(y, x) - 1; | ||
} | ||
} | ||
|
||
destination.header = source.header; | ||
destination.info = source.info; | ||
} | ||
|
||
void rclcpp::TypeAdapter<StampedDigitalElevationMap_CV, | ||
dem_msgs::msg::DigitalElevationMap>::convert_to_custom( | ||
const ros_message_type & source, custom_type & destination) | ||
{ | ||
//RCLCPP_WARN(rclcpp::get_logger("DEM Adapter"), "Conversion from message"); | ||
|
||
destination.mat = | ||
cv::Mat(source.info.height, source.info.width, CV_MAKETYPE(cv::DataType<float>::type, 1)); | ||
for (unsigned int y = 0; y < source.info.height; ++y) { | ||
for (unsigned int x = 0; x < source.info.width; ++x) { | ||
destination.mat.at<float>(y, x) = source.data[y * source.info.width + x] + 1; | ||
} | ||
} | ||
destination.header = source.header; | ||
destination.info = source.info; | ||
} |