Skip to content

Commit c16b0d9

Browse files
committed
Update
1 parent 1dd1b2c commit c16b0d9

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

projected_point_cloud_transport/include/projected_point_cloud_transport/projected_publisher.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,23 @@ class ProjectedPublisher
7070

7171
void projectCloudOntoSphere(const sensor_msgs::msg::PointCloud2& cloud, cv::Mat& projected_pointcloud_image) const;
7272

73+
// bookkeeping variables
74+
geometry_msgs::msg::Pose view_point_; // (Maybe users can set this somehow?)
75+
76+
// general parameters
7377
uint8_t projection_type_;
7478

75-
geometry_msgs::msg::Pose view_point_;
79+
// params for planar projection
80+
int view_height_;
81+
int view_width_;
82+
float ppx_;
83+
float ppy_;
84+
float fx_;
85+
float fy_;
86+
87+
// params for spherical projection
88+
double phi_resolution_;
89+
double theta_resolution_;
7690

7791
};
7892
} // namespace projected_point_cloud_transport

projected_point_cloud_transport/src/projected_publisher.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ namespace projected_point_cloud_transport
4343

4444
void ProjectedPublisher::declareParameters(const std::string & base_topic)
4545
{
46+
// params for planar projection
47+
view_height_ = 720;
48+
view_width_ = 1080;
49+
ppx_ = static_cast<float>(view_width_)/2.0;
50+
ppy_ = static_cast<float>(view_height_)/2.0;
51+
fx_ = view_width_;
52+
fy_ = view_width_;
53+
54+
// params for spherical projection
55+
phi_resolution_ = 0.034; // radians
56+
theta_resolution_ = 0.034; // radians
4657
}
4758

4859
std::string ProjectedPublisher::getTransportName() const
@@ -93,16 +104,8 @@ void ProjectedPublisher::projectCloudOntoPlane(const sensor_msgs::msg::PointClou
93104
// TODO ([email protected]): if the pointcloud is already organized, just point the cv::Mat at the data
94105
projected_pointcloud_image = cv::Mat((int)cloud.height, (int)cloud.width, CV_32FC3, (void*)cloud.data.data());
95106
}else{
96-
// TODO ([email protected]): Make these parameters
97-
const int view_height = 720;
98-
const int view_width = 1080;
99-
projected_pointcloud_image = cv::Mat(cv::Size(view_width, view_height), CV_16UC1, cv::Scalar(0));
100-
const float ppx = view_width/2;
101-
const float ppy = view_height/2;
102-
const float fx = view_width;
103-
const float fy = view_width;
104-
105107
// if the pointcloud is NOT already organized, we need to apply the projection
108+
projected_pointcloud_image = cv::Mat(cv::Size(view_width_, view_height_), CV_16UC1, cv::Scalar(0));
106109

107110
// iterate over the pointcloud
108111
sensor_msgs::PointCloud2ConstIterator<float> iter_x(cloud, "x");
@@ -121,10 +124,10 @@ void ProjectedPublisher::projectCloudOntoPlane(const sensor_msgs::msg::PointClou
121124
// TODO (john-maidbot): rotate the d x/y/z so that z is along the view point orientation
122125
// TODO: can that be made more efficient by transforming the view point instead?
123126

124-
const int col = x/z * fx + ppx;
125-
const int row = y/z * fy + ppy;
127+
const int col = x/z * fx_ + ppx_;
128+
const int row = y/z * fy_ + ppy_;
126129

127-
if(z == 0 || col < 0 || row < 0 || col >= view_width || row >= view_height){
130+
if(z == 0 || col < 0 || row < 0 || col >= view_width_ || row >= view_height_){
128131
continue;
129132
}
130133

@@ -135,11 +138,9 @@ void ProjectedPublisher::projectCloudOntoPlane(const sensor_msgs::msg::PointClou
135138
}
136139

137140
void ProjectedPublisher::projectCloudOntoSphere(const sensor_msgs::msg::PointCloud2& cloud, cv::Mat& projected_pointcloud_image) const{
138-
// TODO ([email protected]): Make these parameters
139-
const double phi_resolution = 0.034; // radians
140-
const double theta_resolution = 0.034; // radians
141-
const int phi_bins = 2 * M_PI / phi_resolution;
142-
const int theta_bins = 2 * M_PI / theta_resolution;
141+
// compute image size based on resolution
142+
const int phi_bins = 2 * M_PI / phi_resolution_;
143+
const int theta_bins = 2 * M_PI / theta_resolution_;
143144

144145
cv::Mat spherical_image{phi_bins, theta_bins, CV_16UC1, cv::Scalar(0)};
145146

@@ -169,8 +170,8 @@ void ProjectedPublisher::projectCloudOntoSphere(const sensor_msgs::msg::PointClo
169170
theta += 2*M_PI;
170171
}
171172

172-
const int phi_index = std::min(static_cast<int>(phi / phi_resolution), phi_bins);
173-
const int theta_index = std::min(static_cast<int>(theta / theta_resolution), theta_bins);
173+
const int phi_index = std::min(static_cast<int>(phi / phi_resolution_), phi_bins);
174+
const int theta_index = std::min(static_cast<int>(theta / theta_resolution_), theta_bins);
174175

175176
auto& cell = spherical_image.at<uint16_t>(phi_index, theta_index);
176177
cell = std::min(cell, static_cast<uint16_t>(rho * 1000)); // mm resolution

projected_point_cloud_transport/src/projected_subscriber.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ void ProjectedSubscriber::deprojectSphereToCloud(const cv::Mat& spherical_image,
164164
// convert the spherical image pixel to a point cloud point
165165
const double rho = static_cast<double>(cell) / 1000.0; // meters
166166
const double phi = row * phi_resolution;
167-
const double theta = col * phi_resolution;
167+
const double theta = col * theta_resolution;
168+
// TODO (john-maidbot): This could be a lookup table if performance is a huge concern
168169
pcl_itr[0] = rho * std::sin(phi) * std::cos(theta);
169170
pcl_itr[1] = rho * std::sin(phi) * std::sin(theta);
170171
pcl_itr[2] = rho * std::cos(phi);

0 commit comments

Comments
 (0)