test_segmentation.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) 2010-2011, Willow Garage, 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 Willow Garage, Inc. 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_segmentation.cpp 5066 2012-03-14 06:42:21Z rusu $
00037  *
00038  */
00039 
00040 #include <gtest/gtest.h>
00041 #include <pcl/kdtree/kdtree_flann.h>
00042 #include <pcl/point_types.h>
00043 #include <pcl/point_cloud.h>
00044 #include <pcl/io/pcd_io.h>
00045 
00046 #include <pcl/segmentation/extract_polygonal_prism_data.h>
00047 #include <pcl/segmentation/segment_differences.h>
00048 
00049 using namespace pcl;
00050 using namespace pcl::io;
00051 
00052 PointCloud<PointXYZ>::Ptr cloud_;
00053 PointCloud<PointXYZ>::Ptr cloud_t_;
00054 KdTree<PointXYZ>::Ptr tree_;
00055 
00057 TEST (SegmentDifferences, Segmentation)
00058 {
00059   SegmentDifferences<PointXYZ> sd;
00060   sd.setInputCloud (cloud_);
00061   sd.setDistanceThreshold (0.00005);
00062 
00063   // Set the target as itself
00064   sd.setTargetCloud (cloud_);
00065 
00066   PointCloud<PointXYZ> output;
00067   sd.segment (output);
00068 
00069   EXPECT_EQ (static_cast<int> (output.points.size ()), 0);
00070   
00071   // Set a different target
00072   sd.setTargetCloud (cloud_t_);
00073   sd.segment (output);
00074   EXPECT_EQ (static_cast<int> (output.points.size ()), 126);
00075   //savePCDFile ("./test/0-t.pcd", output);
00076 
00077   // Reverse
00078   sd.setInputCloud (cloud_t_);
00079   sd.setTargetCloud (cloud_);
00080   sd.segment (output);
00081   EXPECT_EQ (static_cast<int> (output.points.size ()), 127);
00082   //savePCDFile ("./test/t-0.pcd", output);
00083 }
00084 
00086 TEST (ExtractPolygonalPrism, Segmentation)
00087 {
00088   PointCloud<PointXYZ>::Ptr hull (new PointCloud<PointXYZ>);
00089   hull->points.resize (5);
00090 
00091   for (size_t i = 0; i < hull->points.size (); ++i)
00092   {
00093     hull->points[i].x = hull->points[i].y = static_cast<float> (i);
00094     hull->points[i].z = 0.0f;
00095   }
00096 
00097   ExtractPolygonalPrismData<PointXYZ> ex;
00098   ex.setInputCloud (cloud_);
00099   ex.setInputPlanarHull (hull);
00100 
00101   PointIndices output;
00102   ex.segment (output);
00103 
00104   EXPECT_EQ (static_cast<int> (output.indices.size ()), 0);
00105 }
00106 
00107 /* ---[ */
00108 int
00109   main (int argc, char** argv)
00110 {
00111   if (argc < 2)
00112   {
00113     std::cerr << "No test file given. Please download `bun0.pcd` and pass its path to the test." << std::endl;
00114     return (-1);
00115   }
00116 
00117   // Load a standard PCD file from disk
00118   PointCloud<PointXYZ> cloud, cloud_t;
00119   if (loadPCDFile (argv[1], cloud) < 0)
00120   {
00121     std::cerr << "Failed to read test file. Please download `bun0.pcd` and pass its path to the test." << std::endl;
00122     return (-1);
00123   }
00124 
00125   // Tranpose the cloud
00126   cloud_t = cloud;
00127   for (size_t i = 0; i < cloud.points.size (); ++i)
00128     cloud_t.points[i].x += 0.01f;
00129 
00130   cloud_   = cloud.makeShared ();
00131   cloud_t_ = cloud_t.makeShared ();
00132 
00133   testing::InitGoogleTest (&argc, argv);
00134   return (RUN_ALL_TESTS ());
00135 }
00136 /* ]--- */


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:18:32