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
00041 #include <pcl/filters/impl/project_inliers.hpp>
00042
00044 void
00045 pcl::ProjectInliers<pcl::PCLPointCloud2>::applyFilter (PCLPointCloud2 &output)
00046 {
00047 if (indices_->empty ())
00048 {
00049 PCL_WARN ("[pcl::%s::applyFilter] No indices given or empty indices!\n", getClassName ().c_str ());
00050 output.width = output.height = 0;
00051 output.data.clear ();
00052 return;
00053 }
00054
00055
00056
00057 Eigen::VectorXf model_coefficients (model_->values.size ());
00058 for (size_t i = 0; i < model_->values.size (); ++i)
00059 model_coefficients[i] = model_->values[i];
00060
00061
00062 if (!initSACModel (model_type_))
00063 {
00064 PCL_ERROR ("[pcl::%s::segment] Error initializing the SAC model!\n", getClassName ().c_str ());
00065 output.width = output.height = 0;
00066 output.data.clear ();
00067 return;
00068 }
00069 pcl::PointCloud<pcl::PointXYZ> cloud_out;
00070
00071 if (!copy_all_fields_)
00072 sacmodel_->projectPoints (*indices_, model_coefficients, cloud_out, false);
00073 else
00074 sacmodel_->projectPoints (*indices_, model_coefficients, cloud_out, true);
00075
00076 if (copy_all_data_)
00077 {
00078 output.height = input_->height;
00079 output.width = input_->width;
00080 output.is_bigendian = input_->is_bigendian;
00081 output.point_step = input_->point_step;
00082 output.row_step = input_->row_step;
00083 output.data = input_->data;
00084 output.is_dense = input_->is_dense;
00085
00086
00087 int x_idx = -1, y_idx = -1, z_idx = -1;
00088 for (int d = 0; d < static_cast<int> (output.fields.size ()); ++d)
00089 {
00090 if (output.fields[d].name == "x") x_idx = d;
00091 if (output.fields[d].name == "y") y_idx = d;
00092 if (output.fields[d].name == "z") z_idx = d;
00093 }
00094 if (x_idx == -1 || y_idx == -1 || z_idx == -1)
00095 {
00096 PCL_ERROR ("[pcl::%s::segment] X (%d) Y (%d) Z (%d) field dimensions not found!\n", getClassName ().c_str (), x_idx, y_idx, z_idx);
00097 output.width = output.height = 0;
00098 output.data.clear ();
00099 return;
00100 }
00101
00102
00103 for (size_t i = 0; i < indices_->size (); ++i)
00104 {
00105 memcpy (&output.data[(*indices_)[i] * output.point_step + output.fields[x_idx].offset], &cloud_out.points[(*indices_)[i]].x, sizeof (float));
00106 memcpy (&output.data[(*indices_)[i] * output.point_step + output.fields[y_idx].offset], &cloud_out.points[(*indices_)[i]].y, sizeof (float));
00107 memcpy (&output.data[(*indices_)[i] * output.point_step + output.fields[z_idx].offset], &cloud_out.points[(*indices_)[i]].z, sizeof (float));
00108 }
00109 }
00110 else
00111 {
00112 if (!copy_all_fields_)
00113 {
00114 pcl::toPCLPointCloud2<pcl::PointXYZ> (cloud_out, output);
00115 }
00116 else
00117 {
00118
00119 output.height = 1;
00120 output.width = static_cast<uint32_t> (indices_->size ());
00121 output.point_step = input_->point_step;
00122 output.data.resize (output.width * output.point_step);
00123 output.is_bigendian = input_->is_bigendian;
00124 output.row_step = output.point_step * output.width;
00125
00126 output.is_dense = true;
00127
00128
00129 int x_idx = -1, y_idx = -1, z_idx = -1;
00130 for (int d = 0; d < static_cast<int> (output.fields.size ()); ++d)
00131 {
00132 if (output.fields[d].name == "x") x_idx = d;
00133 if (output.fields[d].name == "y") y_idx = d;
00134 if (output.fields[d].name == "z") z_idx = d;
00135 }
00136
00137 if (x_idx == -1 || y_idx == -1 || z_idx == -1)
00138 {
00139 PCL_ERROR ("[pcl::%s::segment] X (%d) Y (%d) Z (%d) field dimensions not found!\n", getClassName ().c_str (), x_idx, y_idx, z_idx);
00140 output.width = output.height = 0;
00141 output.data.clear ();
00142 return;
00143 }
00144
00145
00146 for (size_t i = 0; i < indices_->size (); ++i)
00147 {
00148 memcpy (&output.data[i * output.point_step], &input_->data[(*indices_)[i] * input_->point_step], output.point_step);
00149 memcpy (&output.data[i * output.point_step + output.fields[x_idx].offset], &cloud_out.points[(*indices_)[i]].x, sizeof (float));
00150 memcpy (&output.data[i * output.point_step + output.fields[y_idx].offset], &cloud_out.points[(*indices_)[i]].y, sizeof (float));
00151 memcpy (&output.data[i * output.point_step + output.fields[z_idx].offset], &cloud_out.points[(*indices_)[i]].z, sizeof (float));
00152 }
00153 }
00154 }
00155 }
00156
00158 bool
00159 pcl::ProjectInliers<pcl::PCLPointCloud2>::initSACModel (int model_type)
00160 {
00161
00162 PointCloud<PointXYZ> cloud;
00163 fromPCLPointCloud2 (*input_, cloud);
00164 PointCloud<PointXYZ>::Ptr cloud_ptr = cloud.makeShared ();
00165
00166
00167 switch (model_type)
00168 {
00169 case SACMODEL_PLANE:
00170 {
00171
00172 sacmodel_.reset (new SampleConsensusModelPlane<pcl::PointXYZ> (cloud_ptr));
00173 break;
00174 }
00175 case SACMODEL_LINE:
00176 {
00177
00178 sacmodel_.reset (new SampleConsensusModelLine<pcl::PointXYZ> (cloud_ptr));
00179 break;
00180 }
00181 case SACMODEL_CIRCLE2D:
00182 {
00183
00184 sacmodel_.reset (new SampleConsensusModelCircle2D<pcl::PointXYZ> (cloud_ptr));
00185 break;
00186 }
00187 case SACMODEL_SPHERE:
00188 {
00189
00190 sacmodel_.reset (new SampleConsensusModelSphere<pcl::PointXYZ> (cloud_ptr));
00191 break;
00192 }
00193 case SACMODEL_PARALLEL_LINE:
00194 {
00195
00196 sacmodel_.reset (new SampleConsensusModelParallelLine<pcl::PointXYZ> (cloud_ptr));
00197 break;
00198 }
00199 case SACMODEL_PERPENDICULAR_PLANE:
00200 {
00201
00202 sacmodel_.reset (new SampleConsensusModelPerpendicularPlane<pcl::PointXYZ> (cloud_ptr));
00203 break;
00204 }
00205 case SACMODEL_CYLINDER:
00206 {
00207
00208 sacmodel_.reset (new SampleConsensusModelCylinder<pcl::PointXYZ, Normal> (cloud_ptr));
00209 break;
00210 }
00211 case SACMODEL_NORMAL_PLANE:
00212 {
00213
00214 sacmodel_.reset (new SampleConsensusModelNormalPlane<pcl::PointXYZ, Normal> (cloud_ptr));
00215 break;
00216 }
00217 case SACMODEL_CONE:
00218 {
00219
00220 sacmodel_.reset (new SampleConsensusModelCone<pcl::PointXYZ, Normal> (cloud_ptr));
00221 break;
00222 }
00223 case SACMODEL_NORMAL_SPHERE:
00224 {
00225
00226 sacmodel_.reset (new SampleConsensusModelNormalSphere<pcl::PointXYZ, Normal> (cloud_ptr));
00227 break;
00228 }
00229 case SACMODEL_NORMAL_PARALLEL_PLANE:
00230 {
00231
00232 sacmodel_.reset (new SampleConsensusModelNormalParallelPlane<pcl::PointXYZ, Normal> (cloud_ptr));
00233 break;
00234 }
00235 case SACMODEL_PARALLEL_PLANE:
00236 {
00237
00238 sacmodel_.reset (new SampleConsensusModelParallelPlane<pcl::PointXYZ> (cloud_ptr));
00239 break;
00240 }
00241 default:
00242 {
00243 PCL_ERROR ("[pcl::%s::initSACModel] No valid model given!\n", getClassName ().c_str ());
00244 return (false);
00245 }
00246 }
00247 return (true);
00248 }
00249
00250 #ifndef PCL_NO_PRECOMPILE
00251 #include <pcl/impl/instantiate.hpp>
00252 #include <pcl/point_types.h>
00253
00254
00255 #ifdef PCL_ONLY_CORE_POINT_TYPES
00256 PCL_INSTANTIATE(ProjectInliers, (pcl::PointXYZ)(pcl::PointXYZI)(pcl::PointXYZRGB)(pcl::PointXYZRGBA))
00257 #else
00258 PCL_INSTANTIATE(ProjectInliers, PCL_XYZ_POINT_TYPES)
00259 #endif
00260
00261 #endif // PCL_NO_PRECOMPILE
00262