ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I found an answer how to do that. So there is a Point Tool in RViz which is implemented in files point_tool.h, point_tool.cpp. The event listener processMouseEvent captures any mouse event, and what we need to do is to select a point the same way as it is done in the Point Tool with the only difference that we do not listen events when the mouse pointer does not move. Here's the basic implementation of the callback:

int PointHighlightingTool::processMouseEvent(rviz::ViewportMouseEvent &event) {
  int flags = 0;

  // Check if mouse moved
  if ((event.x == event.last_x) && (event.y == event.last_y)) {
    return flags;
  }

  Ogre::Vector3 pos;
  bool success = context_->getSelectionManager()->get3DPoint( event.viewport, event.x, event.y, pos );

  if (success)  // A point is found
  {
    // Coordinates are stored in the `pos` variable and we can do anything we like with them from now on
    std::ostringstream s;
    s.precision(3);
    s << " [" << pos.x << "," << pos.y << ", " << pos.z << "]";
    ROS_INFO("3D Point %s", s.str().c_str());
  }

  return flags;
}

I found an answer how to do that. So there is a Point Tool in RViz which is implemented in files point_tool.h, point_tool.cpp. The event listener processMouseEvent processMouseEvent captures any any mouse event, and what we need to do is to select a point the same way as it is done in the Point Tool with the only difference that we do not listen events when the mouse pointer does not move. Here's the basic implementation of the callback:

int PointHighlightingTool::processMouseEvent(rviz::ViewportMouseEvent &event) {
  int flags = 0;

  // Check if mouse moved
  if ((event.x == event.last_x) && (event.y == event.last_y)) {
    return flags;
  }

  Ogre::Vector3 pos;
  bool success = context_->getSelectionManager()->get3DPoint( event.viewport, event.x, event.y, pos );

  if (success)  // A point is found
  {
    // Coordinates are stored in the `pos` variable and we can do anything we like with them from now on
    std::ostringstream s;
    s.precision(3);
    s << " [" << pos.x << "," << pos.y << ", " << pos.z << "]";
    ROS_INFO("3D Point %s", s.str().c_str());
  }

  return flags;
}