PCLPlotter可视化特征直方图

PCLPlotter可视化特征直方图

1. PCLPlotter

  • PCL官方文档: https://pcl.readthedocs.io/projects/tutorials/en/master/pcl_plotter.html#basic-code-structure
  • PCLPlotter 提供了一个直接简单的绘图接口,可以绘制许多类型的二维图形,包括多项式函数和特征直方图,比如 FPFH (快速特征直方图)。
  • 利用 PCLPlotter 绘制图形分以下4步:
    • 第一步:声明绘图对象 PCLPlotter
    • 第二步:利用 addPlotData() 函数,添加绘图所需的函数或数据;
    • 第三步:添加窗口特性,可以调整窗口大小和标题;(非必须步骤)
    • 第四步:显示绘图。

2. 绘制函数图形示例代码

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

/* author Kripasindhu Sarkar */

#include <pcl/visualization/pcl_plotter.h>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>  //for std::abs()

using namespace pcl::visualization;

void generateData(double *ax, double *acos, double *asin, int numPoints)
{
	double inc = 7.5 / (numPoints - 1);
	for (int i = 0; i < numPoints; ++i)
	{
		ax[i] = i*inc;
		acos[i] = cos(i * inc);
		asin[i] = sin(i * inc);
	}
}

//.....................callback functions defining Y= f(X)....................
double step(double val)
{
	if (val > 0)
		return (double)(int)val;
	else
		return (double)((int)val - 1);
}

double identity(double val)
{
	return val;
}
//............................................................................

int main()
{
	//defining a plotter
	PCLPlotter *plotter = new PCLPlotter("My Plotter");

	//setting some properties
	plotter->setShowLegend(true);//显示图表的图例

	//generating point correspondances
	int numPoints = 69;
	double ax[100], acos[100], asin[100];
	generateData(ax, acos, asin, numPoints);

	//adding plot data
	plotter->addPlotData(ax, acos, numPoints, "cos");
	plotter->addPlotData(ax, asin, numPoints, "sin");

	//display for 2 seconds
	plotter->spinOnce(3000);	//Calls the interactor and updates the screen once. 
	plotter->clearPlots();		//Remove all plots from the window. 


	//...................plotting implicit functions and custom callbacks....................

	//make a fixed axis
	plotter->setYRange(-10, 10);

	//defining polynomials
	std::vector<double> func1(1, 0);
	func1[0] = 1; //y = 1
	std::vector<double> func2(3, 0);
	func2[2] = 1; //y = x^2

	plotter->addPlotData(std::make_pair(func1, func2), -10, 10, "y = 1/x^2", 100, vtkChart::POINTS);
	plotter->spinOnce(2000);

	plotter->addPlotData(func2, -10, 10, "y = x^2");
	plotter->spinOnce(2000);

	//callbacks
	plotter->addPlotData(identity, -10, 10, "identity");
	plotter->spinOnce(2000);

	plotter->addPlotData(std::abs, -10, 10, "abs");
	plotter->spinOnce(2000);

	plotter->addPlotData(step, -10, 10, "step", 100, vtkChart::POINTS);
	plotter->spinOnce(2000);

	plotter->clearPlots();

	//........................A simple animation..............................
	std::vector<double> fsq(3, 0);
	fsq[2] = -100; //y = x^2
	while (!plotter->wasStopped())
	{
		if (fsq[2] == 100) fsq[2] = -100;
		fsq[2]++;
		char str[50];
		sprintf(str, "y = %dx^2", (int)fsq[2]);
		plotter->addPlotData(fsq, -10, 10, str);

		plotter->spinOnce(100);
		plotter->clearPlots();
	}

	return 1;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MechMaster

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值