IntelliPhoto 0.6

IntelliTriangulation.h
Go to the documentation of this file.
1 #ifndef INTELLITRIANGULATION_H
2 #define INTELLITRIANGULATION_H
3
4 //for unit testing
5 class UnitTest;
6
7 #include <QPoint>
8 #include <vector>
9
13 struct Triangle {
14 QPoint A,B,C;
15 };
16
17 namespace IntelliTriangulation {
18
26 inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
27 return (p1.x() - p3.x()) * (p2.y() - p3.y()) - (p2.x() - p3.x()) * (p1.y() - p3.y());
28 }
29
36 inline bool isInTriangle(Triangle& tri, QPoint& P){
37 float val1, val2, val3;
38 bool neg, pos;
39
40 val1 = IntelliTriangulation::sign(P,tri.A,tri.B);
41 val2 = IntelliTriangulation::sign(P,tri.B,tri.C);
42 val3 = IntelliTriangulation::sign(P,tri.C,tri.A);
43
44 neg = (val1<0.f) || (val2<0.f) || (val3<0.f);
45 pos = (val1>0.f) || (val2>0.f) || (val3>0.f);
46
47 return !(neg && pos);
48 }
49
55 std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
56
63 bool isInPolygon(const std::vector<Triangle> &triangles, QPoint &point);
64 }
65
66 #endif
IntelliTriangulation::isInTriangle
bool isInTriangle(Triangle &tri, QPoint &P)
A function to check if a given point is in a triangle.
Definition: IntelliTriangulation.h:36
IntelliTriangulation::sign
float sign(QPoint &p1, QPoint &p2, QPoint &p3)
A function to get the 2*area of a traingle, using its determinat.
Definition: IntelliTriangulation.h:26
IntelliTriangulation::calculateTriangles
std::vector< Triangle > calculateTriangles(std::vector< QPoint > polyPoints)
A function to split a polygon in its spanning traingles by using Meisters Theorem of graph theory by ...
Definition: IntelliTriangulation.cpp:7
Triangle::B
QPoint B
Definition: IntelliTriangulation.h:14
Triangle::C
QPoint C
Definition: IntelliTriangulation.h:14
Triangle
The Triangle struct holds the 3 vertices of a triangle.
Definition: IntelliTriangulation.h:13
IntelliTriangulation
Definition: IntelliTriangulation.h:17
Triangle::A
QPoint A
Definition: IntelliTriangulation.h:14
UnitTest
Definition: mainUnitTest.cpp:8
IntelliTriangulation::isInPolygon
bool isInPolygon(const std::vector< Triangle > &triangles, QPoint &point)
A function to check if a point lies in a polygon by checking its spanning triangles.
Definition: IntelliTriangulation.cpp:116