summaryrefslogtreecommitdiff
path: root/src/calibration.h
blob: fd16404f636d7cfa91b6f7a86b609697a3f3677a (plain)
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
#pragma once

#include <array>

#include <QSharedPointer>

#include "constants.h"
#include "pixels.h"

namespace op {
using CalibrationColumn = std::array<float, calibrationTableHeight>;
// map [0; discretesInRage] (discretes) to [0; zRangeMm] (mm)
using CalibrationTable = std::array<CalibrationColumn, img_width>;
using CalibrationTablePtr = QSharedPointer<CalibrationTable>;

constexpr auto calibrationColumnHeight = std::tuple_size<CalibrationColumn>();

bool openCalibrationTable(const QString &filename, const CalibrationTablePtr table);

// void dumpCalibrationPixels(std::vector<Pixels> &&calibrationPixels);
enum class DumpFormat { Json, Binary };
void dumpCalibrationPixels(const std::vector<std::shared_ptr<Pixels> > &calibrationPixels,
                           const DumpFormat format = DumpFormat::Json);
bool dump(const CalibrationTablePtr &table, const QString &filename);

// TODO: implement median filter
/*!
 * \brief filter - N pixels at pos -> 1 avg pixels at pos
 */
QList<Pixels> filter(const QList<Pixels> &rawProfiles);

// TODO: move somewhere or combine with dumps.{h,cpp}
std::optional<Pixels> avgFilterAtPos(const std::vector<Pixels> &rawProfiles);
std::optional<Pixels> medianFilterAtPos(const std::vector<Pixels> &rawProfiles);

bool calibrateX(const QList<Pixels> &rawProfiles, CalibrationTablePtr table);
bool calibrateZ(const QList<Pixels> &rawProfiles,
                const uint32_t &stepsPerMm,
                CalibrationTablePtr table);

QImage calibrationTableToImage(const CalibrationTablePtr &calibrationTable);

void interpolate(const CalibrationTablePtr table);
void interpolate(CalibrationColumn &column);

// TODO: remove from this file
namespace {
// static CalibrationTablePtr calibrationTableZ;
// static CalibrationTablePtr calibrationTableX;
} // namespace
} // namespace op