Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
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
00116 if (!input_)
00117 return (false);
00118
00119
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
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