pcl_base.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: pcl_base.cpp 5026 2012-03-12 02:51:44Z rusu $
00037  *
00038  */
00039 
00040 #include <pcl/pcl_base.h>
00041 
00043 void
00044 pcl::PCLBase<sensor_msgs::PointCloud2>::setInputCloud (const PointCloud2ConstPtr &cloud)
00045 {
00046   input_ = cloud;
00047 
00048   for (int d = 0; d < static_cast<int>(cloud->fields.size ()); ++d)
00049   {
00050     if (cloud->fields[d].name == x_field_name_)
00051       x_idx_ = d;
00052     if (cloud->fields[d].name == y_field_name_)
00053       y_idx_ = d;
00054     if (cloud->fields[d].name == z_field_name_)
00055       z_idx_ = d;
00056   }
00057 
00058   // Obtain the size of all fields. Restrict to sizeof FLOAT32 for now
00059   field_sizes_.resize (input_->fields.size ());
00060   for (size_t d = 0; d < input_->fields.size (); ++d)
00061   {
00062     int fsize;
00063     switch (input_->fields[d].datatype)
00064     {
00065       case sensor_msgs::PointField::INT8:
00066       case sensor_msgs::PointField::UINT8:
00067       {
00068         fsize = 1;
00069         break;
00070       }
00071 
00072       case sensor_msgs::PointField::INT16:
00073       case sensor_msgs::PointField::UINT16:
00074       {
00075         fsize = 2;
00076         break;
00077       }
00078 
00079       case sensor_msgs::PointField::INT32:
00080       case sensor_msgs::PointField::UINT32:
00081       case sensor_msgs::PointField::FLOAT32:
00082       {
00083         fsize = 4;
00084         break;
00085       }
00086 
00087       case sensor_msgs::PointField::FLOAT64:
00088       {
00089         fsize = 8;
00090         break;
00091       }
00092 
00093       default:
00094       {
00095         PCL_ERROR ("[PCLBase::setInputCloud] Invalid field type (%d)!\n", input_->fields[d].datatype);
00096         fsize = 0;
00097         break;
00098       }
00099     }
00100     field_sizes_[d] = (std::min) (fsize, static_cast<int>(sizeof (float)));
00101   }
00102 }
00103 
00105 bool
00106 pcl::PCLBase<sensor_msgs::PointCloud2>::deinitCompute ()
00107 {
00108   return (true);
00109 }
00110 
00112 bool
00113 pcl::PCLBase<sensor_msgs::PointCloud2>::initCompute ()
00114 {
00115   // Check if input was set
00116   if (!input_)
00117     return (false);
00118 
00119   // If no point indices have been given, construct a set of indices for the entire input point cloud
00120   if (!indices_)
00121   {
00122     fake_indices_ = true;
00123     indices_.reset (new std::vector<int>);
00124     try
00125     {
00126       indices_->resize (input_->width * input_->height);
00127     }
00128     catch (std::bad_alloc)
00129     {
00130       PCL_ERROR ("[initCompute] Failed to allocate %zu indices.\n", (input_->width * input_->height));
00131     }
00132     for (size_t i = 0; i < indices_->size (); ++i) { (*indices_)[i] = static_cast<int>(i); }
00133   }
00134   // If we have a set of fake indices, but they do not match the number of points in the cloud, update them
00135   if (fake_indices_ && indices_->size () != (input_->width * input_->height))
00136   {
00137     size_t indices_size = indices_->size ();
00138     indices_->resize (input_->width * input_->height);
00139     for (size_t i = indices_size; i < indices_->size (); ++i) { (*indices_)[i] = static_cast<int>(i); }
00140   }
00141 
00142   return (true);
00143 }
00144 


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:16:25