SampleVisualizer.cpp
Go to the documentation of this file.
1 
19 
20 namespace Visualization {
21 
24  {
25  }
26 
28  {
29  }
30 
32  {
33  // Check, if pointer is valid.
34  if(!pPose)
35  throw std::out_of_range("Invalid pointer: absolute pose of primary scene object.");
36 
37  // Set absolute position of the primary scene object.
38  mParentPose = pPose;
39  }
40 
42  unsigned int& pMarkerId,
43  const std::vector<Eigen::Vector3d>& pSamples)
44  {
45  // Check, if publisher is available.
46  if(!pPublisher)
47  throw std::invalid_argument("Empty ros::publisher cannot be used to publish marker messages.");
48 
49  // ONE MESSAGE TO RULE THEM ALL! Well, kind of.
50  visualization_msgs::MarkerArray array;
51 
52  // Generate trajectory marker message.
53  array.markers.push_back(generateTrajectoryMarker(pMarkerId, pSamples));
54 
55  // Add also an arrow pointing from the parent position to every sample.
56  // Draw only every n-th arrow.
57 // for(unsigned int i = 0; i < pSamples.size(); i += VISUALIZATION_OFFSET)
58 // array.markers.push_back(generateArrowMessage(pMarkerId, mParentPose->getPosition(), pSamples[i]));
59 
60  // Publish the marker array.
61  pPublisher->publish(array);
62  }
63 
65  unsigned int& pMarkerId,
66  const std::vector<Eigen::Vector3d>& pAbsoluteSample,
67  const std::vector<Eigen::Vector3d>& pAbsoluteParentSample)
68  {
69  // Check, if publisher is available.
70  if(!pPublisher)
71  throw std::invalid_argument("Empty ros::publisher cannot be used to publish marker messages.");
72 
73  // Check, if both trajectories are equal in length.
74  if(pAbsoluteSample.size() != pAbsoluteParentSample.size())
75  throw std::invalid_argument("Unequal number of samples and corresponding parent poses.");
76 
77  // ONE MESSAGE TO RULE THEM ALL! Well, kind of.
78  visualization_msgs::MarkerArray array;
79 
80  // Visualize the trajectory as a line strip.
81  array.markers.push_back(generateTrajectoryMarker(pMarkerId, pAbsoluteSample));
82 
83  // Draw every support point of the trajectory as arrow.
84  for(unsigned int i = 0; i < pAbsoluteSample.size(); i += VISUALIZATION_OFFSET)
85  array.markers.push_back(generateArrowMessage(pMarkerId, pAbsoluteParentSample[i], pAbsoluteSample[i]));
86 
87  // Publish the marker array.
88  pPublisher->publish(array);
89  }
90 
91  visualization_msgs::Marker SampleVisualizer::generateTrajectoryMarker(unsigned int& pMarkerId, const std::vector<Eigen::Vector3d>& pSamples)
92  {
93  visualization_msgs::Marker msg;
94 
95  // Set time and frame id.
96  msg.header.stamp = ros::Time::now();
97  msg.header.frame_id = getFrameId();
98 
99  // Namespace will represent the nature of the message.
100  msg.ns = getNamespace();
101 
102  // Every sample has its own id.
103  msg.id = pMarkerId++;
104 
105  // Point is represented by a sphere.
106  msg.type = visualization_msgs::Marker::SPHERE_LIST;
107 
108  // We always want to show a marker by publishing ros messages here.
109  msg.action = visualization_msgs::Marker::ADD;
110 
111  // Iterate over all samples and add them to the visualization marker.
112  for(unsigned int i = 0; i < pSamples.size(); i += VISUALIZATION_OFFSET)
113  {
114  Eigen::Vector3d sample = (mParentPose->point->getEigen() + mParentPose->quat->getEigen().toRotationMatrix() * pSamples[i]) * getScaleFactor();
115 
116  geometry_msgs::Point to;
117  to.x = sample[0];
118  to.y = sample[1];
119  to.z = sample[2];
120  msg.points.push_back(to);
121  }
122 
123  // Shall be very small, but must be scaled, too.
124  msg.scale.x = msg.scale.y = msg.scale.z = 0.005 * getScaleFactor();
125 
126  // Samples should be pitch black :).
127  msg.color.r = msg.color.g = msg.color.b = 0.0;
128  msg.color.a = 0.1;
129 
130  // Return the message containing all samples.
131  return msg;
132  }
133 
134  visualization_msgs::Marker SampleVisualizer::generateArrowMessage(unsigned int& pMarkerId, Eigen::Vector3d pFrom, Eigen::Vector3d pTo)
135  {
136  visualization_msgs::Marker msg;
137 
138  // Set time and frame id.
139  msg.header.stamp = ros::Time::now();
140  msg.header.frame_id = getFrameId();
141 
142  // Scale it to be very small and long.
143  msg.scale.x = 0.002;
144  msg.scale.y = 0.008;
145  msg.scale.z = 0.008;
146 
147  // This should be an arrow.
148  msg.type = visualization_msgs::Marker::ARROW;
149 
150  // Namespace will represent the nature of the message.
151  // Yeah, it's really hard to find comments for every line...
152  msg.ns = getNamespace();
153 
154  // Markers with different namespaces but same id represent same object location distribution with different shapes.
155  msg.id = pMarkerId++;
156 
157  // We always want to show a marker by publishing ros messages here.
158  msg.action = visualization_msgs::Marker::ADD;
159 
160  // Create the starting point.
161  geometry_msgs::Point start;
162  start.x = pFrom[0] * getScaleFactor();
163  start.y = pFrom[1] * getScaleFactor();
164  start.z = pFrom[2] * getScaleFactor();
165  msg.points.push_back(start);
166 
167  // Create the end point.
168  geometry_msgs::Point stop;
169  stop.x = pTo[0] * getScaleFactor();
170  stop.y = pTo[1] * getScaleFactor();
171  stop.z = pTo[2] * getScaleFactor();
172  msg.points.push_back(stop);
173 
174  // Take the second color, it stands for the secondary scene object.
175  msg.color.r = 0.6;
176  msg.color.g = 0.6;
177  msg.color.b = 0.6;
178  msg.color.a = 1.0;
179 
180  // Return the link message message.
181  return msg;
182  }
183 
184 }
visualization_msgs::Marker generateTrajectoryMarker(unsigned int &pMarkerId, const std::vector< Eigen::Vector3d > &pSamples)
static const unsigned int VISUALIZATION_OFFSET
visualization_msgs::Marker generateArrowMessage(unsigned int &pMarkerId, Eigen::Vector3d pFrom, Eigen::Vector3d pTo)
boost::shared_ptr< ISM::Pose > mParentPose
void publishTrajectory(boost::shared_ptr< ros::Publisher > pPublisher, unsigned int &pMarkerId, const std::vector< Eigen::Vector3d > &pSamples)
static Time now()
void setParentPose(boost::shared_ptr< ISM::Pose > pPose)


asr_psm_visualizations
Author(s): Gehrung Joachim, Meißner Pascal
autogenerated on Sat Nov 9 2019 03:49:13