@@ -345,6 +345,7 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
345345{
346346
347347 ros::Rate loop_rate (20 );
348+ // ros::Rate loop_rate(5);
348349 map<int , vector<Matrix4d> > jmb;
349350 vector< Vector3d > lbm; // a corrected poses. Same index as the node. These are used for loopedges.
350351 while ( ros::ok () )
@@ -365,31 +366,57 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
365366 int ____solvedUntil = slam->solvedUntil (); // note: solvedUntil is the index until which posegraph was solved
366367 int ____solvedUntil_worldid = manager->which_world_is_this ( manager->getNodeTimestamp (____solvedUntil) );
367368 bool ____solvedUntil_worldid_is_neg = false ;
368- if ( ____solvedUntil_worldid < 0 ) { ____solvedUntil_worldid = -____solvedUntil_worldid - 1 ; ____solvedUntil_worldid_is_neg=true ; }
369+ if ( ____solvedUntil_worldid < 0 ) { /* ____solvedUntil_worldid = -____solvedUntil_worldid - 1;*/ ____solvedUntil_worldid_is_neg=true ; }
369370 // cerr << "\t[opt_traj_publisher_colored_by_world] slam->solvedUntil=" << ____solvedUntil << " ____solvedUntil_worldid" << ____solvedUntil_worldid << endl;
370371
372+ // cout << "[opt_traj_publisher_colored_by_world] i=0" << " i<"<<manager->getNodeLen() ;
373+ // cout << "____solvedUntil=" << ____solvedUntil << " ____solvedUntil_worldid=" << ____solvedUntil_worldid << endl;
371374 for ( int i=0 ; i<manager->getNodeLen () ; i++ )
372375 {
373376 int world_id = manager->which_world_is_this ( manager->getNodeTimestamp (i) );
377+ // cout << "i=" << i << " world#" << world_id << endl;// << " w_TM_i=" << PoseManipUtils::prettyprintMatrix4d( w_TM_i ) << endl;
374378
375379 // i>=0 and i<solvedUntil()
376380 if ( i>=0 && i<= ____solvedUntil ) {
377- Matrix4d w_T_c_optimized, w_T_c;
381+ // Matrix4d w_T_c_optimized;
382+ Matrix4d w_T_c;
378383
379384 // cerr << "world_id=" << world_id << " ";
380385 // cerr << "slam->nodePoseExists("<< i << ") " << slam->nodePoseExists(i) << " ";
381386 // cerr << "manager->nodePoseExists(" << i << ") " << manager->nodePoseExists(i ) << " \n";
382387
383388
384389 // If the optimized pose exists use that else use the odometry pose
385- if ( slam->nodePoseExists (i) ) {
386- w_T_c = slam->getNodePose ( i );
387- // cerr << "w_T_c_optimized=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
388- } else {
389- if ( manager->nodePoseExists (i ) ) {
390- w_T_c = manager->getNodePose ( i );
391- // cerr << "w_T_c=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
390+ int from_slam_or_from_odom = -1 ;
391+ if ( world_id >= 0 ) {
392+ if ( slam->nodePoseExists (i) ) {
393+ w_T_c = slam->getNodePose ( i );
394+ // cerr << "w_T_c_optimized=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
395+ from_slam_or_from_odom = 1 ;
396+ } else {
397+ if ( manager->nodePoseExists (i ) ) {
398+ w_T_c = manager->getNodePose ( i );
399+ // cerr << "w_T_c=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
400+ from_slam_or_from_odom = 2 ;
401+ }
392402 }
403+ } else {
404+ // kidnapped worlds viz, -1, -2 etc.
405+ // use the last pose and add the odometry to it
406+ // TODO
407+ from_slam_or_from_odom = 3 ;
408+
409+ int last_idx = manager->nodeidx_of_world_i_ended ( -world_id - 1 );
410+ Matrix4d w_T_last;
411+ // if( slam->nodePoseExists(i) )
412+ // w_T_last = slam->getNodePose(last_idx );
413+ // else
414+ // w_T_last = manager->getNodePose(last_idx );
415+ w_T_last = *(jmb.at ( -world_id - 1 ).rbegin ());
416+ Matrix4d last_M_i = manager->getNodePose ( last_idx ).inverse () * manager->getNodePose ( i );
417+ w_T_c = w_T_last * last_M_i;
418+
419+
393420 }
394421
395422
@@ -399,6 +426,7 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
399426 jmb[ world_id ].push_back ( w_T_c );
400427 lbm.push_back ( w_T_c.col (3 ).topRows (3 ) );
401428 latest_pose_worldid = world_id;
429+ // cout << " (from_slam_or_from_odom=" << from_slam_or_from_odom << " w_T_c=" << PoseManipUtils::prettyprintMatrix4d( w_T_c ) << endl;
402430
403431 }
404432
@@ -409,21 +437,7 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
409437 int last_idx=-1 ;
410438 Matrix4d w_TM_i;
411439
412- /*
413- if( ____solvedUntil == 0 ) {
414- w_TM_i = manager->getNodePose( i );
415- } else if( world_id < 0 ) {
416- last_idx = manager->nodeidx_of_world_i_ended( -world_id-1 );
417- } else if(world_id == ____solvedUntil_worldid && ____solvedUntil_worldid_is_neg==false) {
418- last_idx = ____solvedUntil;
419- }
420- else if(world_id == ____solvedUntil_worldid && ____solvedUntil_worldid_is_neg==true) {
421- last_idx = ____solvedUntil;
422- } else {
423- // last_idx = manager->nodeidx_of_world_i_started( world_id );
424- w_TM_i = manager->getNodePose( i );
425- }
426- */
440+
427441
428442 if ( ____solvedUntil == 0 ) {
429443 w_TM_i = manager->getNodePose ( i );
@@ -437,7 +451,7 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
437451 last_idx = manager->nodeidx_of_world_i_ended ( -world_id - 1 );
438452 // cout << "last_idx=" << last_idx << endl;
439453 } else {
440- cout << " opt_traj_publisher_colored_by_world impossivle" ;
454+ cout << " \n opt_traj_publisher_colored_by_world impossivle\n " ;
441455 exit (2 );
442456 }
443457
@@ -459,9 +473,12 @@ void opt_traj_publisher_colored_by_world( const NodeDataManager * manager, const
459473 if ( jmb.count ( world_id ) == 0 )
460474 jmb[ world_id ] = vector<Matrix4d>();
461475
476+
477+
462478 jmb[ world_id ].push_back ( w_TM_i );
463479 lbm.push_back ( w_TM_i.col (3 ).topRows (3 ) );
464480 latest_pose_worldid = world_id;
481+ // cout << " w_TM_i=" << PoseManipUtils::prettyprintMatrix4d( w_TM_i ) << " last_idx="<< last_idx << endl;
465482 }
466483
467484
0 commit comments