diff --git a/gtsam_unstable/examples/SmartProjectionFactorTesting.cpp b/gtsam_unstable/examples/SmartProjectionFactorTesting.cpp index 5a09b38e1..8189985ba 100644 --- a/gtsam_unstable/examples/SmartProjectionFactorTesting.cpp +++ b/gtsam_unstable/examples/SmartProjectionFactorTesting.cpp @@ -58,7 +58,7 @@ using namespace gtsam; using namespace boost::assign; namespace NM = gtsam::noiseModel; -// #define USE_BUNDLER + #define USE_BUNDLER using symbol_shorthand::X; using symbol_shorthand::L; @@ -109,8 +109,38 @@ void writeValues(string directory_, const Values& values){ fout << endl; } fout.close(); + } // end of if on landmarks +} + +// Write key values to file +void writeValuesBAL(string directory_, const Values& values, std::vector vector_r, std::vector vector_l, + std::vector vector_u, std::vector vector_v, int totNumPoses, int totNumLandmarks, int totNumMeasurements){ + + string filename = directory_ + "est_BAL_poses.txt"; + ofstream fout; + fout.open(filename.c_str()); + fout.precision(20); + + fout << totNumPoses << " " << totNumLandmarks << " " << totNumMeasurements << endl; + + for(size_t i=0; i::value_type key_value, values.filter()) { + Pose3 CurrPose = key_value.value; + fout << Pose3::Logmap(CurrPose) << endl; + } + if(values.filter().size() > 0) { + // write landmarks + BOOST_FOREACH(Values::ConstFiltered::value_type key_value, values.filter()) { + fout << key_value.value.vector() << endl; + } + fout.close(); + } // end of if on landmarks + } void optimizeGraphLM(NonlinearFactorGraph &graph, gtsam::Values::shared_ptr graphValues, Values &result, boost::shared_ptr &ordering) { @@ -326,6 +356,7 @@ int main(int argc, char** argv) { fin >> rotx >> roty >> rotz >> x >> y >> z >> f >> k1 >> k2; #ifdef USE_BUNDLER boost::shared_ptr Kbundler(new Cal3Bundler(f, k1, k2, 0.0, 0.0)); + // cout << k1 << " " << k2 << endl; K_cameras.push_back(Kbundler); #else boost::shared_ptr K_S2(new Cal3_S2(f, f, 0.0, 0.0, 0.0)); @@ -437,6 +468,8 @@ int main(int argc, char** argv) { cout << "===================================================" << endl; writeValues("./", result); + writeValuesBAL("./", result, vector_r, vector_l, vector_u, vector_v, totNumPoses, totNumLandmarks, totNumMeasurements); + if (debug) cout << numLandmarks << " " << numPoses << " " << optimized << endl; exit(0);