-
Notifications
You must be signed in to change notification settings - Fork 6
/
outline.h
66 lines (50 loc) · 1.63 KB
/
outline.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
/*
* Find the points around a specific object
*
* Useful links on edge detection:
* http://www.m-hikari.com/ams/ams-password-2008/ams-password29-32-2008/nadernejadAMS29-32-2008.pdf
*/
#ifndef H_OUTLINE
#define H_OUTLINE
#include <set>
#include <array>
#include <vector>
#include "data.h"
#include "blobs.h"
// Used to return both point to jump to (if we had to go back a ways
// at a dead end) and the next direction to go
struct EdgePair
{
Coord point;
int index;
EdgePair(const Coord& p, int i)
:point(p), index(i) { }
};
// Get the outline of the object
class Outline
{
const Blobs& blobs;
// Label of this pixel
int label = Blobs::default_label;
// Save the outline of this object
std::vector<Coord> path;
std::set<Coord> sortedpath; // Faster for contains a point check
// Did we find the outline?
bool found = false;
// Used to walk the edge of a box. Relative coordinates
// around the current position.
static const std::array<Coord, 8> matrix;
public:
Outline(const Blobs& blobs, const Coord& point, const int max_length);
bool good() const { return found; }
const std::vector<Coord>& points() const { return path; }
private:
// Find the next pixel on edge by finding index of matrix used to move, or
// if no available locations, moving back through our history till we can move
// and returning that point and the index of the matrix to use to move.
EdgePair findEdge(const Coord& p) const;
// Find next pixel to go to when walking edge, returns index of matrix
// or -1 if all are black
int findIndex(const Coord& p) const;
};
#endif