当前位置:网站首页>ROS knowledge: the structure of the rviz library librviz
ROS knowledge: the structure of the rviz library librviz
2022-06-23 11:59:00 【Mr anhydrous】
One 、 summary
RViz Not just a visual application , It is also a library ! Through the link librviz.so( Or whatever name your operating system likes to call it ), You can access... In your own application RViz Most of the functions .
This tutorial shows a very simple example , It creates a 3D Visual widgets (rviz::RenderPanel), Programmatically create a new grid display , And then use Qt The slider control adjusts the properties of several meshes . The application is called “myviz”.
The source code for this tutorial is located in librviz_tutorial In bag . You can view the source code directly , perhaps ( If you use Ubuntu) You can like this apt-get Install precompiled Debian software package :
sudo apt-get install ros-hydro-visualization-tutorialsTwo 、The Code
myviz The code file is : src/main.cpp, src/myviz.h, src/myviz.cpp.
2.1 main.cpp analysis
This “myviz” Example main() It's simple , It just initializes ROS, Create a QApplication, Create top-level widgets ( The type is “MyViz”), Show it , And run Qt The event loop .
#include <QApplication>
#include <ros/ros.h>
#include "myviz.h"
int main(int argc, char **argv)
{
if( !ros::isInitialized() )
{
ros::init( argc, argv, "myviz", ros::init_options::AnonymousName );
}
QApplication app( argc, argv );
MyViz* myviz = new MyViz();
myviz->show();
app.exec();
delete myviz;
}2.2 myviz.h explain
“MyViz” Class implements the top-level part of this example .
class MyViz: public QWidget
{
Q_OBJECT
public:
MyViz( QWidget* parent = 0 );
virtual ~MyViz();
private Q_SLOTS:
void setThickness( int thickness_percent );
void setCellSize( int cell_size_percent );
private:
rviz::VisualizationManager* manager_;
rviz::RenderPanel* render_panel_;
rviz::Display* grid_;
};Only joined Q_OBJECT, Can be used QT Medium signal and slot Mechanism , and Q_OBJECT To be placed at the front of the class .
The signal and slot are Qt application development The basis of , It connects two unrelated objects , Slot and ordinary C++ The function is the same , It's just that when it's connected to the signal , When sending a signal , The slot will be called automatically. Only when you join Q_OBJECT, You can use QT Medium signal and slot Mechanism .
2. 3 myviz.cpp explain
The full text of myviz.cpp is here: src/myviz.cpp
MyViz Constructor for . This completes most of the work of the class .
MyViz::MyViz( QWidget* parent )
: QWidget( parent )
{
Build and lay out label and slider controls .
QLabel* thickness_label = new QLabel( "Line Thickness" );
QSlider* thickness_slider = new QSlider( Qt::Horizontal );
thickness_slider->setMinimum( 1 );
thickness_slider->setMaximum( 100 );
QLabel* cell_size_label = new QLabel( "Cell Size" );
QSlider* cell_size_slider = new QSlider( Qt::Horizontal );
cell_size_slider->setMinimum( 1 );
cell_size_slider->setMaximum( 100 );
QGridLayout* controls_layout = new QGridLayout();
controls_layout->addWidget( thickness_label, 0, 0 );
controls_layout->addWidget( thickness_slider, 0, 1 );
controls_layout->addWidget( cell_size_label, 1, 0 );
controls_layout->addWidget( cell_size_slider, 1, 1 );Build and lay out rendering panels .
render_panel_ = new rviz::RenderPanel();
QVBoxLayout* main_layout = new QVBoxLayout;
main_layout->addLayout( controls_layout );
main_layout->addWidget( render_panel_ );Set this MyViz Top level layout of widgets .
setLayout( main_layout );Carry signal / Slot connection .
connect( thickness_slider, SIGNAL( valueChanged( int )), this, SLOT( setThickness( int )));
connect( cell_size_slider, SIGNAL( valueChanged( int )), this, SLOT( setCellSize( int )));Next, we initialize the main RViz class .
VisualizationManager yes Display Object's container , Including the main Ogre scene , contain ViewController etc. . It's very important , We may use it every time librviz You need one at a time .
manager_ = new rviz::VisualizationManager( render_panel_ );
render_panel_->initialize( manager_->getSceneManager(), manager_ );
manager_->initialize();
manager_->startUpdate();Create a grid display .
grid_ = manager_->createDisplay( "rviz/Grid", "adjustable grid", true );
ROS_ASSERT( grid_ != NULL );Configure... In the way we like GridDisplay.
grid_->subProp( "Line Style" )->setValue( "Billboards" );
grid_->subProp( "Color" )->setValue( Qt::yellow );Initialize slider value .
thickness_slider->setValue( 25 );
cell_size_slider->setValue( 10 );
}destructor .
MyViz::~MyViz()
{
delete manager_;
}This function is a connection to QSlider Of valueChanged() The signal Qt Slot . It does this by changing the shape of the mesh “ Line width ” Property to set the lineweight of the mesh .
void MyViz::setThickness( int thickness_percent )
{
if( grid_ != NULL )
{
grid_->subProp( "Line Style" )->subProp( "Line Width" )->setValue( thickness_percent / 100.0f );
}
}This function is a connection to QSlider Of valueChanged() The signal Qt Slot . It does this by changing the shape of the mesh “ Cell size ” Property to set the cell size of the grid .
void MyViz::setCellSize( int cell_size_percent )
{
if( grid_ != NULL )
{
grid_->subProp( "Cell Size" )->setValue( cell_size_percent / 10.0f );
}
}3、 ... and 、 perform
After compiling :
rosrun librviz_tutorial myviz
边栏推荐
- QT知识:Qt Widgets小部件类【01】
- Runtime application self-protection (rasp): self-cultivation of application security
- 09 -- 回文对
- 64路PCM电话光端机64路电话+2路百兆以太网电话光端机64路电话PCM语音光端机
- 一张图解码 OpenCloudOS 社区开放日
- 【云驻共创】无码时代,软件开发如何走向每个人?
- 32路电话+2路千兆以太网32路PCM电话光端机支持FXO口FXS语音电话转光纤
- QT5知识:QT绘制图形
- Video data annotation tools and platforms (data annotation company)
- 机器学习系列5:距离空间(1)
猜你喜欢

杜邦分析法解读:安阳钢铁股份有限公司企业投资价值何在?

电脑坏了,换了台电脑,装node环境的时候出了问题,报错URL not defined

汉源高科1路千兆光口转4路千兆以太网电口千兆1光4电光纤收发器

2光2电级联型光纤收发器千兆2光2电光纤收发器迷你嵌入式工业矿用本安型光纤收发器
![[cloud native & microservice viii] source code analysis of weightedresponsetimerule of ribbon load balancing strategy (response time weighting)](/img/cc/afad5b5d327416c809be3b661bcc13.png)
[cloud native & microservice viii] source code analysis of weightedresponsetimerule of ribbon load balancing strategy (response time weighting)

股权转让热点:重庆建科建设工程质量检测有限公司93.75%股权转让

切比雪夫不等式证明及应用

汉源高科1路非压缩4K-DVI光端机4K高清非压缩DVI转光纤4K-DVI高清视频光端机

【云原生&微服务八】Ribbon负载均衡策略之WeightedResponseTimeRule源码剖析(响应时间加权)

halcon知识:dyn_threshold的用法(划痕检测)
随机推荐
Want to learn ETS development? Teach you to develop an iq-eq test application
你真的理解LDO的輸出電容嗎!?
股票网上开户及开户流程怎样?手机开户安全么?
【云驻共创】无码时代,软件开发如何走向每个人?
Runtime application self-protection (rasp): self-cultivation of application security
十大劵商如何开户?在线开户安全么?
Oversampling Series III: quantization error and oversampling rate
得物多活架构设计之路由服务设计
The list of open source summer winners has been publicized, and the field of basic software has become a hot application this year
How does easygbs solve the abnormal use of intercom function?
Oversampling series I: sampling theorem and oversampling rate
Leetcode 1209. 删除字符串中的所有相邻重复项 II(牛逼,终于过了)
Easy to understand soft route brushing tutorial
MySQL matches multiple values in one field
halcon知识:dyn_threshold的用法(划痕检测)
Go zero micro Service Practice Series (VI. cache consistency assurance)
Blue Bridge Cup single chip microcomputer (I) -- turn off peripherals and turn off led
2022工具钳工(初级)考试练习题模拟考试平台操作
Halcon原理:auto_threshold算子
在工作中学习的三个方法