在 pcl 查看器中绘制样条曲线

Plot Splines in pcl viewer

我正在处理形成曲线的点云,我使用 PCL 查看器来可视化它们(图 b)。

我想在同一个查看器中将各个样条曲线与点一起添加,但到目前为止,我只找到了绘制线条的方法,但没有找到绘制样条曲线的方法。但是,我已经设法基于此 link(图 a)在 Vtk 中绘制样条曲线。

这是我对上述情节的代码:

 // Load the point cloud 
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_curve(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile<pcl::PointXYZ>("line.pcd", *cloud_curve) == -1) 
{
    PCL_ERROR("Couldn't read the pcd file.\n");
    exit(1); 
}
// Visualisze curve points in pcl Viewer
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer( "Simple Cloud Viewer"));
viewer->setBackgroundColor(0, 0, 0);
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> handler(cloud_curve, 255 , 0, 0);
viewer->addPointCloud(cloud_curve, handler, "cloud");
viewer->initCameraParameters();

while (!viewer->wasStopped()) {
    viewer->spinOnce(100);
    boost::this_thread::sleep(boost::posix_time::microseconds(100000));
}
// Visualisze splines in vtk Viewer

double p0[3] = {-5.91152, 4.65316, 28063.7};
double p1[3] = { -6.2126, 3.8805, 28034.9};
double p2[3] = {-6.54915, 4.6517, 28007};
// Create a vtkPoints object and store the points in it
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(p0);
points->InsertNextPoint(p1);
points->InsertNextPoint(p2);
// Setup render window, renderer, and interactor
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize(1000,2000); //(width, height)
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkParametricSpline> spline = vtkSmartPointer<vtkParametricSpline>::New();
spline->SetPoints(points);
vtkSmartPointer<vtkParametricFunctionSource> functionSource = vtkSmartPointer<vtkParametricFunctionSource>::New();
functionSource->SetParametricFunction(spline);
functionSource->Update();

// Setup actor and mapper
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(functionSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(1,0,0);
renderWindow->AddRenderer(renderer);
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderWindow->Render();
vtkSmartPointer<vtkInteractorStyleSwitch> style = vtkSmartPointer<vtkInteractorStyleSwitch>::New();
style->SetCurrentStyleToTrackballCamera();
renderWindowInteractor->SetInteractorStyle( style );
renderWindowInteractor->Start();

关于如何在 PCL 查看器中绘制点和样条曲线的任何建议?

我设法通过向 pcl 查看器添加演员来绘制样条线和点:

viewer->getRenderWindow ()->GetRenderers()->GetFirstRenderer()->AddActor(actor);

我在这个discussion

中找到了答案