visualization.cpp
Go to the documentation of this file.
2 
4 {
5 namespace msgs
6 {
7 void footToFootMarker(const Foot& foot, const geometry_msgs::Vector3& foot_size, const std_msgs::ColorRGBA& color, visualization_msgs::Marker& marker)
8 {
9  marker.header = foot.header;
10  marker.ns = "vigir_footstep_planning/step_plan";
11  marker.type = visualization_msgs::Marker::CUBE;
12  marker.action = visualization_msgs::Marker::ADD;
13 
14  marker.pose = foot.pose;
15  marker.pose.position.z += 0.5*foot_size.z;
16  marker.scale = foot_size;
17  marker.color = color;
18 
19  marker.lifetime = ros::Duration();
20 }
21 
22 void feetToFootMarkerArray(const Feet& feet, const geometry_msgs::Vector3& foot_size, const std_msgs::ColorRGBA& color, visualization_msgs::MarkerArray& marker_array)
23 {
24  visualization_msgs::Marker marker;
25  marker_array.markers.clear();
26 
27  footToFootMarker(feet.left, foot_size, color, marker);
28  marker_array.markers.push_back(marker);
29  marker.id++;
30 
31  footToFootMarker(feet.right, foot_size, color, marker);
32  marker_array.markers.push_back(marker);
33 }
34 
35 void stepToFootMarker(const Step& step, const geometry_msgs::Vector3& foot_size, const std_msgs::ColorRGBA& color, visualization_msgs::Marker& marker)
36 {
37  footToFootMarker(step.foot, foot_size, color, marker);
38 }
39 
40 void stepPlanToFootMarkerArray(const std::vector<Step>& steps, const geometry_msgs::Vector3& foot_size, visualization_msgs::MarkerArray& marker_array, bool add_step_index)
41 {
42  std_msgs::ColorRGBA color;
43  color.r = 0.0;
44  color.g = 0.0;
45  color.b = 0.0;
46  color.a = 0.6;
47 
48  visualization_msgs::Marker marker;
49 
50  marker_array.markers.clear();
51 
52  for (std::vector<Step>::const_iterator itr = steps.begin(); itr != steps.end(); itr++)
53  {
54  // colorize
55  color.r = itr->foot.foot_index == Foot::LEFT ? 1.0 : 0.0;
56  color.g = itr->foot.foot_index == Foot::LEFT ? 0.0 : 1.0;
57 
58  // transform
59  stepToFootMarker(*itr, foot_size, color, marker);
60  marker_array.markers.push_back(marker);
61  marker.id++;
62 
63  // add text
64  if (add_step_index)
65  {
66  marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
67  marker.action = visualization_msgs::Marker::ADD;
68  marker.text = boost::lexical_cast<std::string>(itr->step_index);
69  marker.scale.z *= 3;
70  marker.color.r = 1.0;
71  marker.color.g = 1.0;
72  marker.color.b = 1.0;
73  marker.color.a = 0.7;
74 
75  marker_array.markers.push_back(marker);
76  marker.id++;
77  }
78  }
79 }
80 
81 void stepPlanToFootMarkerArray(const StepPlan& step_plan, const geometry_msgs::Vector3& foot_size, visualization_msgs::MarkerArray& marker_array, bool add_step_index)
82 {
83  stepPlanToFootMarkerArray(step_plan.steps, foot_size, marker_array, add_step_index);
84 }
85 
86 void feetToUpperBodyMarker(const Feet& feet, const geometry_msgs::Vector3& upper_body_size, const geometry_msgs::Vector3& upper_body_origin_shift, const std_msgs::ColorRGBA& color, visualization_msgs::Marker& marker, bool flat)
87 {
88  marker.header = feet.header;
89  marker.ns = "vigir_footstep_planning/upper_body";
90  marker.type = visualization_msgs::Marker::CUBE;
91  marker.action = visualization_msgs::Marker::ADD;
92 
93  // approximate upper body position
94  marker.pose.position.x = 0.5 * (feet.left.pose.position.x + feet.right.pose.position.x);
95  marker.pose.position.y = 0.5 * (feet.left.pose.position.y + feet.right.pose.position.y);
96  marker.pose.position.z = 0.5 * (feet.left.pose.position.z + feet.right.pose.position.z);
97  marker.pose.orientation = tf::createQuaternionMsgFromYaw(0.5 * (tf::getYaw(feet.left.pose.orientation) + tf::getYaw(feet.right.pose.orientation)));
98 
99  // determine shift of polygon based on orientation
100  tf::Transform transform;
101  tf::poseMsgToTF(marker.pose, transform);
102  tf::Vector3 shifted;
103  tf::vector3MsgToTF(upper_body_origin_shift, shifted);
104  shifted = transform * shifted;
105 
106  marker.pose.position.x = shifted.getX();
107  marker.pose.position.y = shifted.getY();
108  marker.pose.position.z = shifted.getZ();
109 
110  // finalize marker
111  marker.pose.position.z += flat ? 0.01 : 0.5*upper_body_size.z;
112  marker.scale = upper_body_size;
113  if (flat)
114  marker.scale.z = 0.02;
115  marker.color = color;
116 
117  marker.lifetime = ros::Duration();
118 }
119 
120 void stepPlanToUpperBodyMarkerArray(const std::vector<Step>& steps, const geometry_msgs::Vector3& upper_body_size, const geometry_msgs::Vector3& upper_body_origin_shift, visualization_msgs::MarkerArray& marker_array, bool add_step_index)
121 {
122  std_msgs::ColorRGBA color;
123  color.r = 0.0;
124  color.g = 0.0;
125  color.b = 0.4;
126  color.a = 0.2;
127 
128  visualization_msgs::Marker marker;
129 
130  marker_array.markers.clear();
131 
132  Feet feet;
133  for (std::vector<Step>::const_iterator itr = steps.begin(); itr != steps.end(); itr++)
134  {
135  const Step& step = *itr;
136  if (step.foot.foot_index == Foot::LEFT)
137  feet.left = step.foot;
138  else
139  feet.right = step.foot;
140 
141  if (itr == steps.begin())
142  {
143  feet.header = step.header;
144  continue;
145  }
146 
147  // transform
148  feetToUpperBodyMarker(feet, upper_body_size, upper_body_origin_shift, color, marker);
149  marker_array.markers.push_back(marker);
150  marker.id++;
151 
152  // add text
153  if (add_step_index)
154  {
155  marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
156  marker.action = visualization_msgs::Marker::ADD;
157  marker.text = boost::lexical_cast<std::string>(itr->step_index);
158  marker.scale.z *= 0.1;
159  marker.color.r = 1.0;
160  marker.color.g = 1.0;
161  marker.color.b = 1.0;
162  marker.color.a = 0.7;
163 
164  marker_array.markers.push_back(marker);
165  marker.id++;
166  }
167  }
168 }
169 
170 void stepPlanToUpperBodyMarkerArray(const StepPlan& step_plan, const geometry_msgs::Vector3& upper_body_size, const geometry_msgs::Vector3& upper_body_origin_shift, visualization_msgs::MarkerArray& marker_array, bool add_step_index)
171 {
172  stepPlanToUpperBodyMarkerArray(step_plan.steps, upper_body_size, upper_body_origin_shift, marker_array, add_step_index);
173 }
174 
175 void stepPlanToPath(const StepPlan& step_plan, nav_msgs::Path& path)
176 {
177  path.poses.clear();
178 
179  path.header = step_plan.header;
180  for (std::vector<Step>::const_iterator itr = step_plan.steps.begin(); itr != step_plan.steps.end(); itr++)
181  {
182  geometry_msgs::PoseStamped pose;
183  pose.header = step_plan.header;
184  pose.pose = itr->foot.pose;
185  path.poses.push_back(pose);
186  }
187 }
188 }
189 }
static void poseMsgToTF(const geometry_msgs::Pose &msg, Pose &bt)
void footToFootMarker(const Foot &foot, const geometry_msgs::Vector3 &foot_size, const std_msgs::ColorRGBA &color, visualization_msgs::Marker &marker)
void stepToFootMarker(const Step &step, const geometry_msgs::Vector3 &foot_size, const std_msgs::ColorRGBA &color, visualization_msgs::Marker &marker)
void feetToUpperBodyMarker(const Feet &feet, const geometry_msgs::Vector3 &upper_body_size, const geometry_msgs::Vector3 &upper_body_origin_shift, const std_msgs::ColorRGBA &color, visualization_msgs::Marker &marker, bool flat=false)
std::map< unsigned int, msgs::Step > steps
Definition: step_plan.h:212
static double getYaw(const Quaternion &bt_q)
void stepPlanToUpperBodyMarkerArray(const std::vector< Step > &steps, const geometry_msgs::Vector3 &upper_body_size, const geometry_msgs::Vector3 &upper_body_origin_shift, visualization_msgs::MarkerArray &marker_array, bool add_step_index=true)
TFSIMD_FORCE_INLINE const tfScalar & x() const
void stepPlanToFootMarkerArray(const std::vector< Step > &steps, const geometry_msgs::Vector3 &foot_size, visualization_msgs::MarkerArray &marker_array, bool add_step_index=true)
static void vector3MsgToTF(const geometry_msgs::Vector3 &msg_v, Vector3 &bt_v)
unsigned int step
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
void stepPlanToPath(const StepPlan &step_plan, nav_msgs::Path &path)
void feetToFootMarkerArray(const Feet &feet, const geometry_msgs::Vector3 &foot_size, const std_msgs::ColorRGBA &color, visualization_msgs::MarkerArray &marker_array)


vigir_footstep_planning_msgs
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:45:25