Go to the documentation of this file.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
00031
00032
00033
00034
00035
00036 #include "plan_visualization.h"
00037
00038
00039 float AltitudeZoom=3.0;
00040
00041
00042 ros::Publisher Marker_Publisher;
00043 visualization_msgs::Marker Tail;
00044 visualization_msgs::Marker Terrain;
00045 visualization_msgs::Marker TerrainLine;
00046
00047
00048
00049 void InitMarkerPublisher()
00050 {
00051 ros::NodeHandle n;
00052 Marker_Publisher = n.advertise<visualization_msgs::Marker>("visualization_marker", 1000);
00053 }
00054
00055
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
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
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
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
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
00135 sphere.color.r = r;
00136 sphere.color.g = g;
00137 sphere.color.b = b;
00138 sphere.color.a = a;
00139
00140
00141 Marker_Publisher.publish(sphere);
00142 }
00143
00144
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
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
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
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
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