00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "shape_marker.h"
00031 #include "marker_selection_handler.h"
00032 #include "rviz/default_plugin/marker_display.h"
00033
00034 #include "rviz/visualization_manager.h"
00035 #include "rviz/selection/selection_manager.h"
00036
00037 #include <ogre_tools/shape.h>
00038
00039 namespace rviz
00040 {
00041
00042 ShapeMarker::ShapeMarker(MarkerDisplay* owner, VisualizationManager* manager, Ogre::SceneNode* parent_node)
00043 : MarkerBase(owner, manager, parent_node)
00044 , shape_(0)
00045 {
00046 }
00047
00048 ShapeMarker::~ShapeMarker()
00049 {
00050 delete shape_;
00051 }
00052
00053 void ShapeMarker::onNewMessage(const MarkerConstPtr& old_message, const MarkerConstPtr& new_message)
00054 {
00055 if (!shape_ || old_message->type != new_message->type)
00056 {
00057 delete shape_;
00058 shape_ = 0;
00059
00060 switch ( new_message->type )
00061 {
00062 case visualization_msgs::Marker::CUBE:
00063 {
00064 shape_ = new ogre_tools::Shape(ogre_tools::Shape::Cube, vis_manager_->getSceneManager(), parent_node_);
00065 }
00066 break;
00067
00068 case visualization_msgs::Marker::CYLINDER:
00069 {
00070 shape_ = new ogre_tools::Shape(ogre_tools::Shape::Cylinder, vis_manager_->getSceneManager(), parent_node_);
00071 }
00072 break;
00073
00074 case visualization_msgs::Marker::SPHERE:
00075 {
00076 shape_ = new ogre_tools::Shape(ogre_tools::Shape::Sphere, vis_manager_->getSceneManager(), parent_node_);
00077 }
00078 break;
00079
00080 default:
00081 ROS_BREAK();
00082 break;
00083 }
00084
00085 coll_ = vis_manager_->getSelectionManager()->createCollisionForObject(shape_, SelectionHandlerPtr(new MarkerSelectionHandler(this, MarkerID(new_message->ns, new_message->id))), coll_);
00086 }
00087
00088 Ogre::Vector3 pos, scale;
00089 Ogre::Quaternion orient;
00090 transform(new_message, pos, orient, scale);
00091
00092 if (new_message->scale.x * new_message->scale.y * new_message->scale.z == 0.0f)
00093 {
00094 owner_->setMarkerStatus(getID(), status_levels::Warn, "Scale of 0 in one of x/y/z");
00095 }
00096
00097 shape_->setPosition(pos);
00098 shape_->setOrientation(orient);
00099 shape_->setScale(scale);
00100 shape_->setColor(new_message->color.r, new_message->color.g, new_message->color.b, new_message->color.a);
00101 }
00102
00103 }