plan_visualization.cpp
Go to the documentation of this file.
00001 /*
00002 * Software License Agreement (BSD License)
00003 *Copyright (c) 2015, micROS Team
00004  http://micros.nudt.edu.cn/
00005 *All rights reserved.
00006 * Copyright (c) 2009, Willow Garage, Inc.
00007 * All rights reserved.
00008 *
00009 * Redistribution and use in source and binary forms, with or without
00010 * modification, are permitted provided that the following conditions
00011 * are met:
00012 *
00013 * * Redistributions of source code must retain the above copyright
00014 * notice, this list of conditions and the following disclaimer.
00015 * * Redistributions in binary form must reproduce the above
00016 * copyright notice, this list of conditions and the following
00017 * disclaimer in the documentation and/or other materials provided
00018 * with the distribution.
00019 * * Neither the name of Willow Garage, Inc. nor the names of its
00020 * contributors may be used to endorse or promote products derived
00021 * from this software without specific prior written permission.
00022 *
00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034 * POSSIBILITY OF SUCH DAMAGE.
00035 */
00036 #include "plan_visualization.h"
00037 
00038 //parameter for the map reducing ratio
00039 float AltitudeZoom=3.0;
00040 
00041 //--------------------------------------------
00042 ros::Publisher Marker_Publisher;                
00043 visualization_msgs::Marker Tail;                //path
00044 visualization_msgs::Marker Terrain;             //terrian(ID=999)
00045 visualization_msgs::Marker TerrainLine;         //terrianline(ID=998)
00046 //--------------------------------------------
00047 
00048 //initialize the publisher
00049 void InitMarkerPublisher()
00050 {
00051         ros::NodeHandle n;
00052         Marker_Publisher = n.advertise<visualization_msgs::Marker>("visualization_marker", 1000);
00053 }
00054 
00055 //chooss the color based on the ID
00056 void GetStoreColor(int ID,float& r,float& g,float& b)
00057 {
00058         switch (ID)
00059         {
00060                 case 1: r=1.0; g=0.0; b=0.0;    break;
00061                 case 2: r=0.0; g=0.0; b=1.0;    break;
00062                 case 3: r=0.0; g=1.0; b=1.0;    break;
00063                 case 4: r=1.0; g=1.0; b=0.0;    break;
00064                 case 5: r=1.0; g=0.0; b=1.0;    break;
00065                 default:r=1.0; g=1.0; b=1.0;    break;
00066         }
00067 }
00068 
00069 //intialize the marker
00070 void UInitMarker(visualization_msgs::Marker& marker)
00071 {
00072         marker.header.frame_id = "/my_frame";
00073         marker.header.stamp = ros::Time::now();
00074         marker.ns = "HopField_client";
00075         marker.action = visualization_msgs::Marker::ADD;
00076         marker.pose.orientation.w = 1.0;
00077         marker.scale.x =1;
00078         marker.scale.y =1;
00079         marker.scale.z = 1.0;
00080         marker.color.r=1.0;
00081         marker.color.g=1.0;
00082         marker.color.b=1.0;
00083         marker.color.a=1.0;
00084 }
00085 
00086 //draw the cylinder
00087 void Draw_Cylinder(int ID,float x,float y,float z,float Rad,float Height,float r,float g,float b,float a)
00088 {
00089         visualization_msgs::Marker cylinder;
00090         UInitMarker(cylinder);
00091 
00092         cylinder.id = ID;
00093         cylinder.type = visualization_msgs::Marker::CYLINDER;
00094         
00095         cylinder.pose.position.x = x;
00096         cylinder.pose.position.y = y;
00097         cylinder.pose.position.z = z;
00098         
00099         cylinder.scale.x =2*Rad;
00100         cylinder.scale.y =2*Rad;
00101         cylinder.scale.z =Height;
00102 
00103         cylinder.color.r = r;
00104         cylinder.color.g = g;
00105         cylinder.color.b = b;
00106         cylinder.color.a = a;
00107 
00108         // Publish the marker
00109         for (int i=0;i<2;i++)
00110         {
00111                 Marker_Publisher.publish(cylinder);
00112                 ros::Rate loop_rate(5);
00113                 loop_rate.sleep();
00114         }
00115 }
00116 
00117 //draw the ball
00118 void Draw_Sphere(int ID,float x,float y,float z,float Rad,float r,float g,float b,float a)
00119 {
00120         visualization_msgs::Marker sphere;
00121         UInitMarker(sphere);
00122   
00123         sphere.id = ID;
00124         sphere.type = visualization_msgs::Marker::SPHERE;
00125          
00126         sphere.pose.position.x = x;
00127         sphere.pose.position.y = y;
00128         sphere.pose.position.z = z*AltitudeZoom;
00129  
00130         sphere.scale.x =2*Rad;
00131         sphere.scale.y =2*Rad;
00132         sphere.scale.z =2*Rad;
00133 
00134         // Set the color -- be sure to set alpha to something non-zero!
00135         sphere.color.r = r;
00136         sphere.color.g = g;
00137         sphere.color.b = b;
00138         sphere.color.a = a;
00139 
00140         // Publish the marker
00141         Marker_Publisher.publish(sphere);
00142 }
00143 
00144 //initialize the path
00145 void InitTail(int ID,float r,float g,float b,float a)
00146 {
00147         UInitMarker(Tail);
00148 
00149         Tail.id = ID;
00150         Tail.type = visualization_msgs::Marker::LINE_STRIP;
00151 
00152         Tail.scale.x=2;
00153 
00154         Tail.color.r = r;
00155         Tail.color.g = g;
00156         Tail.color.b = b;
00157         Tail.color.a = a;
00158 }
00159 
00160 //update the path
00161 void AddTailPoint(float x,float y,float z)
00162 {
00163         geometry_msgs::Point p;
00164         p.x = x;
00165         p.y = y;
00166         p.z = z*AltitudeZoom;
00167 
00168         Tail.points.push_back(p);
00169         Marker_Publisher.publish(Tail);
00170 }
00171 
00172 //clean the path
00173 void ResetTail()
00174 {
00175         Tail.points.clear();
00176 }
00177 
00178 
00179 #define TERRAIN_PUSH_POINT(i,j) {p.x=(j)*space;p.y=(i)*space;p.z=max(0,TerrainMap[(i)*space*Width+(j)*space]*AltitudeZoom/90);Terrain.points.push_back(p);}
00180 #define TERRAINLINE_PUSH_POINT(i,j) {p.x=(j)*space;p.y=(i)*space;p.z=max(0,TerrainMap[(i)*space*Width+(j)*space]*AltitudeZoom/90+1);TerrainLine.points.push_back(p);}
00181 
00182 //draw the terrian
00183 void DrawTerrain(int Width,int Height,int space,short* TerrainMap)
00184 {
00185         if (TerrainMap==NULL) return;
00186 
00187         UInitMarker(Terrain);
00188         UInitMarker(TerrainLine);
00189 
00190         Terrain.id = 999;
00191         Terrain.type = visualization_msgs::Marker::TRIANGLE_LIST;
00192         TerrainLine.id = 998;
00193         TerrainLine.type = visualization_msgs::Marker::LINE_LIST;
00194 
00195         int w=Width/space;
00196         int h=Height/space;
00197 
00198         if ((w==0)||(h==0)) return;  
00199 
00200          // Set the pose of the marker.  This is a full 6DOF pose relative to the frame/time specified in the header
00201         geometry_msgs::Point p;
00202         for (int i=0;i<h-1;i++)
00203         {
00204                 for (int j=0;j<w-1;j++)
00205                 {
00206                         TERRAIN_PUSH_POINT(i ,j);
00207                         TERRAIN_PUSH_POINT(i+1,j);
00208                         TERRAIN_PUSH_POINT(i+1,j+1);
00209                         TERRAIN_PUSH_POINT(i ,j);
00210                         TERRAIN_PUSH_POINT(i,j+1);
00211                         TERRAIN_PUSH_POINT(i+1,j+1);
00212 
00213                         TERRAINLINE_PUSH_POINT(i ,j);
00214                         TERRAINLINE_PUSH_POINT(i+1,j);
00215                         TERRAINLINE_PUSH_POINT(i ,j);
00216                         TERRAINLINE_PUSH_POINT(i,j+1);
00217                 }
00218         }
00219 
00220         Terrain.color.r = 0.0f;
00221         Terrain.color.b = 0.0f;
00222         Terrain.color.a = 0.5f;
00223 
00224         ros::Rate loop_rate(5);
00225         for (int i=0;i<3;i++)
00226         {
00227                 Marker_Publisher.publish(Terrain);
00228                 loop_rate.sleep();
00229                 Marker_Publisher.publish(TerrainLine);
00230                 loop_rate.sleep();
00231         }
00232 }
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 


micros_hopfield
Author(s): Xiaojia Xiang
autogenerated on Thu Jun 6 2019 21:05:58