-
Notifications
You must be signed in to change notification settings - Fork 0
/
left_ventricle.cpp
66 lines (54 loc) · 1.8 KB
/
left_ventricle.cpp
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <cmath>
#include "left_ventricle.h"
void LeftVentricle::load (const std::string& filename)
{
std::cerr << "loading data in file \"" << filename << "\"" << std::endl;
std::ifstream in;
in.open (filename);
if (!in)
throw std::runtime_error ("error opening file \"" + filename + "\"");
std::string line;
std::getline (in, line);
std::istringstream stream (line);
stream >> time_resolution;
std::cerr << "time resolution: " << time_resolution << std::endl;
int num_vals = -1;
while (in) {
std::getline (in, line);
if (!in)
break;
std::istringstream stream (line);
double val;
std::vector<double> disp;
while (stream >> val)
disp.push_back (val);
if (disp.size() == 0)
continue;
if (num_vals < 0)
num_vals = disp.size();
else {
if (num_vals != disp.size())
throw std::runtime_error ("malformed data in file \"" + filename + "\"");
}
segments.push_back (Segment (disp));
}
std::cerr << "loaded " << segments.size() << " segments" << std::endl;
}
double LeftVentricle::get_std_dev_TTP_displacement () const
{
std::vector<double> ttp (segments.size());
for (unsigned int n = 0; n < ttp.size(); ++n)
ttp[n] = segments[n].get_index_of_peak_displacement() * time_resolution;
double sum = 0.0;
for (unsigned int n = 0; n < ttp.size(); ++n)
sum += ttp[n];
double mean = sum / ttp.size();
sum = 0.0;
for (unsigned int n = 0; n < ttp.size(); ++n)
sum += pow (ttp[n] - mean, 2);
return sqrt (sum / (ttp.size()-1));
}