example_copy_point_cloud.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) 2009-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: example_CopyPointCloud.cpp 4117 2012-01-31 17:56:02Z aichim $
00037  *
00038  */
00039 
00040 /* This example demonstrates how to copy a point cloud. The destination
00041  * cloud is not required to have the same PointType as the source cloud,
00042  * but of course the destination PointType must have a superset of the
00043  * members of the source PointType.
00044  */
00045 
00046 // STL
00047 #include <iostream>
00048 
00049 // PCL
00050 #include <pcl/point_cloud.h>
00051 #include <pcl/point_types.h>
00052 #include <pcl/common/io.h>
00053 
00054 static void
00055 sameType ();
00056 
00057 static void
00058 differenceType ();
00059 
00060 // We show this function as an example of what you cannot do.
00061 // static void
00062 // badConversion ();
00063 
00064 int
00065 main ()
00066 {
00067   sameType();
00068   differenceType();
00069   // badConversion();
00070   return 0;
00071 }
00072 
00073 void
00074 sameType ()
00075 {
00076   typedef pcl::PointCloud<pcl::PointXYZ> CloudType;
00077   CloudType::Ptr cloud (new CloudType);
00078 
00079   CloudType::PointType p;
00080   p.x = 1; p.y = 2; p.z = 3;
00081   cloud->push_back(p);
00082   std::cout << p.x << " " << p.y << " " << p.z << std::endl;
00083 
00084   CloudType::Ptr cloud2(new CloudType);
00085   copyPointCloud(*cloud, *cloud2);
00086 
00087   CloudType::PointType p_retrieved = cloud2->points[0];
00088   std::cout << p_retrieved.x << " " << p_retrieved.y << " " << p_retrieved.z << std::endl;
00089 }
00090 
00091 void
00092 differenceType ()
00093 {
00094   typedef pcl::PointCloud<pcl::PointXYZ> CloudType;
00095   CloudType::Ptr cloud (new CloudType);
00096 
00097   CloudType::PointType p;
00098   p.x = 1; p.y = 2; p.z = 3;
00099   cloud->push_back(p);
00100   std::cout << p.x << " " << p.y << " " << p.z << std::endl;
00101 
00102   typedef pcl::PointCloud<pcl::PointNormal> CloudType2;
00103   CloudType2::Ptr cloud2(new CloudType2);
00104   copyPointCloud(*cloud, *cloud2);
00105 
00106   CloudType2::PointType p_retrieved = cloud2->points[0];
00107   std::cout << p_retrieved.x << " " << p_retrieved.y << " " << p_retrieved.z << std::endl;
00108 }
00109 
00110 /*
00111 // Of course you can't do this, because pcl::Normal does not have x,y,z members:
00112 error: ‘pcl::PointCloud<pcl::Normal>::PointType’ has no member named ‘x’
00113 
00114 void
00115 badConversion ()
00116 {
00117   typedef pcl::PointCloud<pcl::PointXYZ> CloudType;
00118   CloudType::Ptr cloud (new CloudType);
00119   
00120   CloudType::PointType p;
00121   p.x = 1; p.y = 2; p.z = 3;
00122   cloud->push_back(p);
00123   std::cout << p.x << " " << p.y << " " << p.z << std::endl;
00124 
00125   typedef pcl::PointCloud<pcl::Normal> CloudType2;
00126   CloudType2::Ptr cloud2(new CloudType2);
00127   copyPointCloud(*cloud, *cloud2);
00128   
00129   CloudType2::PointType p_retrieved = cloud2->points[0];
00130   std::cout << p_retrieved.x << " " << p_retrieved.y << " " << p_retrieved.z << std::endl;
00131 }
00132 
00133 */


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