IntelliPhoto  0.5
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  this->fastRenderering = fastRendererOn;
11 }
12 
14 
15 }
16 
18  return getDisplayable(imageData.size(),alpha);
19 }
20 
22  IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), false);
23  shaped->setPolygon(this->polygonData);
24  shaped->imageData.fill(Qt::transparent);
26  return shaped;
27 }
28 
29 void IntelliShapedImage::calculateVisiblity(){
30  if(polygonData.size()<2) {
31  return;
32  }
33  if(fastRenderering) {
34  this->imageData = imageData.convertToFormat(QImage::Format_ARGB32);
35  }
36 
37  if(polygonData.size()<=2) {
38  QColor clr;
39  for(int y = 0; y<imageData.height(); y++) {
40  for(int x = 0; x<imageData.width(); x++) {
41  clr = imageData.pixel(x,y);
42  clr.setAlpha(255);
43  imageData.setPixelColor(x,y,clr);
44  }
45  }
46  if(fastRenderering) {
47  this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
48  }
49  return;
50  }
51  QColor clr;
52  for(int y = 0; y<imageData.height(); y++) {
53  for(int x = 0; x<imageData.width(); x++) {
54  QPoint ptr(x,y);
55  clr = imageData.pixelColor(x,y);
56  bool isInPolygon = IntelliTriangulation::isInPolygon(triangles, ptr);
57  if(isInPolygon) {
58  clr.setAlpha(std::min(255, clr.alpha()));
59  }else{
60  clr.setAlpha(0);
61  }
62  imageData.setPixelColor(x,y,clr);
63  }
64  }
65  if(fastRenderering) {
66  this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
67  }
68 }
69 
70 QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
71  QImage copy = imageData;
72  if(fastRenderering) {
73  copy = copy.convertToFormat(QImage::Format_ARGB32);
74  }
75  for(int y = 0; y<copy.height(); y++) {
76  for(int x = 0; x<copy.width(); x++) {
77  QColor clr = copy.pixelColor(x,y);
78  clr.setAlpha(std::min(alpha,clr.alpha()));
79  copy.setPixelColor(x,y, clr);
80  }
81  }
82  if(fastRenderering) {
83  copy = copy.convertToFormat(QImage::Format_Indexed8);
84  }
85  return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
86 }
87 
88 void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
89  if(polygonData.size()<3) {
90  this->polygonData.clear();
91  }else{
92  this->polygonData.clear();
93  for(auto element:polygonData) {
94  this->polygonData.push_back(QPoint(element.x(), element.y()));
95  }
97  if(fastRenderering) {
98  imageData = imageData.convertToFormat(QImage::Format_ARGB32);
99  }
100  for(int y = 0; y<imageData.height(); y++) {
101  for(int x = 0; x<imageData.width(); x++) {
102  QColor clr = imageData.pixelColor(x,y);
103  clr.setAlpha(255);
104  imageData.setPixelColor(x,y,clr);
105  }
106  }
107  if(fastRenderering) {
108  imageData = imageData.convertToFormat(QImage::Format_Indexed8);
109  }
110  }
111  calculateVisiblity();
112  return;
113 }
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:70
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
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:21
IntelliImage::fastRenderering
bool fastRenderering
fastRendering is the flag that represents the usage of 8bit pictures.
Definition: IntelliImage.h:51
IntelliImage::ImageType::SHAPEDIMAGE
@ SHAPEDIMAGE
IntelliTriangulation::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: IntelliTriangulation.cpp:116
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:22
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
IntelliShapedImage::~IntelliShapedImage
virtual ~IntelliShapedImage() override
An Destructor.
Definition: IntelliShapedImage.cpp:13
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:88