44 #include <boost/bind.hpp> 45 #include <boost/algorithm/string/erase.hpp> 46 #include <boost/foreach.hpp> 47 #include <boost/shared_ptr.hpp> 49 #include <OgreSceneNode.h> 50 #include <OgreSceneManager.h> 70 , messages_received_(0)
76 , angular_thres_(0.5
f)
81 QRegExp depth_filter(
"depth");
82 depth_filter.setCaseSensitivity(Qt::CaseInsensitive);
86 "List only topics with names that relate to depth and color images",
this,
90 "Depth Map Topic",
"", QString::fromStdString(ros::message_traits::datatype<sensor_msgs::Image>()),
91 "sensor_msgs::Image topic to subscribe to.", depth_filter,
this, SLOT(
updateTopic()));
94 new EnumProperty(
"Depth Map Transport Hint",
"raw",
"Preferred method of sending images.",
this,
103 QRegExp color_filter(
"color|rgb|bgr|gray|mono");
104 color_filter.setCaseSensitivity(Qt::CaseInsensitive);
107 "Color Image Topic",
"",
108 QString::fromStdString(ros::message_traits::datatype<sensor_msgs::Image>()),
109 "sensor_msgs::Image topic to subscribe to.", color_filter,
this, SLOT(
updateTopic()));
112 "Color Transport Hint",
"raw",
"Preferred method of sending images.",
this, SLOT(
updateTopic()));
123 "Advanced: set the size of the incoming message queue. Increasing this " 124 "is useful if your incoming TF data is delayed significantly from your" 125 " image data, but it can greatly increase memory usage if the messages are big.",
131 "Automatically scale each point based on its depth value and the camera parameters.",
this,
135 new FloatProperty(
"Auto Size Factor", 1,
"Scaling factor to be applied to the auto size.",
141 "Keep points alive after they have been occluded by a closer point. Points are " 142 "removed after a timeout or when the camera frame moves.",
147 "Amount of seconds before removing occluded points from the depth cloud",
186 if (datatype == ros::message_traits::datatype<sensor_msgs::Image>())
193 int index = topic.lastIndexOf(
"/");
196 ROS_WARN(
"DepthCloudDisplay::setTopic() Invalid topic name: %s", topic.toStdString().c_str());
199 QString transport = topic.mid(index + 1);
200 QString base_topic = topic.mid(0, index);
238 if (use_occlusion_compensation)
292 if (!depthmap_topic.empty() && !depthmap_transport.empty())
307 if (!color_topic.empty() && !color_transport.empty())
366 boost::mutex::scoped_lock lock(
mutex_);
374 boost::mutex::scoped_lock lock(
mutex_);
394 sensor_msgs::ImageConstPtr rgb_msg)
401 std::ostringstream
s;
408 sensor_msgs::CameraInfo::ConstPtr cam_info;
414 if (!cam_info || !depth_msg)
420 s << depth_msg->width <<
" x " << depth_msg->height;
426 s << rgb_msg->width <<
" x " << rgb_msg->height;
429 if (depth_msg->header.frame_id != rgb_msg->header.frame_id)
431 std::stringstream errorMsg;
432 errorMsg <<
"Depth image frame id [" << depth_msg->header.frame_id.c_str()
433 <<
"] doesn't match color image frame id [" << rgb_msg->header.frame_id.c_str() <<
"]";
440 float f = cam_info->K[0];
441 float bx = cam_info->binning_x > 0 ? cam_info->binning_x : 1.0;
448 if (use_occlusion_compensation)
451 Ogre::Quaternion orientation;
452 Ogre::Vector3 position;
457 QString(
"Failed to transform from frame [") + depth_msg->header.frame_id.c_str() +
469 float angle_deg = angle.valueDegrees();
470 if (angle_deg >= 180.0
f)
472 if (angle_deg < -180.0
f)
490 sensor_msgs::PointCloud2Ptr cloud_msg =
493 if (!cloud_msg.get())
497 cloud_msg->header = depth_msg->header;
512 "image_transport",
"image_transport::SubscriberPlugin");
521 std::string transport_name = boost::erase_last_copy(lookup_name,
"_sub");
522 transport_name = transport_name.substr(lookup_name.find(
'/') + 1);
551 property->clearOptions();
553 std::vector<std::string> choices;
555 choices.push_back(
"raw");
560 ros::master::V_TopicInfo::iterator it = topics.begin();
561 ros::master::V_TopicInfo::iterator end = topics.end();
562 for (; it != end; ++it)
570 const std::string& topic_name = ti.
name;
573 if (topic_name.find(topic) == 0 && topic_name != topic && topic_name[topic.size()] ==
'/' &&
574 topic_name.find(
'/', topic.size() + 1) == std::string::npos)
576 std::string transport_type = topic_name.substr(topic.size() + 1);
582 choices.push_back(transport_type);
587 for (
size_t i = 0; i < choices.size(); i++)
589 property->addOptionStd(choices[i]);
~DepthCloudDisplay() override
Ogre::Quaternion current_orientation_
const char * what() const override
boost::shared_ptr< SynchronizerDepthColor > sync_depth_color_
void setStatusStd(StatusProperty::Level level, const std::string &name, const std::string &text)
Show status level and text, using a std::string. Convenience function which converts std::string to Q...
virtual void processMessage(sensor_msgs::Image::ConstPtr msg)
boost::scoped_ptr< image_transport::ImageTransport > rgb_it_
void scanForTransportSubscriberPlugins()
virtual void setString(const QString &str)
void onDisable() override
Derived classes override this to do the actual work of disabling themselves.
virtual void expand()
Expand (show the children of) this Property.
virtual void updateAutoSizeFactor()
void fixedFrameChanged() override
Called by setFixedFrame(). Override to respond to changes to fixed_frame_.
void fillTransportOptionList(EnumProperty *property)
Fill list of available and working transport options.
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz...
boost::shared_ptr< T > createInstance(const std::string &lookup_name)
virtual bool setValue(const QVariant &new_value)
Set the new value for this property. Returns true if the new value is different from the old value...
FloatProperty * point_world_size_property_
virtual void updateTopicFilter()
FloatProperty * auto_size_factor_property_
MultiLayerDepth * ml_depth_data_
message_filters::Synchronizer< SyncPolicyDepthColor > SynchronizerDepthColor
void enableOcclusionCompensation(bool occlusion_compensation)
EnumProperty * xyz_transformer_property_
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
void initialize(DisplayContext *context, Ogre::SceneNode *scene_node)
virtual void updateOcclusionTimeOut()
void onInitialize() override
Override this function to do subclass-specific initialization.
std::vector< TopicInfo > V_TopicInfo
Property specialized to enforce floating point max/min.
void enableFilter(bool enabled)
sensor_msgs::CameraInfo::ConstPtr cam_info_
std::string getTopicStd() const
boost::shared_ptr< image_transport::SubscriberFilter > depthmap_sub_
Property specialized to provide max/min enforcement for integers.
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
virtual void updateTopic()
std::string getStdString()
Displays a point cloud of type sensor_msgs::PointCloud.
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
std::set< std::string > transport_plugin_types_
bool setFloat(float new_value)
Float-typed "SLOT" version of setValue().
boost::shared_ptr< tf2_ros::MessageFilter< sensor_msgs::Image > > depthmap_tf_filter_
boost::scoped_ptr< image_transport::ImageTransport > depthmap_it_
void caminfoCallback(sensor_msgs::CameraInfo::ConstPtr msg)
void addMessage(const sensor_msgs::PointCloudConstPtr &cloud)
ApproximateTime< sensor_msgs::Image, sensor_msgs::Image > SyncPolicyDepthColor
boost::shared_ptr< message_filters::Subscriber< sensor_msgs::CameraInfo > > cam_info_sub_
virtual void reset()
Called to tell the display to clear its state.
EnumProperty * color_transformer_property_
std::vector< std::string > getDeclaredClasses()
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
boost::mutex cam_info_mutex_
Property(const QString &name=QString(), const QVariant default_value=QVariant(), const QString &description=QString(), Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
Constructor.
void update(float wall_dt, float ros_dt) override
Called periodically by the visualization manager.
RosFilteredTopicProperty * color_topic_property_
IMAGE_TRANSPORT_DECL std::string getCameraInfoTopic(const std::string &base_topic)
const std::string & getFixedFrame()
Return the current fixed frame name.
BoolProperty * use_occlusion_compensation_property_
PointCloudCommon * pointcloud_common_
virtual int getInt() const
Return the internal property value as an integer.
BoolProperty(const QString &name=QString(), bool default_value=false, const QString &description=QString(), Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
virtual void setHidden(bool hidden)
Hide or show this property in any PropertyTreeWidget viewing its parent.
virtual std::shared_ptr< tf2_ros::Buffer > getTF2BufferPtr() const =0
Convenience function: returns getFrameManager()->getTF2BufferPtr().
sensor_msgs::PointCloud2Ptr generatePointCloudFromDepth(sensor_msgs::ImageConstPtr depth_msg, sensor_msgs::ImageConstPtr color_msg, sensor_msgs::CameraInfoConstPtr camera_info_msg)
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
bool isEnabled() const
Return true if this Display is enabled, false if not.
IntProperty * queue_size_property_
ros::NodeHandle threaded_nh_
A NodeHandle whose CallbackQueue is run from a different thread than the GUI.
Ogre::Vector3 current_position_
void setShadowTimeOut(double time_out)
virtual float getFloat() const
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Return the pose for a header, relative to the fixed frame, in Ogre classes.
void onEnable() override
Derived classes override this to do the actual work of enabling themselves.
void setAutoSize(bool auto_size)
virtual void updateUseAutoSize()
virtual void updateUseOcclusionCompensation()
EnumProperty * depth_transport_property_
FloatProperty * occlusion_shadow_timeout_property_
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
EnumProperty * color_transport_property_
Property * topic_filter_property_
void hide()
Hide this Property in any PropertyTreeWidgets.
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
bool initialized() const
Returns true if the display has been initialized.
void setTopic(const QString &topic, const QString &datatype) override
Set the ROS topic to listen to for this display.
boost::shared_ptr< image_transport::SubscriberFilter > rgb_sub_
virtual bool getBool() const
virtual void setReadOnly(bool read_only)
Prevent or allow users to edit this property from a PropertyTreeWidget.
bool setStdString(const std::string &std_str)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void reset() override
Called to tell the display to clear its state.
virtual void setString(const QString &str)
Set the value of this property to the given string. Does not force the value to be one of the list of...
uint32_t messages_received_
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
Show status level and text. This is thread-safe.
BoolProperty * use_auto_size_property_
void update(float wall_dt, float ros_dt)
RosFilteredTopicProperty * depth_topic_property_