|
1 | | -use std::collections::HashMap; |
2 | | -use std::fs::read_to_string; |
3 | 1 | use std::time::Instant; |
4 | 2 |
|
5 | | -use nalgebra as na; |
6 | 3 | use plotters::prelude::*; |
7 | 4 |
|
8 | | -use tiny_solver::{ |
9 | | - factors, loss_functions::HuberLoss, optimizer::Optimizer, problem, GaussNewtonOptimizer, |
10 | | -}; |
11 | | - |
12 | | -fn read_g2o(filename: &str) -> (problem::Problem, HashMap<String, na::DVector<f64>>) { |
13 | | - let mut problem = problem::Problem::new(); |
14 | | - let mut init_values = HashMap::<String, na::DVector<f64>>::new(); |
15 | | - for line in read_to_string(filename).unwrap().lines() { |
16 | | - let line: Vec<&str> = line.split(' ').collect(); |
17 | | - match line[0] { |
18 | | - "VERTEX_SE2" => { |
19 | | - let x = line[2].parse::<f64>().unwrap(); |
20 | | - let y = line[3].parse::<f64>().unwrap(); |
21 | | - let theta = line[4].parse::<f64>().unwrap(); |
22 | | - init_values.insert(format!("x{}", line[1]), na::dvector![theta, x, y]); |
23 | | - } |
24 | | - "EDGE_SE2" => { |
25 | | - let id0 = format!("x{}", line[1]); |
26 | | - let id1 = format!("x{}", line[2]); |
27 | | - let dx = line[3].parse::<f64>().unwrap(); |
28 | | - let dy = line[4].parse::<f64>().unwrap(); |
29 | | - let dtheta = line[5].parse::<f64>().unwrap(); |
30 | | - // todo add info matrix |
31 | | - let edge = factors::BetweenFactorSE2 { dx, dy, dtheta }; |
32 | | - problem.add_residual_block( |
33 | | - 3, |
34 | | - &[(&id0, 3), (&id1, 3)], |
35 | | - Box::new(edge), |
36 | | - Some(Box::new(HuberLoss::new(1.0))), |
37 | | - ); |
38 | | - } |
39 | | - _ => { |
40 | | - println!("err"); |
41 | | - break; |
42 | | - } |
43 | | - } |
44 | | - } |
45 | | - let origin_factor = factors::PriorFactor { |
46 | | - v: na::dvector![0.0, 0.0, 0.0], |
47 | | - }; |
48 | | - problem.add_residual_block( |
49 | | - 3, |
50 | | - &[("x0", 3)], |
51 | | - Box::new(origin_factor), |
52 | | - Some(Box::new(HuberLoss::new(1.0))), |
53 | | - ); |
54 | | - (problem, init_values) |
55 | | -} |
| 5 | +use tiny_solver::{helper::read_g2o, optimizer::Optimizer, GaussNewtonOptimizer}; |
56 | 6 |
|
57 | 7 | fn main() { |
58 | 8 | // init logger |
|
0 commit comments