| 26 | double len2_; |
| 27 | |
| 28 | void clickCallback(const geometry_msgs::PoseStamped& msg) { |
| 29 | double x = msg.pose.position.x; |
| 30 | double y = msg.pose.position.y; |
| 31 | points_.push_back(Eigen::Vector3d(x, y, 0)); |
| 32 | if (points_.size() < 2) return; |
| 33 | |
| 34 | // Generate wall using two points |
| 35 | Eigen::Vector3d p1 = points_[0]; |
| 36 | Eigen::Vector3d p2 = points_[1]; |
| 37 | points_.clear(); |
| 38 | |
| 39 | Eigen::Vector3d dir1 = (p2 - p1).normalized(); |
| 40 | double len = (p2 - p1).norm(); |
| 41 | Eigen::Vector3d dir2; |
| 42 | dir2[0] = -dir1[1]; |
| 43 | dir2[1] = dir1[0]; |
| 44 | |
| 45 | pcl::PointXYZ pt_random; |
| 46 | for (double l1 = 0.0; l1 <= len + 1e-3; l1 += 0.1) { |
| 47 | Eigen::Vector3d tmp1 = p1 + l1 * dir1; |
| 48 | for (double l2 = -len2_; l2 <= len2_ + 1e-3; l2 += 0.1) { |
| 49 | Eigen::Vector3d tmp2 = tmp1 + l2 * dir2; |
| 50 | for (double h = -0.5; h < 2.5; h += 0.1) { |
| 51 | pt_random.x = tmp2[0]; |
| 52 | pt_random.y = tmp2[1]; |
| 53 | pt_random.z = h; |
| 54 | map_cloud_.push_back(pt_random); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | map_cloud_.width = map_cloud_.points.size(); |
| 60 | map_cloud_.height = 1; |
| 61 | map_cloud_.is_dense = true; |
| 62 | pcl::toROSMsg(map_cloud_, map_msg_); |
| 63 | map_msg_.header.frame_id = "world"; |
| 64 | all_map_pub_.publish(map_msg_); |
| 65 | } |
| 66 | |
| 67 | int main(int argc, char** argv) { |
| 68 | ros::init(argc, argv, "click_map"); |