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 "points_marker.h"
00031 #include "rviz/default_plugin/marker_display.h"
00032 #include "rviz/common.h"
00033 #include "rviz/visualization_manager.h"
00034
00035 #include <ogre_tools/point_cloud.h>
00036
00037 #include <OGRE/OgreVector3.h>
00038 #include <OGRE/OgreQuaternion.h>
00039 #include <OGRE/OgreSceneNode.h>
00040 #include <OGRE/OgreSceneManager.h>
00041
00042 namespace rviz
00043 {
00044
00045 PointsMarker::PointsMarker(MarkerDisplay* owner, VisualizationManager* manager, Ogre::SceneNode* parent_node)
00046 : MarkerBase(owner, manager, parent_node)
00047 , points_(0)
00048 {
00049 if (parent_node)
00050 {
00051 scene_node_ = parent_node->createChildSceneNode();
00052 }
00053 else
00054 {
00055 scene_node_ = vis_manager_->getSceneManager()->getRootSceneNode()->createChildSceneNode();
00056 }
00057 }
00058
00059 PointsMarker::~PointsMarker()
00060 {
00061 vis_manager_->getSceneManager()->destroySceneNode(scene_node_->getName());
00062 delete points_;
00063 }
00064
00065 void PointsMarker::onNewMessage(const MarkerConstPtr& old_message, const MarkerConstPtr& new_message)
00066 {
00067 ROS_ASSERT(new_message->type == visualization_msgs::Marker::POINTS ||
00068 new_message->type == visualization_msgs::Marker::CUBE_LIST);
00069
00070 if (!points_)
00071 {
00072 points_ = new ogre_tools::PointCloud();
00073 scene_node_->attachObject(points_);
00074 }
00075
00076 Ogre::Vector3 pos, scale;
00077 Ogre::Quaternion orient;
00078 transform(new_message, pos, orient, scale);
00079
00080 switch (new_message->type)
00081 {
00082 case visualization_msgs::Marker::POINTS:
00083 points_->setRenderMode(ogre_tools::PointCloud::RM_BILLBOARDS);
00084 points_->setDimensions(new_message->scale.x, new_message->scale.y, 0.0f);
00085 break;
00086 case visualization_msgs::Marker::CUBE_LIST:
00087 points_->setRenderMode(ogre_tools::PointCloud::RM_BOXES);
00088 points_->setDimensions(scale.x, scale.y, scale.z);
00089 break;
00090 }
00091
00092 scene_node_->setPosition(pos);
00093 scene_node_->setOrientation(orient);
00094
00095 points_->clear();
00096
00097 if (new_message->points.empty())
00098 {
00099 return;
00100 }
00101
00102 float r = new_message->color.r;
00103 float g = new_message->color.g;
00104 float b = new_message->color.b;
00105 float a = new_message->color.a;
00106 points_->setAlpha(a);
00107
00108 bool has_per_point_color = new_message->colors.size() == new_message->points.size();
00109
00110 typedef std::vector< ogre_tools::PointCloud::Point > V_Point;
00111 V_Point points;
00112 points.resize(new_message->points.size());
00113 std::vector<geometry_msgs::Point>::const_iterator it = new_message->points.begin();
00114 std::vector<geometry_msgs::Point>::const_iterator end = new_message->points.end();
00115 for (int i = 0; it != end; ++it, ++i)
00116 {
00117 const geometry_msgs::Point& p = *it;
00118 ogre_tools::PointCloud::Point& point = points[i];
00119
00120 Ogre::Vector3 v(p.x, p.y, p.z);
00121 robotToOgre(v);
00122
00123 point.x = v.x;
00124 point.y = v.y;
00125 point.z = v.z;
00126
00127 if (has_per_point_color)
00128 {
00129 const std_msgs::ColorRGBA& color = new_message->colors[i];
00130 r = color.r;
00131 g = color.g;
00132 b = color.b;
00133 }
00134
00135 point.setColor(r, g, b);
00136 }
00137
00138 points_->addPoints(&points.front(), points.size());
00139 }
00140
00141 }