ROS librviz库


1、可视化管理类:rviz::VisualizationManager

  The VisualizationManager class is the central manager class of rviz, holding all the Displays, Tools, ViewControllers, and other managers.

  It keeps the current view controller for the main render window. It has a timer which calls update() on all the displays. It creates and holds pointers to the other manager objects: SelectionManager, FrameManager, the PropertyManager s, and Ogre::SceneManager.

  /**
   * /brief Constructor
   * Creates managers and sets up global properties.
   * @param render_panel a pointer to the main render panel widget of the app.
   * @param wm a pointer to the window manager (which is really just a
   *        VisualizationFrame, the top-level container widget of rviz).
   */
  explicit VisualizationManager(RenderPanel* render_panel, WindowManagerInterface* wm = nullptr);

  在使用librviz时一般需要创建一个VisualizationManager对象,创建时给它指定渲染窗口RenderPanel,如下为在一个Qt运用的主窗口中嵌入librviz渲染窗口的示例:

// 创建渲染窗口,并将其添加到Qt主窗口布局中

render_panel_ = new rviz::RenderPanel();
QVBoxLayout* main_layout = new QVBoxLayout;
main_layout->addLayout( controls_layout );
main_layout->addWidget( render_panel_ );
setLayout( main_layout );

// 创建可视化管理对象

manager_ = new rviz::VisualizationManager( render_panel_ );

// 为渲染窗口关联场景相机及渲染上下文
render_panel_->initialize( manager_->getSceneManager(), manager_ );

// 初始化操作(必须,)
manager_->initialize();

// 启动刷新定时器,定时刷新librviz中的显示窗口
manager_->startUpdate();

  用于管理Display的接口,Display就是rviz中左侧面板中可以显示的网格、坐标轴、话题等可视化元素

  // 用于管理Display的接口,Display就是rviz中左侧面板中可以显示的网格、坐标轴、话题等可视化元素
  /**
   * /brief Create and add a display to this panel, by class lookup name
   * @param class_lookup_name "lookup name" of the Display subclass, for pluginlib.
   *        Should be of the form "packagename/displaynameofclass", like "rviz/Image".
   * @param name The name of this display instance shown on the GUI, like "Left arm camera".
   * @param enabled Whether to start enabled
   * @return A pointer to the new display.
   */
  Display* createDisplay(const QString& class_lookup_name, const QString& name, bool enabled);

  /**
   * /brief Add a display to be managed by this panel
   * @param display The display to be added
   */
  void addDisplay(Display* display, bool enabled);

  /**
   * /brief Remove and delete all displays
   */
  void removeAllDisplays();

  示例:添加点云话题显示

m_pointCloud2 = m_rvizManager->createDisplay("rviz/PointCloud2","pointCloud2", true);
ROS_ASSERT(m_pointCloud2 != nullptr);
m_pointCloud2->subProp("Topic")->setValue("/pcd_points");
m_pointCloud2->subProp("Unreliable")->setValue("false");
m_pointCloud2->subProp("Selectable")->setValue("true");
m_pointCloud2->subProp("Style")->setValue("Flat Squares");
m_pointCloud2->subProp("Size (m)")->setValue("0.1");
m_pointCloud2->subProp("Alpha")->setValue("1");
m_pointCloud2->subProp("Decay Time")->setValue("0");
m_pointCloud2->subProp("Position Transformer")->setValue("XYZ");//
m_pointCloud2->subProp("Color Transformer")->setValue("Intensity");
m_pointCloud2->subProp("Queue Size")->setValue("10");
m_pointCloud2->subProp("Use rainbow")->setValue("true");
m_pointCloud2->subProp("Invert Rainbow")->setValue("false");
m_pointCloud2->subProp("Autocompute Intensity Bounds")->setValue("true");
// m_pointCloud2->subProp("Min Intensity")->setValue("1");
// m_pointCloud2->subProp("Max Intensity")->setValue("255");
m_rvizManager->setFixedFrame("hx_map");

  rviz/PointCloud2是rviz提供的默认插件,其所有的属性设置均显示在左侧面板:ROS librviz库

  参考坐标系设置获取接口:

  /** @brief Return the fixed frame name.
   * @sa setFixedFrame() */
  QString getFixedFrame() const override;

  /** @brief Set the coordinate frame we should be transforming all fixed data into.
   * @param frame The name of the frame -- must match the frame name broadcast to libTF
   * @sa getFixedFrame() */
  void setFixedFrame(const QString& frame);

  rviz配置保存与加载

  /** @brief Load the properties of each Display and most editable rviz data.
   *
   * This is what is called when loading a "*.rviz" file.
   *
   * @param config The Config object to read from.  Expected to be a Config::Map type.
   * @sa save()
   */
  void load(const Config& config);

  /**
   * /brief Save the properties of each Display and most editable rviz
   *        data.
   *
   * This is what is called when saving a "*.vcg" file.
   * /param config The object to write to.
   * /sa loadDisplayConfig()
   */
  void save(Config config) const;

  还有其他接口暂未用到,具体可查看头文件:rviz/visualization_manager.h

 

 

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/270342.html

(0)
上一篇 2022年6月25日
下一篇 2022年6月25日

相关推荐

发表回复

登录后才能评论