-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptiChain.h
120 lines (102 loc) · 3.04 KB
/
OptiChain.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
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
116
117
118
119
120
/*
Copyright © 2021 TokiNoBug
This file is part of SlopeCraft.
SlopeCraft is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SlopeCraft is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SlopeCraft. If not, see <https://www.gnu.org/licenses/>.
Contact with me:
github:https://github.com/ToKiNoBug
bilibili:https://space.bilibili.com/351429231
*/
#ifndef OPTICHAIN_H
#define OPTICHAIN_H
//#define showImg
#define removeQt
#include <iostream>
#include <string>
#include <Eigen/Dense>
#include <list>
#include <queue>
#ifndef removeQt
#include <QDebug>
#include <QRgb>
#include <QImage>
#include <QLabel>
#endif
using namespace std;
using namespace Eigen;
enum RegionType {idp,Hang,Invalid};
#ifndef removeQt
extern QRgb isTColor;
extern QRgb isFColor;
extern QRgb WaterColor;
extern QRgb greyColor;
#endif
class Region
{
public:
Region(short=-1,short=-1,RegionType=Invalid);
short Beg;
short End;
RegionType type;
bool isIDP() const;
bool isHang() const;
bool isValid() const;
int size() const;
short indexLocal2Global(short) const;
short indexGlobal2Local(short) const;
string toString() const;
};
class OptiChain
{
public:
//Index一律以Height矩阵中的索引为准。Height(r,c+1)<->Base(r,c)
//高度矩阵一律不含水柱顶的玻璃方块
OptiChain(int Size=-1);//default Random Constructor
OptiChain(const ArrayXi & base, const ArrayXi & High,const ArrayXi & Low);
~OptiChain();
void divideAndCompress();
const ArrayXi & getHighLine();
const ArrayXi & getLowLine();
//ArrayXi toDepth() const;
//static ArrayXXi Base;
static const Array3i Both;
static const Array3i Left;
static const Array3i Right;
#ifdef showImg
//static QLabel *SinkIDP;
static QLabel *SinkAll;
static bool AllowSinkHang;
#endif
private:
//int Col;
ArrayXi Base;
ArrayXi HighLine;
ArrayXi LowLine;
queue<Region> Chain;//将一整列按水/空气切分为若干个大的孤立区间
list<Region> SubChain;//将Chain中每个大的孤立区间切分为若干“最大单孤立区间”和“悬空区间”组成的串
void divideToChain();
void divideToSubChain();
bool isAir(int index) const;
bool isWater(int index) const;
bool isSolidBlock(int index) const;
void Sink(const Region&);
int validHeight(int index) const;
#ifndef removeQt
QImage toQImage(int pixelSize);
#endif
void dispSubChain() const;
//private:
void divideToSubChain(const Region&);
};
#ifndef removeQt
QImage Mat2Image(const ArrayXXi&,int pixelSize);
#endif
#endif // OPTICHAIN_H