drawable_submap.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CARTOGRAPHER_RVIZ_SRC_DRAWABLE_SUBMAP_H_
18 #define CARTOGRAPHER_RVIZ_SRC_DRAWABLE_SUBMAP_H_
19 
20 #include <future>
21 
22 #include "Eigen/Core"
23 #include "Eigen/Geometry"
24 #include "OgreManualObject.h"
25 #include "OgreMaterial.h"
26 #include "OgreQuaternion.h"
27 #include "OgreSceneManager.h"
28 #include "OgreSceneNode.h"
29 #include "OgreTexture.h"
30 #include "OgreVector3.h"
32 #include "cartographer_ros_msgs/SubmapEntry.h"
33 #include "cartographer_ros_msgs/SubmapQuery.h"
34 #include "ros/ros.h"
35 #include "rviz/display_context.h"
36 #include "rviz/frame_manager.h"
38 
39 namespace cartographer_rviz {
40 
41 // Contains all the information needed to render a submap onto the final
42 // texture representing the whole map.
43 class DrawableSubmap : public QObject {
44  Q_OBJECT
45 
46  public:
47  // Each submap is identified by a 'trajectory_id' plus a 'submap_index'.
48  // 'scene_manager' is the Ogre scene manager to which to add a node.
50  Ogre::SceneManager* scene_manager,
51  ::rviz::Property* submap_category, const bool visible);
52  ~DrawableSubmap() override;
53  DrawableSubmap(const DrawableSubmap&) = delete;
54  DrawableSubmap& operator=(const DrawableSubmap&) = delete;
55 
56  // Updates the 'metadata' for this submap. If necessary, the next call to
57  // MaybeFetchTexture() will fetch a new submap texture.
58  void Update(const ::std_msgs::Header& header,
59  const ::cartographer_ros_msgs::SubmapEntry& metadata,
60  ::rviz::FrameManager* frame_manager);
61 
62  // If an update is needed, it will send an RPC using 'client' to request the
63  // new data for the submap and returns true.
65 
66  // Returns whether an RPC is in progress.
67  bool QueryInProgress();
68 
69  // Sets the alpha of the submap taking into account its slice height and the
70  // 'current_tracking_z'.
71  void SetAlpha(double current_tracking_z);
72 
73  int submap_index() const { return submap_index_; }
74  int trajectory_id() const { return trajectory_id_; }
75  bool visibility() const { return visibility_->getBool(); }
76  void set_visibility(const bool visibility) {
77  visibility_->setBool(visibility);
78  }
79 
80  Q_SIGNALS:
81  // RPC request succeeded.
82  void RequestSucceeded();
83 
84  private Q_SLOTS:
85  // Callback when an rpc request succeeded.
86  void UpdateSceneNode();
87  void ToggleVisibility();
88 
89  private:
90  void UpdateTransform();
91  float UpdateAlpha(float target_alpha);
92 
93  const int trajectory_id_;
94  const int submap_index_;
95 
96  ::cartographer::common::Mutex mutex_;
97  Ogre::SceneManager* const scene_manager_;
98  Ogre::SceneNode* const scene_node_;
99  Ogre::ManualObject* manual_object_;
100  Ogre::TexturePtr texture_;
101  Ogre::MaterialPtr material_;
102  double submap_z_ = 0. GUARDED_BY(mutex_);
103  Ogre::Vector3 position_ GUARDED_BY(mutex_);
104  Ogre::Quaternion orientation_ GUARDED_BY(mutex_);
105  Eigen::Affine3d slice_pose_ GUARDED_BY(mutex_);
106  std::chrono::milliseconds last_query_timestamp_ GUARDED_BY(mutex_);
107  bool query_in_progress_ = false GUARDED_BY(mutex_);
108  int metadata_version_ = -1 GUARDED_BY(mutex_);
109  int texture_version_ = -1 GUARDED_BY(mutex_);
110  std::future<void> rpc_request_future_;
111  ::cartographer_ros_msgs::SubmapQuery::Response response_ GUARDED_BY(mutex_);
112  float current_alpha_ = 0.f;
113  std::unique_ptr<::rviz::BoolProperty> visibility_;
114 };
115 
116 } // namespace cartographer_rviz
117 
118 #endif // CARTOGRAPHER_RVIZ_SRC_DRAWABLE_SUBMAP_H_
Ogre::ManualObject * manual_object_
void set_visibility(const bool visibility)
Ogre::SceneNode *const scene_node_
std::unique_ptr<::rviz::BoolProperty > visibility_
::cartographer::common::Mutex mutex_
DrawableSubmap & operator=(const DrawableSubmap &)=delete
std::future< void > rpc_request_future_
void SetAlpha(double current_tracking_z)
void Update(const ::std_msgs::Header &header, const ::cartographer_ros_msgs::SubmapEntry &metadata,::rviz::FrameManager *frame_manager)
float UpdateAlpha(float target_alpha)
bool MaybeFetchTexture(ros::ServiceClient *client)
Ogre::SceneManager *const scene_manager_
Ogre::Vector3 position_ GUARDED_BY(mutex_)
DrawableSubmap(int trajectory_id, int submap_index, Ogre::SceneManager *scene_manager,::rviz::Property *submap_category, const bool visible)


cartographer_rviz
Author(s):
autogenerated on Mon Jun 10 2019 12:59:49