forked from varoudis/depthmapX
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathngraph.h
188 lines (174 loc) · 5.66 KB
/
ngraph.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// sala - a component of the depthmapX - spatial network analysis platform
// Copyright (C) 2011-2012, Tasos Varoudis
// 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/>.
// ngraph.h
#pragma once
#include "salalib/pixelref.h"
#include <set>
class PointMap;
struct MetricPair;
struct MetricTriple;
struct AngularTriple;
struct PixelVec
{
PixelRef m_start;
PixelRef m_end;
PixelVec(const PixelRef start = NoPixel, const PixelRef end = NoPixel)
{ m_start = (int) start; m_end = (int) end; };
PixelRef start() const
{ return m_start; }
PixelRef end() const
{ return m_end; }
//
std::istream &read(std::istream &stream, const char dir);
std::istream &read(std::istream &stream, const char dir, const PixelVec& context);
std::ostream &write(std::ostream &stream, const char dir);
std::ostream &write(std::ostream &stream, const char dir, const PixelVec& context);
};
class Bin
{
friend class Node;
protected:
unsigned short m_node_count;
float m_distance;
float m_occ_distance;
public:
char m_dir;
std::vector<PixelVec> m_pixel_vecs;
Bin()
{ m_dir = PixelRef::NODIR; m_node_count = 0; m_distance = 0.0f; m_occ_distance = 0.0f; }
//
void make(const PixelRefVector& pixels, char m_dir);
void extractUnseen(PixelRefVector& pixels, PointMap *pointdata, int binmark);
void extractMetric(std::set<MetricTriple> &pixels, PointMap *pointdata, const MetricTriple& curs);
void extractAngular(std::set<AngularTriple> &pixels, PointMap *pointdata, const AngularTriple& curs);
//
int count() const
{ return m_node_count; }
float distance() const
{ return m_distance; }
float occdistance() const
{ return m_occ_distance; }
//
void setOccDistance(float d)
{ m_occ_distance = d; }
//
bool containsPoint(const PixelRef p) const;
//
// Iterator
protected:
// Conversion back to old fashioned schema:
mutable int m_curvec;
mutable PixelRef m_curpix;
public:
void first() const;
void next() const;
bool is_tail() const;
PixelRef cursor() const;
//
std::istream &read(std::istream &stream);
std::ostream &write(std::ostream &stream);
//
friend std::ostream& operator << (std::ostream& stream, const Bin& bin);
};
class Node
{
protected:
PixelRef m_pixel;
Bin m_bins[32];
public:
// testing some agent stuff:
std::vector<PixelRef> m_occlusion_bins[32];
public:
// Note: this function clears the bins as it goes
void make(const PixelRef pix, PixelRefVector *bins, float *bin_far_dists, int q_octants);
void extractUnseen(PixelRefVector& pixels, PointMap *pointdata);
void extractMetric(std::set<MetricTriple> &pixels, PointMap *pointdata, const MetricTriple& curs);
void extractAngular(std::set<AngularTriple> &pixels, PointMap *pointdata, const AngularTriple& curs);
bool concaveConnected();
bool fullyConnected();
//
void setPixel(const PixelRef& pixel)
{ m_pixel = pixel; }
//
const Bin& bin(int i) const
{ return m_bins[i]; }
Bin& bin(int i)
{ return m_bins[i]; }
//
int count()
{ int c = 0; for (int i = 0; i < 32; i++) c += m_bins[i].count(); return c; }
int bincount(int i)
{ return m_bins[i].count(); }
float bindistance(int i)
{ return m_bins[i].distance(); }
void setbindistances(float bin_dists[32])
{ for (int i = 0; i < 32; i++) m_bins[i].m_distance = bin_dists[i]; }
float occdistance(int i)
{ return m_bins[i].occdistance(); }
//
bool containsPoint(const PixelRef p) const;
//
//
// Iterator:
protected:
// Conversion back to old fashioned schema:
mutable int m_curbin;
public:
void contents(PixelRefVector& hood) const;
void first() const;
void next() const;
bool is_tail() const;
PixelRef cursor() const;
//
std::istream &read(std::istream &stream);
std::ostream &write(std::ostream &stream);
//
friend std::ostream& operator << (std::ostream& stream, const Node& node);
};
// Two little helpers:
class PixelRefH : public PixelRef
{
public:
PixelRefH() : PixelRef()
{;}
PixelRefH(const PixelRef& p) : PixelRef(p)
{;}
friend bool operator > (const PixelRefH& a, const PixelRefH& b);
friend bool operator < (const PixelRefH& a, const PixelRefH& b);
};
inline bool operator > (const PixelRefH& a, const PixelRefH& b)
{
return (a.y > b.y || (a.y == b.y && a.x > b.x));
}
inline bool operator < (const PixelRefH& a, const PixelRefH& b)
{
return (a.y < b.y || (a.y == b.y && a.x < b.x));
}
class PixelRefV : public PixelRef
{
public:
PixelRefV() : PixelRef()
{;}
PixelRefV(const PixelRef& p) : PixelRef(p)
{;}
friend bool operator > (const PixelRefV& a, const PixelRefV& b);
friend bool operator < (const PixelRefV& a, const PixelRefV& b);
};
inline bool operator > (const PixelRefV& a, const PixelRefV& b)
{
return (a.x > b.x || (a.x == b.x && a.y > b.y));
}
inline bool operator < (const PixelRefV& a, const PixelRefV& b)
{
return (a.x < b.x || (a.x == b.x && a.y < b.y));
}