17 #include <pcl/common/common.h> 18 #include <pcl/common/transforms.h> 19 #include <pcl/conversions.h> 20 #include <pcl/io/pcd_io.h> 21 #include <pcl/point_types.h> 29 namespace grid_map_pcl {
32 bool isSetVerbosityLevelToDebug;
33 nh.
param<
bool>(
"set_verbosity_to_debug", isSetVerbosityLevelToDebug,
false);
35 if (!isSetVerbosityLevelToDebug) {
50 std::string outputRosbagName, folderPath;
51 nh.
param<std::string>(
"folder_path", folderPath,
"");
52 nh.
param<std::string>(
"output_grid_map", outputRosbagName,
"output_grid_map.bag");
53 std::string pathToOutputBag = folderPath +
"/" + outputRosbagName;
54 return pathToOutputBag;
58 std::string inputCloudName, folderPath;
59 nh.
param<std::string>(
"folder_path", folderPath,
"");
60 nh.
param<std::string>(
"pcd_filename", inputCloudName,
"input_cloud");
61 std::string pathToCloud = folderPath +
"/" + inputCloudName;
67 nh.
param<std::string>(
"map_frame", mapFrame,
"map");
72 std::string mapRosbagTopic;
73 nh.
param<std::string>(
"map_rosbag_topic", mapRosbagTopic,
"grid_map");
74 return mapRosbagTopic;
78 std::string mapLayerName;
79 nh.
param<std::string>(
"map_layer_name", mapLayerName,
"elevation");
86 ROS_INFO_STREAM(
"Saving grid map successful: " << std::boolalpha << savingSuccessful);
90 const auto stop = std::chrono::high_resolution_clock::now();
91 const auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count() / 1000.0;
96 const auto start = std::chrono::high_resolution_clock::now();
105 Eigen::Affine3f rigidBodyTransform;
106 rigidBodyTransform.setIdentity();
107 rigidBodyTransform.translation() << translation.x(), translation.y(), translation.z();
108 Eigen::Matrix3f rotation(Eigen::Matrix3f::Identity());
112 rigidBodyTransform.rotate(rotation);
114 return rigidBodyTransform;
118 Eigen::Matrix3f rotationMatrix = Eigen::Matrix3f::Identity();
121 rotationMatrix = Eigen::AngleAxisf(angle, Eigen::Vector3f::UnitX());
125 rotationMatrix = Eigen::AngleAxisf(angle, Eigen::Vector3f::UnitY());
129 rotationMatrix = Eigen::AngleAxisf(angle, Eigen::Vector3f::UnitZ());
133 ROS_ERROR(
"Unknown axis while trying to rotate the pointcloud");
135 return rotationMatrix;
139 Eigen::Vector3d mean = Eigen::Vector3d::Zero();
140 for (
const auto& point : inputCloud->points) {
141 mean += Eigen::Vector3d(point.x, point.y, point.z);
143 mean /= inputCloud->points.size();
149 Pointcloud::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
150 pcl::PCLPointCloud2 cloudBlob;
152 pcl::fromPCLPointCloud2(cloudBlob, *cloud);
156 Pointcloud::Ptr
transformCloud(Pointcloud::ConstPtr inputCloud,
const Eigen::Affine3f& transformMatrix) {
157 Pointcloud::Ptr transformedCloud(
new Pointcloud());
158 pcl::transformPointCloud(*inputCloud, *transformedCloud, transformMatrix);
159 return transformedCloud;
void printTimeElapsedToRosInfoStream(const std::chrono::system_clock::time_point &start, const std::string &prefix)
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
void initializeGridMapGeometryFromInputCloud()
std::string getPcdFilePath(const ros::NodeHandle &nh)
std::string getOutputBagPath(const ros::NodeHandle &nh)
Eigen::Matrix3f getRotationMatrix(double angle, XYZ axis)
Eigen::Vector3d calculateMeanOfPointPositions(Pointcloud::ConstPtr inputCloud)
static bool saveToBag(const grid_map::GridMap &gridMap, const std::string &pathToBag, const std::string &topic)
void addLayerFromInputCloud(const std::string &layer)
int loadPCDFile(const std::string &file_name, sensor_msgs::PointCloud2 &cloud)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void processPointcloud(grid_map::GridMapPclLoader *gridMapPclLoader, const ros::NodeHandle &nh)
Pointcloud::Ptr loadPointcloudFromPcd(const std::string &filename)
void preProcessInputCloud()
std::string getParameterPath()
std::string getMapLayerName(const ros::NodeHandle &nh)
ROSLIB_DECL std::string getPath(const std::string &package_name)
Pointcloud::Ptr transformCloud(Pointcloud::ConstPtr inputCloud, const Eigen::Affine3f &transformMatrix)
#define ROS_INFO_STREAM(args)
void setVerbosityLevelToDebugIfFlagSet(const ros::NodeHandle &nh)
void saveGridMap(const grid_map::GridMap &gridMap, const ros::NodeHandle &nh, const std::string &mapTopic)
ROSCONSOLE_DECL bool set_logger_level(const std::string &name, levels::Level level)
::pcl::PointCloud< Point > Pointcloud
Eigen::Affine3f getRigidBodyTransform(const Eigen::Vector3d &translation, const Eigen::Vector3d &intrinsicRpy)
std::string getMapFrame(const ros::NodeHandle &nh)
#define ROSCONSOLE_DEFAULT_NAME
std::string getMapRosbagTopic(const ros::NodeHandle &nh)