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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use {CameraCalibration, Error, MountCalibration, Project, Result};
use nalgebra::Projective3;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct ScanPosition {
pub name: String,
pub images: HashMap<String, Image>,
pub sop: Projective3<f64>,
pub scans: HashMap<String, Scan>,
}
#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct Scan {
pub name: String,
pub file: String,
pub phi_count: usize,
pub theta_count: usize,
}
#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct Image {
pub name: String,
pub cop: Projective3<f64>,
pub camera_calibration_name: String,
pub mount_calibration_name: String,
}
impl ScanPosition {
pub fn image_from_path<P: AsRef<Path>>(&self, path: P) -> Result<&Image> {
use Error;
path.as_ref()
.file_stem()
.map(|file_stem| file_stem.to_string_lossy())
.and_then(|file_stem| self.images.get(file_stem.as_ref()))
.ok_or_else(|| Error::ImageFromPath(path.as_ref().to_path_buf()))
}
pub fn singlescan_rxp_paths(&self, project: &Project) -> Vec<PathBuf> {
let mut path = project
.path
.parent()
.expect("Project path should always have a parent")
.to_path_buf();
path.push("SCANS");
path.push(&self.name);
path.push("SINGLESCANS");
self.scans
.values()
.map(|scan| {
let mut path = path.clone();
path.push(&scan.file);
path
})
.collect()
}
}
impl Image {
pub fn camera_calibration<'a>(&self, project: &'a Project) -> Result<&'a CameraCalibration> {
project
.camera_calibrations
.get(&self.camera_calibration_name)
.ok_or_else(|| {
Error::MissingCameraCalibration(self.camera_calibration_name.clone())
})
}
pub fn mount_calibration<'a>(&self, project: &'a Project) -> Result<&'a MountCalibration> {
project
.mount_calibrations
.get(&self.mount_calibration_name)
.ok_or_else(|| {
Error::MissingMountCalibration(self.mount_calibration_name.clone())
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn scan_position_singlescan_rxp_paths() {
let project = Project::from_path("data/project.RiSCAN").unwrap();
let scan_position = project.scan_positions.get("SP01").unwrap();
let paths = scan_position.singlescan_rxp_paths(&project);
assert_eq!(4, paths.len());
}
}