IntelliPhoto  1
IntelliShapedImage.cpp
Go to the documentation of this file.
3 #include <QPainter>
4 #include <QRect>
5 #include <QDebug>
6 
7 IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn)
8  : IntelliRasterImage(width, height, fastRendererOn){
10 }
11 
13 
14 }
15 
17  return getDisplayable(imageData.size(),alpha);
18 }
19 
21  IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), false);
22  shaped->setPolygon(this->polygonData);
23  shaped->imageData.fill(Qt::transparent);
25  return shaped;
26 }
27 
28 void IntelliShapedImage::calculateVisiblity(){
29  if(polygonData.size()<2) {
30  return;
31  }
32  if(fastRenderering) {
33  this->imageData = imageData.convertToFormat(QImage::Format_ARGB32);
34  }
35 
36  if(polygonData.size()<=2) {
37  QColor clr;
38  for(int y = 0; y<imageData.height(); y++) {
39  for(int x = 0; x<imageData.width(); x++) {
40  clr = imageData.pixel(x,y);
41  clr.setAlpha(255);
42  imageData.setPixelColor(x,y,clr);
43  }
44  }
45  if(fastRenderering) {
46  this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
47  }
48  return;
49  }
50  QColor clr;
51  for(int y = 0; y<imageData.height(); y++) {
52  for(int x = 0; x<imageData.width(); x++) {
53  QPoint ptr(x,y);
54  clr = imageData.pixelColor(x,y);
55  bool isInPolygon = IntelliTriangulation::isInPolygon(triangles, ptr);
56  if(isInPolygon) {
57  clr.setAlpha(std::min(255, clr.alpha()));
58  }else{
59  clr.setAlpha(0);
60  }
61  imageData.setPixelColor(x,y,clr);
62  }
63  }
64  if(fastRenderering) {
65  this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
66  }
67 }
68 
69 QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
70  QImage copy = imageData;
71  if(fastRenderering) {
72  copy = copy.convertToFormat(QImage::Format_ARGB32);
73  }
74  for(int y = 0; y<copy.height(); y++) {
75  for(int x = 0; x<copy.width(); x++) {
76  QColor clr = copy.pixelColor(x,y);
77  clr.setAlpha(std::min(alpha,clr.alpha()));
78  copy.setPixelColor(x,y, clr);
79  }
80  }
81  if(fastRenderering) {
82  copy = copy.convertToFormat(QImage::Format_Indexed8);
83  }
84  return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
85 }
86 
87 void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
88  if(polygonData.size()<3) {
89  this->polygonData.clear();
90  }else{
91  this->polygonData.clear();
92  for(auto element:polygonData) {
93  this->polygonData.push_back(QPoint(element.x(), element.y()));
94  }
96  if(fastRenderering) {
97  imageData = imageData.convertToFormat(QImage::Format_ARGB32);
98  }
99  for(int y = 0; y<imageData.height(); y++) {
100  for(int x = 0; x<imageData.width(); x++) {
101  QColor clr = imageData.pixelColor(x,y);
102  clr.setAlpha(255);
103  imageData.setPixelColor(x,y,clr);
104  }
105  }
106  if(fastRenderering) {
107  imageData = imageData.convertToFormat(QImage::Format_Indexed8);
108  }
109  }
110  calculateVisiblity();
111  return;
112 }
113 
114 std::vector<QPoint> IntelliShapedImage::getPolygon(){
115  return polygonData;
116 }
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:69
IntelliShapedImage.h
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
IntelliShapedImage::getPolygon
virtual std::vector< QPoint > getPolygon() override
getPolygon
Definition: IntelliShapedImage.cpp:114
IntelliShapedImage
The IntelliShapedImage manages a Shapedimage.
Definition: IntelliShapedImage.h:13
IntelliShapedImage::getDeepCopy
virtual IntelliImage * getDeepCopy() override
A function that copys all that returns a [allocated] Image.
Definition: IntelliShapedImage.cpp:20
IntelliImage::fastRenderering
bool fastRenderering
fastRendering is the flag that represents the usage of 8bit pictures.
Definition: IntelliImage.h:51
ImageType::SHAPEDIMAGE
@ SHAPEDIMAGE
IntelliImage::TypeOfImage
ImageType TypeOfImage
The Type, an Image is.
Definition: IntelliImage.h:46
IntelliImage::imageData
QImage imageData
The underlying image data.
Definition: IntelliImage.h:41
IntelliImage
An abstract class which manages the basic IntelliImage operations.
Definition: IntelliImage.h:30
IntelliShapedImage::polygonData
std::vector< QPoint > polygonData
The Vertices of The Polygon. Needs to be a planar Polygon.
Definition: IntelliShapedImage.h:31
IntelliShapedImage::IntelliShapedImage
IntelliShapedImage(int width, int height, bool fastRendererOn)
The Construcor of the IntelliShapedImage. Given the Image dimensions.
Definition: IntelliShapedImage.cpp:7
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
IntelliShapedImage::~IntelliShapedImage
virtual ~IntelliShapedImage() override
An Destructor.
Definition: IntelliShapedImage.cpp:12
IntelliRasterImage
The IntelliRasterImage manages a RASTERIMAGE.
Definition: IntelliRasterImage.h:12
IntelliTriangulation.h
IntelliShapedImage::setPolygon
virtual void setPolygon(const std::vector< QPoint > &polygonData) override
A function that sets the data of the visible Polygon.
Definition: IntelliShapedImage.cpp:87