Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <iostream>
00042 using namespace std;
00043
00044 #include "pcl/common/common_headers.h"
00045 #include "pcl/range_image/range_image.h"
00046 #include "pcl/io/pcd_io.h"
00047 #include "pcl_visualization/range_image_visualizer.h"
00048 #include "pcl_visualization/pcl_visualizer.h"
00049
00050 using namespace pcl;
00051 using namespace pcl_visualization;
00052 typedef PointXYZ PointType;
00053
00054
00055
00056
00057 float angular_resolution = 0.5f;
00058 RangeImage::CoordinateFrame coordinate_frame = RangeImage::CAMERA_FRAME;
00059
00060
00061
00062
00063 void printUsage(const char* progName)
00064 {
00065 cout << "\n\nUsage: "<<progName<<" [options] <scene.pcd>\n\n"
00066 << "Options:\n"
00067 << "-------------------------------------------\n"
00068 << "-r <float> angular resolution in degrees (default "<<angular_resolution<<")\n"
00069 << "-c <int> coordinate frame (default "<<(int)coordinate_frame<<")\n"
00070 << "-h this help\n"
00071 << "\n\n";
00072 }
00073
00074
00075
00076
00077 int main (int argc, char** argv)
00078 {
00079
00080
00081
00082 for (char c; (c = getopt(argc, argv, "r:c:h")) != -1; ) {
00083 switch (c) {
00084 case 'r':
00085 {
00086 angular_resolution = strtod(optarg, NULL);
00087 cout << "Setting angular resolution to "<<angular_resolution<<".\n";
00088 break;
00089 }
00090 case 'c':
00091 {
00092 coordinate_frame = (RangeImage::CoordinateFrame)strtol(optarg, NULL, 0);
00093 cout << "Using coordinate frame "<<(int)coordinate_frame<<".\n";
00094 break;
00095 }
00096 case 'h':
00097 printUsage(argv[0]);
00098 exit(0);
00099 }
00100 }
00101 angular_resolution = deg2rad(angular_resolution);
00102
00103
00104
00105
00106
00107 pcl::PointCloud<PointType> point_cloud;
00108 PointCloud<PointWithViewpoint> far_ranges;
00109 Eigen::Affine3f scene_sensor_pose(Eigen::Affine3f::Identity());
00110 if (optind < argc)
00111 {
00112 sensor_msgs::PointCloud2 point_cloud_data;
00113 if (pcl::io::loadPCDFile(argv[optind], point_cloud_data) == -1)
00114 {
00115 ROS_ERROR_STREAM("Was not able to open file \""<<argv[optind]<<"\".\n");
00116 printUsage(argv[0]);
00117 exit(0);
00118 }
00119 fromROSMsg(point_cloud_data, point_cloud);
00120 RangeImage::extractFarRanges(point_cloud_data, far_ranges);
00121 if (pcl::getFieldIndex(point_cloud_data, "vp_x")>=0)
00122 {
00123 cout << "Scene point cloud has viewpoint information.\n";
00124 PointCloud<PointWithViewpoint> tmp_pc; fromROSMsg(point_cloud_data, tmp_pc);
00125 Eigen::Vector3f average_viewpoint = RangeImage::getAverageViewPoint(tmp_pc);
00126 scene_sensor_pose = Eigen::Translation3f(average_viewpoint) * scene_sensor_pose;
00127 }
00128 }
00129 else
00130 {
00131 cout << "\nNo *.pcd file given => Genarating example point cloud.\n\n";
00132 for (float x=-0.5f; x<=0.5f; x+=0.01f)
00133 {
00134 for (float y=-0.5f; y<=0.5f; y+=0.01f)
00135 {
00136 PointType point; point.x = x; point.y = y; point.z = 2.0f - y;
00137 point_cloud.points.push_back(point);
00138 }
00139 }
00140 point_cloud.width = point_cloud.points.size(); point_cloud.height = 1;
00141 }
00142
00143
00144
00145
00146
00147 float noise_level = 0.0;
00148 float min_range = 0.0f;
00149 int border_size = 1;
00150 RangeImage range_image;
00151 range_image.createFromPointCloud(point_cloud, angular_resolution, deg2rad(360.0f), deg2rad(180.0f),
00152 scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);
00153 range_image.integrateFarRanges(far_ranges);
00154
00155
00156
00157
00158 PCLVisualizer viewer("3D Viewer");
00159 viewer.addCoordinateSystem(1.0f);
00160 viewer.addPointCloud(point_cloud, "original point cloud");
00161
00162
00163
00164
00165
00166 RangeImageVisualizer range_image_widget("Range image");
00167 range_image_widget.setRangeImage(range_image);
00168
00169
00170
00171
00172 while(!viewer.wasStopped() || range_image_widget.isShown())
00173 {
00174 ImageWidgetWX::spinOnce();
00175 viewer.spinOnce(100);
00176 usleep(100000);
00177 }
00178 }