-
Notifications
You must be signed in to change notification settings - Fork 0
/
segmentpoints.cpp
40 lines (32 loc) · 952 Bytes
/
segmentpoints.cpp
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
#include "segmentpoints.h"
using namespace Processing;
SegmentPoints::SegmentPoints()
{
}
PList SegmentPoints::getSegmentPoints_FPCAlgorithm(PList points, int reduction) //FPC Algorithm : Four Point in Circle Algorithm :)
{
PList segmentedPoints;
for(int i = 0 ; i < points.getSize() ; i++)
if ( i % reduction == 0 )
segmentedPoints.pushPoint(points.getPoint(i));
bool adjacent = true;
for(int i = 0 ;i < segmentedPoints.getSize(); i++)
{
if ( i == 0 || i == segmentedPoints.getSize() - 1 )
continue;
Point p1 = segmentedPoints.getPoint(i-1);
Point p2 = segmentedPoints.getPoint(i);
Point p3 = segmentedPoints.getPoint(i + 1);
if ( !( ( p2.x > p1.x && p2.x > p3.x ) || ( p2.y > p1.y && p2.y > p3.y ) ||
( p2.x < p1.x && p2.x < p3.x ) || ( p2.y < p1.y && p2.y < p3.y ) ) ||
adjacent )
{
adjacent = false;
segmentedPoints.removeIndex(i);
i--;
}
else
adjacent = true;
}
return segmentedPoints;
}