ROS librviz库

守听  金牌会员 | 2022-8-12 05:09:33 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 871|帖子 871|积分 2613

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.
  1.   /**
  2.    * \brief Constructor
  3.    * Creates managers and sets up global properties.
  4.    * @param render_panel a pointer to the main render panel widget of the app.
  5.    * @param wm a pointer to the window manager (which is really just a
  6.    *        VisualizationFrame, the top-level container widget of rviz).
  7.    */
  8.   explicit VisualizationManager(RenderPanel* render_panel, WindowManagerInterface* wm = nullptr);
复制代码
  在使用librviz时一般需要创建一个VisualizationManager对象,创建时给它指定渲染窗口RenderPanel,如下为在一个Qt运用的主窗口中嵌入librviz渲染窗口的示例:
  1. // 创建渲染窗口,并将其添加到Qt主窗口布局中
  2. render_panel_ = new rviz::RenderPanel();
  3. QVBoxLayout* main_layout = new QVBoxLayout;
  4. main_layout->addLayout( controls_layout );
  5. main_layout->addWidget( render_panel_ );
  6. setLayout( main_layout );
  7. // 创建可视化管理对象
  8. manager_ = new rviz::VisualizationManager( render_panel_ );
  9. // 为渲染窗口关联场景相机及渲染上下文
  10. render_panel_->initialize( manager_->getSceneManager(), manager_ );
  11. // 初始化操作(必须,)
  12. manager_->initialize();
  13. // 启动刷新定时器,定时刷新librviz中的显示窗口
  14. manager_->startUpdate();
复制代码
  用于管理Display的接口,Display就是rviz中左侧面板中可以显示的网格、坐标轴、话题等可视化元素
  1.   // 用于管理Display的接口,Display就是rviz中左侧面板中可以显示的网格、坐标轴、话题等可视化元素
  2.   /**
  3.    * \brief Create and add a display to this panel, by class lookup name
  4.    * @param class_lookup_name "lookup name" of the Display subclass, for pluginlib.
  5.    *        Should be of the form "packagename/displaynameofclass", like "rviz/Image".
  6.    * @param name The name of this display instance shown on the GUI, like "Left arm camera".
  7.    * @param enabled Whether to start enabled
  8.    * @return A pointer to the new display.
  9.    */
  10.   Display* createDisplay(const QString& class_lookup_name, const QString& name, bool enabled);
  11.   /**
  12.    * \brief Add a display to be managed by this panel
  13.    * @param display The display to be added
  14.    */
  15.   void addDisplay(Display* display, bool enabled);
  16.   /**
  17.    * \brief Remove and delete all displays
  18.    */
  19.   void removeAllDisplays();
复制代码
  示例:添加点云话题显示
  1. m_pointCloud2 = m_rvizManager->createDisplay("rviz/PointCloud2","pointCloud2", true);
  2. ROS_ASSERT(m_pointCloud2 != nullptr);
  3. m_pointCloud2->subProp("Topic")->setValue("/pcd_points");
  4. m_pointCloud2->subProp("Unreliable")->setValue("false");
  5. m_pointCloud2->subProp("Selectable")->setValue("true");
  6. m_pointCloud2->subProp("Style")->setValue("Flat Squares");
  7. m_pointCloud2->subProp("Size (m)")->setValue("0.1");
  8. m_pointCloud2->subProp("Alpha")->setValue("1");
  9. m_pointCloud2->subProp("Decay Time")->setValue("0");
  10. m_pointCloud2->subProp("Position Transformer")->setValue("XYZ");//
  11. m_pointCloud2->subProp("Color Transformer")->setValue("Intensity");
  12. m_pointCloud2->subProp("Queue Size")->setValue("10");
  13. m_pointCloud2->subProp("Use rainbow")->setValue("true");
  14. m_pointCloud2->subProp("Invert Rainbow")->setValue("false");
  15. m_pointCloud2->subProp("Autocompute Intensity Bounds")->setValue("true");
  16. // m_pointCloud2->subProp("Min Intensity")->setValue("1");
  17. // m_pointCloud2->subProp("Max Intensity")->setValue("255");
  18. m_rvizManager->setFixedFrame("hx_map");
复制代码
  rviz/PointCloud2是rviz提供的默认插件,其所有的属性设置均显示在左侧面板:
  参考坐标系设置获取接口:
  1.   /** @brief Return the fixed frame name.
  2.    * @sa setFixedFrame() */
  3.   QString getFixedFrame() const override;
  4.   /** @brief Set the coordinate frame we should be transforming all fixed data into.
  5.    * @param frame The name of the frame -- must match the frame name broadcast to libTF
  6.    * @sa getFixedFrame() */
  7.   void setFixedFrame(const QString& frame);
复制代码
  rviz配置保存与加载
  1.   /** @brief Load the properties of each Display and most editable rviz data.
  2.    *
  3.    * This is what is called when loading a "*.rviz" file.
  4.    *
  5.    * @param config The Config object to read from.  Expected to be a Config::Map type.
  6.    * @sa save()
  7.    */
  8.   void load(const Config& config);
  9.   /**
  10.    * \brief Save the properties of each Display and most editable rviz
  11.    *        data.
  12.    *
  13.    * This is what is called when saving a "*.vcg" file.
  14.    * \param config The object to write to.
  15.    * \sa loadDisplayConfig()
  16.    */
  17.   void save(Config config) const;
复制代码
  还有其他接口暂未用到,具体可查看头文件:rviz/visualization_manager.h
 
  1.  
复制代码
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

守听

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表