00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNERff OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * $Id: pcl_base.cpp 34570 2010-12-06 19:01:39Z rusu $ 00035 * 00036 */ 00037 00044 #include "pcl/pcl_base.h" 00045 #include "pcl/io/io.h" 00046 00048 00051 void 00052 pcl::PCLBase<sensor_msgs::PointCloud2>::setInputCloud (const PointCloud2ConstPtr &cloud) 00053 { 00054 input_ = cloud; 00055 x_idx_ = pcl::getFieldIndex (*input_, x_field_name_); 00056 y_idx_ = pcl::getFieldIndex (*input_, y_field_name_); 00057 z_idx_ = pcl::getFieldIndex (*input_, z_field_name_); 00058 00059 // Obtain the size of all fields. Restrict to sizeof FLOAT32 for now 00060 field_sizes_.resize (input_->fields.size ()); 00061 for (size_t d = 0; d < input_->fields.size (); ++d) 00062 field_sizes_[d] = (std::min) (pcl::getFieldSize (input_->fields[d].datatype), (int)sizeof (float)); 00063 } 00064 00066 00067 bool 00068 pcl::PCLBase<sensor_msgs::PointCloud2>::deinitCompute () 00069 { 00070 // Reset the indices 00071 if (fake_indices_) 00072 { 00073 indices_.reset (); 00074 fake_indices_ = false; 00075 } 00076 return (true); 00077 } 00078 00080 00081 bool 00082 pcl::PCLBase<sensor_msgs::PointCloud2>::initCompute () 00083 { 00084 // Check if input was set 00085 if (!input_) 00086 return (false); 00087 00088 // If no point indices have been given, construct a set of indices for the entire input point cloud 00089 if (!indices_) 00090 { 00091 fake_indices_ = true; 00092 std::vector<int> *indices = new std::vector<int> (input_->width * input_->height); 00093 for (size_t i = 0; i < indices->size (); ++i) { (*indices)[i] = i; } 00094 indices_.reset (indices); 00095 } 00096 return (true); 00097 } 00098