text_view_facing_marker.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <OgreSceneNode.h>
31 #include <OgreSceneManager.h>
32 
33 #include <ros/assert.h>
34 
36 #include <rviz/display_context.h>
39 
41 
42 namespace rviz
43 {
45  DisplayContext* context,
46  Ogre::SceneNode* parent_node)
47  : MarkerBase(owner, context, parent_node), text_(nullptr)
48 {
49 }
50 
52 {
53  delete text_;
54 }
55 
57  const MarkerConstPtr& new_message)
58 {
59  ROS_ASSERT(new_message->type == visualization_msgs::Marker::TEXT_VIEW_FACING);
60 
61  if (!text_)
62  {
63  text_ = new MovableText(new_message->text);
65  scene_node_->attachObject(text_);
66 
67  handler_.reset(
68  new MarkerSelectionHandler(this, MarkerID(new_message->ns, new_message->id), context_));
69  handler_->addTrackedObject(text_);
70  }
71 
72  Ogre::Vector3 pos, scale;
73  Ogre::Quaternion orient;
74  if (!transform(new_message, pos, orient, scale))
75  {
76  scene_node_->setVisible(false);
77  return;
78  }
79 
80  scene_node_->setVisible(true);
81  setPosition(pos);
82  text_->setCharacterHeight(new_message->scale.z);
83  text_->setColor(Ogre::ColourValue(new_message->color.r, new_message->color.g, new_message->color.b,
84  new_message->color.a));
85  text_->setCaption(new_message->text);
86 }
87 
89 {
90  S_MaterialPtr materials;
91  if (text_ && text_->getMaterial().get())
92  {
93  materials.insert(text_->getMaterial());
94  }
95  return materials;
96 }
97 
98 } // namespace rviz
rviz::MovableText::V_CENTER
@ V_CENTER
Definition: movable_text.h:72
rviz::MovableText::setTextAlignment
void setTextAlignment(const HorizontalAlignment &horizontalAlignment, const VerticalAlignment &verticalAlignment)
Definition: movable_text.cpp:182
rviz::MarkerBase::context_
DisplayContext * context_
Definition: marker_base.h:108
rviz::S_MaterialPtr
std::set< Ogre::MaterialPtr > S_MaterialPtr
Definition: marker_base.h:51
rviz::TextViewFacingMarker::~TextViewFacingMarker
~TextViewFacingMarker() override
Definition: text_view_facing_marker.cpp:51
rviz::TextViewFacingMarker::onNewMessage
void onNewMessage(const MarkerConstPtr &old_message, const MarkerConstPtr &new_message) override
Definition: text_view_facing_marker.cpp:56
rviz::MarkerDisplay
Displays "markers" sent in by other ROS nodes on the "visualization_marker" topic.
Definition: marker_display.h:70
marker_selection_handler.h
rviz::MarkerBase::setPosition
virtual void setPosition(const Ogre::Vector3 &position)
Definition: marker_base.cpp:124
rviz::TextViewFacingMarker::text_
MovableText * text_
Definition: text_view_facing_marker.h:62
rviz::TextViewFacingMarker::TextViewFacingMarker
TextViewFacingMarker(MarkerDisplay *owner, DisplayContext *context, Ogre::SceneNode *parent_node)
Definition: text_view_facing_marker.cpp:44
text_view_facing_marker.h
rviz::MarkerBase
Definition: marker_base.h:53
rviz::MovableText::setCaption
void setCaption(const Ogre::String &caption)
Definition: movable_text.cpp:137
rviz::MarkerBase::scene_node_
Ogre::SceneNode * scene_node_
Definition: marker_base.h:110
rviz::MarkerBase::handler_
boost::shared_ptr< MarkerSelectionHandler > handler_
Definition: marker_base.h:116
rviz::MovableText::setCharacterHeight
void setCharacterHeight(Ogre::Real height)
Definition: movable_text.cpp:155
selection_manager.h
rviz::MovableText
Definition: movable_text.h:59
rviz::MovableText::H_CENTER
@ H_CENTER
Definition: movable_text.h:66
rviz::MarkerBase::transform
bool transform(const MarkerConstPtr &message, Ogre::Vector3 &pos, Ogre::Quaternion &orient, Ogre::Vector3 &scale)
Definition: marker_base.cpp:87
rviz
Definition: add_display_dialog.cpp:54
rviz::MovableText::getMaterial
const Ogre::MaterialPtr & getMaterial() const override
Definition: movable_text.h:171
rviz::MarkerSelectionHandler
Definition: marker_selection_handler.h:45
rviz::DisplayContext
Pure-virtual base class for objects which give Display subclasses context in which to work.
Definition: display_context.h:81
rviz::TextViewFacingMarker::getMaterials
S_MaterialPtr getMaterials() override
Definition: text_view_facing_marker.cpp:88
movable_text.h
rviz::MarkerID
std::pair< std::string, int32_t > MarkerID
Definition: interactive_marker_display.h:58
display_context.h
assert.h
ROS_ASSERT
#define ROS_ASSERT(cond)
rviz::MovableText::setColor
void setColor(const Ogre::ColourValue &color)
Definition: movable_text.cpp:146
rviz::MarkerBase::MarkerConstPtr
visualization_msgs::Marker::ConstPtr MarkerConstPtr
Definition: marker_base.h:57


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Sat Jun 1 2024 02:31:53