trianglemesh_display.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Robot Operating System code by the University of Osnabrück
5  * Copyright (c) 2015, University of Osnabrück
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  *
21  * 3. Neither the name of the copyright holder nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
30  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
33  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *
38  *
39  *
40  * trianglemesh_display.cpp
41  *
42  *
43  * authors:
44  *
45  * Sebastian Pütz <spuetz@uni-osnabrueck.de>
46  * Henning Deeken <hdeeken@uni-osnabrueck.de>
47  * Marcel Mrozinski
48  * Nils Oesting
49  */
50 
51 #include <OGRE/OgreSceneNode.h>
52 #include <OGRE/OgreSceneManager.h>
53 
54 #include <tf/transform_listener.h>
55 
57 #include <rviz/frame_manager.h>
58 #include <rviz/display_context.h>
65 
66 #include "trianglemesh_display.h"
67 
68 #include <boost/random/mersenne_twister.hpp>
69 #include <boost/random/uniform_int.hpp>
70 #include <boost/random/variate_generator.hpp>
71 
72 #include <ros/callback_queue.h>
73 
74 namespace rviz_mesh_plugin
75 {
76 
78 
80 {
82  m_tfMeshFilter = 0;
83  m_meshCounter = 0;
84 
85  // topic properties
87  "Topic",
88  "",
89  QString::fromStdString(ros::message_traits::datatype<mesh_msgs::TriangleMeshStamped>()),
90  "Mesh topic to subscribe to.",
91  this,
92  SLOT(updateTopic())
93  );
94 
95  // mesh buffer size property
97  "Mesh Buffer Size",
98  1,
99  "Number of prior meshes to display.",
100  this,
101  SLOT(updateMeshBufferSize())
102  );
104 
105  // Display type selection dropdown
106  m_displayType = new rviz::EnumProperty("Display Type",
107  "Fixed Color",
108  "Select Display Type for Mesh",
109  this,
110  SLOT(updateMesh()),
111  this
112  );
113  m_displayType->addOption("Fixed Color", 0);
114  m_displayType->addOption("Vertex Color", 1);
115  m_displayType->addOption("Textures", 2);
116  m_displayType->addOption("Hide Faces", 3);
117 
118  // face color properties
120  "Faces Color",
121  QColor(0, 255, 0),
122  "The color of the faces.",
124  SLOT(updateMesh()),
125  this
126  );
127 
128  // face alpha properties
130  "Faces Alpha",
131  1.0,
132  "The alpha-value of the faces",
134  SLOT(updateMesh()),
135  this
136  );
137  m_facesAlpha->setMin(0);
138  m_facesAlpha->setMax(1);
139 
140 
142  "Show Wireframe",
143  true,
144  "Show Wireframe",
145  this,
146  SLOT(updateMesh()),
147  this
148  );
149 
150  // wireframe color property
152  "Wireframe Color",
153  QColor(0, 0, 0),
154  "The color of the wireframe.",
156  SLOT(updateMesh()),
157  this
158  );
159 
160  // wireframe alpha property
162  "Wireframe Alpha",
163  1.0,
164  "The alpha-value of the wireframe",
166  SLOT(updateMesh()),
167  this
168  );
171 
173  "Show Normals",
174  true,
175  "Show Normals",
176  this,
177  SLOT(updateMesh()),
178  this
179  );
180 
182  "Normals Color",
183  QColor(255, 0, 255),
184  "The color of the normals.",
186  SLOT(updateMesh()),
187  this
188  );
189 
191  "Normals Alpha",
192  1.0,
193  "The alpha-value of the normals",
195  SLOT(updateMesh()),
196  this
197  );
200 
202  "Normals Scaling Factor",
203  0.1,
204  "Scaling factor of the normals",
206  SLOT(updateMesh()),
207  this
208  );
209 }
210 
211 
213 {
214  unsubscribe();
215  delete m_tfMeshFilter;
216 }
217 
219 {
221  *rviz::Display::context_->getTF2BufferPtr(),
222  rviz::Display::fixed_frame_.toStdString(),
223  1,
225  );
226 
228 
230 
231  m_synchronizer = 0;
232 
234  updateTopic();
235  updateMesh();
236 }
237 
239 {
240  rviz::Display::reset(); // TODO bad hack?!
242  m_messagesReceived = 0;
243  m_meshVisuals.clear();
244 }
245 
247 {
248  unsubscribe();
249  reset();
250  subscribe();
252 }
253 
255 {
256  if (!isEnabled()){
257  return;
258  }
259 
260  try {
262  setStatus(rviz::StatusProperty::Ok, "Topic", "OK");
263  }
264  catch (ros::Exception& e)
265  {
266  setStatus(rviz::StatusProperty::Error, "Topic", QString("Error subscribing: ") + e.what());
267  }
268 
269  // Nothing
270  if (m_meshTopic->getTopicStd().empty())
271  {
273  return;
274  }
275 
276  else
277  {
278  // Geometry & Texture & PointNormals
280 
282  m_meshSubscriber, 10
283  );
284 
286  boost::bind(&TriangleMeshDisplay::incomingMessage, this, _1)
287  );
288  }
289 }
290 
292 {
294 
295  if (m_synchronizer)
296  {
297  delete m_synchronizer;
298  m_synchronizer = 0;
299  }
300 }
301 
303 {
304  subscribe();
305 }
306 
308 {
309  unsubscribe();
310  reset();
311 }
312 
314 {
316  reset();
317 }
318 
319 void TriangleMeshDisplay::incomingMessage(const mesh_msgs::TriangleMeshStamped::ConstPtr& meshMsg)
320 {
322  setStatus(rviz::StatusProperty::Ok, "Topic", QString::number(m_messagesReceived) + " messages received");
323  processMessage(meshMsg);
324 }
325 
327 {
328  reset();
329  m_meshVisuals.rset_capacity(m_meshBufferSize->getInt());
330 }
331 
333 {
334 
335  bool showWireframe = m_showWireframe->getBool();
336  bool showNormals = m_showNormals->getBool();
337  bool showFaces = false;
338  bool showTextures = false;
339  bool useVertexColors = false;
340 
341  switch (m_displayType->getOptionInt()) {
342  default:
343  case 0: // Faces with fixed color
344  showFaces = true;
345  break;
346  case 1: // Faces with vertex color
347  showFaces = true;
348  useVertexColors = true;
349  break;
350  case 2: // Faces with textures
351  showFaces = true;
352  showTextures = true;
353  break;
354  case 3: // No Faces
355  break;
356  }
357 
358  if (!m_meshVisuals.empty())
359  {
360  for (boost::circular_buffer<boost::shared_ptr<TriangleMeshVisual> >::iterator it = m_meshVisuals.begin();
361  it != m_meshVisuals.end();
362  it++)
363  {
364  it->get()->updateMaterial(
366  showFaces, m_facesColor->getOgreColor(), m_facesAlpha->getFloat(), useVertexColors, false,
367  showTextures,
369  );
370  }
371  }
372 }
373 
374 void TriangleMeshDisplay::processMessage(const mesh_msgs::TriangleMeshStamped::ConstPtr& meshMsg){
375  Ogre::Quaternion orientation;
376  Ogre::Vector3 position;
377 
378  if(!context_->getFrameManager()->getTransform(meshMsg->header.frame_id,
379  meshMsg->header.stamp,
380  position, orientation)
381  ){
382  ROS_ERROR("Error transforming from frame '%s' to frame '%s'",
383  meshMsg->header.frame_id.c_str(), qPrintable(rviz::Display::fixed_frame_));
384  return;
385  }
386 
388  if (m_meshVisuals.full())
389  {
390  visual = m_meshVisuals.front();
391  m_meshVisuals.push_back(visual);
392  }
393  else
394  {
395  int randomId = (int)((double)rand() / RAND_MAX * 9998);
396 
397  visual.reset(new TriangleMeshVisual(context_, m_displayID, m_meshCounter, randomId));
398 
399  m_meshVisuals.push_back(visual);
400  m_meshCounter++;
401  }
402 
403  visual->setMessage(meshMsg);
404  updateMesh();
405  visual->setFramePosition(position);
406  visual->setFrameOrientation(orientation);
407 }
408 
409 } // end namespace rviz_mesh_plugin
410 
rviz::BoolProperty::getBool
virtual bool getBool() const
rviz::EnumProperty::getOptionInt
virtual int getOptionInt()
rviz::Display::isEnabled
bool isEnabled() const
rviz::IntProperty::setMin
void setMin(int min)
rviz_mesh_plugin::TriangleMeshDisplay::subscribe
void subscribe()
Set the topics to subscribe.
Definition: trianglemesh_display.cpp:254
rviz::RosTopicProperty
rviz_mesh_plugin::TriangleMeshDisplay::m_scalingFactor
rviz::FloatProperty * m_scalingFactor
Property to set the size of the normals.
Definition: trianglemesh_display.h:220
rviz_mesh_plugin::TriangleMeshDisplay::m_meshTopic
rviz::RosTopicProperty * m_meshTopic
Property to handle topic for meshMsg.
Definition: trianglemesh_display.h:196
rviz::DisplayContext::queueRender
virtual void queueRender()=0
tf2_ros::MessageFilter< mesh_msgs::TriangleMeshStamped >
rviz_mesh_plugin::TriangleMeshDisplay::m_normalsAlpha
rviz::FloatProperty * m_normalsAlpha
Property to set the transparency of the normals.
Definition: trianglemesh_display.h:226
boost::shared_ptr
rviz::StatusProperty::Error
Error
trianglemesh_display.h
rviz_mesh_plugin::TriangleMeshDisplay::m_facesAlpha
rviz::FloatProperty * m_facesAlpha
Property to set faces transparency.
Definition: trianglemesh_display.h:211
rviz_mesh_plugin::TriangleMeshDisplay::onInitialize
void onInitialize()
Initialises all nessessary things to get started.
Definition: trianglemesh_display.cpp:218
rviz_mesh_plugin::TriangleMeshDisplay::m_displayID
size_t m_displayID
DisplayID.
Definition: trianglemesh_display.h:193
rviz::Property::show
void show()
rviz::BoolProperty
rviz::FloatProperty::setMax
void setMax(float max)
message_filters::Cache< mesh_msgs::TriangleMeshStamped >
int_property.h
frame_manager.h
rviz_mesh_plugin::TriangleMeshDisplay::updateTopic
void updateTopic()
Updates the subscribed topic.
Definition: trianglemesh_display.cpp:246
rviz_mesh_plugin::TriangleMeshDisplay::onEnable
void onEnable()
Calls subscribe() if display is enabled.
Definition: trianglemesh_display.cpp:302
rviz_mesh_plugin::TriangleMeshDisplay::m_tfMeshFilter
tf2_ros::MessageFilter< mesh_msgs::TriangleMeshStamped > * m_tfMeshFilter
Messagefilter for meshMsg.
Definition: trianglemesh_display.h:178
enum_property.h
rviz_mesh_plugin::TriangleMeshDisplay::m_normalsColor
rviz::ColorProperty * m_normalsColor
Property to set the color of the normals.
Definition: trianglemesh_display.h:223
ros::Exception
rviz_mesh_plugin::TriangleMeshDisplay::m_synchronizer
message_filters::Cache< mesh_msgs::TriangleMeshStamped > * m_synchronizer
Synchronizer for meshMsgs.
Definition: trianglemesh_display.h:181
rviz::Display::fixed_frame_
QString fixed_frame_
rviz_mesh_plugin::TriangleMeshDisplay::reset
void reset()
Clears whole stored data.
Definition: trianglemesh_display.cpp:238
message_filters::Subscriber::unsubscribe
void unsubscribe()
rviz::FloatProperty::setMin
void setMin(float min)
float_property.h
rviz::ColorProperty
visualization_manager.h
rviz_mesh_plugin::TriangleMeshDisplay::updateMeshBufferSize
void updateMeshBufferSize()
Sets capacity of trianglemesh_visual.
Definition: trianglemesh_display.cpp:326
rviz::Display
rviz::EnumProperty
rviz::FloatProperty
rviz_mesh_plugin::TriangleMeshDisplay::incomingMessage
void incomingMessage(const mesh_msgs::TriangleMeshStamped::ConstPtr &meshMsg)
Tests if messages are valid, calls processMessage().
Definition: trianglemesh_display.cpp:319
rviz_mesh_plugin::TriangleMeshDisplay::m_meshSubscriber
message_filters::Subscriber< mesh_msgs::TriangleMeshStamped > m_meshSubscriber
Subscriber for meshMsg.
Definition: trianglemesh_display.h:175
rviz_mesh_plugin::TriangleMeshDisplay::m_meshVisuals
boost::circular_buffer< boost::shared_ptr< TriangleMeshVisual > > m_meshVisuals
Shared pointer to store the created objects of trianglemesh_visual.
Definition: trianglemesh_display.h:187
class_list_macros.h
rviz::Property::hide
void hide()
rviz::Display::setStatus
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
rviz_mesh_plugin::TriangleMeshDisplay::m_displayType
rviz::EnumProperty * m_displayType
Property to select the display type.
Definition: trianglemesh_display.h:229
rviz_mesh_plugin::TriangleMeshDisplay::m_messagesReceived
uint32_t m_messagesReceived
Counter for the received messages.
Definition: trianglemesh_display.h:184
bool_property.h
rviz_mesh_plugin::TriangleMeshDisplay::updateMesh
void updateMesh()
Updates material for each mesh displayed by trianglemesh_visual.
Definition: trianglemesh_display.cpp:332
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
tf2_ros::MessageFilter::clear
void clear()
rviz::FloatProperty::getFloat
virtual float getFloat() const
rviz::EnumProperty::addOption
virtual void addOption(const QString &option, int value=0)
rviz_mesh_plugin::TriangleMeshDisplay::m_meshBufferSize
rviz::IntProperty * m_meshBufferSize
Property to set meshBufferSize.
Definition: trianglemesh_display.h:199
rviz::StatusProperty::Ok
Ok
rviz_mesh_plugin::TriangleMeshDisplay::m_wireframeColor
rviz::ColorProperty * m_wireframeColor
Property to set wireframe color.
Definition: trianglemesh_display.h:202
rviz_mesh_plugin::TriangleMeshVisual
Class to display mesh data in the main panel of rviz.
Definition: trianglemesh_visual.h:81
rviz_mesh_plugin::TriangleMeshDisplay::processMessage
void processMessage(const mesh_msgs::TriangleMeshStamped::ConstPtr &meshMsg)
Sets data for trianglemesh_visual and updates the mesh.
Definition: trianglemesh_display.cpp:374
rviz_mesh_plugin::TriangleMeshDisplay::~TriangleMeshDisplay
~TriangleMeshDisplay()
Destructor.
Definition: trianglemesh_display.cpp:212
rviz_mesh_plugin::TriangleMeshDisplay::m_facesColor
rviz::ColorProperty * m_facesColor
Property to set faces color.
Definition: trianglemesh_display.h:208
message_filters::SimpleFilter::registerCallback
Connection registerCallback(const boost::function< void(P)> &callback)
tf2_ros::MessageFilter::setTargetFrame
void setTargetFrame(const std::string &target_frame)
rviz_mesh_plugin::TriangleMeshDisplay::displayCounter
static size_t displayCounter
Counter for the number of displays.
Definition: trianglemesh_display.h:91
rviz_mesh_plugin::TriangleMeshDisplay::m_showNormals
rviz::BoolProperty * m_showNormals
Property to select the normals.
Definition: trianglemesh_display.h:235
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const=0
rviz::RosTopicProperty::getTopicStd
std::string getTopicStd() const
rviz_mesh_plugin::TriangleMeshDisplay::m_wireframeAlpha
rviz::FloatProperty * m_wireframeAlpha
Property to set wireframe transparency.
Definition: trianglemesh_display.h:205
callback_queue.h
tf2_ros::MessageFilter::connectInput
void connectInput(F &f)
message_filters::Subscriber::subscribe
void subscribe()
transform_listener.h
rviz::FrameManager::getTransform
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
rviz_mesh_plugin
Definition: face_selection_tool.h:117
rviz_mesh_plugin::TriangleMeshDisplay
TriangleMeshDisplay.
Definition: trianglemesh_display.h:86
rviz::Display::context_
DisplayContext * context_
rviz::FrameManager::registerFilterForTransformStatusCheck
void registerFilterForTransformStatusCheck(tf2_ros::MessageFilter< M > *filter, Display *display)
ROS_ERROR
#define ROS_ERROR(...)
rviz::Display::reset
virtual void reset()
rviz::IntProperty::getInt
virtual int getInt() const
rviz_mesh_plugin::TriangleMeshDisplay::onDisable
void onDisable()
Calls unsubscribe() and reset() if display is disabled.
Definition: trianglemesh_display.cpp:307
rviz_mesh_plugin::TriangleMeshDisplay::unsubscribe
void unsubscribe()
Unsubscribes all topics.
Definition: trianglemesh_display.cpp:291
rviz_mesh_plugin::TriangleMeshDisplay::m_meshCounter
size_t m_meshCounter
Counter for the meshes.
Definition: trianglemesh_display.h:190
rviz_mesh_plugin::TriangleMeshDisplay::m_showWireframe
rviz::BoolProperty * m_showWireframe
Property to select the wireframe.
Definition: trianglemesh_display.h:232
color_property.h
rviz::Display::update_nh_
ros::NodeHandle update_nh_
ros_topic_property.h
rviz::ColorProperty::getOgreColor
Ogre::ColourValue getOgreColor() const
rviz_mesh_plugin::TriangleMeshDisplay::fixedFrameChanged
void fixedFrameChanged()
Sets the fixed frame.
Definition: trianglemesh_display.cpp:313
rviz::IntProperty
display_context.h
rviz_mesh_plugin::TriangleMeshDisplay::TriangleMeshDisplay
TriangleMeshDisplay()
Constructor.
Definition: trianglemesh_display.cpp:79


rviz_mesh_plugin
Author(s): Sebastian Pütz , Henning Deeken , Marcel Mrozinski , Kristin Schmidt , Jan Philipp Vogtherr
autogenerated on Fri Feb 12 2021 04:03:57