00001
00059
00060
00061
00062
00063
00064
00065
00066 #define DEBUG_
00067
00068
00069
00070 #include <ros/ros.h>
00071 #include <pluginlib/class_list_macros.h>
00072 #include <pcl_ros/pcl_nodelet.h>
00073 #include <tf/transform_listener.h>
00074 #include <tf_conversions/tf_eigen.h>
00075
00076
00077 #include <cob_3d_mapping_msgs/ShapeArray.h>
00078 #include <cob_3d_mapping_msgs/CurvedPolygon_Array.h>
00079 #include <visualization_msgs/Marker.h>
00080 #include <arm_navigation_msgs/CollisionMap.h>
00081
00082
00083 #ifdef DEBUG_
00084 #include <cob_3d_mapping_slam/curved_polygons/debug_interface.h>
00085 #endif
00086
00087
00088 #include <cob_3d_mapping_slam/dof/tflink.h>
00089 #include <cob_3d_mapping_slam/dof/dof_uncertainty.h>
00090 #include <cob_3d_mapping_slam/dof/dof_variance.h>
00091
00092
00093 #include <cob_3d_mapping_slam/slam/context.h>
00094 #include <cob_3d_mapping_slam/slam/node.h>
00095 #include <cob_3d_mapping_slam/slam/dummy/robot.h>
00096
00097
00098 #include <cob_3d_mapping_slam/curved_polygons/objctxt.h>
00099 #include <cob_3d_mapping_slam/curved_polygons/key.h>
00100
00101
00102
00103
00104 #define Pr .299
00105 #define Pg .587
00106 #define Pb .114
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 void changeSaturation(float *R, float *G, float *B, float change) {
00125
00126 float P=sqrtf(
00127 (*R)*(*R)*Pr+
00128 (*G)*(*G)*Pg+
00129 (*B)*(*B)*Pb ) ;
00130
00131 *R=std::min(std::max(P+((*R)-P)*change,0.f),1.f);
00132 *G=std::min(std::max(P+((*G)-P)*change,0.f),1.f);
00133 *B=std::min(std::max(P+((*B)-P)*change,0.f),1.f); }
00134
00135
00136 class As_Node
00137 {
00138 protected:
00139 ros::NodeHandle n_;
00140 tf::TransformListener tf_listener_;
00141 public:
00142 As_Node(): n_("~") {
00143 }
00144
00145 virtual ~As_Node() {}
00146
00147 virtual void onInit()=0;
00148
00149 void start() {
00150
00151 }
00152 };
00153
00154 class As_Nodelet : public pcl_ros::PCLNodelet
00155 {
00156 protected:
00157 ros::NodeHandle n_;
00158 public:
00159 As_Nodelet() {
00160 }
00161
00162 virtual ~As_Nodelet() {}
00163
00164 void start() {
00165 PCLNodelet::onInit();
00166 n_ = getNodeHandle();
00167 }
00168 };
00169
00170 template <typename Parent>
00171 class SLAM_Node : public Parent
00172 {
00173 typedef DOF6::DOF6_Source<DOF6::TFLinkvf,DOF6::DOF6_Uncertainty<Dummy::RobotParametersSlow,float> > DOF6;
00174 typedef Slam::Node<Slam_CurvedPolygon::OBJCTXT<DOF6> > Node;
00175
00176
00177 ros::Subscriber curved_poly_sub_;
00178 ros::Subscriber shapes_sub_;
00179 ros::Publisher map_pub_, debug_pub_, debug2_pub_, outline_pub_, collision_map_pub_;
00180
00181 cob_3d_marker::MarkerContainer marker_cont;
00182 cob_3d_marker::MarkerPublisher marker_pub;
00183
00184 std::string world_id_, frame_id_;
00185
00186 bool use_real_world_color_, use_odometry_;
00187 bool dbg_show_grid_;
00188
00189 bool invert_;
00190 ros::Time start_ts_;
00191
00192 Slam::Context<Slam_CurvedPolygon::KEY<DOF6>, Node> *ctxt_;
00193
00194 Eigen::Matrix4f M_last_;
00195 bool first_;
00196
00197 cob_3d_mapping_msgs::CurvedPolygon convert(const cob_3d_mapping_msgs::Shape &sh) {
00198 cob_3d_mapping_msgs::CurvedPolygon r;
00199 r.ID = sh.id;
00200 r.weight = sh.weight;
00201
00202 ROS_ASSERT_MSG(r.parameter.size()==6, "incompatible parameters");
00203 for(int i=0; i<6; i++)
00204 r.parameter[i] = sh.params[i];
00205
00206 pcl::PointCloud<pcl::PointXYZ> pc;
00207 pcl::fromROSMsg(sh.points[0],pc);
00208
00209 for(size_t i=0; i<pc.size(); i++) {
00210 cob_3d_mapping_msgs::polyline_point pt;
00211 pt.x = pc[i].x;
00212 pt.y = pc[i].y;
00213 pt.edge_prob = pc[i].z;
00214 r.polyline.push_back(pt);
00215 }
00216
00217 return r;
00218 }
00219
00220 public:
00221
00222 SLAM_Node(): first_(true), invert_(false), use_real_world_color_(true), use_odometry_(false), dbg_show_grid_(true),
00223 marker_pub(debug2_pub_)
00224 {
00225 }
00226
00227 virtual ~SLAM_Node()
00228 {}
00229
00230 void onInit() {
00231 this->start();
00232
00233 ros::NodeHandle *n=&(this->n_);
00234
00235 shapes_sub_ = this->n_.subscribe("/shapes_array", 1, &SLAM_Node<Parent>::cbShapes, this);
00236 map_pub_ = n->advertise<visualization_msgs::Marker>("map", 10);
00237 debug_pub_ = n->advertise<visualization_msgs::Marker>("debug", 1);
00238 debug2_pub_ = n->advertise<visualization_msgs::Marker>("debug2", 100);
00239 outline_pub_ = n->advertise<visualization_msgs::Marker>("outline", 1);
00240 collision_map_pub_ = n->advertise<arm_navigation_msgs::CollisionMap>("collision_map", 10);
00241
00242 double tr_dist = 1.f, rot_dist=0.8f;
00243 double tr_speed = 0.6, rot_speed=0.6;
00244
00245 n->getParam("translation_size",tr_dist);
00246 n->getParam("rotation_size",rot_dist);
00247
00248 n->getParam("translation_speed",tr_speed);
00249 n->getParam("rotation_speed",rot_speed);
00250
00251 n->getParam("world_id",world_id_);
00252 n->getParam("frame_id",frame_id_);
00253
00254 n->getParam("invert",invert_);
00255
00256 n->getParam("real_world_color",use_real_world_color_);
00257 n->getParam("use_odometry",use_odometry_);
00258 n->getParam("dbg_show_grid",dbg_show_grid_);
00259
00260 ctxt_ = new Slam::Context<Slam_CurvedPolygon::KEY<DOF6>, Node>(tr_dist, rot_dist);
00261 }
00262
00263 void
00264 cbShapes(cob_3d_mapping_msgs::ShapeArray::ConstPtr cpa)
00265 {
00266 std::vector< ::std_msgs::ColorRGBA> color;
00267 cob_3d_mapping_msgs::CurvedPolygon_Array::Ptr ar(new cob_3d_mapping_msgs::CurvedPolygon_Array());
00268 for(size_t i=0; i<cpa->shapes.size(); i++) {
00269 if(cpa->shapes[i].weight>500)
00270 {
00271 ar->polygons.push_back(convert(cpa->shapes[i]));
00272 color.push_back(cpa->shapes[i].color);
00273 }
00274 }
00275 ar->header = cpa->header;
00276 cbPolygons2(ar, color);
00277 }
00278
00279 void
00280 cbPolygons(cob_3d_mapping_msgs::CurvedPolygon_Array::ConstPtr cpa)
00281 {
00282 cbPolygons2(cpa,std::vector< ::std_msgs::ColorRGBA>());
00283 }
00284
00285 void
00286 cbPolygons2(cob_3d_mapping_msgs::CurvedPolygon_Array::ConstPtr cpa, const std::vector< ::std_msgs::ColorRGBA> &color)
00287 {
00288 if(!ctxt_) return;
00289
00290 static bool lock=false;
00291
00292 if(lock) return;
00293
00294 lock=true;
00295 double start_time = ros::Time::now().toSec();
00296 Debug::Interface::get().setTime(ros::Time::now().toSec());
00297
00298 ctxt_->startFrame(cpa->header.stamp.toSec());
00299
00300 if(use_odometry_) {
00301 if(world_id_.size()>0&&frame_id_.size()>0) {
00302 tf::StampedTransform transform;
00303 try
00304 {
00305 std::stringstream ss2;
00306 this->tf_listener_.waitForTransform(frame_id_, world_id_, cpa->header.stamp, ros::Duration(0.2));
00307 this->tf_listener_.lookupTransform(frame_id_, world_id_, cpa->header.stamp, transform);
00308
00309 Eigen::Affine3d af;
00310 tf::TransformTFToEigen(transform, af);
00311 Eigen::Matrix4f _M = af.matrix().cast<float>(), M, R=Eigen::Matrix4f::Identity();
00312
00313 std::cout<<"TSDIFF "<<(transform.stamp_-cpa->header.stamp).toSec()<<"\n";
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 if(first_) {
00325 start_ts_ = cpa->header.stamp;
00326 first_=false;
00327 M_last_ = _M;
00328 }
00329
00330 M = M_last_.inverse()*_M;
00331 if(invert_)
00332 M = M.inverse().eval();
00333
00334 std::cout<<"ODOMETRY\n"<<M<<"\n";
00335 std::cout<<"_M_\n"<<_M<<"\n";
00336
00337 M = M*ctxt_->getPath().getLocal().link_.getTF4();
00338
00339 ctxt_->getPath().getLocal().link_.setVariance(
00340 std::max(ctxt_->getPath().getLocal().link_.getSource2()->getTranslationVariance()*0.8f, 0.05f),
00341 M.col(3).head<3>(),
00342 ctxt_->getPath().getLocal().link_.getSource2()->getRotationVariance()*0.8f,
00343 (typename DOF6::TROTATION)(M.topLeftCorner(3,3))
00344 );
00345 M_last_ = _M;
00346
00347 std::cout<<"ODOMETRY LINK\n"<<ctxt_->getPath().getLocal().link_<<"\n";
00348
00349 }
00350 catch (tf::TransformException ex)
00351 {
00352 ROS_ERROR("[slam] : %s",ex.what());
00353 lock=false;
00354 return;
00355 }
00356 }
00357
00358 ROS_INFO("timestamp %f", (float)(ros::Time::now()-start_ts_).toSec());
00359 }
00360
00361 for(size_t i=0; i<cpa->polygons.size(); i++) {
00362 Slam_CurvedPolygon::ex_curved_polygon ep = cpa->polygons[i];
00363 if(i<color.size())
00364 ep.setColor(color[i]);
00365 *ctxt_ += ep;
00366 }
00367 ctxt_->finishFrame();
00368
00369
00370
00371 {
00372 Eigen::Matrix3f tmp_rot = Eigen::Matrix3f::Identity();
00373 Eigen::Matrix3f tmp_rot2 = Eigen::Matrix3f::Identity();
00374 Eigen::Vector3f tmp_tr = Eigen::Vector3f::Zero();
00375 const Slam::SWAY<Node> *n = &ctxt_->getPath().getLocal();
00376 while(n)
00377 {
00378
00379 tmp_tr = tmp_rot2*tmp_tr + n->link_.getTranslation();
00380 tmp_rot = ((Eigen::Matrix3f)n->link_.getRotation())*tmp_rot;
00381 tmp_rot2= ((Eigen::Matrix3f)n->link_.getRotation());
00382
00383 std::cout<<"ROTn\n"<<(::DOF6::EulerAnglesf)n->link_.getRotation()<<"\n";
00384 std::cout<<"TRn\n"<<n->link_.getTranslation()<<"\n";
00385
00386 std::cout<<"con\n";
00387 size_t next_id = n->id_-1;
00388 const Slam::SWAY<Node> *n2 = NULL;
00389 for(size_t i=0; i<n->node_->getConnections().size(); i++)
00390 if(n->node_->getConnections()[i].id_ == next_id) {
00391 n2 = &n->node_->getConnections()[i];
00392 break;
00393 }
00394 n = n2;
00395 }
00396 std::cout<<"ROT1\n"<<(::DOF6::EulerAnglesf)tmp_rot<<"\n";
00397 std::cout<<"TR1\n"<<tmp_tr<<"\n";
00398 }
00399
00400
00401
00402 visualization_msgs::Marker marker_map, marker_outline;
00403 marker_map.header = cpa->header;
00404 marker_map.pose.position.x = 0;
00405 marker_map.pose.position.y = 0;
00406 marker_map.pose.position.z = 0;
00407 marker_map.pose.orientation.x = 0.0;
00408 marker_map.pose.orientation.y = 0.0;
00409 marker_map.pose.orientation.z = 0.0;
00410 marker_map.pose.orientation.w = 1.0;
00411 marker_map.action = visualization_msgs::Marker::ADD;
00412 marker_map.color.r = marker_map.color.g = marker_map.color.b = marker_map.color.a = 1;
00413
00414 marker_map.type = visualization_msgs::Marker::TRIANGLE_LIST;
00415 marker_map.scale.x = marker_map.scale.y = marker_map.scale.z = 1;
00416 marker_map.id = 5;
00417
00418 marker_outline = marker_map;
00419 marker_outline.id = 9;
00420 marker_outline.type = visualization_msgs::Marker::LINE_LIST;
00421 marker_outline.scale.x = marker_outline.scale.y = marker_outline.scale.z = 0.01;
00422
00423 std_msgs::ColorRGBA line_c;
00424 visualization_msgs::Marker marker_dbg = marker_map;
00425
00426 Eigen::Matrix3f tmp_rot = Eigen::Matrix3f::Identity();
00427 Eigen::Matrix3f tmp_rot2 = Eigen::Matrix3f::Identity();
00428 Eigen::Vector3f tmp_tr = Eigen::Vector3f::Zero();
00429 const Slam::SWAY<Node> *n = &ctxt_->getPath().getLocal();
00430 int node_num=1;
00431 while(n)
00432 {
00433 tmp_tr = tmp_rot2*tmp_tr + n->link_.getTranslation();
00434 tmp_rot = ((Eigen::Matrix3f)n->link_.getRotation())*tmp_rot;
00435 tmp_rot2= ((Eigen::Matrix3f)n->link_.getRotation());
00436
00437 ::std_msgs::ColorRGBA col;
00438 {
00439 srand(node_num++);
00440 int rnd=rand();
00441 col.a=1;
00442 col.r=((rnd>>0)&0xff)/255.;
00443 col.g=((rnd>>8)&0xff)/255.;
00444 col.b=((rnd>>16)&0xff)/255.;
00445 }
00446
00447 marker_cont << cob_3d_marker::MarkerClean();
00448 marker_cont>>&marker_pub;
00449 marker_cont.clear();
00450 marker_cont<<new cob_3d_marker::MarkerList_Line(2)<<new cob_3d_marker::MarkerList_Arrow(3)<<new cob_3d_marker::MarkerList_Text(4)<<new cob_3d_marker::MarkerList_Text(5);
00451
00452 arm_navigation_msgs::CollisionMap collision_map;
00453
00454 for(size_t i=0; i<n->node_->getContext().getObjs().size(); i++)
00455 {
00456
00457 if(use_real_world_color_) {
00458 col = n->node_->getContext().getObjs()[i]->getData().getColor();
00459 changeSaturation(&col.r,&col.g,&col.b, 1.5f);
00460 }
00461
00462 geometry_msgs::Point line_p;
00463
00464 for(size_t j=0; j<n->node_->getContext().getObjs()[i]->getData().getPoints3D().size(); j++) {
00465 Eigen::Vector3f v = tmp_rot*n->node_->getContext().getObjs()[i]->getData().getPoints3D()[j]+tmp_tr;
00466 float edge = n->node_->getContext().getObjs()[i]->getData().getOutline()[j](2);
00467
00468 ::std_msgs::ColorRGBA col_out;
00469 col_out.a=1;
00470 col_out.g=0;
00471 col_out.r=edge;
00472 col_out.b=1-edge;
00473 line_p.x = v(0);
00474 line_p.y = v(1);
00475 line_p.z = v(2);
00476 marker_outline.points.push_back(line_p);
00477 marker_outline.colors.push_back(col_out);
00478
00479 v = tmp_rot*n->node_->getContext().getObjs()[i]->getData().getPoints3D()[(j+1)%n->node_->getContext().getObjs()[i]->getData().getPoints3D().size()]+tmp_tr;
00480 edge = n->node_->getContext().getObjs()[i]->getData().getOutline()[(j+1)%n->node_->getContext().getObjs()[i]->getData().getPoints3D().size()](2);
00481
00482 col_out.r=edge;
00483 col_out.b=1-edge;
00484 line_p.x = v(0);
00485 line_p.y = v(1);
00486 line_p.z = v(2);
00487 marker_outline.points.push_back(line_p);
00488 marker_outline.colors.push_back(col_out);
00489 }
00490
00491 std::vector<Eigen::Vector3f> tris;
00492 n->node_->getContext().getObjs()[i]->getData().getTriangles(tris);
00493
00494 for(size_t j=0; j<tris.size(); j++)
00495 {
00496 Eigen::Vector3f v=tmp_rot*tris[j]+tmp_tr;
00497 line_p.x = v(0);
00498 line_p.y = v(1);
00499 line_p.z = v(2);
00500 marker_map.points.push_back(line_p);
00501 marker_map.colors.push_back(col);
00502 }
00503
00504 if(dbg_show_grid_ && debug_pub_.getNumSubscribers()>0) {
00505 std::vector<std::vector<Eigen::Vector3f> > pts;
00506 n->node_->getContext().getObjs()[i]->getData().getControlPoints(pts);
00507 for(size_t j=0; j<pts.size(); j++)
00508 {
00509 for(size_t k=0; k<pts[j].size()-1; k++)
00510 {
00511 Eigen::Vector3f v=tmp_rot*pts[j][k]+tmp_tr;
00512 line_p.x = v(0);
00513 line_p.y = v(1);
00514 line_p.z = v(2);
00515 line_c=col;
00516 marker_dbg.points.push_back(line_p);
00517 marker_dbg.colors.push_back(line_c);
00518
00519 v=tmp_rot*pts[j][k+1]+tmp_tr;
00520 line_p.x = v(0);
00521 line_p.y = v(1);
00522 line_p.z = v(2);
00523 marker_dbg.points.push_back(line_p);
00524 marker_dbg.colors.push_back(line_c);
00525
00526 if(j+1!=pts.size()) {
00527 v=tmp_rot*pts[j][k]+tmp_tr;
00528 line_p.x = v(0);
00529 line_p.y = v(1);
00530 line_p.z = v(2);
00531 line_c=col;
00532 marker_dbg.points.push_back(line_p);
00533 marker_dbg.colors.push_back(line_c);
00534 v=tmp_rot*pts[j+1][k]+tmp_tr;
00535 line_p.x = v(0);
00536 line_p.y = v(1);
00537 line_p.z = v(2);
00538 line_c=col;
00539 marker_dbg.points.push_back(line_p);
00540 marker_dbg.colors.push_back(line_c);
00541 }
00542
00543 }
00544 }
00545 }
00546
00547
00548 if(debug2_pub_.getNumSubscribers()>0) {
00549 marker_cont<<n->node_->getContext().getObjs()[i]->getData().getSurface();
00550
00551 char buffer[128];
00552 static int nth=0;
00553 sprintf(buffer, "%d",nth++);
00554 n->node_->getContext().getObjs()[i]->getData().getOutline().debug_svg(buffer);
00555
00556 ((cob_3d_marker::MarkerList_Text*)marker_cont.get(5).get())->addText(n->node_->getContext().getObjs()[i]->getData().getNearestPoint(), buffer, 0.05f);
00557
00558 }
00559
00560
00561 {
00562 ::std_msgs::ColorRGBA col;
00563 col.g = col.r = col.b=0;
00564 if(n->node_->getContext().getObjs()[i]->getProcessed())
00565 col.g = 1.f;
00566 else
00567 col.b = 1.f;
00568
00569 addBB(marker_dbg, n->node_->getContext().getObjs()[i]->getData().getBB(), col, tmp_rot,tmp_tr);
00570 }
00571
00572 {
00573 arm_navigation_msgs::OrientedBoundingBox box;
00574
00575 box.center.x = n->node_->getContext().getObjs()[i]->getData().getBB().getCenter()(0);
00576 box.center.y = n->node_->getContext().getObjs()[i]->getData().getBB().getCenter()(1);
00577 box.center.z = n->node_->getContext().getObjs()[i]->getData().getBB().getCenter()(2);
00578
00579 box.extents.x = n->node_->getContext().getObjs()[i]->getData().getBB().getExtension()(0);
00580 box.extents.y = n->node_->getContext().getObjs()[i]->getData().getBB().getExtension()(1);
00581 box.extents.z = n->node_->getContext().getObjs()[i]->getData().getBB().getExtension()(2);
00582
00583 Eigen::AngleAxisf aa(n->node_->getContext().getObjs()[i]->getData().getBB().getAxis());
00584 box.axis.x = aa.axis()(0);
00585 box.axis.y = aa.axis()(1);
00586 box.axis.z = aa.axis()(2);
00587 box.angle = aa.angle();
00588
00589 collision_map.boxes.push_back(box);
00590 }
00591 }
00592 marker_cont>>&marker_pub;
00593
00594 collision_map.header = cpa->header;
00595
00596 if(collision_map_pub_.getNumSubscribers()>0)
00597 collision_map_pub_.publish(collision_map);
00598
00599
00600
00601 col.g = col.r = col.b=0;
00602 col.g = 1.f;
00603 col.b = 1.f;
00604
00605 if(node_num==2)
00606 {
00607 col.g = col.r = col.b=0;
00608 col.r = 1.f;
00609 }
00610
00611 addBB(marker_dbg, n->node_->getContext().getBoundingBox(), col, tmp_rot,tmp_tr);
00612
00613 size_t next_id = n->id_-1;
00614 const Slam::SWAY<Node> *n2 = NULL;
00615 for(size_t i=0; i<n->node_->getConnections().size(); i++)
00616 if(n->node_->getConnections()[i].id_ == next_id) {
00617 n2 = &n->node_->getConnections()[i];
00618 break;
00619 }
00620 n = n2;
00621
00622 }
00623
00624 std::cout<<"TF AFTER ALL\n"<<tmp_rot<<"\n"<<tmp_tr<<std::endl;
00625
00626 map_pub_.publish(marker_map);
00627 outline_pub_.publish(marker_outline);
00628
00629 if(debug_pub_.getNumSubscribers()>0) {
00630 marker_dbg.id = 3;
00631 marker_dbg.type = visualization_msgs::Marker::LINE_LIST;
00632 marker_dbg.scale.x = marker_dbg.scale.y = marker_dbg.scale.z = 0.005;
00633
00634
00635 geometry_msgs::Point line_p;
00636 pcl::PointXYZRGB p;
00637 Eigen::Vector3f from,to,temp;
00638 while(Debug::Interface::get().getArrow(from,to,p.r,p.g,p.b))
00639 {
00640 line_p.x = from(0);
00641 line_p.y = from(1);
00642 line_p.z = from(2);
00643 line_c.r=p.r/255.f;
00644 line_c.g=p.g/255.f;
00645 line_c.b=p.b/255.f;
00646 line_c.a=1;
00647
00648 marker_dbg.points.push_back(line_p);
00649 marker_dbg.colors.push_back(line_c);
00650 line_p.x = to(0);
00651 line_p.y = to(1);
00652 line_p.z = to(2);
00653
00654 marker_dbg.points.push_back(line_p);
00655 marker_dbg.colors.push_back(line_c);
00656 }
00657
00658
00659 {
00660 line_c.r=line_c.g=1;
00661 line_c.b=0;
00662
00663 Eigen::Vector3f mi,ma, ed[8];
00664 mi(0)=-0.43f;
00665 mi(1)=-0.36f;
00666 ma(0)=0.43f;
00667 ma(1)=0.36f;
00668 mi(2)=ma(2)=1.f;
00669
00670 for(int i=0; i<4; i++)
00671 ed[i]=mi;
00672
00673 ed[1](0)=ma(0);
00674 ed[2](0)=ma(0);
00675 ed[2](1)=ma(1);
00676 ed[3](1)=ma(1);
00677
00678 for(int i=0; i<4; i++) {
00679 ed[i+4]=ed[i];
00680 ed[i]*=0.4f;
00681 ed[i+4]*=8;}
00682
00683 Eigen::Vector3f t;
00684 t(0)=t(1)=0;
00685 t(2)=0.4f;
00686 for(int i=0; i<8; i++) ed[i] -= t;
00687
00688 for(int i=0; i<4; i++) {
00689 line_p.x = ed[i](0);
00690 line_p.y = ed[i](1);
00691 line_p.z = ed[i](2);
00692 marker_dbg.points.push_back(line_p);
00693 marker_dbg.colors.push_back(line_c);
00694 line_p.x = ed[(i+1)%4](0);
00695 line_p.y = ed[(i+1)%4](1);
00696 line_p.z = ed[(i+1)%4](2);
00697 marker_dbg.points.push_back(line_p);
00698 marker_dbg.colors.push_back(line_c);
00699 }
00700
00701 for(int i=0; i<4; i++) {
00702 line_p.x = ed[i+4](0);
00703 line_p.y = ed[i+4](1);
00704 line_p.z = ed[i+4](2);
00705 marker_dbg.points.push_back(line_p);
00706 marker_dbg.colors.push_back(line_c);
00707 line_p.x = ed[(i+1)%4+4](0);
00708 line_p.y = ed[(i+1)%4+4](1);
00709 line_p.z = ed[(i+1)%4+4](2);
00710 marker_dbg.points.push_back(line_p);
00711 marker_dbg.colors.push_back(line_c);
00712 }
00713
00714 for(int i=0; i<4; i++) {
00715 line_p.x = ed[i](0);
00716 line_p.y = ed[i](1);
00717 line_p.z = ed[i](2);
00718 marker_dbg.points.push_back(line_p);
00719 marker_dbg.colors.push_back(line_c);
00720 line_p.x = ed[i+4](0);
00721 line_p.y = ed[i+4](1);
00722 line_p.z = ed[i+4](2);
00723 marker_dbg.points.push_back(line_p);
00724 marker_dbg.colors.push_back(line_c);
00725 }
00726
00727 }
00728
00729 debug_pub_.publish(marker_dbg);
00730 }
00731
00732 lock = false;
00733
00734 ROS_ERROR("took %f", ros::Time::now().toSec()-start_time);
00735
00736 }
00737 private:
00738
00739 template<typename T>
00740 void addBB(visualization_msgs::Marker &marker_dbg, const T&bb, const ::std_msgs::ColorRGBA &col, const Eigen::Matrix3f &tmp_rot, const Eigen::Vector3f &tmp_tr) {
00741 geometry_msgs::Point line_p;
00742 Eigen::Vector3f edges[8];
00743
00744 bb.get8Edges(edges);
00745 for(int i=0; i<8; i++)
00746 edges[i] = tmp_rot*edges[i]+tmp_tr;
00747
00748 for(int i=0; i<4; i++)
00749 {
00750 line_p.x = edges[2*i](0);
00751 line_p.y = edges[2*i](1);
00752 line_p.z = edges[2*i](2);
00753 marker_dbg.points.push_back(line_p);
00754 marker_dbg.colors.push_back(col);
00755 line_p.x = edges[2*i+1](0);
00756 line_p.y = edges[2*i+1](1);
00757 line_p.z = edges[2*i+1](2);
00758 marker_dbg.points.push_back(line_p);
00759 marker_dbg.colors.push_back(col);
00760 }
00761
00762 int conv[]={0,1,4,5};
00763 for(int j=0; j<4; j++)
00764 {
00765 int i=conv[j];
00766 line_p.x = edges[i](0);
00767 line_p.y = edges[i](1);
00768 line_p.z = edges[i](2);
00769 marker_dbg.points.push_back(line_p);
00770 marker_dbg.colors.push_back(col);
00771 line_p.x = edges[i+2](0);
00772 line_p.y = edges[i+2](1);
00773 line_p.z = edges[i+2](2);
00774 marker_dbg.points.push_back(line_p);
00775 marker_dbg.colors.push_back(col);
00776 }
00777
00778 for(int i=0; i<4; i++)
00779 {
00780 line_p.x = edges[i](0);
00781 line_p.y = edges[i](1);
00782 line_p.z = edges[i](2);
00783 marker_dbg.points.push_back(line_p);
00784 marker_dbg.colors.push_back(col);
00785 line_p.x = edges[i+4](0);
00786 line_p.y = edges[i+4](1);
00787 line_p.z = edges[i+4](2);
00788 marker_dbg.points.push_back(line_p);
00789 marker_dbg.colors.push_back(col);
00790 }
00791 }
00792 };
00793
00794 #ifdef COMPILE_NODELET
00795
00796 typedef SLAM_Node<pcl::PointXYZ,pcl::PointXYZRGB,As_Nodelet> _SLAM_Nodelet;
00797
00798 PLUGINLIB_DECLARE_CLASS(cob_3d_mapping_slam, _SLAM_Nodelet, _SLAM_Nodelet, nodelet::Nodelet)
00799
00800 #else
00801
00802 int main(int argc, char **argv) {
00803 ros::init(argc, argv, "slam");
00804
00805 SLAM_Node<As_Node> sn;
00806 sn.onInit();
00807
00808 ros::spin();
00809
00810 return 0;
00811 }
00812
00813 #endif