MRPT图形界面

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

  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::guigit

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

sudo apt-get install mrpt-apps libmrpt-dev

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

#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:app

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()函数能够用来自动调整函数图象以适应窗口。ide

 

 

参考:函数

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

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

转载于:https://www.cnblogs.com/21207-iHome/p/6150478.htmlthis