marker_base.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, 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 "marker_base.h"
32 #include <rviz/display_context.h>
35 #include <rviz/frame_manager.h>
36 
37 #include <OgreSceneNode.h>
38 #include <OgreSceneManager.h>
39 #include <OgreEntity.h>
40 #include <OgreSubEntity.h>
41 #include <OgreSharedPtr.h>
42 
43 
44 #include <utility>
45 
46 
47 namespace rviz
48 {
49 MarkerBase::MarkerBase(MarkerDisplay* owner, DisplayContext* context, Ogre::SceneNode* parent_node)
50  : owner_(owner), context_(context), scene_node_(parent_node->createChildSceneNode())
51 {
52 }
53 
55 {
56  context_->getSceneManager()->destroySceneNode(scene_node_);
57 }
58 
59 void MarkerBase::setMessage(const Marker& message)
60 {
61  // copy and save to shared pointer
62  MarkerConstPtr message_ptr(new Marker(message));
63  setMessage(message_ptr);
64 }
65 
67 {
69  message_ = message;
70 
71  expiration_ = ros::Time::now() + message->lifetime;
72 
73  onNewMessage(old, message);
74 }
75 
77 {
78  ROS_ASSERT(message_ && message_->frame_locked);
80 }
81 
83 {
84  return ros::Time::now() >= expiration_;
85 }
86 
88  Ogre::Vector3& pos,
89  Ogre::Quaternion& orient,
90  Ogre::Vector3& scale)
91 {
92  ros::Time stamp = message->header.stamp;
93  if (message->frame_locked)
94  {
95  stamp = ros::Time();
96  }
97 
98  if (!context_->getFrameManager()->transform(message->header.frame_id, stamp, message->pose, pos,
99  orient))
100  {
101  std::string error;
102  context_->getFrameManager()->transformHasProblems(message->header.frame_id, message->header.stamp,
103  error);
104  if (owner_)
105  {
107  }
108  return false;
109  }
110 
111  scale = Ogre::Vector3(message->scale.x, message->scale.y, message->scale.z);
112 
113  return true;
114 }
115 
117 {
118  if (handler_)
119  {
120  handler_->setInteractiveObject(std::move(control));
121  }
122 }
123 
124 void MarkerBase::setPosition(const Ogre::Vector3& position)
125 {
126  scene_node_->setPosition(position);
127 }
128 
129 void MarkerBase::setOrientation(const Ogre::Quaternion& orientation)
130 {
131  scene_node_->setOrientation(orientation);
132 }
133 
134 const Ogre::Vector3& MarkerBase::getPosition() const
135 {
136  return scene_node_->getPosition();
137 }
138 
139 const Ogre::Quaternion& MarkerBase::getOrientation() const
140 {
141  return scene_node_->getOrientation();
142 }
143 
144 void MarkerBase::extractMaterials(Ogre::Entity* entity, S_MaterialPtr& materials)
145 {
146  uint32_t num_sub_entities = entity->getNumSubEntities();
147  for (uint32_t i = 0; i < num_sub_entities; ++i)
148  {
149  Ogre::SubEntity* sub = entity->getSubEntity(i);
150  const Ogre::MaterialPtr& material = sub->getMaterial();
151  materials.insert(material);
152  }
153 }
154 
155 
156 } // namespace rviz
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::MarkerDisplay
Displays "markers" sent in by other ROS nodes on the "visualization_marker" topic.
Definition: marker_display.h:70
marker_selection_handler.h
frame_manager.h
rviz::MarkerBase::onNewMessage
virtual void onNewMessage(const MarkerConstPtr &old_message, const MarkerConstPtr &new_message)=0
rviz::MarkerBase::Marker
visualization_msgs::Marker Marker
Definition: marker_base.h:56
rviz::MarkerBase::setPosition
virtual void setPosition(const Ogre::Vector3 &position)
Definition: marker_base.cpp:124
rviz::StatusProperty::Error
@ Error
Definition: status_property.h:46
marker_display.h
rviz::MarkerBase::scene_node_
Ogre::SceneNode * scene_node_
Definition: marker_base.h:110
rviz::MarkerBase::setOrientation
virtual void setOrientation(const Ogre::Quaternion &orientation)
Definition: marker_base.cpp:129
rviz::MarkerBase::handler_
boost::shared_ptr< MarkerSelectionHandler > handler_
Definition: marker_base.h:116
rviz::MarkerBase::getOrientation
const Ogre::Quaternion & getOrientation() const
Definition: marker_base.cpp:139
rviz::MarkerBase::expired
bool expired()
Definition: marker_base.cpp:82
selection_manager.h
rviz::MarkerBase::setInteractiveObject
void setInteractiveObject(InteractiveObjectWPtr object)
Associate an InteractiveObject with this MarkerBase.
Definition: marker_base.cpp:116
rviz::DisplayContext::getSceneManager
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
rviz::MarkerBase::MarkerBase
MarkerBase(MarkerDisplay *owner, DisplayContext *context, Ogre::SceneNode *parent_node)
Definition: marker_base.cpp:49
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::MarkerBase::setMessage
void setMessage(const Marker &message)
Definition: marker_base.cpp:59
rviz::MarkerBase::~MarkerBase
virtual ~MarkerBase()
Definition: marker_base.cpp:54
rviz::MarkerBase::getPosition
const Ogre::Vector3 & getPosition() const
Definition: marker_base.cpp:134
rviz::DisplayContext
Pure-virtual base class for objects which give Display subclasses context in which to work.
Definition: display_context.h:81
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
ros::Time
rviz::MarkerBase::message_
MarkerConstPtr message_
Definition: marker_base.h:112
rviz::MarkerBase::owner_
MarkerDisplay * owner_
Definition: marker_base.h:107
rviz::FrameManager::transform
bool transform(const Header &header, const geometry_msgs::Pose &pose, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Transform a pose from a frame into the fixed frame.
Definition: frame_manager.h:148
marker_base.h
rviz::MarkerBase::updateFrameLocked
void updateFrameLocked()
Definition: marker_base.cpp:76
rviz::MarkerBase::getID
MarkerID getID()
Definition: marker_base.h:74
display_context.h
rviz::MarkerBase::extractMaterials
void extractMaterials(Ogre::Entity *entity, S_MaterialPtr &materials)
Definition: marker_base.cpp:144
ROS_ASSERT
#define ROS_ASSERT(cond)
rviz::MarkerBase::MarkerConstPtr
visualization_msgs::Marker::ConstPtr MarkerConstPtr
Definition: marker_base.h:57
rviz::MarkerBase::expiration_
ros::Time expiration_
Definition: marker_base.h:114
rviz::InteractiveObjectWPtr
boost::weak_ptr< InteractiveObject > InteractiveObjectWPtr
Definition: interactive_object.h:59
rviz::FrameManager::transformHasProblems
bool transformHasProblems(const std::string &frame, ros::Time time, std::string &error)
Check to see if a transform is known between a given frame and the fixed frame.
Definition: frame_manager.cpp:272
ros::Time::now
static Time now()
rviz::MarkerDisplay::setMarkerStatus
void setMarkerStatus(const MarkerID &id, StatusLevel level, const std::string &text)
Definition: marker_display.cpp:237


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:02