Librviz Tutorial¶
Overview
RViz is not just a visualizer(视觉型的人) application, it is also a library! Much of RViz’s functionality(功能) can be accessed within your own application by linking against librviz.so (or whatever your OS likes to call it).
This tutorial shows a very simple example of creating a 3D visualizer widget(装饰物) (rviz::RenderPanel), programmatically creating a new Grid display within it, then using Qt slider controls to adjust(调整) a couple of the grid’s properties. The app is called “myviz”.
The source code for this tutorial is in the librviz_tutorial package. You can check out the source directly or (if you use Ubuntu) you can just apt-get install(安装) the pre-compiled Debian package like so:
The running application looks like this:

The Code
The code for myviz is in these files: src/main.cpp, src/myviz.h, and src/myviz.cpp.
main.cpp
The full text of main.cpp is here: src/main.cpp
The main() for this “myviz” example is very simple, it just initializes(初始化) ROS, creates a QApplication, creates the top-level widget(装饰物) (of type “MyViz”), shows it, and runs the Qt event loop(环).
myviz.h
The full text of myviz.h is here: src/myviz.h
Class “MyViz” implements(工具) the top level widget for this example.
myviz.cpp
The full text of myviz.cpp is here: src/myviz.cpp
Constructor(构造函数) for MyViz. This does most of the work of the class.
Construct and lay out labels(标签) and slider controls.
Construct and lay out render(致使) panel(仪表板).
Set the top-level layout(布局) for this MyViz widget.
Make signal/slot(位置) connections.
Next we initialize(初始化) the main RViz classes.
The VisualizationManager is the container for Display objects, holds the main Ogre scene, holds the ViewController, etc. It is very central and we will probably need one in every usage(使用) of librviz.
Create a Grid display.
Configure(安装) the GridDisplay the way we like it.
Initialize the slider values.
Destructor.
This function is a Qt slot(位置) connected to a QSlider’s valueChanged() signal. It sets the line thickness(厚度) of the grid by changing the grid’s “Line Width” property.
This function is a Qt slot connected to a QSlider’s valueChanged() signal. It sets the cell size of the grid by changing the grid’s “Cell Size” Property.
Building
The full text of CMakeLists.txt is here: CMakeLists.txt
Running
Just type: