当前位置:网站首页>[PCL self study: pclplotter] pclplotter draws data analysis chart
[PCL self study: pclplotter] pclplotter draws data analysis chart
2022-06-27 23:47:00 【Stanford rabbit】
PCLPlotter Draw the data analysis diagram
One 、 What is? PCLPlotter
PCLPoltter Be similar to Matlab Of plot function , It is used to draw analysis diagram for point cloud data , For example, a certain row or column point cloud Z Change diagram of value .PCLPlotter It provides a very direct and simple drawing interface . We can visualize all types of important plots in the library, such as polynomial functions or histograms . When introducing some specific concepts in this chapter , Please read the document carefully , To know the exact method name .
We learn how to use... Directly from program fragments PCLPlotter Well .
Two 、 The sample program
2.1 Basic drawing process
From the simplest drawing X,Y Related conic ( y = x 2 y=x^2 y=x2) Start .
#include<vector>
#include<iostream>
#include<utility>
#include<pcl/visualization/pcl_plotter.h>
//...
int
main ()
{
// First define a plotter PCLPlotter
pcl::visualization::PCLPlotter * plotter = new PCLPlotter ();
// Then define the polynomial coefficients of the drawing function , for example y = x^2. Its polynomial coefficients are 3 individual , Namely 1,0,0, In a defined container , The first 0 One is a constant , The first 1 Yes x The coefficient of , The first 2 Yes x^2 The coefficient of . except x^2 The coefficient is 1, The rest is 0.
std::vector<double> func1 (3,0);
func1[2] = 1;
// With [- 10,10] by X Axis range , With “y = X ^2” Title , Add polynomials to the plotter func1
plotter->addPlotData (func1, -10, 10, "y = x^2");
// Display polynomial image
plotter->plot ();
return 0;
}
After the above code is run, it is as follows :
From the above code, we can conclude that PCLPlotter The basic code structure of , It's very simple to use , Be similar to Matlab
...
//1. Definition 1 individual plotter.
pcl::visualization::PCLPlotter *plotter = new PCLPlotter ("My Plotter");
...
//2. Use addPlotData* () function Add polynomial coefficient data
plotter->addPlotData* ();
...
//3. Set up Plotter Interface properties
plotter->setWindowSize (900, 600);
plotter->setYTitle ("this is my own function");
...
//4. display
plotter->plot ()
The basic usage framework is introduced , Now we will introduce more details .
2.2 Drawing detail processing
2.2.1 Choose a color scheme for the image
stay addPlotData*() Function , You can choose to add the desired color to the drawing . But if you don't take the initiative ,Plotter Will automatically color according to the color scheme .
The default color scheme is vtkColorSeries::SPECTRUM, It contains... In the whole spectrum 7 Two different shades .
Except for the default , You can also choose vtkColorSeries::WARM, vtkColorSeries::COOL, vtkColorSeries::BLUES, vtkColorSeries::WILD_FLOWER, vtkColorSeries::CITRUS.
You can go through setColorScheme() Function to change the color scheme . To reflect the effect of the color scheme in all drawings , In calling any addPlotData*() Function before calling this function to take effect .
2.2.2 Select different types of data to enter into the chart
You can view... In the document addPlotData() Detailed signature of the function . These prototypes basically illustrate their functions .
① Point-Correspondences( Feature point matching )
This is the most basic way to provide input data . Use std::vectorstd::pair; Provide point correspondence , namely (x,y) coordinate . as follows
...
std::vector<std::pair<double, double> > data;
populateData (data);
plotter->addPlotData (data,"cos");
...
② Table ( form )
The user stores the communication in a text file in the form of a space separated table . This leads to the use of MS Excel Alternative to drawing . Here is a very simple executable file , It carries out MS Excel Plotter The function of .
#include<pcl/visualization/pcl_plotter.h>
int
main (int argc, char ** argv)
{
pcl::visualization::PCLPlotter * plotter = new PCLPlotter ();
plotter->addPlotData (argv[1]);
plotter->plot ();
return 0;
}
③ Polynomial and Rational Functions( Polynomial and rational function )
Polynomials are defined by coefficient vectors , Rational functions are polynomial pairs ( Numerator and denominator pairs ) To define . The following code snippet draws the function y = 1/x The graphic .
...
std::vector<double> func1 (1,0);
func1[0] = 1; // 1
std::vector<double> func2 (2,0);
func1[1] = 1; // x
plotter->addPlotData (std::make_pair (func1, func2),-10, 10, "y = 1/x");
...
④ A custom explicit function( Custom explicit functions )
The user can specify a custom function ,f Describe the relationship as a callback :Y = f(X)
...
double
identity (double val)
{
return val;
}
...
...
plotter->addPlotData (identity,-10, 10,"identity");
...
2.2.3 Add other attributes and decorations
Users can add plots of other properties , As the title , Quadrant title , legend , Background color, etc . Need to be in plotter->plot (); Call these functions any time before they are called .
...
plotter->setTitle ("My plot"); //global title
plotter->setXTitle ("degrees");
plotter->setYTitle ("cos");
plotter->setShowLegend (true); //show legends
...
plotter->plot ();
...
2.2.4 Histogram and line chart
PCLPlotter Provides a very convenient MATLAB Class histogram drawing function (MATLAB Medium hist()). It classifies the raw data according to frequency and draws a bar graph .
...
std::vector<double> freqdata = generateNomalDistData ();
plotter->addHistogramData (freqdata,10); //number of bins are 10
plotter->plot ();
...
2.2.5 Dynamically display graphics as data is added
...
//data and callback defined here
...
plotter->addPlotData (func1, -10, 10, "y = x^2");
plotter->spinOnce (2000); // Dynamic display frequency 2s Refresh once
plotter->clearPlots ();
plotter->addPlotData (identity,-10, 10,"identity");
plotter->spinOnce (2000);
plotter->clearPlots ();
plotter->addPlotData (abs,-5, 5,"abs");
plotter->spinOnce (2000);
...
2.3 Demo
/* \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] = std::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);
plotter->clearPlots ();
//...................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;
}
【 About bloggers 】
Stanford rabbit , male , Master of engineering, Tianjin University . Since graduation, I have been engaged in optical three-dimensional imaging and point cloud processing . Because the three-dimensional processing library used in work is the internal library of the company , Not universally applicable , So I learned to open source by myself PCL Library and its related mathematical knowledge for use . I would like to share the self-study process with you .
Bloggers lack of talent and knowledge , Not yet able to guide , If you have any questions, please leave a message in the comments section for everyone to discuss .
边栏推荐
- C language character pointer and string initialization
- c语言-日期格式化[通俗易懂]
- 【AI应用】NVIDIA GeForce RTX 1080Ti的详情参数
- golang使用mongo-driver操作——查(进阶)
- 【tinyriscv verilator】分支移植到正点原子达芬奇开发板
- 【PCL自学:Segmentation4】基于Min-Cut点云分割
- How vivado adds timing constraints
- Detailed explanation of MATLAB axis coordinate axis related settings
- Zero foundation self-study SQL course | if function
- ICML 2022:ufrgs | optimistic linear support and subsequent features as the basis for optimal strategy transfer
猜你喜欢
随机推荐
How vivado adds timing constraints
Practice torch FX: pytorch based model optimization quantization artifact
vivado VIO IP的用法
实践torch.fx:基于Pytorch的模型优化量化神器
The file or assembly 'cefsharp.core.runtime.dll' or one of its dependencies could not be loaded. Is not a valid Win32 Application. (exception from hresult:0x800700c1)
Online JSON to plaintext tool
c语言字符指针、字符串初始化问题
apipost脚本使用讲解一~全局变量
搭建开源美观的数据库监控系统-Lepus
To build a "strong core" in Nansha, the first IC Nansha conference was held in Nansha
Swing UI——容器(一)
【剑指Offer】48. 最长不含重复字符的子字符串
在线JSON转PlainText工具
【PCL自学:Segmentation4】基于Min-Cut点云分割
C# Winform 读取Resources图片
零基础自学SQL课程 | SQL中的日期函数大全
捷码赋能案例:湖南天辰产研实力迅速提升!实战玩转智慧楼宇/工地等项目
往前一步是优秀,退后一步是懵懂
企业架构师面试的100个问题
Getting started with pytorch







![Technical implementation process of easycvr platform routing log function [code attached]](/img/cc/f4f81cbb72d2d43430a8d15bbbf27b.png)
