line_strip_marker.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "line_strip_marker.h"
00031 #include "rviz/default_plugin/marker_display.h"
00032 #include "rviz/visualization_manager.h"
00033 
00034 #include <rviz/ogre_helpers/billboard_line.h>
00035 
00036 #include <OGRE/OgreVector3.h>
00037 #include <OGRE/OgreQuaternion.h>
00038 #include <OGRE/OgreSceneNode.h>
00039 
00040 namespace rviz
00041 {
00042 
00043 LineStripMarker::LineStripMarker(MarkerDisplay* owner, VisualizationManager* manager, Ogre::SceneNode* parent_node)
00044 : MarkerBase(owner, manager, parent_node)
00045 , lines_(0)
00046 {
00047 }
00048 
00049 LineStripMarker::~LineStripMarker()
00050 {
00051   delete lines_;
00052 }
00053 
00054 void LineStripMarker::onNewMessage(const MarkerConstPtr& old_message, const MarkerConstPtr& new_message)
00055 {
00056   ROS_ASSERT(new_message->type == visualization_msgs::Marker::LINE_STRIP);
00057 
00058   if (!lines_)
00059   {
00060     lines_ = new BillboardLine(vis_manager_->getSceneManager(), scene_node_);
00061   }
00062 
00063   Ogre::Vector3 pos, scale;
00064   Ogre::Quaternion orient;
00065   transform(new_message, pos, orient, scale);
00066 
00067   setPosition(pos);
00068   setOrientation(orient);
00069   lines_->setScale(scale);
00070   lines_->setColor(new_message->color.r, new_message->color.g, new_message->color.b, new_message->color.a);
00071 
00072   lines_->clear();
00073   if (new_message->points.empty())
00074   {
00075     return;
00076   }
00077 
00078   lines_->setLineWidth(new_message->scale.x);
00079   lines_->setMaxPointsPerLine(new_message->points.size());
00080 
00081   bool has_per_point_color = new_message->colors.size() == new_message->points.size();
00082 
00083   size_t i = 0;
00084   std::vector<geometry_msgs::Point>::const_iterator it = new_message->points.begin();
00085   std::vector<geometry_msgs::Point>::const_iterator end = new_message->points.end();
00086   for ( ; it != end; ++it, ++i )
00087   {
00088     const geometry_msgs::Point& p = *it;
00089 
00090     Ogre::Vector3 v( p.x, p.y, p.z );
00091 
00092     Ogre::ColourValue c;
00093     if (has_per_point_color)
00094     {
00095       const std_msgs::ColorRGBA& color = new_message->colors[i];
00096       c.r = color.r;
00097       c.g = color.g;
00098       c.b = color.b;
00099       c.a = new_message->color.a;
00100     }
00101     else
00102     {
00103       c.r = new_message->color.r;
00104       c.g = new_message->color.g;
00105       c.b = new_message->color.b;
00106       c.a = new_message->color.a;
00107     }
00108 
00109     lines_->addPoint( v, c );
00110   }
00111 }
00112 
00113 S_MaterialPtr LineStripMarker::getMaterials()
00114 {
00115   S_MaterialPtr materials;
00116   materials.insert( lines_->getMaterial() );
00117   return materials;
00118 }
00119 
00120 }


rviz
Author(s): Dave Hershberger, Josh Faust
autogenerated on Mon Jan 6 2014 11:54:32