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 #ifndef PCL_PCL_IMPL_BASE_HPP_
00038 #define PCL_PCL_IMPL_BASE_HPP_
00039
00040 #include <pcl/pcl_base.h>
00041 #include <pcl/console/print.h>
00042 #include <cstddef>
00043
00045 template <typename PointT>
00046 pcl::PCLBase<PointT>::PCLBase ()
00047 : input_ ()
00048 , indices_ ()
00049 , use_indices_ (false)
00050 , fake_indices_ (false)
00051 {
00052 }
00053
00055 template <typename PointT>
00056 pcl::PCLBase<PointT>::PCLBase (const PCLBase& base)
00057 : input_ (base.input_)
00058 , indices_ (base.indices_)
00059 , use_indices_ (base.use_indices_)
00060 , fake_indices_ (base.fake_indices_)
00061 {
00062 }
00063
00065 template <typename PointT> void
00066 pcl::PCLBase<PointT>::setInputCloud (const PointCloudConstPtr &cloud)
00067 {
00068 input_ = cloud;
00069 }
00070
00072 template <typename PointT> void
00073 pcl::PCLBase<PointT>::setIndices (const IndicesPtr &indices)
00074 {
00075 indices_ = indices;
00076 fake_indices_ = false;
00077 use_indices_ = true;
00078 }
00079
00081 template <typename PointT> void
00082 pcl::PCLBase<PointT>::setIndices (const IndicesConstPtr &indices)
00083 {
00084 indices_.reset (new std::vector<int> (*indices));
00085 fake_indices_ = false;
00086 use_indices_ = true;
00087 }
00088
00090 template <typename PointT> void
00091 pcl::PCLBase<PointT>::setIndices (const PointIndicesConstPtr &indices)
00092 {
00093 indices_.reset (new std::vector<int> (indices->indices));
00094 fake_indices_ = false;
00095 use_indices_ = true;
00096 }
00097
00099 template <typename PointT> void
00100 pcl::PCLBase<PointT>::setIndices (size_t row_start, size_t col_start, size_t nb_rows, size_t nb_cols)
00101 {
00102 if ((nb_rows > input_->height) || (row_start > input_->height))
00103 {
00104 PCL_ERROR ("[PCLBase::setIndices] cloud is only %d height", input_->height);
00105 return;
00106 }
00107
00108 if ((nb_cols > input_->width) || (col_start > input_->width))
00109 {
00110 PCL_ERROR ("[PCLBase::setIndices] cloud is only %d width", input_->width);
00111 return;
00112 }
00113
00114 size_t row_end = row_start + nb_rows;
00115 if (row_end > input_->height)
00116 {
00117 PCL_ERROR ("[PCLBase::setIndices] %d is out of rows range %d", row_end, input_->height);
00118 return;
00119 }
00120
00121 size_t col_end = col_start + nb_cols;
00122 if (col_end > input_->width)
00123 {
00124 PCL_ERROR ("[PCLBase::setIndices] %d is out of columns range %d", col_end, input_->width);
00125 return;
00126 }
00127
00128 indices_.reset (new std::vector<int>);
00129 indices_->reserve (nb_cols * nb_rows);
00130 for(size_t i = row_start; i < row_end; i++)
00131 for(size_t j = col_start; j < col_end; j++)
00132 indices_->push_back (static_cast<int> ((i * input_->width) + j));
00133 fake_indices_ = false;
00134 use_indices_ = true;
00135 }
00136
00138 template <typename PointT> bool
00139 pcl::PCLBase<PointT>::initCompute ()
00140 {
00141
00142 if (!input_)
00143 return (false);
00144
00145
00146 if (!indices_)
00147 {
00148 fake_indices_ = true;
00149 indices_.reset (new std::vector<int>);
00150 try
00151 {
00152 indices_->resize (input_->points.size ());
00153 }
00154 catch (std::bad_alloc)
00155 {
00156 PCL_ERROR ("[initCompute] Failed to allocate %zu indices.\n", input_->points.size ());
00157 }
00158 for (size_t i = 0; i < indices_->size (); ++i) { (*indices_)[i] = static_cast<int>(i); }
00159 }
00160
00161
00162 if (fake_indices_ && indices_->size () != input_->points.size ())
00163 {
00164 size_t indices_size = indices_->size ();
00165 indices_->resize (input_->points.size ());
00166 for (size_t i = indices_size; i < indices_->size (); ++i) { (*indices_)[i] = static_cast<int>(i); }
00167 }
00168
00169 return (true);
00170 }
00171
00173 template <typename PointT> bool
00174 pcl::PCLBase<PointT>::deinitCompute ()
00175 {
00176 return (true);
00177 }
00178
00179 #define PCL_INSTANTIATE_PCLBase(T) template class PCL_EXPORTS pcl::PCLBase<T>;
00180
00181 #endif //#ifndef PCL_PCL_IMPL_BASE_HPP_
00182