Пример #1
0
sensor_msgs::PointCloud2 mergeVectorOfClouds(const std::vector<sensor_msgs::PointCloud2> &clouds)
{
	int n_points = clouds[0].height * clouds[0].width;
	int n_clouds = clouds.size();

	//all the indices
	std::vector<int> indices(n_points);
	for (int i = 0; i < n_points; ++i)
	{
		indices.at(i) = i;
	}
	sensor_msgs::PointCloud2::Ptr sm_cloud (new sensor_msgs::PointCloud2); //out cloud
	sensor_msgs::PointCloud2::Ptr sm_tmp (new sensor_msgs::PointCloud2); //temporary cloud

	*sm_cloud = clouds[0];

	//now loop on scalar fields and merge them
	for (int i = 1; i < n_clouds; ++i)
	{

		pcl::copyPointCloud(*sm_cloud, indices, *sm_tmp);
		pcl::concatenateFields(*sm_tmp, clouds[i], *sm_cloud);
	}

	return *sm_cloud;
}
Пример #2
0
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;
}