MRPT图形界面

  mrpt-gui模块中提供了三个类以实现显示GUI窗口,每个都有特定的用途:

  All these window classes inherits from mrpt::gui::CBaseGUIWindow, which provides a set of methods and variables common to all the classes. It allow moving/resizing the windows, polling for key strokes, etc. All the classes in this library are in the namespace mrpt::gui

  在Ubuntu中使用如下命令安装mrpt的APP和lib:

sudo apt-get install mrpt-apps libmrpt-dev

  下面的代码绘制一幅正态分布概率密度函数图,自变量范围为0~5。

#include <mrpt/gui/CDisplayWindowPlots.h>
#include <mrpt/math/CVectorTemplate.h>
#include <mrpt/math/distributions.h>
#include <mrpt/system/os.h>
#include <mrpt/system/threads.h>

using namespace std;
using namespace mrpt;
using namespace mrpt::math;
using namespace mrpt::gui;

// ------------------------------------------------------
//                TestDisplayPlots
// ------------------------------------------------------
int main()
{
    CDisplayWindowPlots     win("Example of function plot",500,400); //width:500, height:400 

    // Generate data for a 2D plot:
    CVectorDouble  X,Y;
    for (double x=0;x<5;x+=0.01f)
    {
        //Evaluates the multivariate normal (Gaussian) distribution at a given point "x".
        double y = normalPDF(x, 2,0.3);

        X.push_back(x);
        Y.push_back(y);
    }

    //Adds a new layer with a 2D plot based on two vectors of X and Y points, using a MATLAB-like syntax.
    /*********************************************************************
    The lineFormat string is a combination of the following characters:

    Line styles:
    '.': One point for each data point
    '-': A continuous line
    ':': A dashed line

    Colors:
    k: black
    r: red
    g: green
    b: blue
    m: magenta
    c: cyan

    Line width:
    '1' to '9': The line width (default=1)

    Examples:
    'r.' -> red points.
    'k3' or 'k-3' -> A black line with a line width of 3 pixels.
    ********************************************************************/
    win.plot(X,Y,"b-2");

    //Enable/disable the feature of pan/zoom with the mouse (default=enabled)
    win.enableMousePanZoom(true); 
    //Enable/disable the fixed X/Y aspect ratio fix feature 
    win.axis_equal(false);
    //Fix automatically the view area according to existing graphs
    win.axis_fit();
    //Changes the position of the window on the screen.
    win.setPos(10,10);


    cout << "Press any key to exit..." << endl;
    win.waitForKey();

    //while (!mrpt::system::os::kbhit() &&win.isOpen())
        //mrpt::system::sleep(50);

    return 0;
}

  使用CMake来生成makefile:

SET(sampleName displayPlots)
SET(PRJ_NAME "EXAMPLE_${sampleName}")

# ---------------------------------------
# Declare a new CMake Project:
# ---------------------------------------
PROJECT(${PRJ_NAME})

# These commands are needed by modern versions of CMake:
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

FIND_PACKAGE(MRPT REQUIRED base;gui)

# ---------------------------------------------
# TARGET:
# ---------------------------------------------
# Define the executable target:
ADD_EXECUTABLE(${sampleName} test.cpp  ) 


# Add the required libraries for linking:
TARGET_LINK_LIBRARIES(${sampleName} 
    ${MRPT_LIBS}  # This is filled by FIND_PACKAGE(MRPT ...)
    ""  # Optional extra libs...
    )

  其中,enableMousePanZoom函数参数为true时可以进行如下操作:滚动鼠标中键,可以上下平移函数图象;按住鼠标右键可以对图像进行拖动;鼠标左键可以进行框选将函数图象放大。当设为false时这些操作被禁用。axis_equal函数参数为true时,X、Y坐标轴的单位长度将相等,即以相同的比例显示函数图象。axis_fit()函数可以用来自动调整函数图象以适应窗口。

 

 

参考:

http://www.mrpt.org/MRPT_in_GNU/Linux_repositories

https://github.com/MRPT/mrpt/tree/master/samples/displayPlots

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值