1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::{collections::BTreeMap, sync::Arc};

use crate::{tracking_core::HypothesisTest, CamAndDist, HypothesisTestResult};
use flydra_types::{MyFloat, RawCamName, TrackingParams};

#[derive(Clone)]
pub(crate) struct NewObjectTestFlat3D {
    recon: flydra_mvg::FlydraMultiCameraSystem<MyFloat>,
}

impl NewObjectTestFlat3D {
    pub(crate) fn new(
        recon: flydra_mvg::FlydraMultiCameraSystem<MyFloat>,
        _params: Arc<TrackingParams>,
    ) -> Self {
        // `_params` is unused but required to have the same type signature as
        // the 3d version.
        Self { recon }
    }
}

impl HypothesisTest for NewObjectTestFlat3D {
    fn hypothesis_test(
        &self,
        good_points: &BTreeMap<RawCamName, mvg::DistortedPixel<MyFloat>>,
    ) -> Option<HypothesisTestResult> {
        let recon_ref = &self.recon;
        assert!(good_points.len() < 2, "cannot have >1 camera for Flat3D");
        if let Some((cam_name, xy)) = good_points.iter().next() {
            let cam = recon_ref.cam_by_name(cam_name.as_str()).unwrap();
            if let Some(surface_pt) = crate::flat_2d::distorted_2d_to_flat_3d(&cam, xy) {
                let cams_and_reproj_dist = vec![CamAndDist {
                    raw_cam_name: cam_name.clone(),
                    reproj_dist: 0.0,
                }];
                return Some(HypothesisTestResult {
                    coords: surface_pt,
                    cams_and_reproj_dist,
                });
            }
        }
        None
    }
}