How to draw 2D graphs through PCL in the secondary development of CloudCompare?

0 Preface

  The pcl_plotter function of PCL is used to draw analysis diagrams for point cloud data, such as the change diagram of the Z value of a certain row or column point cloud. pcl_plotter provides a direct and simple plotting interface to visualize all types of important plots in the library such as from polynomial functions or histograms. This article records the use of the pcl_plotter function.

1. Create a function button

  (1) Design the .ui file
  ① Design the button
  insert image description here

  ②Compile.ui
  insert image description here

  (2) Modify the mainwindow.h file
  insert image description here

//menudo2
void doActionplot1();//多项式函数绘图  
void doActionplot2();//多项式有理函数绘图  
void doActionplot3();//点对绘图

  (3) Modify mainwindow.cpp file
  ①Add header file
  insert image description here

#include<pcl/visualization/pcl_plotter.h>

  ②Add implementation code
  insert image description here

//多项式函数绘图
void MainWindow::doActionplot1() {
    
      
}  
  
//多项式有理函数绘图  
void MainWindow::doActionplot2() {
    
      
}  
  
//点对绘图  
void MainWindow::doActionplot3() {
    
      
}

  ③Add signal slot function
  insert image description here

connect(m_UI->actionplot1, &amp;QAction::triggered, this, &amp;MainWindow::doActionplot1);//多项式函数绘图
connect(m_UI->actionplot2, &amp;QAction::triggered, this, &amp;MainWindow::doActionplot2);//多项式有理函数绘图  
connect(m_UI->actionplot3, &amp;QAction::triggered, this, &amp;MainWindow::doActionplot3);//点对绘图

  (4) generate
  insert image description here

2. Polynomial function drawing

  (1) Code drawing
  insert image description here

//多项式函数绘图
void MainWindow::doActionplot1() {
    
      
    //定义一个plottter类  
    pcl::visualization::PCLPlotter * plotter = new pcl::visualization::PCLPlotter();  
    plotter->setShowLegend(true);//显示图例  
    //定义一个多项式函数  
    //y=0+0x+x^2,常数项为0,x的系数为0,x^2的系数为1  
    // 0 0 1  
    pcl::visualization::PCLPlotter::PolynomialFunction func(3, 0);  
    func[2] = 1;  
    //对话获取参数  
    int style = QInputDialog::getInt(this, QStringLiteral("绘图类型选择"), QStringLiteral("类型:0线图,1点图,2条形图,3实体图"), 0, 0, 3);  
    switch (style) {
    
      
    case 0:  
        //将多项式添加进plottter中  
        //X 轴的区间范围:[-10, 10] as the range in X axis and "y = x^2" as title  
        plotter->addPlotData(func, -10, 10, "y=x^2", 100, vtkChart::LINE);//绘线图  
        plotter->setTitle("LINE");  
        break;  
  
    case 1:  
        plotter->addPlotData(func, -10, 10, "y=x^2", 100, vtkChart::POINTS);//绘点图  
        plotter->setTitle("POINTS");  
        break;  
  
    case 2:  
        plotter->addPlotData(func, -10, 10, "y=x^2", 100, vtkChart::BAR);//绘条形图  
        plotter->setTitle("BAR");  
        break;  
  
    case 3:  
        plotter->addPlotData(func, -10, 10, "y=x^2", 100, vtkChart::STACKED);//绘实体图  
        plotter->setTitle("STACKED");  
        break;  
    }  
    //显示图表,完成  
    plotter->plot();  
}

  (2) Drawing results
  ① Line graph
  insert image description here

  ② point map
  insert image description here

  ③ Bar graph
  insert image description here

  ④ Entity diagram
  insert image description here

3. Polynomial rational function drawing

  (1) Code drawing
  insert image description here

//多项式有理函数绘图
void MainWindow::doActionplot2() {
    
      
    //定义一个plottter类  
    pcl::visualization::PCLPlotter * plotter = new pcl::visualization::PCLPlotter();  
    plotter->setShowLegend(true);//显示图例  
    //定义一个多项式有理函数  
    //多项式函数是由系数向量定义,有理函数是由多项式对(分子和分母对)定义  
    //多项式有理函数:1/(6+x^1+x^2)  
    //令分子1为func1  
    //令分母(6+x^1+x^2)为func2  
    pcl::visualization::PCLPlotter::PolynomialFunction func1(1, 0);  
    func1[0] = 1;  
    pcl::visualization::PCLPlotter::PolynomialFunction func2(3, 0);  
    func2[0] = 6;  
    func2[1] = 1;  
    func2[2] = 1;  
    //对话获取参数  
    int style = QInputDialog::getInt(this, QStringLiteral("绘图类型选择"), QStringLiteral("类型:0线图,1点图,2条形图,3实体图"), 0, 0, 3);  
    switch (style) {
    
      
    case 0:  
        //将多项式添加进plottter中  
        //X 轴的区间范围:[-10, 10] as the range in X axis and "1/(6+x^1+x^2)" as title  
        plotter->addPlotData(pcl::visualization::PCLPlotter::RationalFunction(func1,func2), -10, 10, "1/(6+x^1+x^2)", 100, vtkChart::LINE);//绘线图  
        plotter->setTitle("LINE");  
        break;  
  
    case 1:  
        plotter->addPlotData(pcl::visualization::PCLPlotter::RationalFunction(func1, func2), -10, 10, "1/(6+x^1+x^2)", 100, vtkChart::POINTS);//绘点图  
        plotter->setTitle("POINTS");  
        break;  
  
    case 2:  
        plotter->addPlotData(pcl::visualization::PCLPlotter::RationalFunction(func1, func2), -10, 10, "1/(6+x^1+x^2)", 100, vtkChart::BAR);//绘条形图  
        plotter->setTitle("BAR");  
        break;  
  
    case 3:  
        plotter->addPlotData(pcl::visualization::PCLPlotter::RationalFunction(func1, func2), -10, 10, "1/(6+x^1+x^2)", 100, vtkChart::STACKED);//绘实体图  
        plotter->setTitle("STACKED");  
        break;  
    }  
    //显示图表,完成  
    plotter->plot();  
}

  (2) Drawing results
  ① Line graph
  insert image description here

  ② point map
  insert image description here

  ③ Bar graph
  insert image description here

  ④ Entity diagram
  insert image description here

4. Point-to-point drawing

  (1) Code drawing
  insert image description here

//点对绘图
void MainWindow::doActionplot3() {
    
      
    //定义一个plottter类  
    pcl::visualization::PCLPlotter * plotter = new pcl::visualization::PCLPlotter();  
    plotter->setShowLegend(true);//显示图例  
    //添加数据  
    std::vector<std::pair<double, double> > data;          
    data.push_back({
    
     1,1 });  
    data.push_back({
    
     3,3 });  
    data.push_back({
    
     1,3 });  
    data.push_back({
    
     3,1 });  
    data.push_back({
    
     2,5 });  
    data.push_back({
    
     1,1 });  
    //对话获取参数  
    int style = QInputDialog::getInt(this, QStringLiteral("绘图类型选择"), QStringLiteral("类型:0线图,1点图,2条形图,3实体图"), 0, 0, 3);  
    switch (style) {
    
      
    case 0:  
        //将点对添加进plottter中  
        plotter->addPlotData(data, "pair points", vtkChart::LINE);//绘线图  
        plotter->setTitle("LINE");  
        break;  
  
    case 1:  
        plotter->addPlotData(data, "pair points", vtkChart::POINTS);//绘点图  
        plotter->setTitle("POINTS");  
        break;  
  
    case 2:  
        plotter->addPlotData(data, "pair points", vtkChart::BAR);//绘条形图  
        plotter->setTitle("BAR");  
        break;  
  
    case 3:  
        plotter->addPlotData(data, "pair points", vtkChart::STACKED);//绘实体图  
        plotter->setTitle("STACKED");  
        break;  
    }  
    //显示图表,完成  
    plotter->plot();  
}

  (2) Drawing results
  ① Line graph
  insert image description here

  ② point map
  insert image description here

  ③ Bar graph
  insert image description here

  ④ Entity diagram
  insert image description here

References:
[1] SOC Luo Sanpao. PCL Tutorial - PCLPlotter Chart Visualization Class ; 2022-04-11 [accessed 2023-07-13].
[2] Stanford Rabbit. [PCL self-study: PCLPlotter] PCLPlotter drawing data analysis Figure ; 2022-06-25 [accessed 2023-07-13].
[3] jiaojialulu. (14) Visualization Tutorial II ; 2017-04-05 [accessed 2023-07-13]
. Dead. PCL: PCL_PCLPlotter class, draw a line graph ; 2019-08-20 [accessed 2023-07-13].
[5] zhy29563. [PCL] PCLPlotter draws a two-dimensional graph ; 2022-01-14 [accessed 2023-07 -13].
[6] Jie Nijun. Point Cloud Library PCL Study Notes – Visualization – 4. PCLPlotter Visualization Feature Histogram ; 2022-03-04 [accessed 2023-07-13].
[7] Rson555. PCL_PCLPlotter class learning Tutorial ; 2019-01-28 [accessed 2023-07-13].

Guess you like

Origin blog.csdn.net/qq_40640910/article/details/131705424
Recommended