int main(int argc, char **argv){ if (argc < 2){ printf("Error: Debe especificar un archivo .pcd\n"); exit(1); } // Cargar nube de puntos PointCloud::Ptr cloud (new PointCloud), cloud_filt (new PointCloud); pcl::io::loadPCDFile(argv[1],*cloud); // Crear filtro. Remueve todos los puntos que se salen del campo especificado. // En este caso, quita puntos tales que "z" está fuera de [0,1.1]. // Se puede setear como filtro inverso con pass.setFilterLimitsNegative (true); /* pcl::PassThrough<pcl::PointXYZ> pass; pass.setInputCloud(cloud); pass.setFilterFieldName("z"); pass.setFilterLimits(0, 5); pass.setFilterLimitsNegative (true); pass.filter (*cloud_filt);*/ // Crear convex hull alrededor den nube PointCloud::Ptr hull(new PointCloud); pcl::ConcaveHull<pcl::PointXYZ> chull; chull.setInputCloud(cloud); chull.setAlpha(0.1); chull.reconstruct(*hull); // Crear visualizador boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = simpleVis(hull); while (!viewer->wasStopped()){ viewer->spinOnce(100); boost::this_thread::sleep (boost::posix_time::microseconds (100000)); } }
int main(int argc, char **argv){ if (argc < 2){ printf("Error: Debe especificar un archivo .pcd\n"); exit(1); } // Cargar nube de puntos PointCloud::Ptr cloud (new PointCloud); pcl::io::loadPCDFile(argv[1],*cloud); // Crear visualizador boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = simpleVis(cloud); // Segmentar segmentator.setOptimizeCoefficients(true); segmentator.setModelType(pcl::SACMODEL_PLANE); segmentator.setMethodType(pcl::SAC_RANSAC); segmentator.setDistanceThreshold(SEG_THRESHOLD); segmentator.setInputCloud(cloud); pcl::ModelCoefficients::Ptr coefs (new pcl::ModelCoefficients()); pcl::PointIndices::Ptr inliers (new pcl::PointIndices()); segmentator.segment(*inliers,*coefs); // Ver qué se obtuvo printf("Se obtienen %d puntos\n",(int)inliers->indices.size()); if (inliers->indices.size() == 0){ printf("Segmentación no sirvió de nada.\n"); exit(1); } viewer->addPlane(*coefs, "planito"); // Obtener centroide y dibujarlo Eigen::Vector4f centroid; compute3DCentroid(*cloud,centroid); viewer->addSphere(pcl::PointXYZ(centroid(0),centroid(1),centroid(2)), 0.2, "centroide"); // Dibujar un plano en el viewer para indicar más menos qué se obtuvo // http://docs.pointclouds.org/trunk/classpcl_1_1visualization_1_1_p_c_l_visualizer.html while (!viewer->wasStopped()){ viewer->spinOnce(100); boost::this_thread::sleep (boost::posix_time::microseconds (100000)); } }
pcl::RandomSampleConsensus<pcl::PointXYZ> ransac (model_s); ransac.setDistanceThreshold (.01); ransac.computeModel(); ransac.getInliers(inliers); } // copies all inliers of the model computed to another PointCloud pcl::copyPointCloud<pcl::PointXYZ>(*cloud, inliers, *final); // creates the visualization object and adds either our orignial cloud or all of the inliers // depending on the command line arguments specified. boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer; if (pcl::console::find_argument (argc, argv, "-f") >= 0 || pcl::console::find_argument (argc, argv, "-sf") >= 0) viewer = simpleVis(final); else viewer = simpleVis(cloud); setView1(*viewer); while (!viewer->wasStopped ()) { viewer->spinOnce (100); boost::this_thread::sleep (boost::posix_time::microseconds (100000)); } return 0; } //3708.61,6955.86/562.042,697.162,-373.087/5490.76,-774.724,-581.186/0.235781,0.693242,0.681045/0.523599/777,520/0,0 void setView1(pcl::visualization::PCLVisualizer& viewer)
// -------------- // -----Main----- // -------------- int main (int argc, char** argv) { // -------------------------------------- // -----Parse Command Line Arguments----- // -------------------------------------- if (pcl::console::find_argument (argc, argv, "-h") >= 0) { printUsage (argv[0]); return 0; } bool simple(false), rgb(false), custom_c(false), normals(false), shapes(false), viewports(false), interaction_customization(false); if (pcl::console::find_argument (argc, argv, "-s") >= 0) { simple = true; std::cout << "Simple visualisation example\n"; } else if (pcl::console::find_argument (argc, argv, "-c") >= 0) { custom_c = true; std::cout << "Custom colour visualisation example\n"; } else if (pcl::console::find_argument (argc, argv, "-r") >= 0) { rgb = true; std::cout << "RGB colour visualisation example\n"; } else if (pcl::console::find_argument (argc, argv, "-n") >= 0) { normals = true; std::cout << "Normals visualisation example\n"; } else if (pcl::console::find_argument (argc, argv, "-a") >= 0) { shapes = true; std::cout << "Shapes visualisation example\n"; } else if (pcl::console::find_argument (argc, argv, "-v") >= 0) { viewports = true; std::cout << "Viewports example\n"; } else if (pcl::console::find_argument (argc, argv, "-i") >= 0) { interaction_customization = true; std::cout << "Interaction Customization example\n"; } else { printUsage (argv[0]); return 0; } // ------------------------------------ // -----Create example point cloud----- // ------------------------------------ pcl::PointCloud<pcl::PointXYZ>::Ptr basic_cloud_ptr (new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>); std::cout << "Genarating example point clouds.\n\n"; // We're going to make an ellipse extruded along the z-axis. The colour for // the XYZRGB cloud will gradually go from red to green to blue. uint8_t r(255), g(15), b(15); for (float z(-1.0); z <= 1.0; z += 0.05) { for (float angle(0.0); angle <= 360.0; angle += 5.0) { pcl::PointXYZ basic_point; basic_point.x = 0.5 * cosf (pcl::deg2rad(angle)); basic_point.y = sinf (pcl::deg2rad(angle)); basic_point.z = z; basic_cloud_ptr->points.push_back(basic_point); pcl::PointXYZRGB point; point.x = basic_point.x; point.y = basic_point.y; point.z = basic_point.z; uint32_t rgb = (static_cast<uint32_t>(r) << 16 | static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b)); point.rgb = *reinterpret_cast<float*>(&rgb); point_cloud_ptr->points.push_back (point); } if (z < 0.0) { r -= 12; g += 12; } else { g -= 12; b += 12; } } basic_cloud_ptr->width = (int) basic_cloud_ptr->points.size (); basic_cloud_ptr->height = 1; point_cloud_ptr->width = (int) point_cloud_ptr->points.size (); point_cloud_ptr->height = 1; // ---------------------------------------------------------------- // -----Calculate surface normals with a search radius of 0.05----- // ---------------------------------------------------------------- pcl::NormalEstimation<pcl::PointXYZRGB, pcl::Normal> ne; ne.setInputCloud (point_cloud_ptr); pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZRGB> ()); ne.setSearchMethod (tree); pcl::PointCloud<pcl::Normal>::Ptr cloud_normals1 (new pcl::PointCloud<pcl::Normal>); ne.setRadiusSearch (0.05); ne.compute (*cloud_normals1); // --------------------------------------------------------------- // -----Calculate surface normals with a search radius of 0.1----- // --------------------------------------------------------------- pcl::PointCloud<pcl::Normal>::Ptr cloud_normals2 (new pcl::PointCloud<pcl::Normal>); ne.setRadiusSearch (0.1); ne.compute (*cloud_normals2); boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer; if (simple) { viewer = simpleVis(basic_cloud_ptr); } else if (rgb) { viewer = rgbVis(point_cloud_ptr); } else if (custom_c) { viewer = customColourVis(basic_cloud_ptr); } else if (normals) { viewer = normalsVis(point_cloud_ptr, cloud_normals2); } else if (shapes) { viewer = shapesVis(point_cloud_ptr); } else if (viewports) { viewer = viewportsVis(point_cloud_ptr, cloud_normals1, cloud_normals2); } else if (interaction_customization) { viewer = interactionCustomizationVis(); } //-------------------- // -----Main loop----- //-------------------- while (!viewer->wasStopped ()) { viewer->spinOnce (100); boost::this_thread::sleep (boost::posix_time::microseconds (100000)); } }
// -------------- // -----Main----- // -------------- int main (int argc, char** argv) { // -------------------------------------- // -----Parse Command Line Arguments----- // -------------------------------------- if (pcl::console::find_argument (argc, argv, "-h") >= 0) { printUsage (argv[0]); return 0; } bool simple(false), rgb(false), custom_c(false), normals(false), shapes(false), viewports(false), interaction_customization(false); if (pcl::console::find_argument (argc, argv, "-s") >= 0) { simple = true; std::cout << "Simple visualisation example\n"; } else if (pcl::console::find_argument (argc, argv, "-c") >= 0) { custom_c = true; std::cout << "Custom colour visualisation example\n"; } else if (pcl::console::find_argument (argc, argv, "-r") >= 0) { rgb = true; std::cout << "RGB colour visualisation example\n"; } else if (pcl::console::find_argument (argc, argv, "-n") >= 0) { normals = true; std::cout << "Normals visualisation example\n"; } else if (pcl::console::find_argument (argc, argv, "-a") >= 0) { shapes = true; std::cout << "Shapes visualisation example\n"; } else if (pcl::console::find_argument (argc, argv, "-v") >= 0) { viewports = true; std::cout << "Viewports example\n"; } else if (pcl::console::find_argument (argc, argv, "-i") >= 0) { interaction_customization = true; std::cout << "Interaction Customization example\n"; } else { printUsage (argv[0]); return 0; } // ------------------------------------ // -----Create example point cloud----- // ------------------------------------ pcl::PointCloud<pcl::PointXYZ>::Ptr basic_cloud_ptr (new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>); std::cout << "Genarating example point clouds.\n\n"; // We're going to make an ellipse extruded along the z-axis. The colour for // the XYZRGB cloud will gradually go from red to green to blue. uint8_t r(255), g(15), b(15); for (float z(-1.0); z <= 1.0; z += 0.05) { for (float angle(0.0); angle <= 360.0; angle += 5.0) { pcl::PointXYZ basic_point; basic_point.x = 0.5 * cosf (pcl::deg2rad(angle)); basic_point.y = sinf (pcl::deg2rad(angle)); basic_point.z = z; basic_cloud_ptr->points.push_back(basic_point); pcl::PointXYZRGB point; point.x = basic_point.x; point.y = basic_point.y; point.z = basic_point.z; uint32_t rgb = (static_cast<uint32_t>(r) << 16 | static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b)); point.rgb = *reinterpret_cast<float*>(&rgb); point_cloud_ptr->points.push_back (point); } if (z < 0.0) { r -= 12; g += 12; } else { g -= 12; b += 12; } } basic_cloud_ptr->width = (int) basic_cloud_ptr->points.size (); basic_cloud_ptr->height = 1; point_cloud_ptr->width = (int) point_cloud_ptr->points.size (); point_cloud_ptr->height = 1; // ---------------------------------------------------------------- // -----Calculate surface normals with a search radius of 0.05----- // ---------------------------------------------------------------- pcl::NormalEstimation<pcl::PointXYZRGB, pcl::Normal> ne; ne.setInputCloud (point_cloud_ptr); pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZRGB> ()); ne.setSearchMethod (tree); pcl::PointCloud<pcl::Normal>::Ptr cloud_normals1 (new pcl::PointCloud<pcl::Normal>); ne.setRadiusSearch (0.05); ne.compute (*cloud_normals1); // --------------------------------------------------------------- // -----Calculate surface normals with a search radius of 0.1----- // --------------------------------------------------------------- pcl::PointCloud<pcl::Normal>::Ptr cloud_normals2 (new pcl::PointCloud<pcl::Normal>); ne.setRadiusSearch (0.1); ne.compute (*cloud_normals2); // ---------------------------------------------------------------- // -----Load PCD file from Kinect --------------------------------- // - TF ----------------------------------------------------------- pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr_kinect (new pcl::PointCloud<pcl::PointXYZRGB>); pcl::PointCloud<pcl::PointXYZRGB>& point_cloud_kinect = *point_cloud_ptr_kinect; pcl::io::loadPCDFile ("/home/taylor/src/data_pcd/top/kinect_top_rgb.pcd", point_cloud_kinect); // --end import -- boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer; if (simple) { viewer = simpleVis(basic_cloud_ptr); } else if (rgb) { viewer = rgbVis(point_cloud_ptr_kinect); } else if (custom_c) { viewer = customColourVis(point_cloud_ptr_kinect); } else if (normals) { viewer = normalsVis(point_cloud_ptr, cloud_normals2); } else if (shapes) { viewer = shapesVis(point_cloud_ptr); } else if (viewports) { viewer = viewportsVis(point_cloud_ptr, cloud_normals1, cloud_normals2); } else if (interaction_customization) { viewer = interactionCustomizationVis(); } //-------------------- // -----Main loop----- //-------------------- //TF custom cout << "begin custom" << endl; viewer->spinOnce(1000); viewer->setCameraPosition(0.00, 0.00, -1.25, 0.00, 0.00, 0.625, -0.00, -0.99999, 0.000); viewer->setCameraFieldOfView(0.523599); viewer->setCameraClipDistances(0.0, 4.0); viewer->setSize(1000,1000); viewer->updateCamera(); viewer->spinOnce(1000); cout << " " << endl; cout << "drawing sphere..." << endl; pcl::PointXYZ p1; p1.x = -0.031; p1.y = 0.021; p1.z = 0.602; viewer->addSphere(p1, 0.01, 1.0, 0.0, 1.0, "PickedPoint", 0); cout << "end custom" << endl; //end TF Custom while (!viewer->wasStopped ()) { viewer->spinOnce (10000); boost::this_thread::sleep (boost::posix_time::microseconds (100000)); } }
// -------------- // -----Main----- // -------------- int main(int argc, char** argv) { // -------------------------------------- // -----Parse Command Line Arguments----- // -------------------------------------- if (pcl17::console::find_argument(argc, argv, "-h") >= 0) { printUsage(argv[0]); return 0; } bool simple(false), rgb(false), custom_c(false), normals(false), shapes(false), viewports(false), interaction_customization(false); if (pcl17::console::find_argument(argc, argv, "-s") >= 0) { simple = true; std::cout << "Simple visualisation example\n"; } else if (pcl17::console::find_argument(argc, argv, "-c") >= 0) { custom_c = true; std::cout << "Custom colour visualisation example\n"; } else if (pcl17::console::find_argument(argc, argv, "-r") >= 0) { rgb = true; std::cout << "RGB colour visualisation example\n"; } else if (pcl17::console::find_argument(argc, argv, "-n") >= 0) { normals = true; std::cout << "Normals visualisation example\n"; } else if (pcl17::console::find_argument(argc, argv, "-a") >= 0) { shapes = true; std::cout << "Shapes visualisation example\n"; } else if (pcl17::console::find_argument(argc, argv, "-v") >= 0) { viewports = true; std::cout << "Viewports example\n"; } else if (pcl17::console::find_argument(argc, argv, "-i") >= 0) { interaction_customization = true; std::cout << "Interaction Customization example\n"; } else { printUsage(argv[0]); return 0; } // ------------------------------------ // -----Create example point cloud----- // ------------------------------------ pcl17::PointCloud<pcl17::PointXYZRGB>::Ptr basic_cloud_ptr(new pcl17::PointCloud<pcl17::PointXYZRGB>); pcl17::PointCloud<pcl17::PointXYZRGB>::Ptr point_cloud_ptr(new pcl17::PointCloud<pcl17::PointXYZRGB>); pcl17::PointCloud<pcl17::PointXYZRGB>::Ptr cloud_f(new pcl17::PointCloud<pcl17::PointXYZRGB>); pcl17::VoxelGrid<pcl17::PointXYZRGB > sor; //pcl17::PLYReader reader; //reader.read("box.ply",*point_cloud_ptr,0); //pcl17::PointXYZRGB point; if (pcl17::io::loadPCDFile<pcl17::PointXYZRGB>(argv[1], *point_cloud_ptr) == -1) //* load the file { PCL17_ERROR("Couldn't read file test_pcd.pcd \n"); return (-1); } basic_cloud_ptr = point_cloud_ptr; /* std::cout << "Loaded " << point_cloud_ptr->width * point_cloud_ptr->height << " data points" << std::endl; cout << "gobbel" << endl; sor.setInputCloud(point_cloud_ptr); std::cerr << "PointCloud before filtering: " << point_cloud_ptr->width * point_cloud_ptr->height << " data points (" << pcl17::getFieldsList(*point_cloud_ptr) << ")."; std::cout << std::endl; sor.setLeafSize(0.01, 0.01, 0.01); sor.filter(*cloud_f); pcl17::io::savePCDFileASCII("BoxFiltered.pcd", *cloud_f); */ /* for (size_t i = 0; i < point_cloud_ptr->points.size (); ++i) std::cout << " " << point_cloud_ptr->points[i].x << " " << point_cloud_ptr->points[i].y << " " << point_cloud_ptr->points[i].z << std::endl; cout << point_cloud_ptr->width << endl; cout << point_cloud_ptr->height << endl; for(int i=0;i<point_cloud_ptr->width * point_cloud_ptr->height;i++) { point=point_cloud_ptr->points.at(i); point.r = 255; point.g = 0; point.b = 0; basic_cloud_ptr->points.at(i)=point; } cout << basic_cloud_ptr->width << endl; cout << basic_cloud_ptr->height << endl; pcl17::PCDWriter writer; writer.write<pcl17::PointXYZRGB> (argv[1], *basic_cloud_ptr, false); point_cloud_ptr=basic_cloud_ptr; */ // ---------------------------------------------------------------- // -----Calculate surface normals with a search radius of 0.05----- // ---------------------------------------------------------------- pcl17::NormalEstimation<pcl17::PointXYZRGB, pcl17::Normal> ne; ne.setInputCloud(point_cloud_ptr); pcl17::search::KdTree<pcl17::PointXYZRGB>::Ptr tree(new pcl17::search::KdTree<pcl17::PointXYZRGB>()); ne.setSearchMethod(tree); pcl17::PointCloud<pcl17::Normal>::Ptr cloud_normals1(new pcl17::PointCloud<pcl17::Normal>); ne.setRadiusSearch(0.05); ne.compute(*cloud_normals1); // --------------------------------------------------------------- // -----Calculate surface normals with a search radius of 0.1----- // --------------------------------------------------------------- pcl17::PointCloud<pcl17::Normal>::Ptr cloud_normals2(new pcl17::PointCloud<pcl17::Normal>); ne.setRadiusSearch(0.1); ne.compute(*cloud_normals2); boost::shared_ptr<pcl17::visualization::PCLVisualizer> viewer; if (simple) { viewer = simpleVis(basic_cloud_ptr); } else if (rgb) { viewer = rgbVis(point_cloud_ptr); } else if (custom_c) { viewer = customColourVis(basic_cloud_ptr); } else if (normals) { viewer = normalsVis(point_cloud_ptr, cloud_normals2); } else if (shapes) { viewer = shapesVis(point_cloud_ptr); } else if (viewports) { viewer = viewportsVis(point_cloud_ptr, cloud_normals1, cloud_normals2); } else if (interaction_customization) { viewer = interactionCustomizationVis(); } //-------------------- // -----Main loop----- //-------------------- while (!viewer->wasStopped()) { viewer->spinOnce(100); boost::this_thread::sleep(boost::posix_time::microseconds(100000)); } }