ProbabilisticPrimarySceneObjectVisualization.cpp
Go to the documentation of this file.
1 
19 
20 namespace Visualization {
21 
23  : mSceneObject(pName)
24  , mHandle()
25  , mBestHypothesisScore(0.0)
26  {
27  mPublisher.reset(new ros::Publisher(mHandle.advertise<visualization_msgs::MarkerArray>("psm", 1)));
28  }
29 
31  {
32  }
33 
35  {
36  mSceneObjectVisualizers.push_back(pVisualizer);
37  }
38 
39  void ProbabilisticPrimarySceneObjectVisualization::setDrawingParameters(const double pScale, const float pSigmaMultiplicator, const std::string pFrameId)
40  {
41  // Forward parameters to local visualizers.
42  visualizerFrame.setFrameId(pFrameId);
45  visualizerSamples.setFrameId(pFrameId);
47 
48  // Forward parameters to secondary scene objects.
50  visualizer->setDrawingParameters(pScale, pSigmaMultiplicator, pFrameId);
51  }
52 
54  {
55  // Check, if pointer is valid.
56  if(!pPose)
57  throw std::out_of_range("Invalid pointer: absolute pose of primary scene object.");
58 
59  // Set position and orientation.
60  mAbsolutePose = pPose;
61  }
62 
64  {
65  // Check, if pointer is valid.
66  if(!pPose)
67  throw std::out_of_range("Invalid pointer: absolute pose of primary scene object candidate.");
68 
69  // Set position and orientation.
70  mBestCandidatePose = pPose;
71  }
72 
73  void ProbabilisticPrimarySceneObjectVisualization::setLearningSamples(const std::vector<Eigen::Vector3d>& pSamples)
74  {
75  mSamples = pSamples;
76  }
77 
78  void ProbabilisticPrimarySceneObjectVisualization::drawInTargetingMode(const std::string pScene, const std_msgs::ColorRGBA& pColor)
79  {
80  // Stop, if no primary scene object visualizers registered.
81  if(mSceneObjectVisualizers.size() == 0)
82  return;
83 
84  // Only execute when the primary scene object has been found.
85  if(mAbsolutePose)
86  {
87  // Build the namespace.
88  std::string myNamespace = "/" + pScene + "/" + mSceneObject;
89 
90  // The size of a step in the hsv color space.
91  double hsvColorSteps = 1.0 / mSceneObjectVisualizers.size();
92 
93  // Serves as unique id for the marker. Any marker sent with the same id will overwrite the old one.
94  unsigned int markerId = 0;
95 
96  // Draw all secondary scene objects appended to this primary scene in an unique color.
97  for(unsigned int i = 0; i < mSceneObjectVisualizers.size(); i++)
98  {
99  // Create an unique color...
100  std_msgs::ColorRGBA color;
101  color.a = 1.0;
102 
103  // ... by converting an index based postion on the hue axis into RGB
104  ColorHelper::convertHSVToRGB(color, (double) hsvColorSteps * i, 1.0, 1.0);
105 
106  // Set the color of the two rings.
107  mSceneObjectVisualizers[i]->setColors(pColor, color);
108 
109  // Forward namespace to secondary scene object visualizers.
110  mSceneObjectVisualizers[i]->setNamespace(myNamespace);
111 
112  // Visualize the covariance ellipse and the last known object position.
113  mSceneObjectVisualizers[i]->visualizeObjectPositionAsArrow(markerId);
114  mSceneObjectVisualizers[i]->visualizeGaussianKernels(markerId);
115  }
116  }
117  }
118 
119  void ProbabilisticPrimarySceneObjectVisualization::drawInInferenceMode(const std::string pScene, const std_msgs::ColorRGBA& pColor, unsigned int& pMarkerId)
120  {
121  // Stop, if no primary scene object visualizers registered.
122  if(mSceneObjectVisualizers.size() == 0)
123  return;
124 
125  // Only execute when the primary scene object has been found.
126  // DO NOT DRAW FOR BAD RESULTS!
127  if(mBestPose)
128  {
129  // Build the namespace.
130  std::string myNamespace = "/" + pScene + "/" + mSceneObject;
131 
132  // The size of a step in the hsv color space.
133  double hsvColorSteps = 1.0 / mSceneObjectVisualizers.size();
134 
135  // Draw the primary scene object.
136  // Apply some normalization term for the color of the arrows.
137  visualizerFrame.setNamespace(myNamespace);
139 
140  visualizerKinematics.setNamespace("/" + pScene);
141  visualizerKinematics.publishObjectPositionAsPointWithScore(mPublisher, pMarkerId, mBestPose, mBestTermScores, std::min(mBestHypothesisScore / 0.000001, 1.0)); // NOTE The normalization constant here is responsible for coloring the perpendicular object indircator arrow.
142 
143  // Draw all secondary scene objects appended to this primary scene in an unique color.
144  for(unsigned int i = 0; i < mSceneObjectVisualizers.size(); i++)
145  {
146  // Create an unique color...
147  std_msgs::ColorRGBA color;
148  color.a = 1.0;
149 
150  // ... by converting an index based postion on the hue axis into RGB
151  ColorHelper::convertHSVToRGB(color, (double) hsvColorSteps * i, 1.0, 1.0);
152 
153  // Set the color of the two rings.
154  mSceneObjectVisualizers[i]->setColors(pColor, color);
155 
156  // Forward namespace to secondary scene object visualizers.
157  mSceneObjectVisualizers[i]->setNamespace(myNamespace);
158 
159  // Visualize the kinematic chain.
160  mSceneObjectVisualizers[i]->visualizeKinematicChain(pMarkerId);
161  }
162  }
163  }
164 
165  void ProbabilisticPrimarySceneObjectVisualization::drawInLearningMode(const std::string pScene, const std_msgs::ColorRGBA& pColor)
166  {
167  // Stop, if no secondary scene object visualizers registered.
168  if(mSceneObjectVisualizers.size() == 0)
169  return;
170 
171  // Build the namespace.
172  std::string myNamespace = "/" + pScene + "/" + mSceneObject;
173 
174  // The size of a step in the hsv color space.
175  double hsvColorSteps = 1.0 / mSceneObjectVisualizers.size();
176 
177  // Serves as unique id for the marker. Any marker sent with the same id will overwrite the old one.
178  unsigned int markerId = 0;
179 
180  // Draw all secondary scene objects appended to this primary scene in an unique color.
181  for(unsigned int i = 0; i < mSceneObjectVisualizers.size(); i++)
182  {
183  // Create an unique color...
184  std_msgs::ColorRGBA color;
185  color.a = 1.0;
186 
187  // ... by converting an index based postion on the hue axis into RGB
188  ColorHelper::convertHSVToRGB(color, (double) hsvColorSteps * i, 1.0, 1.0);
189 
190  // Set the color of the two rings.
191  mSceneObjectVisualizers[i]->setColors(pColor, color);
192 
193  // Forward namespace to secondary scene object visualizers.
194  mSceneObjectVisualizers[i]->setNamespace(myNamespace);
195 
196  // Visualize the covariance ellipses and the learning data.
197  mSceneObjectVisualizers[i]->visualizeGaussianKernels(markerId);
198  mSceneObjectVisualizers[i]->visualizeRelativeTrajectory(markerId);
199  }
200  }
201 
203  {
204  // Stop, if no secondary scene object visualizers registered.
205  if(mSceneObjectVisualizers.size() == 0)
206  return;
207 
208  // Build the namespace.
209  std::string myNamespace = "/" + pScene + "/" + mSceneObject;
210 
211  // The size of a step in the hsv color space.
212  double hsvColorSteps = 1.0 / mSceneObjectVisualizers.size();
213 
214  // Serves as unique id for the marker. Any marker sent with the same id will overwrite the old one.
215  unsigned int markerId = 0;
216 
217  // Draw all secondary scene objects appended to this primary scene in an unique color.
218  for(unsigned int i = 0; i < mSceneObjectVisualizers.size(); i++)
219  {
220  // Create an unique color...
221  std_msgs::ColorRGBA color;
222  color.a = 1.0;
223 
224  // ... by converting an index based postion on the hue axis into RGB
225  ColorHelper::convertHSVToRGB(color, (double) hsvColorSteps * i, 1.0, 1.0);
226 
227  // Set the color of the two rings.
228  mSceneObjectVisualizers[i]->setColors(color, color);
229 
230  // Forward namespace to secondary scene object visualizers.
231  mSceneObjectVisualizers[i]->setNamespace(myNamespace);
232 
233  // Visualize absolute trajectory.
234  mSceneObjectVisualizers[i]->visualizeAbsoluteTrajectory(markerId);
235  }
236  }
237 
239  {
240  return mSceneObject;
241  }
242 
244  {
245  mTermScores.push_back(pScore / 0.000001); // NOTE The normalization constant here is responsible for coloring the rings around the perpendicular object indircator arrow.
246  }
247 
249  {
250  mTermScores.clear();
251  }
252 
254  {
255  // Better score? Overwrite best pose and term scores!
256  if(pHypothesisScore > mBestHypothesisScore)
257  {
259  mBestHypothesisScore = pHypothesisScore;
260 
261  mBestTermScores.clear();
262  mBestTermScores.insert(mBestTermScores.end(), mTermScores.begin(), mTermScores.end());
263 
264  // Command secondary scene objects to do the same.
265  for(unsigned int i = 0; i < mSceneObjectVisualizers.size(); i++)
266  mSceneObjectVisualizers[i]->overwriteLastBestPose();
267  }
268  }
269 
271  {
272  mBestHypothesisScore /= pNumberOfSlots;
273  }
274 
276  {
277  mBestPose.reset();
278  mBestHypothesisScore = 0.0;
279  }
280 
282  {
284  }
285 
286 }
void publishFrame(boost::shared_ptr< ros::Publisher > pPublisher, unsigned int &pMarkerId, const boost::shared_ptr< ISM::Pose > pPose, double pSize)
void drawInInferenceMode(const std::string pScene, const std_msgs::ColorRGBA &pColor, unsigned int &pMarkerId)
void setNamespace(std::string pNamespace)
void drawInTargetingMode(const std::string pScene, const std_msgs::ColorRGBA &pColor)
void setDrawingParameters(const double pScale, const float pSigmaMultiplicator, const std::string pFrameId)
void publishObjectPositionAsPointWithScore(boost::shared_ptr< ros::Publisher > pPublisher, unsigned int &pMarkerId, const boost::shared_ptr< ISM::Pose > pPose, std::vector< double > pScores, double pQualityOfMatch)
void setFrameId(std::string pFrameId)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void drawInLearningMode(const std::string pScene, const std_msgs::ColorRGBA &pColor)
void appendVisualizer(boost::shared_ptr< ProbabilisticSecondarySceneObjectVisualization > pVisualizer)
std::vector< boost::shared_ptr< ProbabilisticSecondarySceneObjectVisualization > > mSceneObjectVisualizers
static void convertHSVToRGB(std_msgs::ColorRGBA &pColor, double pH, double pS, double pV)
Definition: ColorHelper.cpp:30


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