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/extract_indices.hpp>
00042
00044 void
00045 pcl::ExtractIndices<pcl::PCLPointCloud2>::applyFilter (PCLPointCloud2 &output)
00046 {
00047 if (keep_organized_)
00048 {
00049 output = *input_;
00050 if (negative_)
00051 {
00052
00053 for (size_t i = 0; i < indices_->size (); ++i)
00054 for (size_t j = 0; j < output.fields.size(); ++j)
00055 memcpy (&output.data[(*indices_)[i] * output.point_step + output.fields[j].offset],
00056 &user_filter_value_, sizeof(float));
00057 }
00058 else
00059 {
00060
00061 std::vector<int> all_indices (input_->width * input_->height);
00062 for (int i = 0; i < static_cast<int>(all_indices.size ()); ++i)
00063 all_indices[i] = i;
00064
00065 std::vector<int> indices = *indices_;
00066 std::sort (indices.begin (), indices.end ());
00067
00068
00069 std::vector<int> remaining_indices;
00070 set_difference (all_indices.begin (), all_indices.end (), indices.begin (), indices.end (),
00071 inserter (remaining_indices, remaining_indices.begin ()));
00072
00073
00074 for (size_t i = 0; i < remaining_indices.size (); ++i)
00075 for (size_t j = 0; j < output.fields.size(); ++j)
00076 memcpy (&output.data[remaining_indices[i] * output.point_step + output.fields[j].offset],
00077 &user_filter_value_, sizeof(float));
00078 }
00079 if (!pcl_isfinite (user_filter_value_))
00080 output.is_dense = false;
00081 return;
00082 }
00083 if (indices_->empty () || (input_->width * input_->height == 0))
00084 {
00085 output.width = output.height = 0;
00086 output.data.clear ();
00087
00088 if (negative_)
00089 output = *input_;
00090 return;
00091 }
00092 if (indices_->size () == (input_->width * input_->height))
00093 {
00094
00095 if (negative_)
00096 {
00097 output.width = output.height = 0;
00098 output.data.clear ();
00099 }
00100
00101 else
00102 output = *input_;
00103 return;
00104 }
00105
00106
00107 output.is_bigendian = input_->is_bigendian;
00108 output.point_step = input_->point_step;
00109 output.height = 1;
00110
00111 output.is_dense = false;
00112
00113 if (negative_)
00114 {
00115
00116 std::vector<int> all_indices (input_->width * input_->height);
00117 for (int i = 0; i < static_cast<int>(all_indices.size ()); ++i)
00118 all_indices[i] = i;
00119
00120 std::vector<int> indices = *indices_;
00121 std::sort (indices.begin (), indices.end ());
00122
00123
00124 std::vector<int> remaining_indices;
00125 set_difference (all_indices.begin (), all_indices.end (), indices.begin (), indices.end (),
00126 inserter (remaining_indices, remaining_indices.begin ()));
00127
00128
00129 output.width = static_cast<uint32_t> (remaining_indices.size ());
00130 output.data.resize (remaining_indices.size () * output.point_step);
00131 for (size_t i = 0; i < remaining_indices.size (); ++i)
00132 memcpy (&output.data[i * output.point_step], &input_->data[remaining_indices[i] * output.point_step], output.point_step);
00133 }
00134 else
00135 {
00136
00137 output.width = static_cast<uint32_t> (indices_->size ());
00138 output.data.resize (indices_->size () * output.point_step);
00139 for (size_t i = 0; i < indices_->size (); ++i)
00140 memcpy (&output.data[i * output.point_step], &input_->data[(*indices_)[i] * output.point_step], output.point_step);
00141 }
00142 output.row_step = output.point_step * output.width;
00143 }
00144
00146 void
00147 pcl::ExtractIndices<pcl::PCLPointCloud2>::applyFilter (std::vector<int> &indices)
00148 {
00149 if (negative_)
00150 {
00151
00152 if (indices_->size () == (input_->width * input_->height))
00153 {
00154
00155 indices.clear ();
00156 return;
00157 }
00158
00159
00160 std::vector<int> indices_fullset (input_->width * input_->height);
00161 for (int p_it = 0; p_it < static_cast<int> (indices_fullset.size ()); ++p_it)
00162 indices_fullset[p_it] = p_it;
00163
00164
00165 if (indices_->empty () || (input_->width * input_->height == 0))
00166 {
00167
00168 indices = indices_fullset;
00169 return;
00170 }
00171
00172
00173
00174 std::vector<int> indices_subset = *indices_;
00175 std::sort (indices_subset.begin (), indices_subset.end ());
00176
00177
00178 set_difference (indices_fullset.begin (), indices_fullset.end (), indices_subset.begin (), indices_subset.end (), inserter (indices, indices.begin ()));
00179 }
00180 else
00181 indices = *indices_;
00182 }
00183
00184 #ifndef PCL_NO_PRECOMPILE
00185 #include <pcl/impl/instantiate.hpp>
00186 #include <pcl/point_types.h>
00187
00188 #ifdef PCL_ONLY_CORE_POINT_TYPES
00189 PCL_INSTANTIATE(ExtractIndices, (pcl::PointXYZ)(pcl::PointXYZI)(pcl::PointXYZRGB)(pcl::PointXYZRGBA)(pcl::Normal)(pcl::PointXYZRGBNormal))
00190 #else
00191 PCL_INSTANTIATE(ExtractIndices, PCL_POINT_TYPES)
00192 #endif
00193
00194 #endif // PCL_NO_PRECOMPILE