IntelliPhoto 0.5

IntelliHelper.h
Go to the documentation of this file.
1 #ifndef INTELLIHELPER_H
2 #define INTELLIHELPER_H
3
4 #include <QPoint>
5 #include <vector>
6
10 struct Triangle {
11 QPoint A,B,C;
12 };
13
14 namespace IntelliHelper {
15
23 inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
24 return (p1.x()-p3.x())*(p2.y()-p3.y())-(p2.x()-p3.x())*(p1.y()-p3.y());
25 }
26
33 inline bool isInTriangle(Triangle& tri, QPoint& P){
34 float val1, val2, val3;
35 bool neg, pos;
36
37 val1 = IntelliHelper::sign(P,tri.A,tri.B);
38 val2 = IntelliHelper::sign(P,tri.B,tri.C);
39 val3 = IntelliHelper::sign(P,tri.C,tri.A);
40
41 neg = (val1<0.f) || (val2<0.f) || (val3<0.f);
42 pos = (val1>0.f) || (val2>0.f) || (val3>0.f);
43
44 return !(neg && pos);
45 }
46
52 std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
53
60 bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point);
61 }
62
63 #endif
IntelliHelper::isInTriangle
bool isInTriangle(Triangle &tri, QPoint &P)
A function to check if a given point is in a triangle.
Definition: IntelliHelper.h:33
Triangle::B
QPoint B
Definition: IntelliHelper.h:11
Triangle::C
QPoint C
Definition: IntelliHelper.h:11
IntelliHelper
Definition: IntelliHelper.h:14
Triangle
The Triangle struct holds the 3 vertices of a triangle.
Definition: IntelliHelper.h:10
IntelliHelper::isInPolygon
bool isInPolygon(std::vector< Triangle > &triangles, QPoint &point)
A function to check if a point lies in a polygon by checking its spanning triangles.
Definition: IntelliHelper.cpp:116
Triangle::A
QPoint A
Definition: IntelliHelper.h:11
IntelliHelper::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: IntelliHelper.cpp:7
IntelliHelper::sign
float sign(QPoint &p1, QPoint &p2, QPoint &p3)
A function to get the 2*area of a traingle, using its determinat.
Definition: IntelliHelper.h:23