@@ -1383,11 +1383,13 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
13831383 reint_options.linear_solver_type = ceres::SPARSE_NORMAL_CHOLESKY;
13841384 reint_options.minimizer_progress_to_stdout = false ;
13851385 reint_options.max_num_iterations = 50 ;
1386+ // reint_options.enable_fast_removal = true;
13861387 eigenquaternion_parameterization = new ceres::EigenQuaternionParameterization;
13871388 // robust_norm = new ceres::CauchyLoss(1.0);
13881389 robust_norm = new ceres::HuberLoss (0.1 );
13891390
13901391 std::map< int , std::tuple<int ,int > > changes_to_setid_on_set_union; // key:= worldID, value:= (prev setID of this world, new setID of this world).
1392+ vector<ceres::ResidualBlockId> regularization_terms_list;
13911393
13921394
13931395 while ( reinit_ceres_problem_onnewloopedge_optimize6DOF_isEnabled )
@@ -1855,19 +1857,43 @@ void PoseGraphSLAM::reinit_ceres_problem_onnewloopedge_optimize6DOF()
18551857
18561858
18571859 // -----------------------------
1858- // Mark nodes as constant. Possibly also need to mark starts of each worlds as constants.
1860+ // Mark nodes as constant. Possibly also need to mark starts of each worlds as constants. Can also try setting each sets 1st node as constant.
18591861 // ------------------------------
1862+ for ( int v=0 ; v<regularization_terms_list.size () ; v++ ) {
1863+ reint_problem.RemoveResidualBlock ( regularization_terms_list[v] );
1864+ cout << " Remove " << v << " th regularization term\n " ;
1865+ }
1866+ regularization_terms_list.clear ();
1867+
18601868 std::map< int , bool > mark_as_constant;
18611869 // mark_as_constant[0] = true;
18621870 mark_as_constant[1 ] = true ;
18631871 for ( int ww=0 ; ww<manager->n_worlds (); ww++ ) {
1864- if ( mark_as_constant.count (ww) ==0 )
1865- continue ;
1872+ // if( mark_as_constant.count(ww) ==0 )
1873+ // continue;
1874+ int ww_setid = manager->getWorldsConstPtr ()->find_setID_of_world_i (ww);
1875+ cout << " &&&&&&&&&&&&world#" << ww << " is in setID=" << ww_setid << endl;
1876+ if ( ww_setid >= 0 && ww_setid==ww ) {
1877+
1878+
18661879 int ww_start = manager->nodeidx_of_world_i_started ( ww );
1867- reint_problem.SetParameterBlockConstant ( get_raw_ptr_to_opt_variable_q (ww_start) );
1868- reint_problem.SetParameterBlockConstant ( get_raw_ptr_to_opt_variable_t (ww_start) );
1869- cout << " Mark node#" << ww_start << " as constant\n " ;
1880+ // reint_problem.SetParameterBlockConstant( get_raw_ptr_to_opt_variable_q(ww_start) );
1881+ // reint_problem.SetParameterBlockConstant( get_raw_ptr_to_opt_variable_t(ww_start) );
1882+
1883+ ceres::CostFunction * regularixa_cost = NodePoseRegularization::Create ( getNodePose (ww_start), 1.2 );
1884+ ceres::ResidualBlockId resi_id = reint_problem.AddResidualBlock ( regularixa_cost, NULL , get_raw_ptr_to_opt_variable_q (ww_start), get_raw_ptr_to_opt_variable_t (ww_start) );
1885+ regularization_terms_list.push_back ( resi_id );
1886+
1887+ cout << " node#" << ww_start << " is in world#" << ww << " which has setID as " << ww_setid << endl;
1888+ cout << " Mark node#" << ww_start << " as constant. \n " ;
1889+ }
1890+ else
1891+ cout << " skip\n " ;
18701892 }
1893+ cout << " Total elements in `regularization_terms_list` = " << regularization_terms_list.size () << endl;
1894+
1895+
1896+
18711897
18721898
18731899 // -----------------------
0 commit comments