00001
00063
00064
00065
00066 #include <cob_3d_visualization/shape_marker.h>
00067 #include <pcl/common/transforms.h>
00068
00069 ShapeMarker::ShapeMarker(boost::shared_ptr<interactive_markers::InteractiveMarkerServer> im_server,
00070 cob_3d_mapping_msgs::Shape& shape,std::vector<unsigned int>& moved_shapes_indices,std::vector<unsigned int>& interacted_shapes,
00071 std::vector<unsigned int>& deleted_markers_indices, bool arrows,bool deleted) :
00072 interacted_shapes_(interacted_shapes) , moved_shapes_indices_(moved_shapes_indices) , deleted_markers_indices_(deleted_markers_indices)
00073 {
00074 arrows_ = arrows ;
00075 deleted_ = deleted ;
00076 im_server_ = im_server;
00077 shape_ = shape;
00078 id_ = shape.id;
00079 createShapeMenu ();
00080 createInteractiveMarker();
00081 }
00082
00083 void
00084 ShapeMarker::triangle_refinement(list<TPPLPoly>& i_list,list<TPPLPoly>& o_list){
00085 int n_circle = 20;
00086
00087 TPPLPoly tri_new,tri_temp;
00088 TPPLPoint ptM,ptM01,ptM12,ptM20;
00089 for (std::list<TPPLPoly>::iterator it = i_list.begin (); it != i_list.end (); it++){
00090 int n[4]={0,1,2,0};
00091
00092 ptM.x =(it->GetPoint(n[0]).x+it->GetPoint(n[1]).x+it->GetPoint(n[2]).x)/3;
00093 ptM.y =(it->GetPoint(n[0]).y+it->GetPoint(n[1]).y+it->GetPoint(n[2]).y)/3;
00094
00095 ptM01.x=(it->GetPoint(n[0]).x+it->GetPoint(n[1]).x)/2;
00096 ptM01.y=(it->GetPoint(n[0]).y+it->GetPoint(n[1]).y)/2;
00097
00098 ptM12.x=(it->GetPoint(n[1]).x+it->GetPoint(n[2]).x)/2;
00099 ptM12.y=(it->GetPoint(n[1]).y+it->GetPoint(n[2]).y)/2;
00100
00101 ptM20.x=(it->GetPoint(n[2]).x+it->GetPoint(n[3]).x)/2;
00102 ptM20.y=(it->GetPoint(n[2]).y+it->GetPoint(n[3]).y)/2;
00103
00104 tri_temp.Triangle(ptM01,ptM12,ptM20);
00105
00106
00107 double thresh = shape_.params[9]/6;
00108 if(fabs(it->GetPoint(n[0]).x-ptM.x)>thresh || fabs(it->GetPoint(n[1]).x-ptM.x)>thresh || fabs(it->GetPoint(n[2]).x-ptM.x)>thresh){
00109
00110 for (long i = 0; i < it->GetNumPoints (); i++){
00111 tri_new.Triangle(tri_temp.GetPoint(n[i]),ptM,it->GetPoint(n[i]));
00112
00113 o_list.push_back(tri_new);
00114 tri_new.Triangle(tri_temp.GetPoint(n[i]),it->GetPoint(n[i+1]),ptM);
00115
00116 o_list.push_back(tri_new);
00117 }
00118 }
00119 else{
00120 tri_new.Triangle(it->GetPoint(n[0]),it->GetPoint(n[1]),it->GetPoint(n[2]));
00121 o_list.push_back(tri_new);
00122 }
00123 }
00124 }
00125
00126 void ShapeMarker::getShape (cob_3d_mapping_msgs::Shape& shape) {
00127 shape_ = shape ;
00128 }
00129
00130 bool ShapeMarker::getArrows (){
00131 return arrows_ ;
00132 }
00133
00134 bool ShapeMarker::setArrows (){
00135 arrows_ = false ;
00136 return arrows_ ;
00137 }
00138
00139 bool ShapeMarker::getDeleted (){
00140 return deleted_ ;
00141 }
00142
00143 bool ShapeMarker::setDeleted (){
00144 deleted_ = false ;
00145 return deleted_ ;
00146 }
00147
00148 unsigned int ShapeMarker::getID(){
00149 return id_;
00150 }
00151
00152 void ShapeMarker::deleteMarker(const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback) {
00153
00154 deleted_ = true ;
00155
00156 stringstream ss;
00157 ss << shape_.id ;
00158 deleted_markers_indices_.push_back(shape_.id) ;
00159
00160 visualization_msgs::InteractiveMarker interactiveMarker;
00161 interactiveMarker.name = ss.str() ;
00162
00163 std::cout << "Marker" << interactiveMarker.name << " deleted..."<< std::endl ;
00164
00165
00166 im_server_->erase(ss.str());
00167 im_server_->applyChanges ();
00168
00169
00170 createInteractiveMarker () ;
00171 im_server_->applyChanges ();
00172
00173 }
00174
00175
00176 void ShapeMarker::enableMovement (const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback)
00177 {
00178 interactive_markers::MenuHandler::CheckState check_state;
00179 menu_handler_.getCheckState (feedback->menu_entry_id, check_state);
00180
00181 shape_.header = marker_.header ;
00182
00183
00184 if (check_state == interactive_markers::MenuHandler::UNCHECKED)
00185 {
00186
00187
00188 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::CHECKED);
00189 displayArrows();
00190 }
00191 else if (check_state == interactive_markers::MenuHandler::CHECKED)
00192 {
00193 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::UNCHECKED);
00194 hideArrows(1);
00195 }
00196 menu_handler_.reApply (*im_server_);
00197 im_server_->applyChanges();
00198 }
00199
00200
00201 void ShapeMarker::displayArrows()
00202 {
00203 arrows_ = true ;
00204 moved_shapes_indices_.push_back(shape_.id) ;
00205
00206
00207 createInteractiveMarker () ;
00208
00209
00210 visualization_msgs::InteractiveMarkerControl im_ctrl;
00211
00212
00213
00214
00215
00216
00217
00218
00219 ROS_INFO("Adding the arrows... ");
00220 im_ctrl.name = "arrow_markers" ;
00221
00222 im_ctrl.orientation.w = 1;
00223 im_ctrl.orientation.x = 1;
00224 im_ctrl.orientation.y = 0;
00225 im_ctrl.orientation.z = 0;
00226 im_ctrl.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00227 marker_.controls.push_back (im_ctrl);
00228 im_ctrl.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00229 marker_.controls.push_back (im_ctrl);
00230
00231 im_ctrl.orientation.w = 1;
00232 im_ctrl.orientation.x = 0;
00233 im_ctrl.orientation.y = 1;
00234 im_ctrl.orientation.z = 0;
00235 im_ctrl.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00236 marker_.controls.push_back (im_ctrl);
00237 im_ctrl.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00238 marker_.controls.push_back (im_ctrl);
00239
00240 im_ctrl.orientation.w = 1;
00241 im_ctrl.orientation.x = 0;
00242 im_ctrl.orientation.y = 0;
00243 im_ctrl.orientation.z = 1;
00244 im_ctrl.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00245 marker_.controls.push_back (im_ctrl);
00246 im_ctrl.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00247 marker_.controls.push_back (im_ctrl);
00248
00249
00250 im_server_->insert (marker_);
00251 im_server_->applyChanges() ;
00252
00253
00254 }
00255
00256
00257 void ShapeMarker::hideArrows(int untick)
00258
00259 {
00260 arrows_ = false ;
00261 stringstream ss;
00262 stringstream aa;
00263 std::vector<unsigned int>::iterator iter;
00264
00266 if(marker_.controls.size()>1){
00267 ROS_INFO ("Deleting the Arrows ...") ;
00268 marker_.controls.erase(marker_.controls.end()-6,marker_.controls.end()) ;
00269 im_server_->insert(marker_) ;
00270
00271
00272 if (!untick){
00273 menu_handler_.setCheckState (5, interactive_markers::MenuHandler::UNCHECKED);
00274 menu_handler_.reApply (*im_server_);
00275
00276 }
00277
00279 ss.str("");
00280 ss.clear();
00281 ss << "second_marker_"<< shape_.id;
00282 im_server_->erase(ss.str());
00283
00284 im_server_->applyChanges() ;
00286 }
00287 if (untick){
00288 iter = find (moved_shapes_indices_.begin(), moved_shapes_indices_.end(), shape_.id) ;
00289 if (iter!=moved_shapes_indices_.end()){
00290 moved_shapes_indices_.erase(moved_shapes_indices_.begin()+(iter-moved_shapes_indices_.begin())) ;
00291 }
00292 }
00293 }
00294
00295 void ShapeMarker::resetMarker()
00296 {
00297
00298 stringstream aa;
00299 stringstream ss;
00300
00301 hideNormal(0);
00302 hideCentroid(0);
00303 hideContour(0);
00304 if (shape_.type == cob_3d_mapping_msgs::Shape::CYLINDER){
00305 hideSymAxis(0);
00306 hideOrigin(0);
00307 }
00308 }
00309
00310
00311
00312 void
00313 ShapeMarker::createShapeMenu ()
00314 {
00315
00316
00317 interactive_markers::MenuHandler::EntryHandle eh_1, eh_2, eh_3, eh_4, eh_5, eh_6, eh_7;
00318
00319 eh_1 = menu_handler_.insert ("Menu");
00320 eh_2 = menu_handler_.insert (eh_1, "Display Normal",boost::bind (&ShapeMarker::displayNormalCB, this, _1));
00321 eh_3 = menu_handler_.insert (eh_1, "Display Centroid",boost::bind (&ShapeMarker::displayCentroidCB, this, _1));
00322 eh_4 = menu_handler_.insert (eh_1, "Display Contour",boost::bind (&ShapeMarker::displayContourCB, this, _1));
00323 eh_7 = menu_handler_.insert (eh_1, "Show ID",boost::bind (&ShapeMarker::displayIDCB, this, _1));
00324 eh_5 = menu_handler_.insert (eh_1, "Enable Movement",boost::bind (&ShapeMarker::enableMovement, this, _1));
00325 eh_6 = menu_handler_.insert (eh_1, "Delete Marker",boost::bind (&ShapeMarker::deleteMarker, this, _1));
00326
00327
00328 menu_handler_.setVisible (eh_1, true);
00329 menu_handler_.setCheckState (eh_1, interactive_markers::MenuHandler::NO_CHECKBOX);
00330
00331 menu_handler_.setVisible (eh_2, true);
00332 menu_handler_.setCheckState (eh_2, interactive_markers::MenuHandler::UNCHECKED);
00333
00334 menu_handler_.setVisible (eh_3, true);
00335 menu_handler_.setCheckState (eh_3, interactive_markers::MenuHandler::UNCHECKED);
00336
00337 menu_handler_.setVisible (eh_4, true);
00338 menu_handler_.setCheckState (eh_4, interactive_markers::MenuHandler::UNCHECKED);
00339
00340 menu_handler_.setVisible (eh_5, true);
00341 menu_handler_.setCheckState (eh_5, interactive_markers::MenuHandler::UNCHECKED);
00342
00343 menu_handler_.setVisible (eh_6, true);
00344 menu_handler_.setCheckState (eh_6, interactive_markers::MenuHandler::NO_CHECKBOX);
00345
00346 menu_handler_.setVisible (eh_7, true);
00347 menu_handler_.setCheckState (eh_7, interactive_markers::MenuHandler::UNCHECKED);
00348
00349
00350 if(shape_.type==cob_3d_mapping_msgs::Shape::CYLINDER){
00351 interactive_markers::MenuHandler::EntryHandle eh_7,eh_8;
00352
00353 eh_7 = menu_handler_.insert (eh_1, "Show Symmetry Axis",boost::bind (&ShapeMarker::displaySymAxisCB, this, _1));
00354 menu_handler_.setVisible (eh_7, true);
00355 menu_handler_.setCheckState (eh_7, interactive_markers::MenuHandler::UNCHECKED);
00356
00357 eh_8 = menu_handler_.insert (eh_1, "Show Cylinder Origin",boost::bind (&ShapeMarker::displayOriginCB, this, _1));
00358 menu_handler_.setVisible (eh_8,true);
00359 menu_handler_.setCheckState (eh_8, interactive_markers::MenuHandler::UNCHECKED);
00360 }
00361 }
00362
00363 void
00364 ShapeMarker::createMarker (visualization_msgs::InteractiveMarkerControl& im_ctrl)
00365 {
00366 marker.id = shape_.id;
00367
00368 marker.header = shape_.header;
00369
00370
00371
00372 marker.type = visualization_msgs::Marker::TRIANGLE_LIST;
00373 marker.ns = "shape visualization";
00374 marker.action = visualization_msgs::Marker::ADD;
00375 marker.lifetime = ros::Duration ();
00376
00377
00378 marker.color.g = shape_.color.g;
00379 marker.color.b = shape_.color.b;
00380 marker.color.r = shape_.color.r;
00381 if (arrows_ || deleted_){
00382 marker.color.a = 0.5;
00383 }
00384 else
00385 {
00386 marker.color.a = shape_.color.a;
00387
00388 }
00389
00390
00391 marker.scale.x = 1;
00392 marker.scale.y = 1;
00393 marker.scale.z = 1;
00394
00395
00396 TPPLPartition pp;
00397 list<TPPLPoly> polys, tri_list;
00398
00399 Eigen::Vector3f v, normal, origin;
00400
00401 if(shape_.type== cob_3d_mapping_msgs::Shape::CYLINDER)
00402 {
00403 cob_3d_mapping::Cylinder c;
00404 cob_3d_mapping::fromROSMsg (shape_, c);
00405
00406
00407
00408
00409 c.triangulate(tri_list);
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450 }
00451 if(shape_.type== cob_3d_mapping_msgs::Shape::POLYGON)
00452 {
00453 cob_3d_mapping::Polygon p;
00454
00455 if (shape_.params.size () == 4)
00456 {
00457 cob_3d_mapping::fromROSMsg (shape_, p);
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 }
00469 else
00470 {
00471 ROS_WARN("Unsupported polygon type, aborting...");
00472 return;
00473 }
00474 p.triangulate(tri_list);
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496 }
00497
00498 if(tri_list.size() == 0)
00499 {
00500 ROS_WARN("Could not triangulate, will not display this shape! (ID: %d)", shape_.id);
00501 return;
00502 }
00503
00504
00505 marker.points.resize (tri_list.size()*3);
00506 TPPLPoint pt;
00507 int ctr=0;
00508 for (std::list<TPPLPoly>::iterator it = tri_list.begin (); it != tri_list.end (); it++)
00509 {
00510
00511
00512 switch(shape_.type)
00513 {
00514 case(cob_3d_mapping_msgs::Shape::POLYGON):
00515 {
00516 for (long i = 0; i < it->GetNumPoints (); i++)
00517 {
00518 pt = it->GetPoint (i);
00519 marker.points[3*ctr+i].x = pt.x;
00520 marker.points[3*ctr+i].y = pt.y;
00521 marker.points[3*ctr+i].z = 0;
00522
00523 }
00524
00525 break;
00526 }
00527 case(cob_3d_mapping_msgs::Shape::CYLINDER):
00528 {
00529 for (long i = 0; i < it->GetNumPoints (); i++)
00530 {
00531 pt = it->GetPoint(i);
00532
00533
00534
00535
00536
00537 double r = shape_.params[3];
00538 double alpha = pt.x / r;
00539
00540 marker.points[3*ctr+i].x = sin(alpha) * r;
00541 marker.points[3*ctr+i].y = pt.y;
00542 marker.points[3*ctr+i].z = cos(alpha) * r;
00543
00545
00546
00547
00548 }
00549 break;
00550 }
00551 }
00552 ctr++;
00553 }
00554
00555 marker.pose = shape_.pose;
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568 im_ctrl.markers.push_back (marker);
00569
00570
00571
00572 marker_.pose = marker.pose;
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582 delete_contour_marker_ = contour_marker_;
00583 for (unsigned int i=0; i<delete_contour_marker_.markers.size(); i++)
00584 {
00585 delete_contour_marker_.markers[i].action = visualization_msgs::Marker::DELETE;
00586 }
00587 visualization_msgs::Marker cmarker;
00588 cmarker.action = visualization_msgs::Marker::ADD;
00589 cmarker.type = visualization_msgs::Marker::LINE_STRIP;
00590 cmarker.lifetime = ros::Duration();
00591 cmarker.header = shape_.header ;
00592
00593 cmarker.ns = "contours" ;
00594
00595 cmarker.scale.x = 0.02;
00596 cmarker.scale.y = 0.02;
00597 cmarker.scale.z = 1;
00598
00599 cmarker.color.r = 0;
00600 cmarker.color.g = 0;
00601 cmarker.color.b = 1;
00602 cmarker.color.a = 1.0;
00603
00604 cmarker.pose = shape_.pose;
00605
00606 cob_3d_mapping::Polygon p;
00607 cob_3d_mapping::fromROSMsg (shape_, p);
00608
00609 for(unsigned int i=0; i<p.contours_.size(); i++)
00610 {
00611 cmarker.id = (p.id_+1)*10+ctr;
00612 ctr ++ ;
00613 for(unsigned int j=0; j<p.contours_[i].size(); j++)
00614 {
00615
00616
00617 cmarker.points.resize(p.contours_[i].size()+1);
00618 cmarker.points[j].x = p.contours_[i][j](0);
00619 cmarker.points[j].y = p.contours_[i][j](1);
00620 cmarker.points[j].z = 0;
00621 }
00622 cmarker.points[p.contours_[i].size()].x = p.contours_[i][0](0);
00623 cmarker.points[p.contours_[i].size()].y = p.contours_[i][0](1);
00624 cmarker.points[p.contours_[i].size()].z = 0;
00625 contour_marker_.markers.push_back(cmarker);
00626 }
00627 }
00628
00629 TPPLPoint
00630 ShapeMarker::msgToPoint2D (const pcl::PointXYZ &point)
00631 {
00632
00633 TPPLPoint pt;
00634 Eigen::Vector3f p = transformation_ * point.getVector3fMap ();
00635 pt.x = p (0);
00636 pt.y = p (1);
00637
00638 return pt;
00639 }
00640
00641 void
00642 ShapeMarker::createInteractiveMarker ()
00643 {
00644 visualization_msgs::InteractiveMarker imarker ;
00645
00646
00647 stringstream ss;
00648 if(!arrows_ && !deleted_) {
00649 ss.str("");
00650 ss.clear() ;
00651 ss << shape_.id ;
00652 marker_.name = ss.str ();
00653 marker_.header = shape_.header;
00654 marker_.header.stamp = ros::Time::now() ;
00655 }
00656
00657 else if(arrows_)
00658 {
00659 ROS_INFO("Second Marker... ") ;
00660 ss.str("");
00661 ss.clear() ;
00662 ss << "second_marker_" <<shape_.id ;
00663 imarker_.name = ss.str ();
00664 imarker_.header = shape_.header;
00665 imarker_.header.stamp = ros::Time::now() ;
00666 }
00667 else if(deleted_)
00668 {
00669 ROS_INFO("Deleted Marker... ") ;
00670 ss.str("");
00671 ss.clear() ;
00672 ss << "deleted_marker_" <<shape_.id ;
00673 deleted_imarker_.name = ss.str ();
00674 deleted_imarker_.header = shape_.header;
00675 deleted_imarker_.header.stamp = ros::Time::now() ;
00676 }
00677 visualization_msgs::InteractiveMarkerControl im_ctrl_for_second_marker;
00678
00679
00680 if (!deleted_ && !arrows_) {
00681 ss.str("");
00682 ss.clear() ;
00683 ss.str ("");
00684 im_ctrl.always_visible = true;
00685 ss << "shape_" << shape_.id << "_control";
00686 im_ctrl.name = ss.str ();
00687 im_ctrl.description = "shape_markers";
00688 im_ctrl.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00689
00690 createMarker (im_ctrl);
00691 marker_.controls.push_back(im_ctrl) ;
00692 im_server_->insert (marker_ );
00693 im_server_ ->applyChanges() ;
00694 menu_handler_.apply (*im_server_, marker_.name);
00695 }
00696 else if (arrows_)
00697 {
00698 createMarker (im_ctrl_for_second_marker);
00699 imarker_.controls.push_back(im_ctrl_for_second_marker) ;
00700 im_server_->insert (imarker_ );
00701 im_server_ ->applyChanges() ;
00702
00703 }
00704 else if(deleted_){
00705 im_ctrl_for_second_marker.always_visible = true;
00706 im_ctrl_for_second_marker.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00707
00708 createMarker (im_ctrl_for_second_marker);
00709 deleted_imarker_.controls.push_back(im_ctrl_for_second_marker) ;
00710 im_server_->insert (deleted_imarker_ );
00711 im_server_ ->applyChanges() ;
00712 menu_handler_.apply (*im_server_, deleted_imarker_.name);
00713 }
00714 }
00715
00716
00717 void
00718 ShapeMarker::displayNormalCB (const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback)
00719 {
00720
00721 interactive_markers::MenuHandler::CheckState check_state;
00722
00723 menu_handler_.getCheckState (feedback->menu_entry_id, check_state);
00724 if (check_state == interactive_markers::MenuHandler::UNCHECKED)
00725 {
00726
00727 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::CHECKED);
00728
00729 displayNormal();
00730 }
00731 else if (check_state == interactive_markers::MenuHandler::CHECKED)
00732 {
00733
00734 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::UNCHECKED);
00735 hideNormal(1);
00736 }
00737 menu_handler_.reApply (*im_server_);
00738 im_server_->applyChanges ();
00739
00740 }
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00819 void ShapeMarker::displayNormal(){
00820
00821 ROS_INFO(" displayNormalCB from shape[ %d ]...", shape_.id);
00822
00823 std::vector<unsigned int>::iterator iter;
00824 visualization_msgs::InteractiveMarker imarker;
00825 stringstream ss;
00826
00827 ss << "normal_" << shape_.id;
00828 imarker.name = ss.str();
00829 imarker.header = shape_.header;
00830 ss.str("");
00831 ss.clear();
00832
00833 visualization_msgs::Marker marker;
00834 marker.header = shape_.header;
00835 marker.type = visualization_msgs::Marker::ARROW;
00836 marker.action = visualization_msgs::Marker::ADD;
00837 marker.lifetime = ros::Duration ();
00838
00839
00840 marker.color.r = 1;
00841 marker.color.g = 0;
00842 marker.color.b = 0;
00843 marker.color.a = 1;
00844
00845
00846 marker.scale.x = 0.05;
00847 marker.scale.y = 0.1;
00848 marker.scale.z = 0.1;
00849
00850
00851 marker.points.resize (2);
00852 marker.points[0] = shape_.pose.position;
00853
00854 marker.points[1].x = shape_.pose.position.x + shape_.params[0];
00855 marker.points[1].y = shape_.pose.position.y + shape_.params[1];
00856 marker.points[1].z = shape_.pose.position.z + shape_.params[2];
00857
00858 visualization_msgs::InteractiveMarkerControl im_ctrl_n;
00859
00860 ss << "normal_ctrl_" << shape_.id;
00861 im_ctrl_n.name = ss.str ();
00862 im_ctrl_n.description = "display_normal";
00863
00864
00865 im_ctrl_n.markers.push_back (marker);
00866 imarker.controls.push_back (im_ctrl_n);
00867 im_server_->insert (imarker);
00868
00869 interacted_shapes_.push_back(shape_.id) ;
00870 }
00871
00872 void ShapeMarker::hideNormal(int untick){
00873
00874 stringstream ss;
00875 std::vector<unsigned int>::iterator iter;
00876
00877 ss << "normal_" << shape_.id;
00878 im_server_->erase(ss.str());
00879 im_server_->applyChanges ();
00880 if(!untick){
00881 menu_handler_.setCheckState (2, interactive_markers::MenuHandler::UNCHECKED);
00882 menu_handler_.reApply (*im_server_);
00883 im_server_->applyChanges() ;
00884 }
00885
00886 if(untick){
00887
00888 iter = find (interacted_shapes_.begin(), interacted_shapes_.end(), shape_.id) ;
00889 if (iter!=interacted_shapes_.end()){
00890 interacted_shapes_.erase(interacted_shapes_.begin()+(iter-interacted_shapes_.begin())) ;
00891 }
00892 }
00893 }
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00997 void
00998 ShapeMarker::displayCentroidCB (const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback)
00999 {
01000 stringstream ss;
01001 interactive_markers::MenuHandler::CheckState check_state;
01002 menu_handler_.getCheckState (feedback->menu_entry_id, check_state);
01003 if (check_state == interactive_markers::MenuHandler::UNCHECKED)
01004 {
01005
01006 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::CHECKED);
01007 displayCentroid();
01008 }
01009 if (check_state == interactive_markers::MenuHandler::CHECKED)
01010 {
01011
01012 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::UNCHECKED);
01013 hideCentroid(1);
01014 }
01015 menu_handler_.reApply (*im_server_);
01016 im_server_->applyChanges ();
01017
01018
01019 }
01020
01021 void ShapeMarker::displayCentroid(){
01022
01023 ROS_INFO(" displayCentroidCB from shape[ %d ]...", shape_.id);
01024 std::vector<unsigned int>::iterator iter;
01025
01026 stringstream ss;
01027 ss.clear();
01028 ss.str("");
01029 visualization_msgs::InteractiveMarker imarker;
01030 ss << "centroid_" << shape_.id;
01031 imarker.name = ss.str();
01032 imarker.header = shape_.header;
01033 ss.str("");
01034 ss.clear();
01035
01036 visualization_msgs::Marker marker;
01037 marker.header = shape_.header;
01038
01039 marker.type = visualization_msgs::Marker::SPHERE;
01040 marker.action = visualization_msgs::Marker::ADD;
01041 marker.lifetime = ros::Duration ();
01042
01043
01044 marker.color.r = 0;
01045 marker.color.g = 0;
01046 marker.color.b = 1;
01047 marker.color.a = 1;
01048
01049
01050 marker.scale.x = 0.04;
01051 marker.scale.y = 0.04;
01052 marker.scale.z = 0.04;
01053
01054
01055 marker.pose.position = shape_.pose.position;
01056
01057
01058 visualization_msgs::InteractiveMarkerControl im_ctrl;
01059 im_ctrl.always_visible = true;
01060 ss << "centroid_ctrl_" << shape_.id;
01061 im_ctrl.name = ss.str ();
01062 im_ctrl.markers.push_back (marker);
01063 imarker.controls.push_back (im_ctrl);
01064 im_server_->insert (imarker);
01065
01066 interacted_shapes_.push_back(shape_.id) ;
01067 }
01068
01069 void ShapeMarker::hideCentroid(int untick){
01070 stringstream ss;
01071 std::vector<unsigned int>::iterator iter;
01072
01073 ss.clear();
01074 ss.str("");
01075 ss << "centroid_" << shape_.id;
01076 im_server_->erase(ss.str());
01077 im_server_->applyChanges ();
01078
01079 if(!untick){
01080 menu_handler_.setCheckState (3, interactive_markers::MenuHandler::UNCHECKED);
01081 menu_handler_.reApply (*im_server_);
01082 im_server_->applyChanges() ;
01083 }
01084
01085 if(untick){
01086
01087 iter = find (interacted_shapes_.begin(), interacted_shapes_.end(), shape_.id) ;
01088 if (iter!=interacted_shapes_.end()){
01089 interacted_shapes_.erase(interacted_shapes_.begin()+(iter-interacted_shapes_.begin())) ;
01090 }
01091 }
01092 }
01093
01094 void ShapeMarker::displayContourCB(const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback) {
01095
01096 interactive_markers::MenuHandler::CheckState check_state;
01097 menu_handler_.getCheckState (feedback->menu_entry_id, check_state);
01098 if (check_state == interactive_markers::MenuHandler::UNCHECKED)
01099 {
01100
01101 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::CHECKED);
01102 displayContour();
01103 }
01104 else if (check_state == interactive_markers::MenuHandler::CHECKED)
01105 {
01106 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::UNCHECKED);
01107 hideContour(1);
01108 }
01109 menu_handler_.reApply (*im_server_);
01110 im_server_->applyChanges ();
01111 }
01112
01113
01114 void ShapeMarker::displayContour(){
01115 ROS_INFO(" displayContourCB from shape[ %d ]...", shape_.id);
01116 std::vector<unsigned int>::iterator iter ;
01117
01118 stringstream aa;
01119 stringstream ss;
01120 int ctr = 0;
01121
01122 visualization_msgs::Marker marker;
01123 marker.action = visualization_msgs::Marker::ADD;
01124 marker.type = visualization_msgs::Marker::LINE_STRIP;
01125 marker.lifetime = ros::Duration();
01126 marker.header = shape_.header ;
01127
01128 marker.ns = "contours" ;
01129
01130 marker.scale.x = 0.02;
01131 marker.scale.y = 0.02;
01132 marker.scale.z = 1;
01133
01134 marker.color.r = 0;
01135 marker.color.g = 0;
01136 marker.color.b = 1;
01137 marker.color.a = 1.0;
01138
01139 marker.pose = shape_.pose;
01140
01141 cob_3d_mapping::Polygon p;
01142 cob_3d_mapping::fromROSMsg (shape_, p);
01143
01144 visualization_msgs::InteractiveMarker imarker;
01145 visualization_msgs::InteractiveMarkerControl im_ctrl_ ;
01146 for(unsigned int i=0; i<p.contours_.size(); i++)
01147 {
01148 marker.id = ctr ;
01149 ctr ++ ;
01150 for(unsigned int j=0; j<p.contours_[i].size(); j++)
01151 {
01152
01153
01154 marker.points.resize(p.contours_[i].size()+1);
01155 marker.points[j].x = p.contours_[i][j](0);
01156 marker.points[j].y = p.contours_[i][j](1);
01157 marker.points[j].z = 0;
01158 }
01159 marker.points[p.contours_[i].size()].x = p.contours_[i][0](0);
01160 marker.points[p.contours_[i].size()].y = p.contours_[i][0](1);
01161 marker.points[p.contours_[i].size()].z = 0;
01162 im_ctrl_.markers.push_back(marker);
01163
01164 }
01165
01166 im_ctrl_.always_visible = true ;
01167 im_ctrl_.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
01168
01169 ss << "contour_" << shape_.id;
01170 imarker.name = ss.str() ;
01171
01172 imarker.header = shape_.header ;
01173 imarker.controls.push_back(im_ctrl_);
01174 im_server_->insert (imarker);
01175
01176 interacted_shapes_.push_back(shape_.id) ;
01177
01178 }
01179
01180 void ShapeMarker::hideContour(int untick){
01181 stringstream ss;
01182 std::vector<unsigned int>::iterator iter;
01183
01184 ss.clear() ;
01185 ss.str("");
01186 ss << "contour_" << shape_.id;
01187 im_server_->erase(ss.str());
01188 im_server_->applyChanges ();
01189 if(!untick){
01190 menu_handler_.setCheckState (4, interactive_markers::MenuHandler::UNCHECKED);
01191 menu_handler_.reApply (*im_server_);
01192 im_server_->applyChanges() ;
01193 }
01194
01195 if(untick){
01196 iter = find (interacted_shapes_.begin(), interacted_shapes_.end(), shape_.id) ;
01197 if (iter!=interacted_shapes_.end()){
01198 interacted_shapes_.erase(interacted_shapes_.begin()+(iter-interacted_shapes_.begin())) ;
01199 }
01200 }
01201 }
01202
01203 void
01204 ShapeMarker::displaySymAxisCB (const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback)
01205 {
01206
01207 interactive_markers::MenuHandler::CheckState check_state;
01208
01209 menu_handler_.getCheckState (feedback->menu_entry_id, check_state);
01210 if (check_state == interactive_markers::MenuHandler::UNCHECKED)
01211 {
01212
01213 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::CHECKED);
01214 displaySymAxis();
01215 }
01216 else if (check_state == interactive_markers::MenuHandler::CHECKED)
01217 {
01218
01219 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::UNCHECKED);
01220 hideSymAxis(1);
01221 }
01222 menu_handler_.reApply (*im_server_);
01223 im_server_->applyChanges ();
01224
01225 }
01226
01227 void ShapeMarker::displaySymAxis(){
01228
01229 ROS_INFO(" displaySymAxis from shape[ %d ]...", shape_.id);
01230
01231 visualization_msgs::InteractiveMarker imarker;
01232 stringstream ss;
01233
01234 ss << "symaxis_" << shape_.id;
01235 imarker.name = ss.str();
01236 imarker.header = shape_.header;
01237 ss.str("");
01238 ss.clear();
01239
01240 visualization_msgs::Marker marker;
01241 marker.header = shape_.header;
01242 marker.type = visualization_msgs::Marker::ARROW;
01243 marker.action = visualization_msgs::Marker::ADD;
01244 marker.lifetime = ros::Duration ();
01245
01246
01247 marker.color.r = 1;
01248 marker.color.g = 1;
01249 marker.color.b = 0;
01250 marker.color.a = 1;
01251
01252
01253 marker.scale.x = 0.05;
01254 marker.scale.y = 0.1;
01255 marker.scale.z = 0.1;
01256
01257
01258 marker.points.resize (2);
01259
01260 marker.points[0].x = shape_.params[6];
01261 marker.points[0].y = shape_.params[7];
01262 marker.points[0].z = shape_.params[8];
01263
01264 marker.points[1].x = shape_.params[6] - shape_.params[3];
01265 marker.points[1].y = shape_.params[7] - shape_.params[4];
01266 marker.points[1].z = shape_.params[8] - shape_.params[5];
01267
01268 visualization_msgs::InteractiveMarkerControl im_ctrl_n;
01269
01270 ss << "symaxis_ctrl_" << shape_.id;
01271 im_ctrl_n.name = ss.str ();
01272 im_ctrl_n.description = "display_symaxis";
01273
01274 im_ctrl_n.markers.push_back (marker);
01275 imarker.controls.push_back (im_ctrl_n);
01276 im_server_->insert (imarker);
01277
01278 interacted_shapes_.push_back(shape_.id) ;
01279
01280
01281 }
01282
01283 void ShapeMarker::hideSymAxis(int untick){
01284
01285 stringstream ss;
01286 std::vector<unsigned int>::iterator iter;
01287
01288 ss << "symaxis_" << shape_.id;
01289 im_server_->erase(ss.str());
01290 im_server_->applyChanges ();
01291
01292 if(untick){
01293
01294 iter = find (interacted_shapes_.begin(), interacted_shapes_.end(), shape_.id) ;
01295 if (iter!=interacted_shapes_.end()){
01296 interacted_shapes_.erase(interacted_shapes_.begin()+(iter-interacted_shapes_.begin())) ;
01297 }
01298 }
01299 if(!untick){
01300 menu_handler_.setCheckState (7, interactive_markers::MenuHandler::UNCHECKED);
01301 menu_handler_.reApply (*im_server_);
01302 im_server_->applyChanges() ;
01303 }
01304 }
01305
01306 void
01307 ShapeMarker::displayOriginCB (const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback)
01308 {
01309 stringstream ss;
01310 interactive_markers::MenuHandler::CheckState check_state;
01311 menu_handler_.getCheckState (feedback->menu_entry_id, check_state);
01312 if (check_state == interactive_markers::MenuHandler::UNCHECKED)
01313 {
01314
01315 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::CHECKED);
01316 displayOrigin();
01317 }
01318 if (check_state == interactive_markers::MenuHandler::CHECKED)
01319 {
01320
01321 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::UNCHECKED);
01322 hideOrigin(1);
01323 }
01324 menu_handler_.reApply (*im_server_);
01325 im_server_->applyChanges ();
01326
01327
01328 }
01329
01330 void ShapeMarker::displayOrigin(){
01331
01332 ROS_INFO(" displayOriginCB from shape[ %d ]...", shape_.id);
01333 std::vector<unsigned int>::iterator iter;
01334
01335 stringstream ss;
01336 ss.clear();
01337 ss.str("");
01338 visualization_msgs::InteractiveMarker imarker;
01339 ss << "origin_" << shape_.id;
01340 imarker.name = ss.str();
01341 imarker.header = shape_.header;
01342 ss.str("");
01343 ss.clear();
01344
01345 visualization_msgs::Marker marker;
01346 marker.header = shape_.header;
01347
01348 marker.type = visualization_msgs::Marker::SPHERE;
01349 marker.action = visualization_msgs::Marker::ADD;
01350 marker.lifetime = ros::Duration ();
01351
01352
01353 marker.color.r = 1;
01354 marker.color.g = 0;
01355 marker.color.b = 1;
01356 marker.color.a = 1;
01357
01358
01359 marker.scale.x = 0.04;
01360 marker.scale.y = 0.04;
01361 marker.scale.z = 0.04;
01362
01363
01364 marker.pose.position.x = shape_.params[6];
01365 marker.pose.position.y = shape_.params[7];
01366 marker.pose.position.z = shape_.params[8];
01367
01368
01369 visualization_msgs::InteractiveMarkerControl im_ctrl;
01370 im_ctrl.always_visible = true;
01371 ss << "origin_ctrl_" << shape_.id;
01372 im_ctrl.name = ss.str ();
01373 im_ctrl.markers.push_back (marker);
01374 imarker.controls.push_back (im_ctrl);
01375 im_server_->insert (imarker);
01376
01377 interacted_shapes_.push_back(shape_.id) ;
01378
01379 }
01380
01381 void ShapeMarker::hideOrigin(int untick){
01382 stringstream ss;
01383 std::vector<unsigned int>::iterator iter;
01384
01385 ss.clear();
01386 ss.str("");
01387 ss << "origin_" << shape_.id;
01388 im_server_->erase(ss.str());
01389 im_server_->applyChanges ();
01390
01391 if(untick){
01392
01393 iter = find (interacted_shapes_.begin(), interacted_shapes_.end(), shape_.id) ;
01394 if (iter!=interacted_shapes_.end()){
01395 interacted_shapes_.erase(interacted_shapes_.begin()+(iter-interacted_shapes_.begin())) ;
01396 }
01397 }
01398 if(!untick){
01399 menu_handler_.setCheckState (8, interactive_markers::MenuHandler::UNCHECKED);
01400 menu_handler_.reApply (*im_server_);
01401 im_server_->applyChanges() ;
01402 }
01403
01404 }
01405
01406 void ShapeMarker::displayIDCB(const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback)
01407 {
01408
01409 interactive_markers::MenuHandler::CheckState check_state;
01410 menu_handler_.getCheckState (feedback->menu_entry_id, check_state);
01411 if (check_state == interactive_markers::MenuHandler::UNCHECKED)
01412 {
01413
01414 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::CHECKED);
01415 displayID();
01416 }
01417 else if (check_state == interactive_markers::MenuHandler::CHECKED)
01418 {
01419 menu_handler_.setCheckState (feedback->menu_entry_id, interactive_markers::MenuHandler::UNCHECKED);
01420 hideID(1);
01421 }
01422 menu_handler_.reApply (*im_server_);
01423 im_server_->applyChanges ();
01424 }
01425
01426
01427 void ShapeMarker::displayID()
01428 {
01429 ROS_INFO(" displayID from shape[ %d ]...", shape_.id);
01430 std::vector<unsigned int>::iterator iter ;
01431
01432 stringstream aa;
01433 stringstream ss;
01434 int ctr = 0;
01435
01436 visualization_msgs::Marker marker;
01437 marker.action = visualization_msgs::Marker::ADD;
01438 marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
01439 marker.lifetime = ros::Duration();
01440 marker.header = shape_.header ;
01441
01442 marker.ns = "contours" ;
01443
01444
01445 marker.pose = shape_.pose;
01446
01447
01448
01449
01450 marker.scale.z = 0.1;
01451
01452 marker.color.r = 0;
01453 marker.color.g = 0;
01454 marker.color.b = 1;
01455 marker.color.a = 1.0;
01456
01457
01458 visualization_msgs::InteractiveMarker imarker;
01459 visualization_msgs::InteractiveMarkerControl im_ctrl_ ;
01460
01461 im_ctrl_.markers.push_back(marker);
01462
01463 im_ctrl_.always_visible = true ;
01464 im_ctrl_.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
01465
01466 ss << "id_" << shape_.id;
01467 imarker.name = ss.str() ;
01468
01469 imarker.header = shape_.header ;
01470 imarker.controls.push_back(im_ctrl_);
01471 im_server_->insert (imarker);
01472
01473 interacted_shapes_.push_back(shape_.id) ;
01474
01475 }
01476
01477 void ShapeMarker::hideID(int untick)
01478 {
01479 stringstream ss;
01480 std::vector<unsigned int>::iterator iter;
01481
01482 ss.clear() ;
01483 ss.str("");
01484 ss << "id_" << shape_.id;
01485 im_server_->erase(ss.str());
01486 im_server_->applyChanges ();
01487 if(!untick){
01488 menu_handler_.setCheckState (4, interactive_markers::MenuHandler::UNCHECKED);
01489 menu_handler_.reApply (*im_server_);
01490 im_server_->applyChanges() ;
01491 }
01492
01493 if(untick){
01494 iter = find (interacted_shapes_.begin(), interacted_shapes_.end(), shape_.id) ;
01495 if (iter!=interacted_shapes_.end()){
01496 interacted_shapes_.erase(interacted_shapes_.begin()+(iter-interacted_shapes_.begin())) ;
01497 }
01498 }
01499 }
01500