int ExtractSIFT::compute() { ccPointCloud* cloud = getSelectedEntityAsCCPointCloud(); if (!cloud) return -1; PCLCloud::Ptr sm_cloud (new PCLCloud); std::vector<std::string> req_fields; req_fields.resize(2); req_fields[0] = "xyz"; // always needed switch (m_mode) { case RGB: req_fields[1] = "rgb"; break; case SCALAR_FIELD: req_fields[1] = m_field_to_use; break; } cc2smReader converter; converter.setInputCloud(cloud); converter.getAsSM(req_fields, *sm_cloud); //Now change the name of the field to use to a standard name, only if in OTHER_FIELD mode if (m_mode == SCALAR_FIELD) { int field_index = pcl::getFieldIndex(*sm_cloud, m_field_to_use_no_space); sm_cloud->fields.at(field_index).name = "intensity"; //we always use intensity as name... even if it is curvature or another field. } //initialize all possible clouds pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_i (new pcl::PointCloud<pcl::PointXYZI>); pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_rgb (new pcl::PointCloud<pcl::PointXYZRGB>); pcl::PointCloud<pcl::PointXYZ>::Ptr out_cloud (new pcl::PointCloud<pcl::PointXYZ>); //Now do the actual computation if (m_mode == SCALAR_FIELD) { FROM_PCL_CLOUD(*sm_cloud, *cloud_i); estimateSIFT<pcl::PointXYZI, pcl::PointXYZ>(cloud_i, out_cloud, m_nr_octaves, m_min_scale, m_nr_scales_per_octave, m_min_contrast ); } else if (m_mode == RGB) { FROM_PCL_CLOUD(*sm_cloud, *cloud_rgb); estimateSIFT<pcl::PointXYZRGB, pcl::PointXYZ>(cloud_rgb, out_cloud, m_nr_octaves, m_min_scale, m_nr_scales_per_octave, m_min_contrast ); } PCLCloud::Ptr out_cloud_sm (new PCLCloud); TO_PCL_CLOUD(*out_cloud, *out_cloud_sm); if ( (out_cloud_sm->height * out_cloud_sm->width) == 0) { //cloud is empty return -53; } ccPointCloud* out_cloud_cc = sm2ccConverter(out_cloud_sm).getCCloud(); if (!out_cloud_cc) { //conversion failed (not enough memory?) return -1; } std::stringstream name; if (m_mode == RGB) name << "SIFT Keypoints_" << m_nr_octaves << "_" << "rgb" << "_" << m_min_scale << "_" << m_nr_scales_per_octave << "_" << m_min_contrast; else name << "SIFT Keypoints_" << m_nr_octaves << "_" << m_field_to_use_no_space << "_" << m_min_scale << "_" << m_nr_scales_per_octave << "_" << m_min_contrast; out_cloud_cc->setName(name.str().c_str()); out_cloud_cc->setDisplay(cloud->getDisplay()); if (cloud->getParent()) cloud->getParent()->addChild(out_cloud_cc); emit newEntity(out_cloud_cc); return 1; }
int ExtractSIFT::compute() { ccPointCloud* cloud = getSelectedEntityAsCCPointCloud(); if (!cloud) return -1; std::list<std::string> req_fields; try { req_fields.push_back("xyz"); // always needed switch (m_mode) { case RGB: req_fields.push_back("rgb"); break; case SCALAR_FIELD: req_fields.push_back(qPrintable(m_field_to_use)); //DGM: warning, toStdString doesn't preserve "local" characters break; default: assert(false); break; } } catch (const std::bad_alloc&) { //not enough memory return -1; } PCLCloud::Ptr sm_cloud = cc2smReader(cloud).getAsSM(req_fields); if (!sm_cloud) return -1; //Now change the name of the field to use to a standard name, only if in OTHER_FIELD mode if (m_mode == SCALAR_FIELD) { int field_index = pcl::getFieldIndex(*sm_cloud, m_field_to_use_no_space); sm_cloud->fields.at(field_index).name = "intensity"; //we always use intensity as name... even if it is curvature or another field. } //initialize all possible clouds pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_i (new pcl::PointCloud<pcl::PointXYZI>); pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_rgb (new pcl::PointCloud<pcl::PointXYZRGB>); pcl::PointCloud<pcl::PointXYZ>::Ptr out_cloud (new pcl::PointCloud<pcl::PointXYZ>); //Now do the actual computation if (m_mode == SCALAR_FIELD) { FROM_PCL_CLOUD(*sm_cloud, *cloud_i); estimateSIFT<pcl::PointXYZI, pcl::PointXYZ>(cloud_i, out_cloud, m_nr_octaves, m_min_scale, m_nr_scales_per_octave, m_min_contrast ); } else if (m_mode == RGB) { FROM_PCL_CLOUD(*sm_cloud, *cloud_rgb); estimateSIFT<pcl::PointXYZRGB, pcl::PointXYZ>(cloud_rgb, out_cloud, m_nr_octaves, m_min_scale, m_nr_scales_per_octave, m_min_contrast ); } PCLCloud::Ptr out_cloud_sm (new PCLCloud); TO_PCL_CLOUD(*out_cloud, *out_cloud_sm); if ( out_cloud_sm->height * out_cloud_sm->width == 0) { //cloud is empty return -53; } ccPointCloud* out_cloud_cc = sm2ccConverter(out_cloud_sm).getCloud(); if (!out_cloud_cc) { //conversion failed (not enough memory?) return -1; } std::stringstream name; if (m_mode == RGB) name << "SIFT Keypoints_" << m_nr_octaves << "_" << "rgb" << "_" << m_min_scale << "_" << m_nr_scales_per_octave << "_" << m_min_contrast; else name << "SIFT Keypoints_" << m_nr_octaves << "_" << m_field_to_use_no_space << "_" << m_min_scale << "_" << m_nr_scales_per_octave << "_" << m_min_contrast; out_cloud_cc->setName(name.str().c_str()); out_cloud_cc->setDisplay(cloud->getDisplay()); //copy global shift & scale out_cloud_cc->setGlobalScale(cloud->getGlobalScale()); out_cloud_cc->setGlobalShift(cloud->getGlobalShift()); if (cloud->getParent()) cloud->getParent()->addChild(out_cloud_cc); emit newEntity(out_cloud_cc); return 1; }