mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-14 12:20:32 +02:00
Restyled project for uncrustify
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#include "IntelliColorPicker.h"
|
||||
|
||||
IntelliColorPicker::IntelliColorPicker(){
|
||||
firstColor = {255,0,0,255};
|
||||
secondColor = {0,255,255,255};
|
||||
firstColor = {255,0,0,255};
|
||||
secondColor = {0,255,255,255};
|
||||
}
|
||||
|
||||
IntelliColorPicker::~IntelliColorPicker(){
|
||||
@@ -10,21 +10,21 @@ IntelliColorPicker::~IntelliColorPicker(){
|
||||
}
|
||||
|
||||
void IntelliColorPicker::switchColors(){
|
||||
std::swap(firstColor, secondColor);
|
||||
std::swap(firstColor, secondColor);
|
||||
}
|
||||
|
||||
QColor IntelliColorPicker::getFirstColor(){
|
||||
return this->firstColor;
|
||||
return this->firstColor;
|
||||
}
|
||||
|
||||
QColor IntelliColorPicker::getSecondColor(){
|
||||
return this->secondColor;
|
||||
return this->secondColor;
|
||||
}
|
||||
|
||||
void IntelliColorPicker::setFirstColor(QColor Color){
|
||||
this->firstColor = Color;
|
||||
this->firstColor = Color;
|
||||
}
|
||||
|
||||
void IntelliColorPicker::setSecondColor(QColor Color){
|
||||
this->secondColor = Color;
|
||||
this->secondColor = Color;
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
#ifndef INTELLITOOLSETCOLORTOOL_H
|
||||
#define INTELLITOOLSETCOLORTOOL_H
|
||||
|
||||
#include"QColor"
|
||||
#include"QPoint"
|
||||
#include"QColorDialog"
|
||||
#include "QColor"
|
||||
#include "QPoint"
|
||||
#include "QColorDialog"
|
||||
|
||||
/*!
|
||||
* \brief The IntelliColorPicker manages the selected colors for one whole project.
|
||||
*/
|
||||
class IntelliColorPicker{
|
||||
class IntelliColorPicker {
|
||||
public:
|
||||
/*!
|
||||
* \brief IntelliColorPicker constructor, setting 2 preset colors, be careful, theese color may change in production.
|
||||
*/
|
||||
IntelliColorPicker();
|
||||
/*!
|
||||
* \brief IntelliColorPicker constructor, setting 2 preset colors, be careful, theese color may change in production.
|
||||
*/
|
||||
IntelliColorPicker();
|
||||
|
||||
/*!
|
||||
* \brief IntelliColorPicker destructor clears up his used memory, if there is some.
|
||||
*/
|
||||
virtual ~IntelliColorPicker();
|
||||
/*!
|
||||
* \brief IntelliColorPicker destructor clears up his used memory, if there is some.
|
||||
*/
|
||||
virtual ~IntelliColorPicker();
|
||||
|
||||
/*!
|
||||
* \brief A function switching primary and secondary color.
|
||||
*/
|
||||
void switchColors();
|
||||
/*!
|
||||
* \brief A function switching primary and secondary color.
|
||||
*/
|
||||
void switchColors();
|
||||
|
||||
/*!
|
||||
* \brief A function to read the primary selected color.
|
||||
* \return Returns the primary color.
|
||||
*/
|
||||
QColor getFirstColor();
|
||||
/*!
|
||||
* \brief A function to read the primary selected color.
|
||||
* \return Returns the primary color.
|
||||
*/
|
||||
QColor getFirstColor();
|
||||
|
||||
/*!
|
||||
* \brief A function to read the secondary selected color.
|
||||
* \return Returns the secondary color.
|
||||
*/
|
||||
QColor getSecondColor();
|
||||
/*!
|
||||
* \brief A function to read the secondary selected color.
|
||||
* \return Returns the secondary color.
|
||||
*/
|
||||
QColor getSecondColor();
|
||||
|
||||
/*!
|
||||
* \brief A function to set the primary color.
|
||||
* \param Color - The color to be set as primary.
|
||||
*/
|
||||
void setFirstColor(QColor Color);
|
||||
/*!
|
||||
* \brief A function to set the primary color.
|
||||
* \param Color - The color to be set as primary.
|
||||
*/
|
||||
void setFirstColor(QColor Color);
|
||||
|
||||
/*!
|
||||
* \brief A function to set the secondary color.
|
||||
* \param Color - The color to be set as secondary.
|
||||
*/
|
||||
void setSecondColor(QColor Color);
|
||||
/*!
|
||||
* \brief A function to set the secondary color.
|
||||
* \param Color - The color to be set as secondary.
|
||||
*/
|
||||
void setSecondColor(QColor Color);
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief The primary color.
|
||||
*/
|
||||
QColor firstColor;
|
||||
/*!
|
||||
* \brief The primary color.
|
||||
*/
|
||||
QColor firstColor;
|
||||
|
||||
/*!
|
||||
* \brief The secondary color.
|
||||
*/
|
||||
QColor secondColor;
|
||||
/*!
|
||||
* \brief The secondary color.
|
||||
*/
|
||||
QColor secondColor;
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLSETCOLORTOOL_H
|
||||
|
||||
@@ -1,123 +1,123 @@
|
||||
#include"IntelliHelper.h"
|
||||
#include<algorithm>
|
||||
#include<queue>
|
||||
#include<cmath>
|
||||
#include "IntelliHelper.h"
|
||||
#include <algorithm>
|
||||
#include <queue>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
std::vector<Triangle> IntelliHelper::calculateTriangles(std::vector<QPoint> polyPoints){
|
||||
// helper for managing the triangle vertices and their state
|
||||
struct TriangleHelper{
|
||||
QPoint vertex;
|
||||
float interiorAngle;
|
||||
int index;
|
||||
bool isTip;
|
||||
};
|
||||
// helper for managing the triangle vertices and their state
|
||||
struct TriangleHelper {
|
||||
QPoint vertex;
|
||||
float interiorAngle;
|
||||
int index;
|
||||
bool isTip;
|
||||
};
|
||||
|
||||
// calculates the inner angle of 'point'
|
||||
auto calculateInner = [](QPoint& point, QPoint& prev, QPoint& post){
|
||||
QPoint AP(point.x()-prev.x(), point.y()-prev.y());
|
||||
QPoint BP(point.x()-post.x(), point.y()-post.y());
|
||||
// calculates the inner angle of 'point'
|
||||
auto calculateInner = [](QPoint& point, QPoint& prev, QPoint& post){
|
||||
QPoint AP(point.x()-prev.x(), point.y()-prev.y());
|
||||
QPoint BP(point.x()-post.x(), point.y()-post.y());
|
||||
|
||||
float topSclar = AP.x()*BP.x()+AP.y()*BP.y();
|
||||
float absolute = sqrt(pow(AP.x(),2.)+pow(AP.y(),2.))*sqrt(pow(BP.x(),2.)+pow(BP.y(),2.));
|
||||
return acos(topSclar/absolute);
|
||||
};
|
||||
float topSclar = AP.x()*BP.x()+AP.y()*BP.y();
|
||||
float absolute = sqrt(pow(AP.x(),2.)+pow(AP.y(),2.))*sqrt(pow(BP.x(),2.)+pow(BP.y(),2.));
|
||||
return acos(topSclar/absolute);
|
||||
};
|
||||
|
||||
// gets the first element of vec for which element.isTip == true holds
|
||||
auto getTip= [](const std::vector<TriangleHelper>& vec){
|
||||
size_t min = 0;
|
||||
for(size_t i=0; i<vec.size(); i++){
|
||||
if(vec[i].interiorAngle<vec[min].interiorAngle){
|
||||
min = i;
|
||||
}
|
||||
}
|
||||
return vec[min];
|
||||
};
|
||||
// gets the first element of vec for which element.isTip == true holds
|
||||
auto getTip= [](const std::vector<TriangleHelper>& vec){
|
||||
size_t min = 0;
|
||||
for(size_t i=0; i<vec.size(); i++) {
|
||||
if(vec[i].interiorAngle<vec[min].interiorAngle) {
|
||||
min = i;
|
||||
}
|
||||
}
|
||||
return vec[min];
|
||||
};
|
||||
|
||||
// get the vertex Index bevor index in relation to the container length
|
||||
auto getPrev = [](int index, int length){
|
||||
return (index-1)>=0?(index-1):(length-1);
|
||||
};
|
||||
// get the vertex Index bevor index in relation to the container length
|
||||
auto getPrev = [](int index, int length){
|
||||
return (index-1)>=0 ? (index-1) : (length-1);
|
||||
};
|
||||
|
||||
// get the vertex Index after index in relation to the container lenght
|
||||
auto getPost = [](int index, int length){
|
||||
return (index+1)%length;
|
||||
};
|
||||
// get the vertex Index after index in relation to the container lenght
|
||||
auto getPost = [](int index, int length){
|
||||
return (index+1)%length;
|
||||
};
|
||||
|
||||
// return if the vertex is a tip
|
||||
auto isTip = [](float angle){
|
||||
return static_cast<double>(angle)<(M_PI/2.);
|
||||
};
|
||||
// return if the vertex is a tip
|
||||
auto isTip = [](float angle){
|
||||
return static_cast<double>(angle)<(M_PI/2.);
|
||||
};
|
||||
|
||||
std::vector<TriangleHelper> Vertices;
|
||||
std::vector<Triangle> Triangles;
|
||||
std::vector<TriangleHelper> Vertices;
|
||||
std::vector<Triangle> Triangles;
|
||||
|
||||
// set up all vertices and calculate intirior angle
|
||||
for(int i=0; i<static_cast<int>(polyPoints.size()); i++){
|
||||
TriangleHelper helper;
|
||||
int prev = getPrev(i, static_cast<int>(polyPoints.size()));
|
||||
int post = getPost(i, static_cast<int>(polyPoints.size()));
|
||||
// set up all vertices and calculate intirior angle
|
||||
for(int i=0; i<static_cast<int>(polyPoints.size()); i++) {
|
||||
TriangleHelper helper;
|
||||
int prev = getPrev(i, static_cast<int>(polyPoints.size()));
|
||||
int post = getPost(i, static_cast<int>(polyPoints.size()));
|
||||
|
||||
helper.vertex = polyPoints[static_cast<size_t>(i)];
|
||||
helper.index = i;
|
||||
helper.vertex = polyPoints[static_cast<size_t>(i)];
|
||||
helper.index = i;
|
||||
|
||||
helper.interiorAngle = calculateInner(polyPoints[static_cast<size_t>(i)],
|
||||
polyPoints[static_cast<size_t>(prev)],
|
||||
polyPoints[static_cast<size_t>(post)]);
|
||||
helper.isTip = isTip(helper.interiorAngle);
|
||||
Vertices.push_back(helper);
|
||||
}
|
||||
helper.interiorAngle = calculateInner(polyPoints[static_cast<size_t>(i)],
|
||||
polyPoints[static_cast<size_t>(prev)],
|
||||
polyPoints[static_cast<size_t>(post)]);
|
||||
helper.isTip = isTip(helper.interiorAngle);
|
||||
Vertices.push_back(helper);
|
||||
}
|
||||
|
||||
// search triangles based on the intirior angles of each vertey
|
||||
while(Triangles.size() != polyPoints.size()-2){
|
||||
Triangle tri;
|
||||
TriangleHelper smallest = getTip(Vertices);
|
||||
int prev = getPrev(smallest.index, static_cast<int>(Vertices.size()));
|
||||
int post = getPost(smallest.index, static_cast<int>(Vertices.size()));
|
||||
// search triangles based on the intirior angles of each vertey
|
||||
while(Triangles.size() != polyPoints.size()-2) {
|
||||
Triangle tri;
|
||||
TriangleHelper smallest = getTip(Vertices);
|
||||
int prev = getPrev(smallest.index, static_cast<int>(Vertices.size()));
|
||||
int post = getPost(smallest.index, static_cast<int>(Vertices.size()));
|
||||
|
||||
// set triangle and push it
|
||||
tri.A = Vertices[static_cast<size_t>(prev)].vertex;
|
||||
tri.B = Vertices[static_cast<size_t>(smallest.index)].vertex;
|
||||
tri.C = Vertices[static_cast<size_t>(post)].vertex;
|
||||
Triangles.push_back(tri);
|
||||
// set triangle and push it
|
||||
tri.A = Vertices[static_cast<size_t>(prev)].vertex;
|
||||
tri.B = Vertices[static_cast<size_t>(smallest.index)].vertex;
|
||||
tri.C = Vertices[static_cast<size_t>(post)].vertex;
|
||||
Triangles.push_back(tri);
|
||||
|
||||
// update Vertice array
|
||||
Vertices.erase(Vertices.begin()+smallest.index);
|
||||
for(size_t i=static_cast<size_t>(smallest.index); i<Vertices.size(); i++){
|
||||
Vertices[i].index-=1;
|
||||
}
|
||||
// update Vertice array
|
||||
Vertices.erase(Vertices.begin()+smallest.index);
|
||||
for(size_t i=static_cast<size_t>(smallest.index); i<Vertices.size(); i++) {
|
||||
Vertices[i].index-=1;
|
||||
}
|
||||
|
||||
// update post und prev index
|
||||
post = post-1;
|
||||
prev = prev<smallest.index?prev:(prev-1);
|
||||
// update post und prev index
|
||||
post = post-1;
|
||||
prev = prev<smallest.index ? prev : (prev-1);
|
||||
|
||||
// calcultae neighboors of prev and post to calculate new interior angles
|
||||
int prevOfPrev = getPrev(prev, static_cast<int>(Vertices.size()));
|
||||
int postOfPrev = getPost(prev, static_cast<int>(Vertices.size()));
|
||||
// calcultae neighboors of prev and post to calculate new interior angles
|
||||
int prevOfPrev = getPrev(prev, static_cast<int>(Vertices.size()));
|
||||
int postOfPrev = getPost(prev, static_cast<int>(Vertices.size()));
|
||||
|
||||
int prevOfPost = getPrev(post, static_cast<int>(Vertices.size()));
|
||||
int postOfPost = getPost(post, static_cast<int>(Vertices.size()));
|
||||
int prevOfPost = getPrev(post, static_cast<int>(Vertices.size()));
|
||||
int postOfPost = getPost(post, static_cast<int>(Vertices.size()));
|
||||
|
||||
// update vertices with interior angles
|
||||
// updtae prev
|
||||
Vertices[static_cast<size_t>(prev)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(prev)].vertex,
|
||||
Vertices[static_cast<size_t>(prevOfPrev)].vertex,
|
||||
Vertices[static_cast<size_t>(postOfPrev)].vertex);
|
||||
Vertices[static_cast<size_t>(prev)].isTip = isTip(Vertices[static_cast<size_t>(prev)].interiorAngle);
|
||||
// update post
|
||||
Vertices[static_cast<size_t>(post)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(post)].vertex,
|
||||
Vertices[static_cast<size_t>(prevOfPost)].vertex,
|
||||
Vertices[static_cast<size_t>(postOfPost)].vertex);
|
||||
Vertices[static_cast<size_t>(post)].isTip = isTip(Vertices[static_cast<size_t>(post)].interiorAngle);
|
||||
}
|
||||
return Triangles;
|
||||
// update vertices with interior angles
|
||||
// updtae prev
|
||||
Vertices[static_cast<size_t>(prev)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(prev)].vertex,
|
||||
Vertices[static_cast<size_t>(prevOfPrev)].vertex,
|
||||
Vertices[static_cast<size_t>(postOfPrev)].vertex);
|
||||
Vertices[static_cast<size_t>(prev)].isTip = isTip(Vertices[static_cast<size_t>(prev)].interiorAngle);
|
||||
// update post
|
||||
Vertices[static_cast<size_t>(post)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(post)].vertex,
|
||||
Vertices[static_cast<size_t>(prevOfPost)].vertex,
|
||||
Vertices[static_cast<size_t>(postOfPost)].vertex);
|
||||
Vertices[static_cast<size_t>(post)].isTip = isTip(Vertices[static_cast<size_t>(post)].interiorAngle);
|
||||
}
|
||||
return Triangles;
|
||||
}
|
||||
|
||||
bool IntelliHelper::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){
|
||||
for(auto triangle : triangles){
|
||||
if(IntelliHelper::isInTriangle(triangle, point)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
for(auto triangle : triangles) {
|
||||
if(IntelliHelper::isInTriangle(triangle, point)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
#ifndef INTELLIHELPER_H
|
||||
#define INTELLIHELPER_H
|
||||
|
||||
#include<QPoint>
|
||||
#include<vector>
|
||||
#include <QPoint>
|
||||
#include <vector>
|
||||
|
||||
/*!
|
||||
* \brief The Triangle struct holds the 3 vertices of a triangle.
|
||||
*/
|
||||
struct Triangle{
|
||||
QPoint A,B,C;
|
||||
struct Triangle {
|
||||
QPoint A,B,C;
|
||||
};
|
||||
|
||||
namespace IntelliHelper {
|
||||
|
||||
/*!
|
||||
* \brief A function to get the 2*area of a traingle, using its determinat.
|
||||
* \param p1 - The Point to check its side.
|
||||
* \param p2 - The first Point of the spanning Line
|
||||
* \param p3 - The second Point of the spanning line.
|
||||
* \return Returns the area of the traingle*2
|
||||
*/
|
||||
inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
|
||||
return (p1.x()-p3.x())*(p2.y()-p3.y())-(p2.x()-p3.x())*(p1.y()-p3.y());
|
||||
}
|
||||
/*!
|
||||
* \brief A function to get the 2*area of a traingle, using its determinat.
|
||||
* \param p1 - The Point to check its side.
|
||||
* \param p2 - The first Point of the spanning Line
|
||||
* \param p3 - The second Point of the spanning line.
|
||||
* \return Returns the area of the traingle*2
|
||||
*/
|
||||
inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
|
||||
return (p1.x()-p3.x())*(p2.y()-p3.y())-(p2.x()-p3.x())*(p1.y()-p3.y());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief A function to check if a given point is in a triangle.
|
||||
* \param tri - The triangle to check, if it contains the point.
|
||||
* \param P - The point to check if it is in the triangle.
|
||||
* \return Returns true if the point is in the triangle, false otheriwse
|
||||
*/
|
||||
inline bool isInTriangle(Triangle& tri, QPoint& P){
|
||||
float val1, val2, val3;
|
||||
bool neg, pos;
|
||||
/*!
|
||||
* \brief A function to check if a given point is in a triangle.
|
||||
* \param tri - The triangle to check, if it contains the point.
|
||||
* \param P - The point to check if it is in the triangle.
|
||||
* \return Returns true if the point is in the triangle, false otheriwse
|
||||
*/
|
||||
inline bool isInTriangle(Triangle& tri, QPoint& P){
|
||||
float val1, val2, val3;
|
||||
bool neg, pos;
|
||||
|
||||
val1 = IntelliHelper::sign(P,tri.A,tri.B);
|
||||
val2 = IntelliHelper::sign(P,tri.B,tri.C);
|
||||
val3 = IntelliHelper::sign(P,tri.C,tri.A);
|
||||
val1 = IntelliHelper::sign(P,tri.A,tri.B);
|
||||
val2 = IntelliHelper::sign(P,tri.B,tri.C);
|
||||
val3 = IntelliHelper::sign(P,tri.C,tri.A);
|
||||
|
||||
neg = (val1<0.f) || (val2<0.f) || (val3<0.f);
|
||||
pos = (val1>0.f) || (val2>0.f) || (val3>0.f);
|
||||
neg = (val1<0.f) || (val2<0.f) || (val3<0.f);
|
||||
pos = (val1>0.f) || (val2>0.f) || (val3>0.f);
|
||||
|
||||
return !(neg && pos);
|
||||
}
|
||||
return !(neg && pos);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief A function to split a polygon in its spanning traingles by using Meisters Theorem of graph theory by clipping ears of a planar graph.
|
||||
* \param polyPoints - The Vertices of the polygon.
|
||||
* \return Returns a Container of disjoint Triangles, which desribe the polygon area.
|
||||
*/
|
||||
std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
|
||||
/*!
|
||||
* \brief A function to split a polygon in its spanning traingles by using Meisters Theorem of graph theory by clipping ears of a planar graph.
|
||||
* \param polyPoints - The Vertices of the polygon.
|
||||
* \return Returns a Container of disjoint Triangles, which desribe the polygon area.
|
||||
*/
|
||||
std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
|
||||
|
||||
/*!
|
||||
* \brief A function to check if a point lies in a polygon by checking its spanning triangles.
|
||||
* \param triangles - The spanning triangles of the planar polygon.
|
||||
* \param point - The point to checl, if it lies in the polygon.
|
||||
* \return Returns true if the point lies in the üpolygon, otherwise false.
|
||||
*/
|
||||
bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point);
|
||||
/*!
|
||||
* \brief A function to check if a point lies in a polygon by checking its spanning triangles.
|
||||
* \param triangles - The spanning triangles of the planar polygon.
|
||||
* \param point - The point to checl, if it lies in the polygon.
|
||||
* \return Returns true if the point lies in the üpolygon, otherwise false.
|
||||
*/
|
||||
bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user