IntelliShapedImage.cpp
Go to the documentation of this file.
#include "Image/IntelliShapedImage.h"
#include "IntelliHelper/IntelliTriangulation.h"
#include <QPainter>
#include <QRect>
#include <QDebug>
IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn)
: IntelliRasterImage(width, height, fastRendererOn){
TypeOfImage = ImageType::SHAPEDIMAGE;
}
IntelliShapedImage::~IntelliShapedImage(){
}
QImage IntelliShapedImage::getDisplayable(int alpha){
return getDisplayable(imageData.size(),alpha);
}
IntelliImage* IntelliShapedImage::getDeepCopy(){
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), false);
shaped->setPolygon(this->polygonData);
shaped->imageData.fill(Qt::transparent);
shaped->TypeOfImage = ImageType::SHAPEDIMAGE;
return shaped;
}
void IntelliShapedImage::calculateVisiblity(){
if(polygonData.size()<2) {
return;
}
if(fastRenderering) {
this->imageData = imageData.convertToFormat(QImage::Format_ARGB32);
}
if(polygonData.size()<=2) {
QColor clr;
for(int y = 0; y<imageData.height(); y++) {
for(int x = 0; x<imageData.width(); x++) {
clr = imageData.pixel(x,y);
clr.setAlpha(255);
imageData.setPixelColor(x,y,clr);
}
}
if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
}
return;
}
QColor clr;
for(int y = 0; y<imageData.height(); y++) {
for(int x = 0; x<imageData.width(); x++) {
QPoint ptr(x,y);
clr = imageData.pixelColor(x,y);
bool isInPolygon = IntelliTriangulation::isInPolygon(triangles, ptr);
if(isInPolygon) {
clr.setAlpha(std::min(255, clr.alpha()));
}else{
clr.setAlpha(0);
}
imageData.setPixelColor(x,y,clr);
}
}
if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
}
}
QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
QImage copy = imageData;
if(fastRenderering) {
copy = copy.convertToFormat(QImage::Format_ARGB32);
}
for(int y = 0; y<copy.height(); y++) {
for(int x = 0; x<copy.width(); x++) {
QColor clr = copy.pixelColor(x,y);
clr.setAlpha(std::min(alpha,clr.alpha()));
copy.setPixelColor(x,y, clr);
}
}
if(fastRenderering) {
copy = copy.convertToFormat(QImage::Format_Indexed8);
}
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
}
void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
if(polygonData.size()<3) {
this->polygonData.clear();
}else{
this->polygonData.clear();
for(auto element:polygonData) {
this->polygonData.push_back(QPoint(element.x(), element.y()));
}
triangles = IntelliTriangulation::calculateTriangles(polygonData);
if(fastRenderering) {
imageData = imageData.convertToFormat(QImage::Format_ARGB32);
}
for(int y = 0; y<imageData.height(); y++) {
for(int x = 0; x<imageData.width(); x++) {
QColor clr = imageData.pixelColor(x,y);
clr.setAlpha(255);
imageData.setPixelColor(x,y,clr);
}
}
if(fastRenderering) {
imageData = imageData.convertToFormat(QImage::Format_Indexed8);
}
}
calculateVisiblity();
return;
}
std::vector<QPoint> IntelliShapedImage::getPolygon(){
return polygonData;
}
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