PCL Series--three-dimensional reconstruction of moving cube algorithm

Source: Internet
Author: User
Tags set background

PCL series
    • PCL Series--read in the PCD format file operation
    • PCL Series--writing point cloud data to a PCD format file
    • PCL Series-Stitching two point clouds
    • PCL Series--extracting Narf key points from depth image (Rangeimage)
    • PCL Series--how to visualize depth images
    • PCL Series--How to use the iterative nearest point method (ICP) Registration
    • PCL Series--How to gradually register a pair of point clouds
    • PCL Series--Poisson reconstruction of three-dimensional reconstruction
    • PCL Series--three-dimensional reconstruction of greedy triangular projection algorithm
    • PCL Series--three-dimensional reconstruction of moving cube algorithm
Description

Through this tutorial, we will learn to:

    • If the three-dimensional point cloud reconstruction is done by moving the cube algorithm.
    • The program supports two file formats: *.pcd and *.ply .
    • The program reads the point cloud file First, then calculates the normal vector and puts the normal vector and the point cloud coordinates together, then uses the moving cube algorithm to reconstruct, finally displays the result.
Operation
    • Create a new file in VS2010 recon_marchingCubes.cpp , and then copy the following code to the file.
    • Refer to the previous article to configure the properties of the item. Sets the Include directory and Library directory and additional dependencies.
#include <pcl/point_types.h>#include <pcl/io/pcd_io.h>#include <pcl/io/ply_io.h>#include <pcl/kdtree/kdtree_flann.h>#include <pcl/features/normal_3d.h>#include <pcl/surface/marching_cubes_hoppe.h>#include <pcl/surface/marching_cubes_rbf.h>#include <pcl/surface/gp3.h>#include <pcl/visualization/pcl_visualizer.h>#include <boost/thread/thread.hpp>#include <fstream>#include <iostream>#include <stdio.h>#include <string.h>#include <string>intMain (intargcChar* * argv) {//Determine file format    Chartmpstr[ -];strcpy(tmpstr,argv[1]);Char* Pext =STRRCHR(Tmpstr,'. ');STD::stringExtply ("Ply");STD::stringEXTPCD ("PCD");if(Pext) {*pext=' + ';    pext++; }STD::stringExt (pext);//If file format is not supported, exit the program    if(! (ext = = extply) | | (ext = = EXTPCD))) {STD::cout<<"file format not supported!"<<STD:: Endl;STD::cout<<"Supported file formats: *.PCD and *.ply! "<<STD:: Endl;return(-1); }//Select input mode according to file formatPCL::P OINTCLOUD&LT;PCL::P ointxyz>::P TR Cloud (NewPCL::P OINTCLOUD&LT;PCL::P ointxyz>);//Create point cloud object pointer to store input    if(ext = = extply) {if(Pcl::io::loadplyfile (argv[1], *cloud) = =-1) {Pcl_error ("Could not read ply file!\n") ;return-1; }    }Else{if(Pcl::io::loadpcdfile (argv[1], *cloud) = =-1) {Pcl_error ("Could not read PCD file!\n") ;return-1; }    }//Estimation method vectorPCL::NORMALESTIMATION&LT;PCL::P ointxyz, pcl::normal> N; PCL::P ointcloud<pcl::normal>::P tr normals (NewPCL::P ointcloud<pcl::normal>); PCL::SEARCH::KDTREE&LT;PCL::P ointxyz>::P tr Tree (NewPCL::SEARCH::KDTREE&LT;PCL::P ointxyz>);  Tree->setinputcloud (Cloud);  N.setinputcloud (Cloud);  N.setsearchmethod (tree); N.setksearch ( -); N.compute (*normals);//Calculate normals, results stored in normals  //* normals cannot contain both the normal vector of the point and the curvature of the surface  //Put the point cloud and the normals togetherPCL::P OINTCLOUD&LT;PCL::P ointnormal>::P tr cloud_with_normals (NewPCL::P OINTCLOUD&LT;PCL::P ointnormal>); Pcl::concatenatefields (*cloud, *normals, *cloud_with_normals);//* cloud_with_normals = cloud + normals  //Create search TreePCL::SEARCH::KDTREE&LT;PCL::P ointnormal>::P tr Tree2 (NewPCL::SEARCH::KDTREE&LT;PCL::P ointnormal>); Tree2->setinputcloud (cloud_with_normals);//Initialize the Marchingcubes object and set the parametersPCL::MARCHINGCUBES&LT;PCL::P ointnormal> *MC; MC =NewPCL::MARCHINGCUBESHOPPE&LT;PCL::P ointnormal> ();/ * if (HOPPE_OR_RBF = = 0) mc = new PCL::MARCHINGCUBESHOPPE<PCL::P ointnormal> ();    else {mc = new PCL::MARCHINGCUBESRBF<PCL::P ointnormal> (); (REINTERPRET_CAST<PCL::MARCHINGCUBESRBF<PCL::P ointnormal>*> (MC))->setoffsurfacedisplacement (off  _surface_displacement); }    */    //Create a multi-deformed mesh for storing resultsPCL::P Olygonmesh Mesh;//Set parameters for the Marchingcubes objectMc->setisolevel (0.0f); Mc->setgridresolution ( -, -, -); Mc->setpercentageextendgrid (0.0f);//Set Search methodMc->setinputcloud (cloud_with_normals);//Perform refactoring, save results in meshMc->reconstruct (mesh);//Save grid DiagramPcl::io::saveplyfile ("Result.ply", mesh);//Show result graphBoost::shared_ptr<pcl::visualization::P clvisualizer> Viewer (NewPcl::visualization::P Clvisualizer ("3D Viewer")); Viewer->setbackgroundcolor (0,0,0);//Set BackgroundViewer->addpolygonmesh (Mesh,"My");//Set the displayed gridViewer->addcoordinatesystem (1.0);//Set coordinate systemViewer->initcameraparameters (); while(!viewer->wasstopped ()) {Viewer->spinonce ( -); Boost::this_thread::sleep (boost::p osix_time::microseconds (100000)); }return(0);}
    • Rebuild the project.
    • To change the project's debug directory, hold down SHIFT while you click the right mouse button to open the Cmd window in the current window.
    • Enter in the command line recon_marchingCubes.exe bunny.points.ply to execute the program. Get the result as shown.

PCL Series--three-dimensional reconstruction of moving cube algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.