Ask Your Question
2

How do I convert a mesh to a pointcloud for use with pcl ICP

asked 2012-05-12 10:06:20 -0500

brawner gravatar image

updated 2012-05-13 08:45:28 -0500

I want to find partial overlaps between meshes in the household object database and pointcloud sensor data. My method is to convert the arm_navigation_msgs::Shape to a pcl::PointCloud and then find clusters that overlap through pcl::IterativeClosestPoint. I have all pieces working, I just think my function for converting the shape meshes to pointclouds is inefficient. Is there a way to take advantage of the underlying structure to speed up the conversion?

This is my current implementation

pcl::PointCloud<pcl::PointXYZ> PCLMeshOverlap::convertMeshToPointcloud(arm_navigation_msgs::Shape mesh)
{
    ROS_INFO("Converting mesh to pointcloud");
    pcl::PointCloud<pcl::PointXYZ> cloud_out;
    pcl::PointXYZ point;
    for (int i = 0; i < mesh.vertices.size(); i++)
    {
        float isNew = true;
        for (int j = 0; j < cloud_out.points.size(); j++)
        {
            if (    mesh.vertices.at(i).x == cloud_out.points.at(j).x &&
                    mesh.vertices.at(i).y == cloud_out.points.at(j).y &&
                    mesh.vertices.at(i).z == cloud_out.points.at(j).z   )
            {
                isNew = false;
                break;
            }
        }
        if (isNew)
        {
            point.x = mesh.vertices.at(i).x;
            point.y = mesh.vertices.at(i).y;
            point.z = mesh.vertices.at(i).z;
            cloud_out.points.push_back(point);
        }
    }
    cloud_out.width = cloud_out.points.size();
    cloud_out.height = 1;
    cloud_out.is_dense = true;
    cloud_out.header.frame_id = "/base_link";
    return cloud_out;
}

*Edited because the original code had some typos

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-12-18 19:01:25 -0500

isura gravatar image

updated 2014-05-29 09:55:21 -0500

You could do this in ROS Hydro PCL 1.7 if your mesh was a pcl::PolygonMesh:

#include <pcl io="" vtk_lib_io.h="">

const std::string meshFileName = "test.stl";

pcl::PolygonMesh testMesh;
pcl::io::loadPolygonFileSTL( meshFileName, testMesh );    
pcl_conversions::fromPCL( testMesh.cloud, output );
edit flag offensive delete link more

Comments

Does this conversion sample points on the surfaces or strictly converts the vertices in the STL file into points in the point cloud? If not, is there any tool out that does sample points on the surfaces?

ben gravatar imageben ( 2014-02-03 16:09:57 -0500 )edit

@ben to my knowledge this just converts vertices in the STL file into points in the point cloud. I am not aware of a tool that resamples points. Did you find any good solution?

isura gravatar imageisura ( 2014-05-09 15:12:00 -0500 )edit
0

answered 2016-09-14 07:35:45 -0500

Sagexs gravatar image

have a look at https://github.com/PointCloudLibrary/... it samples point on the surface

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-05-12 10:06:20 -0500

Seen: 7,600 times

Last updated: Sep 14 '16