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 "sphere_list_marker.h"
00031 #include "marker_selection_handler.h"
00032 #include "rviz/default_plugin/marker_display.h"
00033 #include "rviz/common.h"
00034
00035 #include "rviz/visualization_manager.h"
00036 #include "rviz/selection/selection_manager.h"
00037
00038 #include <ogre_tools/shape.h>
00039 #include <tf/transform_listener.h>
00040
00041 #include <OGRE/OgreSceneManager.h>
00042 #include <OGRE/OgreSceneNode.h>
00043 #include <OGRE/OgreMaterialManager.h>
00044 #include <OGRE/OgreStaticGeometry.h>
00045 #include <OGRE/OgreEntity.h>
00046
00047 namespace rviz
00048 {
00049
00050 SphereListMarker::SphereListMarker(MarkerDisplay* owner, VisualizationManager* manager, Ogre::SceneNode* parent_node)
00051 : MarkerBase(owner, manager, parent_node)
00052 , geometry_(0)
00053 {
00054 static uint32_t count = 0;
00055 std::stringstream ss;
00056 ss << "SphereListMarker" << count++;
00057
00058 geometry_ = vis_manager_->getSceneManager()->createStaticGeometry(ss.str());
00059
00060 ss << "Material";
00061 material_name_ = ss.str();
00062 material_ = Ogre::MaterialManager::getSingleton().create( material_name_, ROS_PACKAGE_NAME );
00063 material_->setReceiveShadows(false);
00064 material_->getTechnique(0)->setLightingEnabled(true);
00065 material_->getTechnique(0)->setAmbient( 0.5, 0.5, 0.5 );
00066 }
00067
00068 SphereListMarker::~SphereListMarker()
00069 {
00070 vis_manager_->getSceneManager()->destroyStaticGeometry(geometry_);
00071 }
00072
00073 void SphereListMarker::onNewMessage(const MarkerConstPtr& old_message, const MarkerConstPtr& new_message)
00074 {
00075 ROS_ASSERT(new_message->type == visualization_msgs::Marker::SPHERE_LIST);
00076
00077 if (!old_message)
00078 {
00079 SelectionManager* sel_manager = vis_manager_->getSelectionManager();
00080 coll_ = sel_manager->createHandle();
00081 sel_manager->addPickTechnique(coll_, material_);
00082 sel_manager->addObject(coll_, SelectionHandlerPtr(new MarkerSelectionHandler(this, MarkerID(new_message->ns, new_message->id))));
00083 }
00084
00085 float r = new_message->color.r;
00086 float g = new_message->color.g;
00087 float b = new_message->color.b;
00088 float a = new_message->color.a;
00089 material_->getTechnique(0)->setAmbient( r*0.5, g*0.5, b*0.5 );
00090 material_->getTechnique(0)->setDiffuse( r, g, b, a );
00091
00092 if ( a < 0.9998 )
00093 {
00094 material_->getTechnique(0)->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
00095 material_->getTechnique(0)->setDepthWriteEnabled( false );
00096 }
00097 else
00098 {
00099 material_->getTechnique(0)->setSceneBlending( Ogre::SBT_REPLACE );
00100 material_->getTechnique(0)->setDepthWriteEnabled( true );
00101 }
00102
00103 Ogre::Vector3 pos, scale;
00104 Ogre::Quaternion orient;
00105 transform(new_message, pos, orient, scale);
00106
00107 if (new_message->scale.x * new_message->scale.y * new_message->scale.z == 0.0f)
00108 {
00109 owner_->setMarkerStatus(getID(), status_levels::Warn, "Scale of 0 in one of x/y/z");
00110 }
00111
00112 Ogre::SceneManager* scene_manager = vis_manager_->getSceneManager();
00113 Ogre::Entity* entity = scene_manager->createEntity("SphereListMarker Temp", "ogre_tools_sphere.mesh");
00114
00115 entity->setMaterialName(material_name_);
00116 geometry_->reset();
00117
00118 std::vector<geometry_msgs::Point>::const_iterator it = new_message->points.begin();
00119 std::vector<geometry_msgs::Point>::const_iterator end = new_message->points.end();
00120 for ( ; it != end; ++it )
00121 {
00122 const geometry_msgs::Point& p = *it;
00123
00124 Ogre::Vector3 point(p.x, p.y, p.z);
00125 robotToOgre(point);
00126
00127 point = pos + (orient * point);
00128
00129 geometry_->addEntity(entity, point, orient, scale);
00130 }
00131
00132 geometry_->build();
00133
00134 scene_manager->destroyEntity(entity);
00135 }
00136
00137 }