-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern_search_result.h
86 lines (71 loc) · 1.5 KB
/
pattern_search_result.h
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
#pragma once
#include <vector>
#include <limits>
/////////////////////////////////////////////////////////////////////////////
//! \brief Pattern search result
class PsResult final
{
public:
int x; //!< \brief vector x component
int y; //!< \brief vector y component
double cost; //!< \brief cost
double quality; //!< \brief Difference between minimal and maximal cost in last search (quality criteria)
//! \brief Constructor
PsResult()
: x(0)
, y(0)
, cost(std::numeric_limits<double>::max())
, quality(0.0)
{
}
};
/////////////////////////////////////////////////////////////////////////////
//! \brief Pattern search result matrix / 2D array
template<typename T>
class PsArray2x2 final
{
public:
//! \brief Constructor
PsArray2x2()
: m_rows(0)
, m_cols(0)
, m_data()
{
}
//! \brief Constructor
explicit PsArray2x2(int rows, int cols)
: m_rows(rows)
, m_cols(cols)
{
m_data.resize(rows*cols);
}
//! \brief Number of rows (height)
__inline int rows() const
{
return m_rows;
}
//! \brief Number of columns (width)
__inline int cols() const
{
return m_cols;
}
//! \brief Get offset of row, col
__inline size_t offset(int row, int col) const
{
return (size_t)row * m_cols + col;
}
//! \brief Setter
__inline T &operator() (int row, int col)
{
return m_data[offset(row, col)];
}
//! \brief Getter
__inline const T &operator() (int row, int col) const
{
return m_data[offset(row, col)];
}
private:
int m_rows;
int m_cols;
std::vector<T> m_data;
};