merge_selection.cpp
Go to the documentation of this file.
00001 #include <pcl/apps/cloud_composer/merge_selection.h>
00002 #include <pcl/apps/cloud_composer/items/cloud_item.h>
00003 
00004 #include <pcl/filters/extract_indices.h>
00005 #include <pcl/point_types.h>
00006 #include <pcl/impl/instantiate.hpp>
00007 #include <pcl/apps/cloud_composer/impl/merge_selection.hpp>
00008 
00009 pcl::cloud_composer::MergeSelection::MergeSelection (QMap <const CloudItem*, pcl::PointIndices::ConstPtr > selected_item_index_map, QObject* parent)
00010   : MergeCloudTool (0, parent)
00011   , selected_item_index_map_ (selected_item_index_map)
00012 {
00013   
00014 }
00015 
00016 pcl::cloud_composer::MergeSelection::~MergeSelection ()
00017 {
00018   
00019 }
00020 
00021 QList <pcl::cloud_composer::CloudComposerItem*>
00022 pcl::cloud_composer::MergeSelection::performAction (ConstItemList input_data, PointTypeFlags::PointType type)
00023 {
00024   if (type != PointTypeFlags::NONE)
00025   {
00026     switch (type)
00027     {
00028       case (PointTypeFlags::XYZ):
00029         return this->performTemplatedAction<pcl::PointXYZ> (input_data);
00030       case (PointTypeFlags::XYZ | PointTypeFlags::RGB):
00031         return this->performTemplatedAction<pcl::PointXYZRGB> (input_data);
00032       case (PointTypeFlags::XYZ | PointTypeFlags::RGBA):
00033         return this->performTemplatedAction<pcl::PointXYZRGBA> (input_data);
00034     }
00035   }
00036   
00037   QList <CloudComposerItem*> output;
00038 
00039   // Check input data length
00040   if ( input_data.size () == 0 && selected_item_index_map_.isEmpty() )
00041   {
00042     qCritical () << "Empty input in MergeSelection!";
00043     return output;
00044   }
00045 
00046   //Make sure all input items are cloud items
00047   foreach (const CloudComposerItem* input_item, input_data)
00048   {
00049     if (input_item->type () !=  CloudComposerItem::CLOUD_ITEM )
00050     {
00051       qCritical () << "Input in MergeSelection not valid, contained non-CloudItem input";
00052       return output;
00053     }
00054   }
00055 
00056   pcl::ExtractIndices<pcl::PCLPointCloud2> filter;
00057   pcl::PCLPointCloud2::Ptr merged_cloud (new pcl::PCLPointCloud2);
00058   foreach (const CloudItem* input_cloud_item, selected_item_index_map_.keys ())
00059   {
00060     //If this cloud hasn't been completely selected 
00061     if (!input_data.contains (input_cloud_item))
00062     {
00063       pcl::PCLPointCloud2::ConstPtr input_cloud = input_cloud_item->data (ItemDataRole::CLOUD_BLOB).value <pcl::PCLPointCloud2::ConstPtr> ();
00064       qDebug () << "Extracting "<<selected_item_index_map_.value(input_cloud_item)->indices.size() << " points out of "<<input_cloud->width;
00065       filter.setInputCloud (input_cloud);
00066       filter.setIndices (selected_item_index_map_.value (input_cloud_item));
00067       pcl::PCLPointCloud2::Ptr original_minus_indices = boost::make_shared <pcl::PCLPointCloud2> ();
00068       filter.setNegative (true);
00069       filter.filter (*original_minus_indices);
00070       filter.setNegative (false);
00071       pcl::PCLPointCloud2::Ptr selected_points (new pcl::PCLPointCloud2);
00072       filter.filter (*selected_points);
00073       
00074       qDebug () << "Original minus indices is "<<original_minus_indices->width;
00075       Eigen::Vector4f source_origin = input_cloud_item->data (ItemDataRole::ORIGIN).value<Eigen::Vector4f> ();
00076       Eigen::Quaternionf source_orientation =  input_cloud_item->data (ItemDataRole::ORIENTATION).value<Eigen::Quaternionf> ();
00077       CloudItem* new_cloud_item = new CloudItem (input_cloud_item->text ()
00078                                              , original_minus_indices
00079                                              , source_origin
00080                                              , source_orientation);
00081       output.append (new_cloud_item);
00082       pcl::PCLPointCloud2::Ptr temp_cloud = boost::make_shared <pcl::PCLPointCloud2> ();
00083       concatenatePointCloud (*merged_cloud, *selected_points, *temp_cloud);
00084       merged_cloud = temp_cloud;
00085     }
00086     //Append the input item to the original list
00087     //input_data.append (input_cloud_item);
00088   }
00089   //Just concatenate for all fully selected clouds
00090   foreach (const CloudComposerItem* input_item, input_data)
00091   {
00092     pcl::PCLPointCloud2::ConstPtr input_cloud = input_item->data (ItemDataRole::CLOUD_BLOB).value <pcl::PCLPointCloud2::ConstPtr> ();
00093     
00094     pcl::PCLPointCloud2::Ptr temp_cloud = boost::make_shared <pcl::PCLPointCloud2> ();
00095     concatenatePointCloud (*merged_cloud, *input_cloud, *temp_cloud);
00096     merged_cloud = temp_cloud;
00097   }
00098   
00099   CloudItem* cloud_item = new CloudItem ("Cloud from Selection"
00100                                          , merged_cloud);
00101 
00102   output.append (cloud_item);
00103     
00104   return output;
00105 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:25:28