forked from varoudis/depthmapX
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathspacepix.h
163 lines (138 loc) · 5.63 KB
/
spacepix.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// sala - a component of the depthmapX - spatial network analysis platform
// Copyright (C) 2011-2012, Tasos Varoudis
// Copyright (C) 2018, Petros Koutsolampros
// This program 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.
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
// This is my code to make a set of axial lines from a set of boundary lines
#pragma once
#include "salalib/pafcolor.h"
#include "salalib/pixelref.h"
#include "genlib/p2dpoly.h"
#include "genlib/pafmath.h"
#include "genlib/simplematrix.h"
#include "genlib/stringutils.h"
#include <deque>
#include <map>
class SalaShape;
class PixelBase {
protected:
size_t m_rows;
size_t m_cols;
QtRegion m_region;
public:
PixelBase() { ; }
// constrain is constrain to bounding box (i.e., in row / col bounds)
virtual PixelRef pixelate(const Point2f &, bool constrain = true, int scalefactor = 1) const = 0;
PixelRefVector pixelateLine(Line l, int scalefactor = 1) const;
PixelRefVector pixelateLineTouching(Line l, double tolerance) const;
PixelRefVector quickPixelateLine(PixelRef p, PixelRef q);
bool includes(const PixelRef pix) const { return (pix.x >= 0 && pix.x < static_cast<short>(m_cols) &&
pix.y >= 0 && pix.y < static_cast<short>(m_rows)); }
size_t getCols() const { return m_cols; }
size_t getRows() const { return m_rows; }
const QtRegion &getRegion() const { return m_region; }
};
/////////////////////////////////////////////
// couple of quick helpers
struct LineTest {
Line line;
unsigned int test;
LineTest(const Line &l = Line(), int t = -1) {
line = l;
test = t;
}
// operator Line() {return line;}
};
struct LineKey {
unsigned int file : 4;
unsigned int layer : 6;
unsigned int lineref : 20;
operator int() { return *(int *)this; }
LineKey(int value = 0) { *(int *)this = value; }
friend bool operator<(LineKey a, LineKey b);
friend bool operator>(LineKey a, LineKey b);
friend bool operator==(LineKey a, LineKey b);
};
inline bool operator<(LineKey a, LineKey b) { return int(a) < int(b); }
inline bool operator>(LineKey a, LineKey b) { return int(a) > int(b); }
inline bool operator==(LineKey a, LineKey b) { return int(a) == int(b); }
/////////////////////////////////////////////
class SpacePixel : public PixelBase {
friend class PointMap;
friend class AxialMaps;
friend class AxialPolygons;
friend class ShapeMap; // for transfer to everything being ShapeMaps
protected:
bool m_lock;
mutable bool m_newline;
protected:
PafColor m_color;
int m_style; // allows for bold / dotted lines etc
std::string m_name;
bool m_show;
bool m_edit;
depthmapX::RowMatrix<std::vector<int>> m_pixel_lines;
int m_ref;
std::map<int, LineTest> m_lines;
//
// for screen drawing
mutable std::vector<int> m_display_lines;
mutable int m_current;
//
// for line testing
mutable unsigned int m_test;
//
public:
SpacePixel(const std::string &name = std::string("Default"));
//
SpacePixel(const SpacePixel &spacepixel);
SpacePixel &operator=(const SpacePixel &spacepixel);
void construct(const SpacePixel &spacepixel);
//
PixelRef pixelate(const Point2f &p, bool constrain = true, int = 1) const;
// PixelRefVector pixelate( const Line& l ) const;
//
void initLines(int size, const Point2f &min, const Point2f &max, double density = 1.0);
void reinitLines(double density); // just reinitialises pixel lines, keeps lines, current ref and test setting
//
void addLine(const Line &l);
void sortPixelLines();
//
int addLineDynamic(const Line &l);
virtual void makeViewportLines(const QtRegion &viewport) const;
virtual bool findNextLine(bool &) const;
virtual const Line &getNextLine() const;
//
bool intersect(const Line &l, double tolerance = 0.0);
bool intersect_exclude(const Line &l, double tolerance = 0.0);
void cutLine(Line &l, short dir);
QtRegion &getRegion() const { return (QtRegion &)m_region; }
void setRegion(QtRegion ®ion) { m_region = region; }
//
const std::map<int, LineTest> &getAllLines() const // Danger! Use solely to look at the raw line data
{
return m_lines;
}
//
// For easy layer manipulation:
void setName(const std::string &name) { m_name = name; }
std::string getName() { return m_name; }
void setShow(bool show = true) { m_show = show; }
bool isShown() const { return m_show; }
void setEditable(bool edit = true) { m_edit = edit; }
bool isEditable() const { return m_edit; }
public:
virtual bool read(std::istream &stream);
virtual bool write(std::ofstream &stream);
friend bool operator==(const SpacePixel &a, const SpacePixel &b);
};
// simply check they are the same name... useful for findindex from the group
inline bool operator==(const SpacePixel &a, const SpacePixel &b) { return a.m_name == b.m_name; }