shape_marker.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 "shape_marker.h"
33 
34 #include <rviz/display_context.h>
36 
38 
39 #include <OgreSceneNode.h>
40 #include <OgreMatrix3.h>
41 
42 namespace rviz
43 {
44 ShapeMarker::ShapeMarker(MarkerDisplay* owner, DisplayContext* context, Ogre::SceneNode* parent_node)
45  : MarkerBase(owner, context, parent_node), shape_(nullptr)
46 {
47 }
48 
50 {
51  delete shape_;
52 }
53 
54 void ShapeMarker::onNewMessage(const MarkerConstPtr& old_message, const MarkerConstPtr& new_message)
55 {
56  if (!shape_ || old_message->type != new_message->type)
57  {
58  delete shape_;
59  shape_ = nullptr;
60 
61  Shape::Type shape_type = Shape::Cube;
62  switch (new_message->type)
63  {
64  case visualization_msgs::Marker::CUBE:
65  shape_type = Shape::Cube;
66  break;
67  case visualization_msgs::Marker::CYLINDER:
68  shape_type = Shape::Cylinder;
69  break;
70  case visualization_msgs::Marker::SPHERE:
71  shape_type = Shape::Sphere;
72  break;
73  default:
74  ROS_BREAK();
75  break;
76  }
77  shape_ = new Shape(shape_type, context_->getSceneManager(), scene_node_);
78 
79  handler_.reset(
80  new MarkerSelectionHandler(this, MarkerID(new_message->ns, new_message->id), context_));
81  handler_->addTrackedObjects(shape_->getRootNode());
82  }
83 
84  Ogre::Vector3 pos, scale, scale_correct;
85  Ogre::Quaternion orient;
86  if (!transform(new_message, pos, orient, scale))
87  {
88  scene_node_->setVisible(false);
89  return;
90  }
91 
92  scene_node_->setVisible(true);
93  setPosition(pos);
94  setOrientation(orient * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3(1, 0, 0)));
95 
96  scale_correct = Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3(1, 0, 0)) * scale;
97 
98  shape_->setScale(scale_correct);
99 
100  shape_->setColor(new_message->color.r, new_message->color.g, new_message->color.b,
101  new_message->color.a);
102 }
103 
105 {
106  S_MaterialPtr materials;
107  extractMaterials(shape_->getEntity(), materials);
108  return materials;
109 }
110 
111 } // namespace rviz
rviz::MarkerBase::context_
DisplayContext * context_
Definition: marker_base.h:108
shape.h
rviz::Shape::getRootNode
Ogre::SceneNode * getRootNode()
Get the root scene node (pivot node) for this object.
Definition: shape.h:100
rviz::Shape::Cylinder
@ Cylinder
Definition: shape.h:58
ROS_BREAK
#define ROS_BREAK()
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
rviz::Shape::setColor
void setColor(float r, float g, float b, float a) override
Set the color of the object. Values are in the range [0, 1].
Definition: shape.cpp:136
rviz::MarkerBase::setPosition
virtual void setPosition(const Ogre::Vector3 &position)
Definition: marker_base.cpp:124
rviz::ShapeMarker::onNewMessage
void onNewMessage(const MarkerConstPtr &old_message, const MarkerConstPtr &new_message) override
Definition: shape_marker.cpp:54
rviz::MarkerBase
Definition: marker_base.h:53
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
selection_manager.h
rviz::Shape::Type
Type
Definition: shape.h:54
rviz::DisplayContext::getSceneManager
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
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::ShapeMarker::shape_
Shape * shape_
Definition: shape_marker.h:52
rviz::MarkerSelectionHandler
Definition: marker_selection_handler.h:45
rviz::Shape::getEntity
Ogre::Entity * getEntity()
Definition: shape.h:110
rviz::DisplayContext
Pure-virtual base class for objects which give Display subclasses context in which to work.
Definition: display_context.h:81
rviz::Shape::Sphere
@ Sphere
Definition: shape.h:59
rviz::ShapeMarker::ShapeMarker
ShapeMarker(MarkerDisplay *owner, DisplayContext *context, Ogre::SceneNode *parent_node)
Definition: shape_marker.cpp:44
rviz::MarkerID
std::pair< std::string, int32_t > MarkerID
Definition: interactive_marker_display.h:58
shape_marker.h
rviz::Shape
Definition: shape.h:51
rviz::ShapeMarker::~ShapeMarker
~ShapeMarker() override
Definition: shape_marker.cpp:49
display_context.h
rviz::Shape::setScale
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: shape.cpp:156
rviz::MarkerBase::extractMaterials
void extractMaterials(Ogre::Entity *entity, S_MaterialPtr &materials)
Definition: marker_base.cpp:144
rviz::ShapeMarker::getMaterials
S_MaterialPtr getMaterials() override
Definition: shape_marker.cpp:104
rviz::MarkerBase::MarkerConstPtr
visualization_msgs::Marker::ConstPtr MarkerConstPtr
Definition: marker_base.h:57
rviz::Shape::Cube
@ Cube
Definition: shape.h:57


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