@@ -43,6 +43,17 @@ namespace projected_point_cloud_transport
4343
4444void 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
4859std::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
137140void 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
0 commit comments