IntelliPhoto 0.5

IntelliShapedImage.cpp
Go to the documentation of this file.
1 #include "Image/IntelliShapedImage.h"
2 #include "IntelliHelper/IntelliHelper.h"
3 #include <QPainter>
4 #include <QRect>
5 #include <QDebug>
6
7 IntelliShapedImage::IntelliShapedImage(int weight, int height)
8 : IntelliRasterImage(weight, height){
9 }
10
11 IntelliShapedImage::~IntelliShapedImage(){
12
13 }
14
15 QImage IntelliShapedImage::getDisplayable(int alpha){
16 return getDisplayable(imageData.size(),alpha);
17 }
18
19 IntelliImage* IntelliShapedImage::getDeepCopy(){
20 IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
21 shaped->setPolygon(this->polygonData);
22 shaped->imageData.fill(Qt::transparent);
23 return shaped;
24 }
25
26 void IntelliShapedImage::calculateVisiblity(){
27 if(polygonData.size()<=2) {
28 QColor clr;
29 for(int y=0; y<imageData.height(); y++) {
30 for(int x=0; x<imageData.width(); x++) {
31 clr = imageData.pixel(x,y);
32 clr.setAlpha(255);
33 imageData.setPixelColor(x,y,clr);
34 }
35 }
36 return;
37 }
38 QColor clr;
39 for(int y=0; y<imageData.height(); y++) {
40 for(int x=0; x<imageData.width(); x++) {
41 QPoint ptr(x,y);
42 clr = imageData.pixelColor(x,y);
43 bool isInPolygon = IntelliHelper::isInPolygon(triangles, ptr);
44 if(isInPolygon) {
45 clr.setAlpha(std::min(255, clr.alpha()));
46 }else{
47 clr.setAlpha(0);
48 }
49 imageData.setPixelColor(x,y,clr);
50 }
51 }
52 }
53
54 QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
55 QImage copy = imageData;
56 for(int y = 0; y<copy.height(); y++) {
57 for(int x = 0; x<copy.width(); x++) {
58 QColor clr = copy.pixelColor(x,y);
59 clr.setAlpha(std::min(alpha,clr.alpha()));
60 copy.setPixelColor(x,y, clr);
61 }
62 }
63 return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
64 }
65
66 void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
67 if(polygonData.size()<3) {
68 this->polygonData.clear();
69 }else{
70 this->polygonData.clear();
71 for(auto element:polygonData) {
72 this->polygonData.push_back(QPoint(element.x(), element.y()));
73 }
74 triangles = IntelliHelper::calculateTriangles(polygonData);
75 }
76 calculateVisiblity();
77 return;
78 }
IntelliShapedImage::getDisplayable
virtual QImage getDisplayable(const QSize &displaySize, int alpha=255) override
A function returning the displayable ImageData in a requested transparence and size.
Definition: IntelliShapedImage.cpp:54
IntelliShapedImage.h
IntelliHelper.h
IntelliShapedImage
The IntelliShapedImage manages a Shapedimage.
Definition: IntelliShapedImage.h:11
IntelliShapedImage::getDeepCopy
virtual IntelliImage * getDeepCopy() override
A function that copys all that returns a [allocated] Image.
Definition: IntelliShapedImage.cpp:19
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
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
IntelliImage::imageData
QImage imageData
The underlying image data.
Definition: IntelliImage.h:32
IntelliImage
An abstract class which manages the basic IntelliImage operations.
Definition: IntelliImage.h:24
IntelliShapedImage::polygonData
std::vector< QPoint > polygonData
The Vertices of The Polygon. Needs to be a planar Polygon.
Definition: IntelliShapedImage.h:28
IntelliShapedImage::IntelliShapedImage
IntelliShapedImage(int weight, int height)
The Construcor of the IntelliShapedImage. Given the Image dimensions.
Definition: IntelliShapedImage.cpp:7
IntelliShapedImage::~IntelliShapedImage
virtual ~IntelliShapedImage() override
An Destructor.
Definition: IntelliShapedImage.cpp:11
IntelliRasterImage
The IntelliRasterImage manages a Rasterimage.
Definition: IntelliRasterImage.h:9
IntelliShapedImage::setPolygon
virtual void setPolygon(const std::vector< QPoint > &polygonData) override
A function that sets the data of the visible Polygon.
Definition: IntelliShapedImage.cpp:66