drawable_submap.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef CARTOGRAPHER_RVIZ_SRC_DRAWABLE_SUBMAP_H_
00018 #define CARTOGRAPHER_RVIZ_SRC_DRAWABLE_SUBMAP_H_
00019 
00020 #include <future>
00021 #include <memory>
00022 
00023 #include "Eigen/Core"
00024 #include "Eigen/Geometry"
00025 #include "OgreSceneManager.h"
00026 #include "OgreSceneNode.h"
00027 #include "absl/synchronization/mutex.h"
00028 #include "cartographer/io/submap_painter.h"
00029 #include "cartographer/mapping/id.h"
00030 #include "cartographer/transform/rigid_transform.h"
00031 #include "cartographer_ros/submap.h"
00032 #include "cartographer_ros_msgs/SubmapEntry.h"
00033 #include "cartographer_ros_msgs/SubmapQuery.h"
00034 #include "cartographer_rviz/ogre_slice.h"
00035 #include "ros/ros.h"
00036 #include "rviz/display_context.h"
00037 #include "rviz/frame_manager.h"
00038 #include "rviz/ogre_helpers/axes.h"
00039 #include "rviz/ogre_helpers/movable_text.h"
00040 #include "rviz/properties/bool_property.h"
00041 
00042 namespace cartographer_rviz {
00043 
00044 // Contains all the information needed to render a submap onto the final
00045 // texture representing the whole map.
00046 class DrawableSubmap : public QObject {
00047   Q_OBJECT
00048 
00049  public:
00050   DrawableSubmap(const ::cartographer::mapping::SubmapId& submap_id,
00051                  ::rviz::DisplayContext* display_context,
00052                  Ogre::SceneNode* map_node, ::rviz::Property* submap_category,
00053                  bool visible, const bool pose_axes_visible,
00054                  float pose_axes_length, float pose_axes_radius);
00055   ~DrawableSubmap() override;
00056   DrawableSubmap(const DrawableSubmap&) = delete;
00057   DrawableSubmap& operator=(const DrawableSubmap&) = delete;
00058 
00059   // Updates the 'metadata' for this submap. If necessary, the next call to
00060   // MaybeFetchTexture() will fetch a new submap texture.
00061   void Update(const ::std_msgs::Header& header,
00062               const ::cartographer_ros_msgs::SubmapEntry& metadata);
00063 
00064   // If an update is needed, it will send an RPC using 'client' to request the
00065   // new data for the submap and returns true.
00066   bool MaybeFetchTexture(ros::ServiceClient* client);
00067 
00068   // Returns whether an RPC is in progress.
00069   bool QueryInProgress();
00070 
00071   // Sets the alpha of the submap taking into account its slice height and the
00072   // 'current_tracking_z'. 'fade_out_start_distance_in_meters' defines the
00073   // distance in z direction in meters, before which the submap will be shown
00074   // at full opacity.
00075   void SetAlpha(double current_tracking_z, float fade_out_distance_in_meters);
00076 
00077   // Sets the visibility of a slice. It will be drawn if the parent submap
00078   // is also visible.
00079   void SetSliceVisibility(size_t slice_index, bool visible);
00080 
00081   ::cartographer::mapping::SubmapId id() const { return id_; }
00082   int version() const { return metadata_version_; }
00083   bool visibility() const { return visibility_->getBool(); }
00084   void set_visibility(const bool visibility) {
00085     visibility_->setBool(visibility);
00086   }
00087   void set_pose_markers_visibility(const bool visibility) {
00088     pose_axes_visible_ = visibility;
00089     TogglePoseMarkerVisibility();
00090   }
00091 
00092  Q_SIGNALS:
00093   // RPC request succeeded.
00094   void RequestSucceeded();
00095 
00096  private Q_SLOTS:
00097   // Callback when an rpc request succeeded.
00098   void UpdateSceneNode();
00099   void ToggleVisibility();
00100   void TogglePoseMarkerVisibility();
00101 
00102  private:
00103   const ::cartographer::mapping::SubmapId id_;
00104 
00105   absl::Mutex mutex_;
00106   ::rviz::DisplayContext* const display_context_;
00107   Ogre::SceneNode* const submap_node_;
00108   Ogre::SceneNode* const submap_id_text_node_;
00109   std::vector<std::unique_ptr<OgreSlice>> ogre_slices_;
00110   ::cartographer::transform::Rigid3d pose_ GUARDED_BY(mutex_);
00111   ::rviz::Axes pose_axes_;
00112   bool pose_axes_visible_;
00113   ::rviz::MovableText submap_id_text_;
00114   std::chrono::milliseconds last_query_timestamp_ GUARDED_BY(mutex_);
00115   bool query_in_progress_ GUARDED_BY(mutex_) = false;
00116   int metadata_version_ GUARDED_BY(mutex_) = -1;
00117   std::future<void> rpc_request_future_;
00118   std::unique_ptr<::cartographer::io::SubmapTextures> submap_textures_
00119       GUARDED_BY(mutex_);
00120   float current_alpha_ = 0.f;
00121   std::unique_ptr<::rviz::BoolProperty> visibility_;
00122 };
00123 
00124 }  // namespace cartographer_rviz
00125 
00126 #endif  // CARTOGRAPHER_RVIZ_SRC_DRAWABLE_SUBMAP_H_


cartographer_rviz
Author(s): The Cartographer Authors
autogenerated on Wed Jul 10 2019 04:10:34