heightmap_utils.h
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2015, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 
37 #ifndef JSK_PCL_ROS_HEIGHTMAP_UTILS_H_
38 #define JSK_PCL_ROS_HEIGHTMAP_UTILS_H_
39 
40 #include <jsk_recognition_msgs/HeightmapConfig.h>
42 
43 namespace jsk_pcl_ros
44 {
45  typedef pcl::PointXYZI HeightMapPointType;
46 
47  inline std::string getHeightmapConfigTopic(const std::string& base_topic)
48  {
49  return base_topic + "/config";
50  }
51 
52  inline void convertHeightMapToPCL(const cv::Mat &float_image,
53  pcl::PointCloud<HeightMapPointType > &cloud,
54  float max_x_, float min_x_, float max_y_, float min_y_)
55  {
56  int height = float_image.rows;
57  int width = float_image.cols;
58  cloud.points.reserve(float_image.rows * float_image.cols); // normal
59  double dx = (max_x_ - min_x_) / width;
60  double dy = (max_y_ - min_y_) / height;
61  for (size_t j = 0; j < height; j++) {
62  for (size_t i = 0; i < width; i++) {
63  float v = float_image.at<cv::Vec2f>(j, i)[0];
64  float fint = float_image.at<cv::Vec2f>(j, i)[1];
65  if (v != -FLT_MAX) {
66  HeightMapPointType p;
67  p.y = j * dy + min_y_ + dy / 2.0;
68  p.x = i * dx + min_x_ + dx / 2.0;
69  p.z = v;
70  p.intensity = fint;
71  cloud.points.push_back(p); // normal
72  }
73  }
74  }
75  }
76 
77  inline void convertHeightMapToPCLOrganize(const cv::Mat &float_image,
78  pcl::PointCloud<HeightMapPointType > &cloud,
79  float max_x_, float min_x_, float max_y_, float min_y_)
80  {
81  int height = float_image.rows;
82  int width = float_image.cols;
83  cloud.points.resize(height * width); // organized
84  cloud.width = width;
85  cloud.height = height;
86  double dx = (max_x_ - min_x_) / width;
87  double dy = (max_y_ - min_y_) / height;
88  for (size_t j = 0; j < height; j++) {
89  for (size_t i = 0; i < width; i++) {
90  float v = float_image.at<cv::Vec2f>(j, i)[0];
91  float fint = float_image.at<cv::Vec2f>(j, i)[1];
92  HeightMapPointType p;
93  p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN(); // organized
94  if (v != -FLT_MAX) {
95  p.y = j * dy + min_y_ + dy / 2.0;
96  p.x = i * dx + min_x_ + dx / 2.0;
97  p.z = v;
98  p.intensity = fint;
99  }
100  cloud.points[(j * width) + i] = p; // organized
101  }
102  }
103  }
104 }
105 
106 #endif
std::string getHeightmapConfigTopic(const std::string &base_topic)
void convertHeightMapToPCLOrganize(const cv::Mat &float_image, pcl::PointCloud< HeightMapPointType > &cloud, float max_x_, float min_x_, float max_y_, float min_y_)
pcl::PointXYZI HeightMapPointType
height
p
void convertHeightMapToPCL(const cv::Mat &float_image, pcl::PointCloud< HeightMapPointType > &cloud, float max_x_, float min_x_, float max_y_, float min_y_)
GLfloat v[8][3]
width


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Mon May 3 2021 03:03:46