PCL box select vertices (to remove these points) and display the remaining points in another window __PCL

Source: Internet
Author: User

Reference 1:http://m.blog.csdn.net/article/details?id=51338298

The box selection vertex refers to article 1, and all of the code in this article is as follows:

#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <iostream>
#include <vector>
using namespace Std;

PCL::P OINTCLOUD&LT;PCL::P ointxyz&gt::P TR Cloud (New PCL::P OINTCLOUD&LT;PCL::P ointxyz> ());
Boost::shared_ptr<pcl::visualization::P clvisualizer> Viewer (new pcl::visualization::P clvisualizer ("Viewer" ));
PCL::P OINTCLOUD&LT;PCL::P ointxyz&gt::P tr clicked_points_3d (new PCL::P OINTCLOUD&LT;PCL::P ointxyz>);
int num = 0;
std::vector< int> totalindices;
BOOL Myfind (int temp1,const vector<int>& temp)
{

for (int i = 0; i < temp.size (); i++)
{
if (Temp1 = = Temp[i])
return true;
}

return false;
}
void Pp_callback (const pcl::visualization::areapickingevent& event, void* args)
{
std::vector< int > indices;
if (event.getpointsindices (indices) = =-1)
Return


for (int i = 0; i < indices.size (); ++i)
{
Clicked_points_3d->points.push_back (cloud->points.at (indices[i));
Totalindices.push_back (Indices[i]);
}
Pcl::visualization::P ointcloudcolorhandlercustom<pcl::P ointxyz> Red (clicked_points_3d, 255, 0, 0)
Std::stringstream SS;
Std::string Cloudname;
SS << num++;
SS >> Cloudname;
Cloudname + = "_cloudname";
Viewer->addpointcloud (clicked_points_3d, Red, cloudname);
Viewer->setpointcloudrenderingproperties (pcl::visualization::P cl_visualizer_point_size, CloudName);
}
void Main ()
{
if (Pcl::io::loadpcdfile ("ISM_TRAIN_WOLF.PCD", *cloud))
{
Std::cerr << "Error:cannot Open File" << Std::endl;
Return
}
Viewer->addpointcloud (Cloud, "test");
Viewer->setcameraposition (0, 0,-2, 0,-1, 0, 0);
Viewer->registerareapickingcallback (Pp_callback, (void*) &cloud);
int i = 0;
while (!viewer->wasstopped ())
{
if (I < 60)
{
Viewer->spinonce (100);
Boost::this_thread::sleep (boost::p osix_time::microseconds (100000));
i++;
Print ();
}
Else
Break
Print ();
}
The point cloud for the ② box (to be removed) exists in another window Viewer2:
Boost::shared_ptr<pcl::visualization::P clvisualizer> viewer2 (new pcl::visualization::P Clvisualizer (" Viewer2 "));
PCL::P OINTCLOUD&LT;PCL::P ointxyz&gt::P tr Outcloud (new PCL::P OINTCLOUD&LT;PCL::P ointxyz> ());
Pcl::copypointcloud (*cloud, totalindices, *outcloud);
Viewer2->addpointcloud (Outcloud, "test2");
Viewer2->setcameraposition (0, 0,-2, 0,-1, 0, 0);
while (!viewer2->wasstopped ())
//{


Viewer2->spinonce (100);
Boost::this_thread::sleep (boost::p osix_time::microseconds (100000));


//}
The remaining point cloud in the ③ after removal is in another window Viewer3:
vector<int>finalindices;
for (int i = 0; i < 3400; i++)
{
if (Myfind (i, totalindices) = = False)
Finalindices.push_back (i);
}


Boost::shared_ptr<pcl::visualization::P clvisualizer> viewer3 (new pcl::visualization::P Clvisualizer (" Viewer3 "));
PCL::P OINTCLOUD&LT;PCL::P ointxyz&gt::P tr Finalcloud (new PCL::P OINTCLOUD&LT;PCL::P ointxyz> ());
Pcl::copypointcloud (*cloud, finalindices, *finalcloud);
Viewer3->addpointcloud (Finalcloud, "test3");
Viewer3->setcameraposition (0, 0,-2, 0,-1, 0, 0);
while (!viewer3->wasstopped ())
{
Viewer3->spinonce (100);
Boost::this_thread::sleep (boost::p osix_time::microseconds (100000));

}

}

In Window 1, first press the X key to start (/end) the box selection mode. (Press the R key to move the point of view to the center of the object (Wolf)) and then select the box to delete (shown in red). After the selection, in the Window 3 show the remaining points, the effect as shown (delete the wolf's tail):


On the basis of this article, it is easy to continue to refine other functions (such as box selection after the other key to delete the box selection, add the S key to save to PCD, etc.).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.