utility.cpp 1.06 KB
Newer Older
Matteo Spanio's avatar
update    
Matteo Spanio committed
1
#include "utility.hpp"
Matteo's avatar
update  
Matteo committed
2
3

using namespace std;
Matteo Spanio's avatar
update    
Matteo Spanio committed
4
5
namespace fs = std::filesystem;
using json = nlohmann::json;
Matteo's avatar
update  
Matteo committed
6

Matteo Spanio's avatar
update    
Matteo Spanio committed
7
8
Threshold::Threshold(float percentual, int angle, int scale, int pos) {
    if (percentual < 0 || percentual > 100) throw std::invalid_argument("Percentual must be between 0 and 100");
Matteo's avatar
update  
Matteo committed
9

Matteo Spanio's avatar
update    
Matteo Spanio committed
10
11
12
13
    this->percentual = percentual;
    this->angle = angle;
    this->scale = scale;
    this->pos = pos;
Matteo's avatar
update  
Matteo committed
14
15
}

Matteo Spanio's avatar
update    
Matteo Spanio committed
16
17
18
SceneObject::SceneObject(int minDist, Threshold threshold) {
    this->minDist = minDist;
    this->threshold = threshold;
Matteo's avatar
update  
Matteo committed
19
20
}

Matteo Spanio's avatar
update    
Matteo Spanio committed
21
22
23
24
SceneObject SceneObject::from_file(fs::path path, ROI obj) {
    ifstream iConfig(path);
    json j;
    iConfig >> j;
Matteo's avatar
update  
Matteo committed
25

Matteo Spanio's avatar
update    
Matteo Spanio committed
26
27
28
29
30
31
    if (obj == ROI::TAPE) {
        return SceneObject(j["MinDist"],
                           Threshold(j["TapeThresholdPercentual"], j["AngleThresh"], j["ScaleThresh"], j["PosThresh"]));
    } else {
        return SceneObject(j["MinDistCapstan"], Threshold(j["CapstanThresholdPercentual"], j["AngleThreshCapstan"],
                                                          j["ScaleThreshCapstan"], j["PosThreshCapstan"]));
Matteo's avatar
update  
Matteo committed
32
33
    }
}