?create视角控制器并加载设置
/*
rviz::ViewManager *view_manager_;
view_manager_ = manager_->getViewManager();
*/
void QRviz::setView(int flag)
{
QSettings view_setting("view_setting", "view_setting");//Qt保存的参数
if(0 == flag)
{
//第三人称
//"rviz/TopDownOrtho"是没有Focal Point及以下的选项
view_manager_->setCurrentFrom(view_manager_->create("rviz/ThirdPersonFollower"));
view_manager_->setRenderPanel(render_panel_);
view_manager_->getCurrent()->subProp("Target Frame")->setValue("base_link");//固定视角跟随
view_manager_->getCurrent()->subProp("Near Clip Distance")->setValue(view_setting.value("ncdistance0","0.001").toString());
view_manager_->getCurrent()->subProp("Focal Point")->setValue("1.90735e-06;-7.62939e-06;0");
view_manager_->getCurrent()->subProp("Focal Shape Size")->setValue("0.05");
view_manager_->getCurrent()->subProp("Focal Shape Fixed Size")->setValue("true");
view_manager_->getCurrent()->subProp("Distance")->setValue(view_setting.value("distance","8").toString());
view_manager_->getCurrent()->subProp("Yaw")->setValue(view_setting.value("yaw","0.785398").toString());
view_manager_->getCurrent()->subProp("Pitch")->setValue(view_setting.value("pitch","0.785398").toString());
else if(1 == flag)
{
//俯视角
view_manager_->setCurrentFrom(view_manager_->create("rviz/TopDownOrtho"));
view_manager_->setRenderPanel(render_panel_);
view_manager_->getCurrent()->subProp("Target Frame")->setValue("base_link");
view_manager_->getCurrent()->subProp("Near Clip Distance")->setValue(view_setting.value("ncdistance1","0.001").toString());
view_manager_->getCurrent()->subProp("Scale")->setValue(view_setting.value("scale","70").toString());
view_manager_->getCurrent()->subProp("Angle")->setValue(view_setting.value("angle","0.000").toString());
}
}
更改设置并更新
void QRviz::setViewConfig(int view, int mode,bool b)
{
QSettings view_setting("view_setting", "view_setting");
if(view == 1)
{
if(mode == 0)
{
if(b == true)
{
distance = distance - add_distance;
}else
{
distance = distance + add_distance;
}
view_manager_->getCurrent()->subProp("Distance")->setValue(distance);
}
else if(mode == 1)
{
if(b == true)
{
X_T = X_T + add_XY;
}else
{
X_T = X_T - add_XY;
}
view_manager_->getCurrent()->subProp("Focal Point")->subProp("X")->setValue(X_T);
}
else if(mode == 2)
{
if(b == true)
{
Y_T = Y_T - add_XY;
}else
{
Y_T = Y_T + add_XY;
}
view_manager_->getCurrent()->subProp("Focal Point")->subProp("Y")->setValue(Y_T);
}
}
else if(view == 2)
{
if(mode == 0)
{
if(b == true)
{
scale = scale + add_distance;
}else
{
scale = scale - add_distance;
}
view_manager_->getCurrent()->subProp("Scale")->setValue(scale);
}
else if(mode == 1)
{
if(b == true)
{
X_D = X_D + add_XY;
}else
{
X_D = X_D - add_XY;
}
view_manager_->getCurrent()->subProp("X")->setValue(X_D);
}
else if(mode == 2)
{
if(b == true)
{
Y_D = Y_D + add_XY;
}else
{
Y_D = Y_D - add_XY;
}
view_manager_->getCurrent()->subProp("Y")->setValue(Y_D);
}
}
view_manager_->getCurrent()->activate();
}
重点是更改完设置后需要调用activate()进行更新,不然配置无法生效
view_manager_->getCurrent()->activate();
插件加载
其实也就是工具加载,rviz通用工具也是内部自带插件。
事先再ros工作空间中编译好插件,编译方法与再rviz中使用插件一样。
//.h文件中
#include <pluginlib/class_loader.hpp>
void Set_3DGoal();
//插件加载
rviz::PluginlibFactory<rviz::Tool> *plugin;
//.cpp
plugin = new rviz::PluginlibFactory<rviz::Tool>("rviz_plugins", "rviz::Tool");//加载插件,只要new了就行
//就像调用通用工具一样调用插件
void QRviz::Set_3DGoal()
{
current_tool= tool_manager_->addTool("rviz_plugins/Goal3DTool");
tool_manager_->setCurrentTool( current_tool );
manager_->startUpdate();//更新所有图层
}