ompl_rviz_viewer.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2014, University of Colorado, Boulder
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the Univ of CO, Boulder nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 /* Author: Dave Coleman <dave@dav.ee>
00036    Desc:   Tools for displaying OMPL components in Rviz
00037 */
00038 
00039 // ROS
00040 #include <ros/ros.h>
00041 #include <visualization_msgs/Marker.h>
00042 
00043 // Boost
00044 #include <boost/numeric/ublas/matrix.hpp>
00045 #include <boost/numeric/ublas/io.hpp>
00046 
00047 // OMPL
00048 #include <ompl/base/SpaceInformation.h>
00049 #include <ompl/base/spaces/SE3StateSpace.h>
00050 #include <ompl/geometric/PathGeometric.h>
00051 #include <ompl/base/PlannerData.h>
00052 #include <ompl/config.h>
00053 
00054 namespace ob = ompl::base;
00055 namespace og = ompl::geometric;
00056 namespace bnu = boost::numeric::ublas;
00057 
00058 namespace ompl_rviz_viewer
00059 {
00060 
00061 static const std::string BASE_FRAME = "/world";
00062 
00063 // *********************************************************************************************************
00064 // Nat_Rounding helper function to make readings from cost map more accurate
00065 // *********************************************************************************************************
00066 int nat_round(double x)
00067 {
00068   return static_cast<int>(floor(x + 0.5f));
00069 }
00070 
00071 // Helper function for converting a point to the correct cost
00072 double getCost(const geometry_msgs::Point &point, bnu::matrix<int> &cost)
00073 {
00074   return double(cost( nat_round(point.y), nat_round(point.x) )) / 2.0;
00075 }
00076 
00077 double getCostHeight(const geometry_msgs::Point &point, bnu::matrix<int> &cost)
00078 {
00079   //std::cout << "------------------------" << std::endl;
00080 
00081   // check if whole number
00082   if (floor(point.x) == point.x && floor(point.y) == point.y)
00083     return getCost(point, cost);
00084 
00085   // else do Bilinear Interpolation
00086   // From http://supercomputingblog.com/graphics/coding-bilinear-interpolation/
00087 
00088   // top left
00089   geometry_msgs::Point a;
00090   a.x = floor(point.x);
00091   a.y = ceil(point.y);
00092   a.z = getCost(a, cost);
00093 
00094   // bottom left
00095   geometry_msgs::Point b;
00096   b.x = floor(point.x);
00097   b.y = floor(point.y);
00098   b.z = getCost(b, cost);
00099 
00100   // bottom right
00101   geometry_msgs::Point c;
00102   c.x = ceil(point.x);
00103   c.y = floor(point.y);
00104   c.z = getCost(c, cost);
00105 
00106   // top right
00107   geometry_msgs::Point d;
00108   d.x = ceil(point.x);
00109   d.y = ceil(point.y);
00110   d.z = getCost(d, cost);
00111 
00112 
00113   //std::cout << "a: " << a << std::endl;
00114   //std::cout << "b: " << b << std::endl;
00115   //std::cout << "c: " << c << std::endl;
00116   //std::cout << "d: " << d << std::endl;
00117 
00118   double R1 = ((c.x - point.x)/(c.x - b.x))*b.z + ((point.x - b.x)/(c.x - b.x))*c.z;
00119   double R2 = ((c.x - point.x)/(c.x - b.x))*a.z + ((point.x - b.x)/(c.x - b.x))*d.z;
00120 
00121   //std::cout << "R1: " << R1 << std::endl;
00122   //std::cout << "R2: " << R2 << std::endl;
00123 
00124   // After the two R values are calculated, the value of P can finally be calculated by a weighted average of R1 and R2.  
00125   double val;
00126 
00127   if ( a.y - b.y == 0) // division by zero
00128     val = R1;
00129   else
00130     val = ((a.y - point.y)/(a.y - b.y))*R1 + ((point.y - b.y)/(a.y - b.y))*R2;
00131 
00132   //std::cout << "val: " << val << std::endl;
00133   return val + 0.2;
00134 }
00135 
00136 
00137 class OmplRvizViewer
00138 {
00139 private:
00140 
00141   // A shared node handle
00142   ros::NodeHandle nh_;
00143 
00144   // Show more visual and console output, with general slower run time.
00145   bool verbose_;
00146 
00147   // A shared ROS publisher
00148   ros::Publisher marker_pub_;
00149 
00150 public:
00151 
00156   OmplRvizViewer(bool verbose)
00157     : verbose_(verbose)
00158   {
00159     // ROS Publishing stuff
00160     marker_pub_ = nh_.advertise<visualization_msgs::Marker>("ompl_rviz_markers", 1);
00161     ros::Duration(1).sleep();
00162 
00163     ROS_INFO_STREAM_NAMED("ompl_rviz_viewer","OmplRvizViewer Ready.");
00164   }
00165 
00169   ~OmplRvizViewer()
00170   {
00171 
00172   }
00173 
00177   std::vector<std::pair<double, double> > convertSolutionToVector(og::PathGeometric& path)
00178   {
00179     // The returned result
00180     std::vector<std::pair<double, double> > coordinates;
00181 
00182     // Get data
00183     const std::vector<ob::State*>& states = path.getStates();
00184 
00185     // Convert solution to coordinate vector
00186     //for( std::vector<ob::State*>::const_iterator state_it = states.begin();
00187     //         state_it != states.end(); ++state_it )
00188     for( size_t state_id = 0; state_id < states.size(); ++state_id )
00189     {
00190       const ob::State *state = states[ state_id ];
00191 
00192       if (!state)
00193         continue; // no data?
00194 
00195       // Convert to RealVectorStateSpace
00196       const ob::RealVectorStateSpace::StateType *real_state =
00197         static_cast<const ob::RealVectorStateSpace::StateType*>(state);
00198 
00199       // Add to vector of results
00200       coordinates.push_back( std::pair<double,double>( real_state->values[0], real_state->values[1] ) );
00201     }
00202 
00203     return coordinates;
00204   }
00205 
00209   void displayTriangles(PPMImage *image, bnu::matrix<int> &cost)
00210   {
00211     visualization_msgs::Marker marker;
00212     // Set the frame ID and timestamp.  See the TF tutorials for information on these.
00213     marker.header.frame_id = BASE_FRAME;
00214     marker.header.stamp = ros::Time::now();
00215 
00216     // Set the namespace and id for this marker.  This serves to create a unique ID
00217     marker.ns = "cost_map";
00218 
00219     // Set the marker type.
00220     marker.type = visualization_msgs::Marker::TRIANGLE_LIST;
00221 
00222     // Set the marker action.  Options are ADD and DELETE
00223     marker.action = visualization_msgs::Marker::ADD;
00224     marker.id = 1;
00225 
00226     marker.pose.position.x = 0;
00227     marker.pose.position.y = 0;
00228     marker.pose.position.z = 0;
00229     marker.pose.orientation.x = 0.0;
00230     marker.pose.orientation.y = 0.0;
00231     marker.pose.orientation.z = 0.0;
00232     marker.pose.orientation.w = 1.0;
00233     marker.scale.x = 1.0;
00234     marker.scale.y = 1.0;
00235     marker.scale.z = 1.0;
00236     marker.color.r = 255;
00237     marker.color.g = 0;
00238     marker.color.b = 0;
00239     marker.color.a = 1.0;
00240 
00241     // Visualize Results -------------------------------------------------------------------------------------------------
00242     for( size_t marker_id = 0; marker_id < image->getSize(); ++marker_id )
00243     {
00244 
00245       unsigned int x = marker_id % image->x;    // Map index back to coordinates
00246       unsigned int y = marker_id / image->x;    // Map index back to coordinates
00247 
00248       // Make right and down triangle
00249       // Check that we are not on the far right or bottom
00250       if( ! (x + 1 >= image->x ||  y + 1 >= image->y ) )
00251       {
00252         addPoint( x,   y, &marker, image, cost );
00253         addPoint( x+1, y, &marker, image, cost );
00254         addPoint( x,   y+1, &marker, image, cost );
00255       }
00256 
00257       // Make back and down triangle
00258       // Check that we are not on the far left or bottom
00259       if( ! ( int(x) - 1 < 0 ||  y + 1 >= image->y ) )
00260       {
00261         addPoint( x,   y, &marker, image, cost );
00262         addPoint( x,   y+1, &marker, image, cost );
00263         addPoint( x-1, y+1, &marker, image, cost );
00264       }
00265 
00266     }
00267 
00268     marker_pub_.publish( marker );
00269   }
00270 
00271   // *********************************************************************************************************
00272   // Helper Function to display triangles
00273   // *********************************************************************************************************
00274   void addPoint( int x, int y, visualization_msgs::Marker* marker, PPMImage *image, bnu::matrix<int> &cost )
00275   {
00276     // Point
00277     geometry_msgs::Point point;
00278     point.x = x;
00279     point.y = y;
00280     point.z = getCost(point, cost); // to speed things up, we know is always whole number
00281     marker->points.push_back( point );
00282 
00283     // Color
00284     std_msgs::ColorRGBA color;
00285     color.r = image->data[ image->getID( x, y ) ].red / 255.0;
00286     color.g = image->data[ image->getID( x, y ) ].green / 255.0;
00287     color.b = image->data[ image->getID( x, y ) ].blue / 255.0;
00288     color.a = 1.0;
00289     marker->colors.push_back( color );
00290   }
00291 
00292   // *********************************************************************************************************
00293   // Helper Function for Display Graph that makes the exploration lines follow the curvature of the map
00294   // *********************************************************************************************************
00295   void interpolateLine( const geometry_msgs::Point &p1, const geometry_msgs::Point &p2, visualization_msgs::Marker* marker, 
00296     std_msgs::ColorRGBA &color, bnu::matrix<int> &cost )
00297   {
00298     // Copy to non-const
00299     geometry_msgs::Point point_a = p1;
00300     geometry_msgs::Point point_b = p2;
00301 
00302     // Get the heights
00303     point_a.z = getCostHeight(point_a, cost);
00304     point_b.z = getCostHeight(point_b, cost);
00305 
00306     ROS_INFO_STREAM("a is: " << point_a);
00307     ROS_INFO_STREAM("b is: " << point_b);
00308 
00309     // Switch the coordinates such that x1 < x2
00310     if( point_a.x > point_b.x )
00311     {
00312       // Swap the coordinates      
00313       geometry_msgs::Point point_temp = point_a;      
00314       point_a = point_b;
00315       point_b = point_temp;
00316     }
00317 
00318     // temp
00319     std_msgs::ColorRGBA color2 = color;
00320     color2.r = 1;
00321 
00322     // Show the straight line --------------------------------------------------------------------
00323     if( false )
00324     {
00325       // Change Color
00326       color.g = 0.8;
00327 
00328       // Add the point pair to the line message
00329       marker->points.push_back( point_a );
00330       marker->points.push_back( point_b );
00331       marker->colors.push_back( color );
00332       marker->colors.push_back( color );
00333 
00334       // Show start and end point
00335       publishSphere(point_a, color2);
00336       publishSphere(point_b, color2);
00337     }
00338 
00339     // Interpolate the line ----------------------------------------------------------------------
00340     color.g = 0.0;
00341 
00342     // Calculate slope between the lines
00343     double m = (point_b.y - point_a.y)/(point_b.x - point_a.x);
00344 
00345     // Calculate the y-intercep
00346     double b = point_a.y - m * point_a.x;
00347 
00348     // Define the interpolation interval
00349     double interval = 0.25; //0.5;
00350 
00351     // Make new locations
00352     geometry_msgs::Point temp_a = point_a; // remember the last point
00353     geometry_msgs::Point temp_b = point_a; // move along this point
00354 
00355     // Loop through the line adding segements along the cost map
00356     for( temp_b.x = point_a.x + interval; temp_b.x < point_b.x; temp_b.x += interval )
00357     {
00358       publishSphere(temp_a, color2);
00359 
00360       // Find the y coordinate
00361       temp_b.y = m*temp_b.x + b;
00362 
00363       // Add the new heights
00364       temp_a.z = getCostHeight(temp_a, cost);
00365       temp_b.z = getCostHeight(temp_b, cost);
00366 
00367       // Add the point pair to the line message
00368       marker->points.push_back( temp_a );
00369       marker->points.push_back( temp_b );
00370 
00371       // Add colors
00372       marker->colors.push_back( color );
00373       marker->colors.push_back( color );
00374 
00375       // Remember the last coordiante for next iteration
00376       temp_a = temp_b;
00377     }
00378 
00379     // Finish the line for non-even interval lengths
00380     marker->points.push_back( temp_a );
00381     marker->points.push_back( point_b );
00382 
00383     // Add colors
00384     marker->colors.push_back( color );
00385     marker->colors.push_back( color );
00386 
00387   }
00388 
00389   // *********************************************************************************************************
00390   // Display Explored Space
00391   // *********************************************************************************************************
00392   void displayGraph(bnu::matrix<int> &cost, ob::PlannerDataPtr planner_data)
00393   {
00394     visualization_msgs::Marker marker;
00395     // Set the frame ID and timestamp.  See the TF tutorials for information on these.
00396     marker.header.frame_id = BASE_FRAME;
00397     marker.header.stamp = ros::Time();
00398 
00399     // Set the namespace and id for this marker.  This serves to create a unique ID
00400     marker.ns = "space_exploration";
00401 
00402     // Set the marker type.
00403     marker.type = visualization_msgs::Marker::LINE_LIST;
00404 
00405     // Set the marker action.  Options are ADD and DELETE
00406     marker.action = visualization_msgs::Marker::ADD;
00407     marker.id = 0;
00408 
00409     marker.pose.position.x = 0.0;
00410     marker.pose.position.y = 0.0;
00411     marker.pose.position.z = 0.0;
00412 
00413     marker.pose.orientation.x = 0.0;
00414     marker.pose.orientation.y = 0.0;
00415     marker.pose.orientation.z = 0.0;
00416     marker.pose.orientation.w = 1.0;
00417 
00418     marker.scale.x = 0.2;
00419     marker.scale.y = 1.0;
00420     marker.scale.z = 1.0;
00421 
00422     marker.color.r = 1.0;
00423     marker.color.g = 0.0;
00424     marker.color.b = 0.0;
00425     marker.color.a = 1.0;
00426 
00427     std::pair<double, double> this_vertex;
00428     std::pair<double, double> next_vertex;
00429 
00430     // Make line color
00431     std_msgs::ColorRGBA color;
00432     color.r = 0.0;
00433     color.g = 0.0;
00434     color.b = 1.0;
00435     color.a = 1.0;
00436 
00437     ROS_INFO("Publishing Graph");
00438 
00439 
00440     // TEMP
00441     geometry_msgs::Point p1;
00442     p1.x = 0;
00443     p1.y = 0;
00444     geometry_msgs::Point p2;
00445     p2.x = 6;
00446     p2.y = 0;
00447     interpolateLine( p1, p2, &marker, color, cost );
00448 
00449     /*
00450     // Loop through all verticies
00451     for( int vertex_id = 0; vertex_id < int( planner_data->numVertices() ); ++vertex_id )
00452     {
00453 
00454       this_vertex = getCoordinates( vertex_id, planner_data );
00455 
00456       // Get the out edges from the current vertex
00457       std::vector<unsigned int> edge_list;
00458       planner_data->getEdges( vertex_id, edge_list );
00459 
00460       // Now loop through each edge
00461       for( std::vector<unsigned int>::const_iterator edge_it = edge_list.begin();
00462            edge_it != edge_list.end(); ++edge_it)
00463       {
00464         // Convert vertex id to next coordinates
00465         next_vertex = getCoordinates( *edge_it, planner_data );
00466 
00467         interpolateLine( this_vertex.first, this_vertex.second, next_vertex.first, next_vertex.second, &marker, &color, cost );
00468       }
00469 
00470     }
00471     */
00472 
00473     // Publish the marker
00474     marker_pub_.publish( marker );
00475   }
00476 
00477   // *********************************************************************************************************
00478   // Display Sample Points
00479   // *********************************************************************************************************
00480   void displaySamples(bnu::matrix<int> &cost, ob::PlannerDataPtr planner_data)
00481   {
00482     visualization_msgs::Marker marker;
00483     // Set the frame ID and timestamp.
00484     marker.header.frame_id = BASE_FRAME;
00485     marker.header.stamp = ros::Time();
00486 
00487     // Set the namespace and id for this marker.  This serves to create a unique ID
00488     marker.ns = "sample_locations";
00489 
00490     // Set the marker type.
00491     marker.type = visualization_msgs::Marker::SPHERE_LIST;
00492 
00493     // Set the marker action.  Options are ADD and DELETE
00494     marker.action = visualization_msgs::Marker::ADD;
00495     marker.id = 0;
00496 
00497     marker.pose.position.x = 1.0;
00498     marker.pose.position.y = 1.0;
00499     marker.pose.position.z = 1.0;
00500 
00501     marker.pose.orientation.x = 0.0;
00502     marker.pose.orientation.y = 0.0;
00503     marker.pose.orientation.z = 0.0;
00504     marker.pose.orientation.w = 1.0;
00505 
00506     marker.scale.x = 0.4;
00507     marker.scale.y = 0.4;
00508     marker.scale.z = 0.4;
00509 
00510     marker.color.r = 1.0;
00511     marker.color.g = 0.0;
00512     marker.color.b = 0.0;
00513     marker.color.a = 1.0;
00514 
00515     std::pair<double, double> this_vertex;
00516 
00517     // Make line color
00518     std_msgs::ColorRGBA color;
00519     color.r = 0.8;
00520     color.g = 0.1;
00521     color.b = 0.1;
00522     color.a = 1.0;
00523 
00524     // Point
00525     geometry_msgs::Point point_a;
00526 
00527     ROS_INFO("Publishing Spheres");
00528 
00529     // Loop through all verticies
00530     for( int vertex_id = 0; vertex_id < int( planner_data->numVertices() ); ++vertex_id )
00531     {
00532 
00533       this_vertex = getCoordinates( vertex_id, planner_data );
00534 
00535       // First point
00536       point_a.x = this_vertex.first;
00537       point_a.y = this_vertex.second;
00538       point_a.z = getCostHeight(point_a, cost); 
00539 
00540       // Add the point pair to the line message
00541       marker.points.push_back( point_a );
00542       marker.colors.push_back( color );
00543     }
00544 
00545     // Publish the marker
00546     marker_pub_.publish( marker );
00547   }
00548 
00549   void publishSphere(const geometry_msgs::Point &point, const std_msgs::ColorRGBA &color)
00550   {
00551     visualization_msgs::Marker sphere_marker;
00552 
00553     sphere_marker.header.frame_id = BASE_FRAME;
00554 
00555     // Set the namespace and id for this marker.  This serves to create a unique ID
00556     sphere_marker.ns = "Sphere";
00557     // Set the marker type.
00558     sphere_marker.type = visualization_msgs::Marker::SPHERE_LIST;
00559     // Set the marker action.  Options are ADD and DELETE
00560     sphere_marker.action = visualization_msgs::Marker::ADD;
00561     // Marker group position and orientation
00562     sphere_marker.pose.position.x = 0;
00563     sphere_marker.pose.position.y = 0;
00564     sphere_marker.pose.position.z = 0;
00565     sphere_marker.pose.orientation.x = 0.0;
00566     sphere_marker.pose.orientation.y = 0.0;
00567     sphere_marker.pose.orientation.z = 0.0;
00568     sphere_marker.pose.orientation.w = 1.0;
00569 
00570     // Add the point pair to the line message
00571     sphere_marker.points.push_back( point );
00572     sphere_marker.colors.push_back( color );
00573     // Lifetime
00574     //sphere_marker.lifetime = ros
00575 
00576     // Set the frame ID and timestamp.  See the TF tutorials for information on these.
00577     sphere_marker.header.stamp = ros::Time::now();
00578 
00579     static int sphere_id_ = 0;
00580     sphere_marker.id = ++sphere_id_;
00581     sphere_marker.color = color;
00582     sphere_marker.scale.x = 0.3;
00583     sphere_marker.scale.y = 0.3;
00584     sphere_marker.scale.z = 0.3;
00585 
00586     // Update the single point with new pose
00587     sphere_marker.points[0] = point;
00588     sphere_marker.colors[0] = color;
00589 
00590     // Publish
00591     marker_pub_.publish( sphere_marker );
00592     ros::spinOnce();
00593   }
00594 
00595   
00596   // *********************************************************************************************************
00597   // Display Result Path
00598   // *********************************************************************************************************
00599   void displayResult( og::PathGeometric& path, std_msgs::ColorRGBA* color, bnu::matrix<int> &cost )
00600   {
00601     const std::vector<std::pair<double, double> > coordinates = convertSolutionToVector(path);
00602 
00603     visualization_msgs::Marker marker;
00604     // Set the frame ID and timestamp.
00605     marker.header.frame_id = BASE_FRAME;
00606     marker.header.stamp = ros::Time();
00607 
00608     // Set the namespace and id for this marker.  This serves to create a unique ID
00609     marker.ns = "result_path";
00610 
00611     // Set the marker type.
00612     marker.type = visualization_msgs::Marker::LINE_LIST;
00613 
00614     // Set the marker action.  Options are ADD and DELETE
00615     marker.action = visualization_msgs::Marker::ADD;
00616 
00617     // Provide a new id every call to this function
00618     static int result_id = 0;
00619     marker.id = result_id++;
00620 
00621     marker.pose.position.x = 1.0;
00622     marker.pose.position.y = 1.0;
00623     marker.pose.position.z = 1.0;
00624 
00625     marker.pose.orientation.x = 0.0;
00626     marker.pose.orientation.y = 0.0;
00627     marker.pose.orientation.z = 0.0;
00628     marker.pose.orientation.w = 1.0;
00629 
00630     marker.scale.x = 0.4;
00631     marker.scale.y = 1.0;
00632     marker.scale.z = 1.0;
00633 
00634     marker.color.r = 1.0;
00635     marker.color.g = 0.0;
00636     marker.color.b = 0.0;
00637     marker.color.a = 1.0;
00638 
00639     ROS_INFO("Publishing result");
00640 
00641     // Get the initial points
00642     double x1 = coordinates[0].first;
00643     double y1 = coordinates[0].second;
00644     // Declare the second points
00645     double x2;
00646     double y2;
00647 
00648     // Convert path coordinates to red line
00649     for( unsigned int i = 1; i < coordinates.size(); ++i )
00650     {
00651       x2 = coordinates[i].first;
00652       y2 = coordinates[i].second;
00653 
00654       // Points
00655       geometry_msgs::Point point_a;
00656       geometry_msgs::Point point_b;
00657 
00658       // First point
00659       point_a.x = x1;
00660       point_a.y = y1;
00661       point_a.z = getCostHeight(point_a, cost); 
00662 
00663       // Create a second point
00664       point_b.x = x2;
00665       point_b.y = y2;
00666       point_b.z = getCostHeight(point_b, cost);
00667 
00668       // Add the point pair to the line message
00669       marker.points.push_back( point_a );
00670       marker.points.push_back( point_b );
00671       marker.colors.push_back( *color );
00672       marker.colors.push_back( *color );
00673 
00674       // Save these coordinates for next line
00675       x1 = x2;
00676       y1 = y2;
00677     }
00678 
00679     // Publish the marker
00680     marker_pub_.publish( marker );
00681   }
00682 
00683   // *********************************************************************************************************
00684   // Helper Function: gets the x,y coordinates for a given vertex id
00685   // *********************************************************************************************************
00686   std::pair<double, double> getCoordinates( int vertex_id, ob::PlannerDataPtr planner_data )
00687   {
00688     ob::PlannerDataVertex vertex = planner_data->getVertex( vertex_id );
00689 
00690     // Get this vertex's coordinates
00691     const ob::State *state = vertex.getState();
00692 
00693     if (!state)
00694     {
00695       ROS_ERROR("No state found for a vertex");
00696       exit(1);
00697     }
00698 
00699     // Convert to RealVectorStateSpace
00700     const ob::RealVectorStateSpace::StateType *real_state =
00701       static_cast<const ob::RealVectorStateSpace::StateType*>(state);
00702 
00703     return std::pair<double, double>( real_state->values[0], real_state->values[1] );
00704   }
00705   
00706 
00707 }; // end class
00708 
00709 typedef boost::shared_ptr<OmplRvizViewer> OmplRvizViewerPtr;
00710 typedef boost::shared_ptr<const OmplRvizViewer> OmplRvizViewerConstPtr;
00711 
00712 } // end namespace


ompl_rviz_viewer
Author(s): Dave Coleman
autogenerated on Thu Jul 17 2014 18:58:04