-
Notifications
You must be signed in to change notification settings - Fork 4
/
pipeline.hpp
115 lines (78 loc) · 2.31 KB
/
pipeline.hpp
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
#pragma once
#include <iostream>
#include <functional>
#include <filesystem>
#include <map>
#include <fstream>
#include <sstream>
#include <string>
#include "ply.hpp"
#include "common.hpp"
#include "fastsamplefilter.hpp"
#include "fastoutlierfilter.hpp"
namespace fs = std::filesystem;
namespace FPCFilter
{
class Pipeline
{
std::unique_ptr<PlyFile> ply;
std::ostream& log;
std::string source;
bool isLoaded = false;
bool isVerbose = false;
public:
Pipeline(const std::string &source, std::ostream& logstream, const bool verbose) : source(source), isVerbose(verbose), log(logstream) {}
void load()
{
const auto start = std::chrono::steady_clock::now();
this->ply = std::make_unique<PlyFile>(this->source);
this->isLoaded = true;
if (this->isVerbose) {
const std::chrono::duration<double> diff = std::chrono::steady_clock::now() - start;
log << " ?> Loaded " << this->ply->points.size() << " points in " << diff.count() << "s" << std::endl;
}
}
void crop(const Polygon &p)
{
if (!this->isLoaded)
{
const auto start = std::chrono::steady_clock::now();
this->ply = std::make_unique<PlyFile>(this->source, [&p](const float x, const float y, const float z)
{ return p.inside(x, y); });
this->isLoaded = true;
if (this->isVerbose) {
const std::chrono::duration<double> diff = std::chrono::steady_clock::now() - start;
log << " ?> Loaded " << this->ply->points.size() << " points (cropped) in " << diff.count() << "s" << std::endl;
}
return;
}
throw NotImplementedException("Filtering loaded ply is not supported");
}
void sample(double radius)
{
if (!this->isLoaded)
this->load();
FastSampleFilter filter(radius, this->log, this->isVerbose);
filter.run(*this->ply);
}
void filter(double std, int meank)
{
if (!this->isLoaded)
this->load();
FastOutlierFilter filter(std, meank, this->log, this->isVerbose);
filter.run(*this->ply);
}
void write(const std::string &target)
{
if (!this->isLoaded)
this->load();
if (fs::exists(target))
fs::remove(target);
std::ofstream writer(target, std::ofstream::binary);
if (!writer.is_open())
throw std::invalid_argument(std::string("Cannot open file ") + target);
this->ply->write(writer);
writer.close();
};
};
}