Gazebo | Ignition | Community
Ask Your Question

Karandaras's profile - activity

2018-06-15 08:12:56 -0600 received badge  Favorite Question (source)
2015-04-17 02:08:26 -0600 received badge  Famous Question (source)
2014-07-18 01:46:07 -0600 received badge  Good Question (source)
2014-07-18 01:46:02 -0600 received badge  Enlightened (source)
2014-07-18 01:46:02 -0600 received badge  Good Answer (source)
2013-07-03 20:34:06 -0600 received badge  Notable Question (source)
2013-05-15 10:33:07 -0600 received badge  Nice Answer (source)
2013-05-15 10:31:11 -0600 received badge  Nice Question (source)
2013-04-10 14:02:25 -0600 received badge  Self-Learner (source)
2013-04-10 14:02:25 -0600 received badge  Teacher (source)
2013-04-10 14:02:21 -0600 received badge  Student (source)
2013-02-18 03:06:46 -0600 received badge  Popular Question (source)
2013-02-13 10:10:24 -0600 received badge  Famous Question (source)
2013-02-13 10:10:24 -0600 received badge  Popular Question (source)
2013-02-13 10:10:24 -0600 received badge  Notable Question (source)
2013-01-05 04:58:42 -0600 commented answer how to draw lines from a plugin or via messages

I would be glad to hear if my code got used. Keep up the good work with the simulator.

2013-01-05 04:57:52 -0600 received badge  Editor (source)
2012-10-21 07:09:58 -0600 answered a question how to draw lines from a plugin or via messages

Thanks for the answer. I already added a simple way of drawing to the Scene class. It is probably not the best way, but it works for me and allows me to continue my work.

Here is the code I used for that.

Added needed stuff to the Scene header

gazebo/rendering/Scene.hh

/// \brief Subscribe to draw for line drawing
private: transport::SubscriberPtr drawingSub;

/// \brief Drawing callback
/// \param[in] _msg The message data.
private: void OnDrawing(ConstDrawingPtr &_msg);

/// \brief Process a drawing message
/// \param[in] _msg The message data.
private: bool ProcessDrawingMsg(ConstDrawingPtr &_msg);

/// \def DrawingMsgs_L
/// \brief List of drawing messages.
typedef std::list<boost::shared_ptr<msgs::Drawing const> > DrawingMsgs_L;

/// \brief List of drawing message to process.
private: DrawingMsgs_L drawingMsgs;

New functions for the drawing

gazebo/rendering/Scene.cc

/////////////////////////////////////////////////
void Scene::OnDrawing(ConstDrawingPtr &_msg)
{
  boost::mutex::scoped_lock lock(*this->receiveMutex);
  this->drawingMsgs.push_back(_msg);
}

/////////////////////////////////////////////////
bool Scene::ProcessDrawingMsg(ConstDrawingPtr &_msg)
{
  Ogre::SceneNode *sceneNode = NULL;
  Ogre::ManualObject *obj = NULL;
  bool attached = false;

  if (this->manager->hasManualObject(_msg->name()))
  {
    sceneNode = this->manager->getSceneNode(_msg->name());
    obj = this->manager->getManualObject(_msg->name());
    attached = true;
  }
  else
  {
    sceneNode = this->manager->getRootSceneNode()->createChildSceneNode(_msg->name());
    obj = this->manager->createManualObject(_msg->name());
  }

  sceneNode->setVisible(_msg->visible());
  obj->setVisible(_msg->has_visible());
  obj->estimateVertexCount(_msg->point_size());

  obj->clear();
  std::string material = "Gazebo/Red";
  if(_msg->has_material()) {
    material = _msg->material();
  }

  if(!_msg->has_mode())
    obj->begin(material, Ogre::RenderOperation::OT_LINE_LIST);
  else if(_msg->mode() == msgs::Drawing::POINT_LIST)
    obj->begin(material, Ogre::RenderOperation::OT_POINT_LIST);
  else if(_msg->mode() == msgs::Drawing::LINE_LIST)
    obj->begin(material, Ogre::RenderOperation::OT_LINE_LIST);
  else if(_msg->mode() == msgs::Drawing::LINE_STRIP)
    obj->begin(material, Ogre::RenderOperation::OT_LINE_STRIP);
  else if(_msg->mode() == msgs::Drawing::TRIANGLE_LIST)
    obj->begin(material, Ogre::RenderOperation::OT_TRIANGLE_LIST);
  else if(_msg->mode() == msgs::Drawing::TRIANGLE_STRIP)
    obj->begin(material, Ogre::RenderOperation::OT_TRIANGLE_STRIP);
  else if(_msg->mode() == msgs::Drawing::TRIANGLE_FAN)
    obj->begin(material, Ogre::RenderOperation::OT_TRIANGLE_FAN);

  int p = _msg->point_size();
  for(int i=0; i<p; i++) {
    obj->position(_msg->point(i).position().x(), _msg->point(i).position().y(), _msg->point(i).position().z());
    if(_msg->point(i).has_color())
      obj->colour(Conversions::Convert(msgs::Convert(_msg->point(i).color())));
  }
  obj->end();

  if (!attached)
    sceneNode->attachObject(obj);

  if(_msg->has_pose()) {
    sceneNode->setPosition(Conversions::Convert(msgs::Convert(_msg->pose().position())));
    sceneNode->setOrientation(Conversions::Convert(msgs::Convert(_msg->pose().orientation())));
  }

  return true;
}

Changes adding the new function to be processed during prerender

gazebo/rendering/Scene.cc

void Scene::PreRender()
{
  // ...
  static SensorMsgs_L::iterator sensorIter;
  static LinkMsgs_L::iterator linkIter;
  static DrawingMsgs_L::iterator drawingIter;

  // ...
  // Process the link messages
  linkIter = this->linkMsgs.begin();
  while (linkIter != this->linkMsgs.end())
  {
    if (this->ProcessLinkMsg(*linkIter))
      this->linkMsgs.erase(linkIter++);
    else
      ++linkIter;
  }

  // Process the drawing messages
  drawingIter = this->drawingMsgs.begin();
  while (drawingIter != this->drawingMsgs.end())
  {
    if (this->ProcessDrawingMsg(*drawingIter))
      this->drawingMsgs.erase(drawingIter++);
    else
      ++drawingIter;
  }
  // ...
}

Registering the new subscriber

gazebo/rendering/Scene.cc

Scene::Scene(const std::string &_name, bool _enableVisualizations)
{
  // ...
  this->sceneSub = this->node->Subscribe("~/scene", &Scene::OnScene, this);

  this->drawingSub = this->node->Subscribe("~/draw", &Scene::OnDrawing, this);
  // ...
}

Message definition

gazebo/msgs/drawing.proto

package gazebo.msgs;

/// \ingroup gazebo_msgs ...
(more)
2012-10-21 06:46:00 -0600 commented answer how to draw lines from a plugin or via messages

Thanks for the answer.

2012-10-11 04:01:27 -0600 asked a question how to draw lines from a plugin or via message

Hello,

can anyone tell me how to draw lines via messages or from a plugin? I already tried DynamicLines and Scene->DrawLine from inside a world plugin but without results. It either crashed the server or nothing happened at all.

Thanks for the help and best regards Bastian

2012-10-11 04:00:53 -0600 asked a question how to draw lines from a plugin or via messages

Hello,

can anyone tell me how to draw lines via messages or from a plugin? I already tried DynamicLines and Scene->DrawLine from inside a world plugin but without results. It either crashed the server or nothing happened at all.

Thanks for the help and best regards Bastian