예제 #1
0
파일: LoadPCD.cpp 프로젝트: eile/trunk
int LoadPCD::compute()
{
	//for each selected filename
	for (int k = 0; k < m_filenames.size(); ++k)
	{
		QString filename = m_filenames[k];

        boost::shared_ptr<PCLCloud> cloud_ptr_in = loadSensorMessage(filename);
        
		if (!cloud_ptr_in) //loading failed?
			return 0;

		PCLCloud::Ptr cloud_ptr;
        if (!cloud_ptr_in->is_dense) //data may contain nans. Remove them
        {
            //now we need to remove nans
            pcl::PassThrough<PCLCloud> passFilter;
            passFilter.setInputCloud(cloud_ptr_in);

			cloud_ptr = PCLCloud::Ptr(new PCLCloud);
            passFilter.filter(*cloud_ptr);
        }
        else
		{
            cloud_ptr = cloud_ptr_in;
		}

        ccPointCloud* out_cloud = sm2ccConverter(cloud_ptr).getCCloud();
		if (!out_cloud)
			return -31;

		QString cloud_name = QFileInfo(filename).baseName();
		out_cloud->setName(cloud_name);

		QFileInfo fi(filename);
		QString containerName = QString("%1 (%2)").arg(fi.fileName()).arg(fi.absolutePath());

		ccHObject* cloudContainer = new ccHObject(containerName);
		assert(out_cloud);
		cloudContainer->addChild(out_cloud);

		emit newEntity(cloudContainer);
	}

	return 1;
}
예제 #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;
}
예제 #3
0
파일: LoadPCD.cpp 프로젝트: RobH616/trunk
int LoadPCD::compute()
{
	//for each selected filename
	for (int k = 0; k < m_filenames.size(); ++k)
	{
		Eigen::Vector4f origin;
		Eigen::Quaternionf orientation;

		QString filename = m_filenames[k];

		boost::shared_ptr<PCLCloud> cloud_ptr_in = loadSensorMessage(filename, origin, orientation);

		if (!cloud_ptr_in) //loading failed?
			return 0;

		PCLCloud::Ptr cloud_ptr;
		if (!cloud_ptr_in->is_dense) //data may contain nans. Remove them
		{
			//now we need to remove nans
			pcl::PassThrough<PCLCloud> passFilter;
			passFilter.setInputCloud(cloud_ptr_in);

			cloud_ptr = PCLCloud::Ptr(new PCLCloud);
			passFilter.filter(*cloud_ptr);
		}
		else
		{
			cloud_ptr = cloud_ptr_in;
		}

		//now we construct a ccGBLSensor with these characteristics
		ccGBLSensor * sensor = new ccGBLSensor;

		// get orientation as rot matrix
		Eigen::Matrix3f eigrot = orientation.toRotationMatrix();

		// and copy it into a ccGLMatrix
		ccGLMatrix ccRot;
		for (int i = 0; i < 3; ++i)
		{
			for (int j = 0; j < 3; ++j)
			{
				ccRot.getColumn(j)[i] = eigrot(i,j);
			}
		}

		ccRot.getColumn(3)[3] = 1.0;

		// now in a format good for CloudComapre
		//ccGLMatrix ccRot = ccGLMatrix::FromQuaternion(orientation.coeffs().data());

		//ccRot = ccRot.transposed();
		ccRot.setTranslation(origin.data());

		sensor->setRigidTransformation(ccRot);
		sensor->setDeltaPhi(static_cast<PointCoordinateType>(0.05));
		sensor->setDeltaTheta(static_cast<PointCoordinateType>(0.05));
		sensor->setVisible(true);

		//uncertainty to some default
		sensor->setUncertainty(static_cast<PointCoordinateType>(0.01));

		ccPointCloud* out_cloud = sm2ccConverter(cloud_ptr).getCloud();
		if (!out_cloud)
			return -31;

		sensor->setGraphicScale(out_cloud->getBB().getDiagNorm() / 10);

		//do the projection on sensor
		ccGenericPointCloud* cloud = ccHObjectCaster::ToGenericPointCloud(out_cloud);
		int errorCode;
		CCLib::SimpleCloud* projectedCloud = sensor->project(cloud,errorCode,true);
		if (projectedCloud)
		{
			//DGM: we don't use it but we still have to delete it!
			delete projectedCloud;
			projectedCloud = 0;
		}

		QString cloud_name = QFileInfo(filename).baseName();
		out_cloud->setName(cloud_name);

		QFileInfo fi(filename);
		QString containerName = QString("%1 (%2)").arg(fi.fileName()).arg(fi.absolutePath());

		ccHObject* cloudContainer = new ccHObject(containerName);
		out_cloud->addChild(sensor);
		cloudContainer->addChild(out_cloud);

		emit newEntity(cloudContainer);
	}

	return 1;
}
예제 #4
0
int MLSSmoothingUpsampling::compute()
{
	//pointer to selected cloud
	ccPointCloud* cloud = getSelectedEntityAsCCPointCloud();
	if (!cloud)
		return -1;

	//get xyz in sensor_msgs format
	cc2smReader converter;
	converter.setInputCloud(cloud);

	//take out the xyz info
	sensor_msgs::PointCloud2 sm_xyz = converter.getXYZ();
	sensor_msgs::PointCloud2 sm_cloud;

	//take out the current scalar field (if any)
	if (cloud->getCurrentDisplayedScalarField())
	{
		const char* current_sf_name = cloud->getCurrentDisplayedScalarField()->getName();

		sensor_msgs::PointCloud2 sm_field = converter.getFloatScalarField(current_sf_name);
		//change its name
		std::string new_name = "scalar";
		sm_field.fields[0].name = new_name.c_str();
		//put everithing together
		pcl::concatenateFields(sm_xyz, sm_field, sm_cloud);
	}
	else
	{
		sm_cloud = sm_xyz;
	}

	//get as pcl point cloud
	pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_cloud  (new pcl::PointCloud<pcl::PointXYZ>);
	pcl::fromROSMsg(sm_cloud, *pcl_cloud);

	//create storage for outcloud
	pcl::PointCloud<pcl::PointNormal>::Ptr normals (new pcl::PointCloud<pcl::PointNormal>);
#ifdef LP_PCL_PATCH_ENABLED
	pcl::PointIndicesPtr mapping_indices;
	smooth_mls<pcl::PointXYZ, pcl::PointNormal> (pcl_cloud, *m_parameters, normals, mapping_indices);
#else
	smooth_mls<pcl::PointXYZ, pcl::PointNormal> (pcl_cloud, *m_parameters, normals);
#endif

	sensor_msgs::PointCloud2::Ptr sm_normals (new sensor_msgs::PointCloud2);
	pcl::toROSMsg(*normals, *sm_normals);

	ccPointCloud* new_cloud = sm2ccConverter(sm_normals).getCCloud();
	if (!new_cloud)
	{
		//conversion failed (not enough memory?)
		return -1;
	}

	new_cloud->setName(cloud->getName()+QString("_smoothed")); //original name + suffix
	new_cloud->setDisplay(cloud->getDisplay());

#ifdef LP_PCL_PATCH_ENABLED
	//copy the original scalar fields here
	copyScalarFields(cloud, new_cloud, mapping_indices, true);
#endif

    //disable original cloud
    cloud->setEnabled(false);
	if (cloud->getParent())
		cloud->getParent()->addChild(new_cloud);

	emit newEntity(new_cloud);

	return 1;
}
예제 #5
0
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;
}