contrek 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -3
- data/CHANGELOG.md +25 -0
- data/Gemfile.lock +1 -1
- data/README.md +133 -33
- data/Rakefile +3 -0
- data/contrek.gemspec +6 -3
- data/ext/cpp_polygon_finder/PolygonFinder/Makefile +44 -0
- data/ext/cpp_polygon_finder/PolygonFinder/images/sample_10240x10240.png +0 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/Main.cpp +14 -5
- data/ext/cpp_polygon_finder/PolygonFinder/src/Tests.cpp +136 -15
- data/ext/cpp_polygon_finder/PolygonFinder/src/Tests.h +5 -4
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/CpuTimer.h +44 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/Bitmap.cpp +8 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/Bitmap.h +3 -4
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.cpp +63 -573
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.h +17 -18
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/RemoteFastPngBitmap.cpp +22 -5
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/RemoteFastPngBitmap.h +4 -8
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/spng.c +6980 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/spng.h +537 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/FinderUtils.cpp +101 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/FinderUtils.h +16 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.cpp +0 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.h +4 -7
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.cpp +13 -13
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.h +5 -7
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.cpp +47 -41
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.h +15 -10
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.cpp +181 -178
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.h +19 -20
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Polygon.h +20 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.cpp +52 -137
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.h +85 -16
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/RectBounds.h +39 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/ClippedPolygonFinder.cpp +14 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/ClippedPolygonFinder.h +17 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cluster.cpp +117 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cluster.h +32 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.cpp +344 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.h +46 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/EndPoint.cpp +14 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/EndPoint.h +22 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/FakeCluster.cpp +13 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/FakeCluster.h +17 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Finder.cpp +139 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Finder.h +52 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Hub.cpp +23 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Hub.h +40 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.cpp +70 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.h +47 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/PartPool.cpp +24 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/PartPool.h +23 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.cpp +182 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.h +30 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.cpp +108 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.h +52 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Poolable.cpp +59 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Poolable.h +52 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Position.cpp +31 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Position.h +25 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Queue.h +36 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Queueable.h +230 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Sequence.cpp +35 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Sequence.h +20 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Shape.cpp +26 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Shape.h +23 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Tile.cpp +105 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Tile.h +56 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/Matcher.cpp +3 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/Matcher.h +5 -8
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBMatcher.h +3 -7
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBNotMatcher.cpp +2 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBNotMatcher.h +4 -8
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/ValueNotMatcher.cpp +2 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/ValueNotMatcher.h +3 -7
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/LinearReducer.cpp +23 -15
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/LinearReducer.h +6 -8
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/Reducer.cpp +2 -5
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/Reducer.h +4 -8
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/UniqReducer.cpp +9 -12
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/UniqReducer.h +3 -7
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/VisvalingamReducer.cpp +26 -27
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/VisvalingamReducer.h +76 -87
- data/ext/cpp_polygon_finder/cpp_polygon_finder.cpp +167 -138
- data/ext/cpp_polygon_finder/extconf.rb +14 -0
- data/lib/contrek/bitmaps/sample_generator.rb +56 -0
- data/lib/contrek/cpp/cpp_concurrent_finder.rb +9 -0
- data/lib/contrek/finder/bounds.rb +17 -0
- data/lib/contrek/finder/concurrent/cluster.rb +2 -2
- data/lib/contrek/finder/concurrent/cursor.rb +8 -8
- data/lib/contrek/finder/concurrent/finder.rb +19 -15
- data/lib/contrek/finder/concurrent/part.rb +2 -2
- data/lib/contrek/finder/concurrent/partitionable.rb +1 -1
- data/lib/contrek/finder/concurrent/polyline.rb +17 -15
- data/lib/contrek/finder/concurrent/sequence.rb +11 -0
- data/lib/contrek/finder/concurrent/tile.rb +3 -3
- data/lib/contrek/finder/node_cluster.rb +16 -8
- data/lib/contrek/finder/polygon_finder.rb +9 -10
- data/lib/contrek/finder/result.rb +13 -0
- data/lib/contrek/results/cpp_result.rb +21 -0
- data/lib/contrek/version.rb +1 -1
- data/lib/contrek.rb +11 -1
- metadata +59 -10
- data/ext/cpp_polygon_finder/PolygonFinder/.cproject +0 -136
- data/ext/cpp_polygon_finder/PolygonFinder/.project +0 -27
- data/ext/cpp_polygon_finder/PolygonFinder/.settings/org.eclipse.ltk.core.refactoring.prefs +0 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/PngBitmap.cpp +0 -48
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/PngBitmap.h +0 -32
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
#include "ValueNotMatcher.h"
|
|
10
10
|
#include <iostream>
|
|
11
11
|
|
|
12
|
-
ValueNotMatcher::ValueNotMatcher(
|
|
12
|
+
ValueNotMatcher::ValueNotMatcher(unsigned int value) : Matcher(value) {
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
ValueNotMatcher::~ValueNotMatcher() {
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
bool ValueNotMatcher::match(
|
|
18
|
+
bool ValueNotMatcher::match(unsigned int value) {
|
|
19
19
|
return(this->value != value);
|
|
20
20
|
}
|
|
@@ -6,16 +6,12 @@
|
|
|
6
6
|
* Copyright 2025 Emanuele Cesaroni
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
#
|
|
10
|
-
#define POLYGON_MATCHERS_VALUENOTMATCHER_H_
|
|
11
|
-
|
|
9
|
+
#pragma once
|
|
12
10
|
#include "Matcher.h"
|
|
13
11
|
|
|
14
12
|
class ValueNotMatcher : public Matcher {
|
|
15
13
|
public:
|
|
16
|
-
ValueNotMatcher(
|
|
14
|
+
explicit ValueNotMatcher(unsigned int value);
|
|
17
15
|
virtual ~ValueNotMatcher();
|
|
18
|
-
bool match(
|
|
16
|
+
bool match(unsigned int value);
|
|
19
17
|
};
|
|
20
|
-
|
|
21
|
-
#endif /* POLYGON_MATCHERS_VALUENOTMATCHER_H_ */
|
|
@@ -8,33 +8,41 @@
|
|
|
8
8
|
|
|
9
9
|
#include <iterator>
|
|
10
10
|
#include <list>
|
|
11
|
+
#include <iostream>
|
|
12
|
+
#include <algorithm>
|
|
11
13
|
#include "LinearReducer.h"
|
|
12
14
|
#include "Reducer.h"
|
|
13
15
|
|
|
14
|
-
LinearReducer::LinearReducer(std::
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
LinearReducer::~LinearReducer() {
|
|
16
|
+
LinearReducer::LinearReducer(std::vector<Point*> &list_of_points)
|
|
17
|
+
: Reducer(list_of_points) {
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
void LinearReducer::reduce() {
|
|
21
|
-
|
|
22
|
-
std::list<Point*>::iterator end_p = std::next(start_p, 1);
|
|
21
|
+
if (points.size() < 2) return;
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
Point* start_p = points[0];
|
|
24
|
+
Point* end_p = points[1];
|
|
25
|
+
auto dir = seq_dir(start_p, end_p);
|
|
25
26
|
|
|
26
|
-
for (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
for (size_t i = 2; i < points.size(); ++i) {
|
|
28
|
+
Point* point = points[i];
|
|
29
|
+
auto act_seq = seq_dir(end_p, point);
|
|
30
|
+
if (act_seq == dir) {
|
|
31
|
+
auto it = std::find_if(points.begin(), points.end(), [&](Point* p) { // TODO(ema): optimize...
|
|
32
|
+
return p->x == end_p->x && p->y == end_p->y;
|
|
33
|
+
});
|
|
34
|
+
if (it != points.end()) {
|
|
35
|
+
size_t removed_idx = std::distance(points.begin(), it);
|
|
36
|
+
points.erase(it);
|
|
37
|
+
if (removed_idx <= i) i--;
|
|
38
|
+
}
|
|
31
39
|
} else {
|
|
32
40
|
dir = act_seq;
|
|
33
|
-
end_p = point;
|
|
34
41
|
}
|
|
42
|
+
end_p = point;
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
45
|
|
|
38
|
-
int
|
|
39
|
-
{ return
|
|
46
|
+
std::array<int, 2> LinearReducer::seq_dir(Point *a, Point *b)
|
|
47
|
+
{ return { b->x - a->x, b->y - a->y };
|
|
40
48
|
}
|
|
@@ -6,18 +6,16 @@
|
|
|
6
6
|
* Copyright 2025 Emanuele Cesaroni
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
|
|
9
|
+
#pragma once
|
|
10
|
+
#include <vector>
|
|
11
|
+
#include <array>
|
|
12
12
|
#include "Reducer.h"
|
|
13
13
|
|
|
14
14
|
class LinearReducer : public Reducer {
|
|
15
15
|
public:
|
|
16
|
-
LinearReducer(std::
|
|
17
|
-
virtual ~LinearReducer();
|
|
16
|
+
explicit LinearReducer(std::vector<Point*>& list_of_points);
|
|
18
17
|
void reduce();
|
|
18
|
+
|
|
19
19
|
private:
|
|
20
|
-
int
|
|
20
|
+
std::array<int, 2> seq_dir(Point *a, Point *b);
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
#endif /* POLYGON_REDUCERS_LINEARREDUCER_H_ */
|
|
@@ -8,11 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
#include "Reducer.h"
|
|
10
10
|
|
|
11
|
-
Reducer::Reducer(std::
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
Reducer::~Reducer() {
|
|
11
|
+
Reducer::Reducer(std::vector<Point*>& list_of_points)
|
|
12
|
+
: points(list_of_points) {
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
void Reducer::reduce() {
|
|
@@ -6,20 +6,16 @@
|
|
|
6
6
|
* Copyright 2025 Emanuele Cesaroni
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
#
|
|
10
|
-
#define POLYGON_REDUCERS_REDUCER_H_
|
|
11
|
-
|
|
9
|
+
#pragma once
|
|
12
10
|
#include <list>
|
|
11
|
+
#include <vector>
|
|
13
12
|
#include "../finder/Node.h"
|
|
14
13
|
|
|
15
14
|
struct Point;
|
|
16
15
|
class Reducer {
|
|
17
16
|
public:
|
|
18
|
-
Reducer(std::
|
|
19
|
-
virtual ~Reducer();
|
|
17
|
+
explicit Reducer(std::vector<Point*>& list_of_points);
|
|
20
18
|
virtual void reduce();
|
|
21
19
|
protected:
|
|
22
|
-
std::
|
|
20
|
+
std::vector<Point*> &points;
|
|
23
21
|
};
|
|
24
|
-
|
|
25
|
-
#endif /* POLYGON_REDUCERS_REDUCER_H_ */
|
|
@@ -6,25 +6,22 @@
|
|
|
6
6
|
* Copyright 2025 Emanuele Cesaroni
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
#include <vector>
|
|
10
|
+
#include <algorithm>
|
|
11
|
+
#include <iostream>
|
|
9
12
|
#include "UniqReducer.h"
|
|
10
13
|
#include "Reducer.h"
|
|
11
|
-
#include "algorithm"
|
|
12
|
-
#include "list"
|
|
13
|
-
#include "iterator"
|
|
14
|
-
#include "iostream"
|
|
15
14
|
|
|
16
|
-
UniqReducer::UniqReducer(std::
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
UniqReducer::~UniqReducer() {
|
|
15
|
+
UniqReducer::UniqReducer(std::vector<Point*>& list_of_points) : Reducer(list_of_points) {
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
struct is_near {
|
|
23
|
-
bool operator() (Point
|
|
24
|
-
|
|
19
|
+
bool operator() (Point* first, Point* second) const {
|
|
20
|
+
return first->x == second->x && first->y == second->y;
|
|
21
|
+
}
|
|
25
22
|
};
|
|
26
23
|
|
|
27
24
|
void UniqReducer::reduce() {
|
|
28
|
-
|
|
25
|
+
auto last = std::unique(points.begin(), points.end(), is_near());
|
|
26
|
+
points.erase(last, points.end());
|
|
29
27
|
}
|
|
30
|
-
|
|
@@ -6,16 +6,12 @@
|
|
|
6
6
|
* Copyright 2025 Emanuele Cesaroni
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
|
|
9
|
+
#pragma once
|
|
10
|
+
#include <vector>
|
|
12
11
|
#include "Reducer.h"
|
|
13
12
|
|
|
14
13
|
class UniqReducer : public Reducer {
|
|
15
14
|
public:
|
|
16
|
-
UniqReducer(std::
|
|
17
|
-
virtual ~UniqReducer();
|
|
15
|
+
explicit UniqReducer(std::vector<Point*>& list_of_points);
|
|
18
16
|
void reduce();
|
|
19
17
|
};
|
|
20
|
-
|
|
21
|
-
#endif /* POLYGON_REDUCERS_UNIQREDUCER_H_ */
|
|
@@ -6,45 +6,44 @@
|
|
|
6
6
|
* Copyright 2025 Emanuele Cesaroni
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
#include <
|
|
10
|
-
#include <list>
|
|
9
|
+
#include <vector>
|
|
11
10
|
#include "VisvalingamReducer.h"
|
|
12
|
-
#include "Reducer.h"
|
|
13
11
|
|
|
14
|
-
VisvalingamReducer::VisvalingamReducer(std::
|
|
12
|
+
VisvalingamReducer::VisvalingamReducer(std::vector<Point*>& list_of_points, float tolerance)
|
|
13
|
+
: Reducer(list_of_points) {
|
|
15
14
|
this->tolerance = tolerance * tolerance;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
VisvalingamReducer::~VisvalingamReducer() {
|
|
19
|
-
}
|
|
17
|
+
VisvalingamReducer::~VisvalingamReducer() {}
|
|
20
18
|
|
|
21
19
|
void VisvalingamReducer::reduce() {
|
|
22
|
-
std::
|
|
23
|
-
|
|
20
|
+
std::vector<Point*> new_points = this->simplify();
|
|
21
|
+
points.assign(new_points.begin(), new_points.end());
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
|
|
24
|
+
std::vector<Point*> VisvalingamReducer::simplify() {
|
|
25
|
+
Vertex* vwLine = Vertex::buildLine(points);
|
|
27
26
|
float minArea = this->tolerance;
|
|
28
27
|
for (;;) {
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
minArea = simplifyVertex(vwLine);
|
|
29
|
+
if (minArea >= this->tolerance) break;
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
return(simp);
|
|
31
|
+
return Vertex::getCoordinates(vwLine);
|
|
34
32
|
}
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
|
|
34
|
+
float VisvalingamReducer::simplifyVertex(Vertex* vwLine) {
|
|
35
|
+
Vertex* curr = vwLine;
|
|
37
36
|
float minArea = curr->getArea();
|
|
38
|
-
|
|
39
|
-
while (curr
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
Vertex* minVertex = nullptr;
|
|
38
|
+
while (curr) {
|
|
39
|
+
float area = curr->getArea();
|
|
40
|
+
if (area < minArea) {
|
|
41
|
+
minArea = area;
|
|
42
|
+
minVertex = curr;
|
|
43
|
+
}
|
|
44
|
+
curr = curr->get_next();
|
|
46
45
|
}
|
|
47
|
-
if (minVertex
|
|
48
|
-
if (!vwLine->isLiving())
|
|
49
|
-
return
|
|
46
|
+
if (minVertex && minArea < this->tolerance) minVertex->remove();
|
|
47
|
+
if (!vwLine->isLiving()) return -1;
|
|
48
|
+
return minArea;
|
|
50
49
|
}
|
|
@@ -6,116 +6,105 @@
|
|
|
6
6
|
* Copyright 2025 Emanuele Cesaroni
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
|
|
9
|
+
#pragma once
|
|
10
|
+
#include <vector>
|
|
12
11
|
#include <cmath>
|
|
13
12
|
#include <limits>
|
|
14
|
-
#include <list>
|
|
15
13
|
#include "Reducer.h"
|
|
16
|
-
#include "../finder/Node.h"
|
|
17
14
|
|
|
18
15
|
struct Point;
|
|
19
16
|
|
|
20
17
|
class VisvalingamReducer : public Reducer {
|
|
21
18
|
public:
|
|
22
|
-
VisvalingamReducer(std::
|
|
19
|
+
VisvalingamReducer(std::vector<Point*>& list_of_points, float tolerance);
|
|
23
20
|
virtual ~VisvalingamReducer();
|
|
24
21
|
void reduce();
|
|
25
|
-
std::
|
|
22
|
+
std::vector<Point*> simplify();
|
|
23
|
+
|
|
26
24
|
class Triangle {
|
|
27
25
|
public:
|
|
28
|
-
static int area(Point
|
|
29
|
-
return
|
|
26
|
+
static int area(Point* a, Point* b, Point* c) {
|
|
27
|
+
return std::abs(((c->x - a->x) * (b->y - a->y) - (b->x - a->x) * (c->y - a->y)) / 2);
|
|
30
28
|
}
|
|
31
29
|
};
|
|
32
|
-
class Vertex {
|
|
33
|
-
const float MAX_AREA = std::numeric_limits<float>::max();
|
|
34
|
-
Vertex(Point *pt) {
|
|
35
|
-
this->pt = pt;
|
|
36
|
-
this->prev = nullptr;
|
|
37
|
-
this->next = nullptr;
|
|
38
|
-
this->area = MAX_AREA;
|
|
39
|
-
this->isLive = true;
|
|
40
|
-
}
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
Vertex *get_next() {
|
|
61
|
-
return(this->next);
|
|
62
|
-
}
|
|
63
|
-
bool isLiving()
|
|
64
|
-
{ return(this->isLive);
|
|
31
|
+
class Vertex {
|
|
32
|
+
const float MAX_AREA = std::numeric_limits<float>::max();
|
|
33
|
+
explicit Vertex(Point* pt) {
|
|
34
|
+
this->pt = pt;
|
|
35
|
+
this->prev = nullptr;
|
|
36
|
+
this->next = nullptr;
|
|
37
|
+
this->area = MAX_AREA;
|
|
38
|
+
this->isLive = true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
Point* pt;
|
|
43
|
+
void setNext(Vertex* nextp) { this->next = nextp; }
|
|
44
|
+
void setPrec(Vertex* prev) { this->prev = prev; }
|
|
45
|
+
void updateArea() {
|
|
46
|
+
if (!prev || !next)
|
|
47
|
+
{ this->area = MAX_AREA;
|
|
48
|
+
return;
|
|
65
49
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
50
|
+
this->area = Triangle::area(this->prev->pt, this->pt, this->next->pt);
|
|
51
|
+
}
|
|
52
|
+
float getArea() { return this->area; }
|
|
53
|
+
Vertex* get_next() { return this->next; }
|
|
54
|
+
bool isLiving() { return this->isLive; }
|
|
55
|
+
|
|
56
|
+
static Vertex* buildLine(std::vector<Point*>& pts) {
|
|
57
|
+
Vertex* first = nullptr;
|
|
58
|
+
Vertex* prev = nullptr;
|
|
59
|
+
for (Point* p : pts) {
|
|
60
|
+
Vertex* v = new Vertex(p);
|
|
61
|
+
if (!first) first = v;
|
|
62
|
+
v->setPrec(prev);
|
|
63
|
+
if (prev) {
|
|
64
|
+
prev->setNext(v);
|
|
76
65
|
prev->updateArea();
|
|
77
|
-
}
|
|
78
|
-
prev = v;
|
|
79
66
|
}
|
|
80
|
-
|
|
67
|
+
prev = v;
|
|
81
68
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this->next->updateArea();
|
|
94
|
-
if (result == nullptr) result = this->next;
|
|
95
|
-
}
|
|
96
|
-
this->isLive = false;
|
|
97
|
-
return(result);
|
|
69
|
+
return first;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Vertex* remove() {
|
|
73
|
+
Vertex* tmpPrev = this->prev;
|
|
74
|
+
Vertex* tmpNext = this->next;
|
|
75
|
+
Vertex* result = nullptr;
|
|
76
|
+
if (tmpPrev) {
|
|
77
|
+
tmpPrev->setNext(tmpNext);
|
|
78
|
+
tmpPrev->updateArea();
|
|
79
|
+
result = tmpPrev;
|
|
98
80
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
{ coords->push_back(curr->pt);
|
|
104
|
-
curr = curr->get_next();
|
|
105
|
-
if (curr == nullptr) break;
|
|
106
|
-
}
|
|
107
|
-
return(coords);
|
|
81
|
+
if (tmpNext) {
|
|
82
|
+
tmpNext->setPrec(tmpPrev);
|
|
83
|
+
tmpNext->updateArea();
|
|
84
|
+
if (!result) result = tmpNext;
|
|
108
85
|
}
|
|
86
|
+
this->isLive = false;
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static std::vector<Point*> getCoordinates(Vertex* head) {
|
|
91
|
+
std::vector<Point*> coords;
|
|
92
|
+
Vertex* curr = head;
|
|
93
|
+
while (curr) {
|
|
94
|
+
coords.push_back(curr->pt);
|
|
95
|
+
curr = curr->get_next();
|
|
96
|
+
}
|
|
97
|
+
return coords;
|
|
98
|
+
}
|
|
109
99
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
100
|
+
private:
|
|
101
|
+
Vertex* next;
|
|
102
|
+
Vertex* prev;
|
|
103
|
+
float area;
|
|
104
|
+
bool isLive;
|
|
105
|
+
};
|
|
115
106
|
|
|
116
107
|
private:
|
|
117
|
-
float simplifyVertex(
|
|
108
|
+
float simplifyVertex(Vertex* vwLine);
|
|
118
109
|
float tolerance;
|
|
119
110
|
};
|
|
120
|
-
|
|
121
|
-
#endif /* POLYGON_REDUCERS_VISVALINGAMREDUCER_H_ */
|