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 
46  DisplayContext* context,
47  Ogre::SceneNode* parent_node )
48  : MarkerBase( owner, context, parent_node )
49  , shape_( 0 )
50 {
51 }
52 
54 {
55  delete shape_;
56 }
57 
58 void ShapeMarker::onNewMessage( const MarkerConstPtr& old_message,
59  const MarkerConstPtr& new_message )
60 {
61  if (!shape_ || old_message->type != new_message->type)
62  {
63  delete shape_;
64  shape_ = 0;
65 
66  Shape::Type shape_type = Shape::Cube;
67  switch( new_message->type )
68  {
69  case visualization_msgs::Marker::CUBE: shape_type = Shape::Cube; break;
70  case visualization_msgs::Marker::CYLINDER: shape_type = Shape::Cylinder; break;
71  case visualization_msgs::Marker::SPHERE: shape_type = Shape::Sphere; break;
72  default:
73  ROS_BREAK();
74  break;
75  }
76  shape_ = new Shape( shape_type, context_->getSceneManager(), scene_node_ );
77 
78  handler_.reset( new MarkerSelectionHandler( this, MarkerID( new_message->ns, new_message->id ), context_ ));
79  handler_->addTrackedObjects( shape_->getRootNode() );
80  }
81 
82  Ogre::Vector3 pos, scale, scale_correct;
83  Ogre::Quaternion orient;
84  transform(new_message, pos, orient, scale);
85 
86  if (owner_ && (new_message->scale.x * new_message->scale.y
87  * new_message->scale.z == 0.0f))
88  {
90  "Scale of 0 in one of x/y/z");
91  }
92 
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,
101  new_message->color.b, new_message->color.a);
102 }
103 
105 {
106  S_MaterialPtr materials;
107  extractMaterials(shape_->getEntity(), materials);
108  return materials;
109 }
110 
111 }
Ogre::SceneNode * scene_node_
Definition: marker_base.h:104
bool transform(const MarkerConstPtr &message, Ogre::Vector3 &pos, Ogre::Quaternion &orient, Ogre::Vector3 &scale)
Definition: marker_base.cpp:88
virtual S_MaterialPtr getMaterials()
void setMarkerStatus(MarkerID id, StatusLevel level, const std::string &text)
virtual void setPosition(const Ogre::Vector3 &position)
ShapeMarker(MarkerDisplay *owner, DisplayContext *context, Ogre::SceneNode *parent_node)
MarkerDisplay * owner_
Definition: marker_base.h:101
void extractMaterials(Ogre::Entity *entity, S_MaterialPtr &materials)
virtual void setColor(float r, float g, float b, float a)
Set the color of the object. Values are in the range [0, 1].
Definition: shape.cpp:142
std::pair< std::string, int32_t > MarkerID
Pure-virtual base class for objects which give Display subclasses context in which to work...
boost::shared_ptr< MarkerSelectionHandler > handler_
Definition: marker_base.h:110
DisplayContext * context_
Definition: marker_base.h:102
MarkerID getID()
Definition: marker_base.h:77
visualization_msgs::Marker::ConstPtr MarkerConstPtr
Definition: marker_base.h:63
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
std::set< Ogre::MaterialPtr > S_MaterialPtr
Definition: marker_base.h:57
virtual void setOrientation(const Ogre::Quaternion &orientation)
virtual void onNewMessage(const MarkerConstPtr &old_message, const MarkerConstPtr &new_message)
Ogre::SceneNode * getRootNode()
Get the root scene node (pivot node) for this object.
Definition: shape.h:97
#define ROS_BREAK()
Displays "markers" sent in by other ROS nodes on the "visualization_marker" topic.
virtual void setScale(const Ogre::Vector3 &scale)
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: shape.cpp:162
Ogre::Entity * getEntity()
Definition: shape.h:104


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:42