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,10 +1,10 @@
|
||||
#include"Image/IntelliImage.h"
|
||||
#include<QSize>
|
||||
#include<QPainter>
|
||||
#include "Image/IntelliImage.h"
|
||||
#include <QSize>
|
||||
#include <QPainter>
|
||||
|
||||
IntelliImage::IntelliImage(int weight, int height)
|
||||
:imageData(QSize(weight, height), QImage::Format_ARGB32){
|
||||
imageData.fill(QColor(255,255,255,255));
|
||||
: imageData(QSize(weight, height), QImage::Format_ARGB32){
|
||||
imageData.fill(QColor(255,255,255,255));
|
||||
}
|
||||
|
||||
IntelliImage::~IntelliImage(){
|
||||
@@ -12,71 +12,71 @@ IntelliImage::~IntelliImage(){
|
||||
}
|
||||
|
||||
bool IntelliImage::loadImage(const QString &fileName){
|
||||
// Holds the image
|
||||
QImage loadedImage;
|
||||
// Holds the image
|
||||
QImage loadedImage;
|
||||
|
||||
// If the image wasn't loaded leave this function
|
||||
if (!loadedImage.load(fileName))
|
||||
return false;
|
||||
// If the image wasn't loaded leave this function
|
||||
if (!loadedImage.load(fileName))
|
||||
return false;
|
||||
|
||||
// scaled Image to size of Layer
|
||||
loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio);
|
||||
// scaled Image to size of Layer
|
||||
loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio);
|
||||
|
||||
imageData = loadedImage.convertToFormat(QImage::Format_ARGB32);
|
||||
return true;
|
||||
imageData = loadedImage.convertToFormat(QImage::Format_ARGB32);
|
||||
return true;
|
||||
}
|
||||
|
||||
void IntelliImage::resizeImage(QImage *image, const QSize &newSize){
|
||||
// Check if we need to redraw the image
|
||||
if (image->size() == newSize)
|
||||
return;
|
||||
void IntelliImage::resizeImage(QImage*image, const QSize &newSize){
|
||||
// Check if we need to redraw the image
|
||||
if (image->size() == newSize)
|
||||
return;
|
||||
|
||||
// Create a new image to display and fill it with white
|
||||
QImage newImage(newSize, QImage::Format_ARGB32);
|
||||
newImage.fill(qRgb(255, 255, 255));
|
||||
// Create a new image to display and fill it with white
|
||||
QImage newImage(newSize, QImage::Format_ARGB32);
|
||||
newImage.fill(qRgb(255, 255, 255));
|
||||
|
||||
// Draw the image
|
||||
QPainter painter(&newImage);
|
||||
painter.drawImage(QPoint(0, 0), *image);
|
||||
*image = newImage;
|
||||
// Draw the image
|
||||
QPainter painter(&newImage);
|
||||
painter.drawImage(QPoint(0, 0), *image);
|
||||
*image = newImage;
|
||||
}
|
||||
|
||||
void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawPoint(p1);
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawPoint(p1);
|
||||
}
|
||||
|
||||
void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawPoint(p1);
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawPoint(p1);
|
||||
}
|
||||
|
||||
void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawLine(p1, p2);
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawLine(p1, p2);
|
||||
}
|
||||
|
||||
void IntelliImage::drawPlain(const QColor& color){
|
||||
imageData.fill(color);
|
||||
imageData.fill(color);
|
||||
}
|
||||
|
||||
QColor IntelliImage::getPixelColor(QPoint& point){
|
||||
return imageData.pixelColor(point);
|
||||
return imageData.pixelColor(point);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#ifndef INTELLIIMAGE_H
|
||||
#define INTELLIIMAGE_H
|
||||
|
||||
#include<QImage>
|
||||
#include<QPoint>
|
||||
#include<QColor>
|
||||
#include<QSize>
|
||||
#include<QWidget>
|
||||
#include<vector>
|
||||
#include <QImage>
|
||||
#include <QPoint>
|
||||
#include <QColor>
|
||||
#include <QSize>
|
||||
#include <QWidget>
|
||||
#include <vector>
|
||||
|
||||
/*!
|
||||
* \brief The Types, which an Image can be.
|
||||
*/
|
||||
enum class ImageType{
|
||||
Raster_Image,
|
||||
Shaped_Image
|
||||
enum class ImageType {
|
||||
Raster_Image,
|
||||
Shaped_Image
|
||||
};
|
||||
|
||||
class IntelliTool;
|
||||
@@ -21,110 +21,112 @@ class IntelliTool;
|
||||
/*!
|
||||
* \brief An abstract class which manages the basic IntelliImage operations.
|
||||
*/
|
||||
class IntelliImage{
|
||||
friend IntelliTool;
|
||||
class IntelliImage {
|
||||
friend IntelliTool;
|
||||
protected:
|
||||
void resizeImage(QImage *image, const QSize &newSize);
|
||||
void resizeImage(QImage*image, const QSize &newSize);
|
||||
|
||||
/*!
|
||||
* \brief The underlying image data.
|
||||
*/
|
||||
QImage imageData;
|
||||
/*!
|
||||
* \brief The underlying image data.
|
||||
*/
|
||||
QImage imageData;
|
||||
public:
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliImage(int weight, int height);
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliImage(int weight, int height);
|
||||
|
||||
/*!
|
||||
* \brief An Abstract Destructor.
|
||||
*/
|
||||
virtual ~IntelliImage() = 0;
|
||||
/*!
|
||||
* \brief An Abstract Destructor.
|
||||
*/
|
||||
virtual ~IntelliImage() = 0;
|
||||
|
||||
|
||||
/*!
|
||||
* \brief A funtcion used to draw a pixel on the Image with the given Color.
|
||||
* \param p1 - The coordinates of the pixel, which should be drawn. [Top-Left-System]
|
||||
* \param color - The color of the pixel.
|
||||
*/
|
||||
virtual void drawPixel(const QPoint &p1, const QColor& color);
|
||||
/*!
|
||||
* \brief A funtcion used to draw a pixel on the Image with the given Color.
|
||||
* \param p1 - The coordinates of the pixel, which should be drawn. [Top-Left-System]
|
||||
* \param color - The color of the pixel.
|
||||
*/
|
||||
virtual void drawPixel(const QPoint &p1, const QColor& color);
|
||||
|
||||
/*!
|
||||
* \brief A function that draws A Line between two given Points in a given color.
|
||||
* \param p1 - The coordinates of the first Point.
|
||||
* \param p2 - The coordinates of the second Point.
|
||||
* \param color - The color of the line.
|
||||
* \param penWidth - The width of the line.
|
||||
*/
|
||||
virtual void drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth);
|
||||
/*!
|
||||
* \brief A function that draws A Line between two given Points in a given color.
|
||||
* \param p1 - The coordinates of the first Point.
|
||||
* \param p2 - The coordinates of the second Point.
|
||||
* \param color - The color of the line.
|
||||
* \param penWidth - The width of the line.
|
||||
*/
|
||||
virtual void drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth);
|
||||
|
||||
/*!
|
||||
* \brief A
|
||||
* \param p1
|
||||
* \param color
|
||||
* \param penWidth
|
||||
*/
|
||||
virtual void drawPoint(const QPoint &p1, const QColor& color, const int& penWidth);
|
||||
/*!
|
||||
* \brief A
|
||||
* \param p1
|
||||
* \param color
|
||||
* \param penWidth
|
||||
*/
|
||||
virtual void drawPoint(const QPoint &p1, const QColor& color, const int& penWidth);
|
||||
|
||||
/*!
|
||||
* \brief A function that clears the whole image in a given Color.
|
||||
* \param color - The color, in which the image will be filled.
|
||||
*/
|
||||
virtual void drawPlain(const QColor& color);
|
||||
/*!
|
||||
* \brief A function that clears the whole image in a given Color.
|
||||
* \param color - The color, in which the image will be filled.
|
||||
*/
|
||||
virtual void drawPlain(const QColor& color);
|
||||
|
||||
/*!
|
||||
* \brief A function returning the displayable ImageData in a requested transparence and size.
|
||||
* \param displaySize - The size, in whcih the Image should be displayed.
|
||||
* \param alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(const QSize& displaySize, int alpha)=0;
|
||||
/*!
|
||||
* \brief A function returning the displayable ImageData in a requested transparence and size.
|
||||
* \param displaySize - The size, in whcih the Image should be displayed.
|
||||
* \param alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(const QSize& displaySize, int alpha) = 0;
|
||||
|
||||
/**
|
||||
* @brief A function returning the displayable ImageData in a requested transparence and it's standart size.
|
||||
* @param alpha - The maximum alpha value, a pixel can have.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255)=0;
|
||||
/**
|
||||
* @brief A function returning the displayable ImageData in a requested transparence and it's standart size.
|
||||
* @param alpha - The maximum alpha value, a pixel can have.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255) = 0;
|
||||
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy()=0;
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() = 0;
|
||||
|
||||
/*!
|
||||
* \brief An abstract function that calculates the visiblity of the Image data if needed.
|
||||
*/
|
||||
virtual void calculateVisiblity()=0;
|
||||
/*!
|
||||
* \brief An abstract function that calculates the visiblity of the Image data if needed.
|
||||
*/
|
||||
virtual void calculateVisiblity() = 0;
|
||||
|
||||
/*!
|
||||
* \brief An abstract function that sets the data of the visible Polygon, if needed.
|
||||
* \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData)=0;
|
||||
/*!
|
||||
* \brief An abstract function that sets the data of the visible Polygon, if needed.
|
||||
* \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) = 0;
|
||||
|
||||
/*!
|
||||
* \brief A function that returns the Polygondata if existent.
|
||||
* \return The Polygondata if existent.
|
||||
*/
|
||||
virtual std::vector<QPoint> getPolygonData(){ return std::vector<QPoint>();}
|
||||
/*!
|
||||
* \brief A function that returns the Polygondata if existent.
|
||||
* \return The Polygondata if existent.
|
||||
*/
|
||||
virtual std::vector<QPoint> getPolygonData(){
|
||||
return std::vector<QPoint>();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief A function that loads and sclaes an image to the fitting dimensions.
|
||||
* \param fileName - The path+name of the image which to loaded.
|
||||
* \return True if the image could be loaded, false otherwise.
|
||||
*/
|
||||
virtual bool loadImage(const QString &fileName);
|
||||
/*!
|
||||
* \brief A function that loads and sclaes an image to the fitting dimensions.
|
||||
* \param fileName - The path+name of the image which to loaded.
|
||||
* \return True if the image could be loaded, false otherwise.
|
||||
*/
|
||||
virtual bool loadImage(const QString &fileName);
|
||||
|
||||
/*!
|
||||
* \brief A function that returns the pixelcolor at a certain point
|
||||
* \param point - The point from whcih to get the coordinates.
|
||||
* \return The color of the Pixel as QColor.
|
||||
*/
|
||||
virtual QColor getPixelColor(QPoint& point);
|
||||
/*!
|
||||
* \brief A function that returns the pixelcolor at a certain point
|
||||
* \param point - The point from whcih to get the coordinates.
|
||||
* \return The color of the Pixel as QColor.
|
||||
*/
|
||||
virtual QColor getPixelColor(QPoint& point);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include"Image/IntelliRasterImage.h"
|
||||
#include<QPainter>
|
||||
#include<QRect>
|
||||
#include<QDebug>
|
||||
#include "Image/IntelliRasterImage.h"
|
||||
#include <QPainter>
|
||||
#include <QRect>
|
||||
#include <QDebug>
|
||||
|
||||
IntelliRasterImage::IntelliRasterImage(int weight, int height)
|
||||
:IntelliImage(weight, height){
|
||||
: IntelliImage(weight, height){
|
||||
|
||||
}
|
||||
|
||||
@@ -13,32 +13,32 @@ IntelliRasterImage::~IntelliRasterImage(){
|
||||
}
|
||||
|
||||
IntelliImage* IntelliRasterImage::getDeepCopy(){
|
||||
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height());
|
||||
raster->imageData.fill(Qt::transparent);
|
||||
return raster;
|
||||
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height());
|
||||
raster->imageData.fill(Qt::transparent);
|
||||
return raster;
|
||||
}
|
||||
|
||||
void IntelliRasterImage::calculateVisiblity(){
|
||||
// not used in raster image
|
||||
// not used in raster image
|
||||
}
|
||||
|
||||
QImage IntelliRasterImage::getDisplayable(int alpha){
|
||||
return getDisplayable(imageData.size(), alpha);
|
||||
return getDisplayable(imageData.size(), alpha);
|
||||
}
|
||||
|
||||
QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){
|
||||
QImage copy = imageData;
|
||||
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);
|
||||
}
|
||||
}
|
||||
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
||||
QImage copy = imageData;
|
||||
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);
|
||||
}
|
||||
}
|
||||
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
||||
}
|
||||
|
||||
void IntelliRasterImage::setPolygon(const std::vector<QPoint>& polygonData){
|
||||
qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n";
|
||||
return;
|
||||
qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
#ifndef INTELLIRASTER_H
|
||||
#define INTELLIRASTER_H
|
||||
|
||||
#include"Image/IntelliImage.h"
|
||||
#include "Image/IntelliImage.h"
|
||||
|
||||
/*!
|
||||
* \brief The IntelliRasterImage manages a Rasterimage.
|
||||
*/
|
||||
class IntelliRasterImage : public IntelliImage{
|
||||
friend IntelliTool;
|
||||
class IntelliRasterImage : public IntelliImage {
|
||||
friend IntelliTool;
|
||||
protected:
|
||||
/*!
|
||||
* \brief A function that calculates the visibility of the image if a polygon is given. [does nothing in Rasterimage]
|
||||
*/
|
||||
virtual void calculateVisiblity() override;
|
||||
/*!
|
||||
* \brief A function that calculates the visibility of the image if a polygon is given. [does nothing in Rasterimage]
|
||||
*/
|
||||
virtual void calculateVisiblity() override;
|
||||
public:
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliRasterImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliRasterImage(int weight, int height);
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliRasterImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliRasterImage(int weight, int height);
|
||||
|
||||
/*!
|
||||
* \brief An Destructor.
|
||||
*/
|
||||
virtual ~IntelliRasterImage() override;
|
||||
/*!
|
||||
* \brief An Destructor.
|
||||
*/
|
||||
virtual ~IntelliRasterImage() override;
|
||||
|
||||
/*!
|
||||
* \brief A function returning the displayable ImageData in a requested transparence and size.
|
||||
* \param displaySize - The size, in whcih the Image should be displayed.
|
||||
* \param alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(const QSize& displaySize,int alpha) override;
|
||||
/*!
|
||||
* \brief A function returning the displayable ImageData in a requested transparence and size.
|
||||
* \param displaySize - The size, in whcih the Image should be displayed.
|
||||
* \param alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(const QSize& displaySize,int alpha) override;
|
||||
|
||||
/**
|
||||
* @brief A function returning the displayable ImageData in a requested transparence and it's standart size.
|
||||
* @param alpha - The maximum alpha value, a pixel can have.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255) override;
|
||||
/**
|
||||
* @brief A function returning the displayable ImageData in a requested transparence and it's standart size.
|
||||
* @param alpha - The maximum alpha value, a pixel can have.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255) override;
|
||||
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() override;
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() override;
|
||||
|
||||
/*!
|
||||
* \brief An abstract function that sets the data of the visible Polygon, if needed.
|
||||
* \param polygonData - The Vertices of the Polygon. Nothing happens.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
/*!
|
||||
* \brief An abstract function that sets the data of the visible Polygon, if needed.
|
||||
* \param polygonData - The Vertices of the Polygon. Nothing happens.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include"Image/IntelliShapedImage.h"
|
||||
#include"IntelliHelper/IntelliHelper.h"
|
||||
#include<QPainter>
|
||||
#include<QRect>
|
||||
#include<QDebug>
|
||||
#include "Image/IntelliShapedImage.h"
|
||||
#include "IntelliHelper/IntelliHelper.h"
|
||||
#include <QPainter>
|
||||
#include <QRect>
|
||||
#include <QDebug>
|
||||
|
||||
IntelliShapedImage::IntelliShapedImage(int weight, int height)
|
||||
:IntelliRasterImage(weight, height){
|
||||
: IntelliRasterImage(weight, height){
|
||||
}
|
||||
|
||||
IntelliShapedImage::~IntelliShapedImage(){
|
||||
@@ -13,66 +13,66 @@ IntelliShapedImage::~IntelliShapedImage(){
|
||||
}
|
||||
|
||||
QImage IntelliShapedImage::getDisplayable(int alpha){
|
||||
return getDisplayable(imageData.size(),alpha);
|
||||
return getDisplayable(imageData.size(),alpha);
|
||||
}
|
||||
|
||||
IntelliImage* IntelliShapedImage::getDeepCopy(){
|
||||
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
|
||||
shaped->setPolygon(this->polygonData);
|
||||
shaped->imageData.fill(Qt::transparent);
|
||||
return shaped;
|
||||
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
|
||||
shaped->setPolygon(this->polygonData);
|
||||
shaped->imageData.fill(Qt::transparent);
|
||||
return shaped;
|
||||
}
|
||||
|
||||
void IntelliShapedImage::calculateVisiblity(){
|
||||
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);
|
||||
}
|
||||
}
|
||||
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 = IntelliHelper::isInPolygon(triangles, ptr);
|
||||
if(isInPolygon){
|
||||
clr.setAlpha(std::min(255, clr.alpha()));
|
||||
}else{
|
||||
clr.setAlpha(0);
|
||||
}
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
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 = IntelliHelper::isInPolygon(triangles, ptr);
|
||||
if(isInPolygon) {
|
||||
clr.setAlpha(std::min(255, clr.alpha()));
|
||||
}else{
|
||||
clr.setAlpha(0);
|
||||
}
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
|
||||
QImage copy = imageData;
|
||||
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);
|
||||
}
|
||||
}
|
||||
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
||||
QImage copy = imageData;
|
||||
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);
|
||||
}
|
||||
}
|
||||
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 = IntelliHelper::calculateTriangles(polygonData);
|
||||
}
|
||||
calculateVisiblity();
|
||||
return;
|
||||
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 = IntelliHelper::calculateTriangles(polygonData);
|
||||
}
|
||||
calculateVisiblity();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,76 +1,78 @@
|
||||
#ifndef INTELLISHAPE_H
|
||||
#define INTELLISHAPE_H
|
||||
|
||||
#include"Image/IntelliRasterImage.h"
|
||||
#include<vector>
|
||||
#include"IntelliHelper/IntelliHelper.h"
|
||||
#include "Image/IntelliRasterImage.h"
|
||||
#include <vector>
|
||||
#include "IntelliHelper/IntelliHelper.h"
|
||||
|
||||
/*!
|
||||
* \brief The IntelliShapedImage manages a Shapedimage.
|
||||
*/
|
||||
class IntelliShapedImage : public IntelliRasterImage{
|
||||
friend IntelliTool;
|
||||
class IntelliShapedImage : public IntelliRasterImage {
|
||||
friend IntelliTool;
|
||||
private:
|
||||
/*!
|
||||
* \brief The Triangulation of the Polygon. Saved here for performance reasons.
|
||||
*/
|
||||
std::vector<Triangle> triangles;
|
||||
/*!
|
||||
* \brief The Triangulation of the Polygon. Saved here for performance reasons.
|
||||
*/
|
||||
std::vector<Triangle> triangles;
|
||||
|
||||
/*!
|
||||
* \brief Calculates the visibility based on the underlying polygon.
|
||||
*/
|
||||
virtual void calculateVisiblity() override;
|
||||
/*!
|
||||
* \brief Calculates the visibility based on the underlying polygon.
|
||||
*/
|
||||
virtual void calculateVisiblity() override;
|
||||
protected:
|
||||
|
||||
/*!
|
||||
* \brief The Vertices of The Polygon. Needs to be a planar Polygon.
|
||||
*/
|
||||
std::vector<QPoint> polygonData;
|
||||
/*!
|
||||
* \brief The Vertices of The Polygon. Needs to be a planar Polygon.
|
||||
*/
|
||||
std::vector<QPoint> polygonData;
|
||||
public:
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliShapedImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliShapedImage(int weight, int height);
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliShapedImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliShapedImage(int weight, int height);
|
||||
|
||||
/*!
|
||||
* \brief An Destructor.
|
||||
*/
|
||||
virtual ~IntelliShapedImage() override;
|
||||
/*!
|
||||
* \brief An Destructor.
|
||||
*/
|
||||
virtual ~IntelliShapedImage() override;
|
||||
|
||||
/*!
|
||||
* \brief A function returning the displayable ImageData in a requested transparence and size.
|
||||
* \param displaySize - The size, in whcih the Image should be displayed.
|
||||
* \param alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(const QSize& displaySize, int alpha=255) override;
|
||||
/*!
|
||||
* \brief A function returning the displayable ImageData in a requested transparence and size.
|
||||
* \param displaySize - The size, in whcih the Image should be displayed.
|
||||
* \param alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(const QSize& displaySize, int alpha=255) override;
|
||||
|
||||
/**
|
||||
* @brief A function returning the displayable ImageData in a requested transparence and it's standart size.
|
||||
* @param alpha - The maximum alpha value, a pixel can have.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255) override;
|
||||
/**
|
||||
* @brief A function returning the displayable ImageData in a requested transparence and it's standart size.
|
||||
* @param alpha - The maximum alpha value, a pixel can have.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255) override;
|
||||
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() override;
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() override;
|
||||
|
||||
/*!
|
||||
* \brief A function that returns the Polygondata if existent.
|
||||
* \return The Polygondata if existent.
|
||||
*/
|
||||
virtual std::vector<QPoint> getPolygonData() override{return polygonData;}
|
||||
/*!
|
||||
* \brief A function that returns the Polygondata if existent.
|
||||
* \return The Polygondata if existent.
|
||||
*/
|
||||
virtual std::vector<QPoint> getPolygonData() override {
|
||||
return polygonData;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief A function that sets the data of the visible Polygon.
|
||||
* \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
/*!
|
||||
* \brief A function that sets the data of the visible Polygon.
|
||||
* \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user