test_grid_projection.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2012-, Open Perception, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of the copyright holder(s) nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id: test_surface.cpp 6579 2012-07-27 18:57:32Z rusu $
00037  *
00038  */
00039 
00040 #include <gtest/gtest.h>
00041 
00042 #include <pcl/point_types.h>
00043 #include <pcl/io/pcd_io.h>
00044 #include <pcl/io/vtk_io.h>
00045 #include <pcl/features/normal_3d.h>
00046 #include <pcl/surface/grid_projection.h>
00047 #include <pcl/common/common.h>
00048 
00049 using namespace pcl;
00050 using namespace pcl::io;
00051 using namespace std;
00052 
00053 PointCloud<PointXYZ>::Ptr cloud (new PointCloud<PointXYZ>);
00054 PointCloud<PointNormal>::Ptr cloud_with_normals (new PointCloud<PointNormal>);
00055 search::KdTree<PointXYZ>::Ptr tree;
00056 search::KdTree<PointNormal>::Ptr tree2;
00057 
00058 // add by ktran to test update functions
00059 PointCloud<PointXYZ>::Ptr cloud1 (new PointCloud<PointXYZ>);
00060 PointCloud<PointNormal>::Ptr cloud_with_normals1 (new PointCloud<PointNormal>);
00061 search::KdTree<PointXYZ>::Ptr tree3;
00062 search::KdTree<PointNormal>::Ptr tree4;
00063 
00065 TEST (PCL, GridProjection)
00066 {
00067   // Init objects
00068   PolygonMesh grid;
00069   GridProjection<PointNormal> gp;
00070 
00071   // Set parameters
00072   gp.setInputCloud (cloud_with_normals);
00073   gp.setSearchMethod (tree2);
00074   gp.setResolution (0.005);
00075   gp.setPaddingSize (3);
00076 
00077   // Reconstruct
00078   gp.reconstruct (grid);
00079   //saveVTKFile ("./test/bun0-grid.vtk", grid);
00080   EXPECT_GE (grid.cloud.width, 5180);
00081   EXPECT_GE (int (grid.polygons.size ()), 1295);
00082   EXPECT_EQ (int (grid.polygons.at (0).vertices.size ()), 4);
00083   EXPECT_EQ (int (grid.polygons.at (0).vertices.at (0)), 0);
00084 }
00085 
00086 /* ---[ */
00087 int
00088 main (int argc, char** argv)
00089 {
00090   if (argc < 2)
00091   {
00092     std::cerr << "No test file given. Please download `bun0.pcd` and pass its path to the test." << std::endl;
00093     return (-1);
00094   }
00095 
00096   // Load file
00097   pcl::PCLPointCloud2 cloud_blob;
00098   loadPCDFile (argv[1], cloud_blob);
00099   fromPCLPointCloud2 (cloud_blob, *cloud);
00100 
00101   // Create search tree
00102   tree.reset (new search::KdTree<PointXYZ> (false));
00103   tree->setInputCloud (cloud);
00104 
00105   // Normal estimation
00106   NormalEstimation<PointXYZ, Normal> n;
00107   PointCloud<Normal>::Ptr normals (new PointCloud<Normal> ());
00108   n.setInputCloud (cloud);
00109   //n.setIndices (indices[B);
00110   n.setSearchMethod (tree);
00111   n.setKSearch (20);
00112   n.compute (*normals);
00113 
00114   // Concatenate XYZ and normal information
00115   pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
00116       
00117   // Create search tree
00118   tree2.reset (new search::KdTree<PointNormal>);
00119   tree2->setInputCloud (cloud_with_normals);
00120 
00121   // Process for update cloud
00122   if(argc == 3){
00123     pcl::PCLPointCloud2 cloud_blob1;
00124     loadPCDFile (argv[2], cloud_blob1);
00125     fromPCLPointCloud2 (cloud_blob1, *cloud1);
00126         // Create search tree
00127     tree3.reset (new search::KdTree<PointXYZ> (false));
00128     tree3->setInputCloud (cloud1);
00129 
00130     // Normal estimation
00131     NormalEstimation<PointXYZ, Normal> n1;
00132     PointCloud<Normal>::Ptr normals1 (new PointCloud<Normal> ());
00133     n1.setInputCloud (cloud1);
00134 
00135     n1.setSearchMethod (tree3);
00136     n1.setKSearch (20);
00137     n1.compute (*normals1);
00138 
00139     // Concatenate XYZ and normal information
00140     pcl::concatenateFields (*cloud1, *normals1, *cloud_with_normals1);
00141     // Create search tree
00142     tree4.reset (new search::KdTree<PointNormal>);
00143     tree4->setInputCloud (cloud_with_normals1);
00144   }
00145 
00146   // Testing
00147   testing::InitGoogleTest (&argc, argv);
00148   return (RUN_ALL_TESTS ());
00149 }
00150 /* ]--- */


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:34:59