Using selection in rviz plugin [closed]

asked 2014-06-07 09:49:43 -0600

Chris L gravatar image

My aim is to use the select plugin from RVIZ to interactively select and modify the characteristics of the point cloud (such as RGB values etc). The select tool in RVIZ shows all the selected points (in the selection panel) when a certain region is highlighted. I would like to access those points and change their properties.

I have used the following plugin already present on ROS board (comment of the last question):

The problem is that I am unable to access the points which RVIZ selection panel shows once a specific region in a point cloud is highlighted. I have tried accessing the rviz::PropertyTreeModel in rviz::SelectionManager; however the rowcount is zero, hence the rviz::PropertyTreeModel does not seem to have any children which i find very weird.

Going through the source code of RVIZ selection manager (and selection panel) it seems that all the information is stored in the rviz::PropertyTreeModel.

Additionally I have tried to access the getSelection() method in the selection manager that returns rviz::M_Picked; however, when i try to iterate over the boost::unorderedmap I get a segmentation fault (which I am currently trying to debug).

I will be thankful if someone can point me in the right direction. Kindly inform me if I am doing something wrong or if I am overlooking any specific aspect.

I have mentioned the code below (it's the same as this code on github -- i would like to thank Philipp Bartels for posting this code). The SelectedPointsTopic class mentioned below inherits from the SelectionTool class which is derived from the Tool class:

int SelectedPointsTopic::processMouseEvent( rviz::ViewportMouseEvent& event )
 int flags = rviz::SelectionTool::processMouseEvent( event );

 // determine current selection mode
 if( event.alt() )
   selecting_ = false;
   if( event.leftDown() )
     selecting_ = true;

 if( selecting_ )
   if( event.leftUp() )

     rviz::SelectionManager* sel_manager = context_->getSelectionManager();
     const rviz::M_Picked& selection = sel_manager->getSelection();
     rviz::PropertyTreeModel *model = sel_manager->getPropertyModel();

     int num_points = model->rowCount();

     std::cout << " Selection size: " << selection.size() <<std::endl;
     std::cout << " Point size: " << num_points <<std::endl;

     //BOOST_FOREACH(rviz::M_Picked::value_type i, selection){
     //   std::cout << i.second.pixel_count << " " <<std::endl;

     if( num_points <= 0 )
       return flags;

     sensor_msgs::PointCloud2 msg_pc;
     msg_pc.header.frame_id = context_->getFixedFrame().toStdString();
     msg_pc.height = 1;
     msg_pc.width = num_points;
     msg_pc.point_step = 3 * 4;
     msg_pc.row_step = num_points * msg_pc.point_step;
     msg_pc.is_dense = false;
     msg_pc.is_bigendian = false; msg_pc.row_step );
     msg_pc.fields.resize( 3 );

     msg_pc.fields[0].name = "x";
     msg_pc.fields[0].offset = 0;
     msg_pc.fields[0].datatype = sensor_msgs::PointField::FLOAT32;
     msg_pc.fields[0].count = 1;

     msg_pc.fields[1].name = "y";
     msg_pc.fields[1].offset = 4;
     msg_pc.fields[1].datatype = sensor_msgs::PointField::FLOAT32;
     msg_pc.fields[1].count = 1;

     msg_pc.fields[2].name = "z";
     msg_pc.fields[2].offset = 8;
     msg_pc.fields[2].datatype = sensor_msgs::PointField::FLOAT32;
     msg_pc.fields[2].count = 1;

     for( int i = 0; i < num_points; i++ )
       QModelIndex child_index = model->index( i, 0 );
       rviz::Property* child = model->getProp( child_index );
       rviz::VectorProperty* subchild = (rviz::VectorProperty*) child->childAt( 0 );
       Ogre::Vector3 vec = subchild->getVector();

       uint8_t* ptr = &[0] + i ...
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Chris L
close date 2014-06-10 11:07:45.130986