Merge branch 'PolygonFixes' into 'dev'

Polygon Fixes

See merge request creyd/intelliphoto!27
This commit is contained in:
Bastian Schindler
2020-01-07 16:41:13 +00:00
11 changed files with 67 additions and 21 deletions

View File

@@ -5,6 +5,7 @@
IntelliImage::IntelliImage(int weight, int height)
: imageData(QSize(weight, height), QImage::Format_ARGB32){
imageData.fill(QColor(255,255,255,255));
}
IntelliImage::~IntelliImage(){

View File

@@ -8,13 +8,7 @@
#include <QWidget>
#include <vector>
/*!
* \brief The Types, which an Image can be.
*/
enum class ImageType {
Raster_Image,
Shaped_Image
};
#include "IntelliHelper/IntelliHelper.h"
class IntelliTool;
@@ -23,6 +17,16 @@ class IntelliTool;
*/
class IntelliImage {
friend IntelliTool;
public:
/*!
* \brief The Types, which an Image can be.
*/
enum class ImageType {
Raster_Image,
Shaped_Image
};
protected:
void resizeImage(QImage*image, const QSize &newSize);
@@ -30,6 +34,11 @@ void resizeImage(QImage*image, const QSize &newSize);
* \brief The underlying image data.
*/
QImage imageData;
/*!
* \brief The Type, an Image is.
*/
ImageType TypeOfImage;
public:
/*!
* \brief The Construcor of the IntelliImage. Given the Image dimensions.
@@ -114,6 +123,10 @@ virtual std::vector<QPoint> getPolygonData(){
return std::vector<QPoint>();
}
virtual ImageType getTypeOfImage(){
return TypeOfImage;
}
/*!
* \brief A function that loads and sclaes an image to the fitting dimensions.
* \param filePath - The path+name of the image which to loaded.

View File

@@ -5,7 +5,7 @@
IntelliRasterImage::IntelliRasterImage(int weight, int height)
: IntelliImage(weight, height){
TypeOfImage = IntelliImage::ImageType::Raster_Image;
}
IntelliRasterImage::~IntelliRasterImage(){
@@ -15,6 +15,7 @@ IntelliRasterImage::~IntelliRasterImage(){
IntelliImage* IntelliRasterImage::getDeepCopy(){
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height());
raster->imageData.fill(Qt::transparent);
raster->TypeOfImage = IntelliImage::ImageType::Raster_Image;
return raster;
}

View File

@@ -6,6 +6,7 @@
IntelliShapedImage::IntelliShapedImage(int weight, int height)
: IntelliRasterImage(weight, height){
TypeOfImage = IntelliImage::ImageType::Shaped_Image;
}
IntelliShapedImage::~IntelliShapedImage(){
@@ -20,6 +21,7 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
shaped->setPolygon(this->polygonData);
shaped->imageData.fill(Qt::transparent);
shaped->TypeOfImage = IntelliImage::ImageType::Shaped_Image;
return shaped;
}

View File

@@ -3,7 +3,6 @@
#include "Image/IntelliRasterImage.h"
#include <vector>
#include "IntelliHelper/IntelliHelper.h"
/*!
* \brief The IntelliShapedImage manages a Shapedimage.

View File

@@ -22,7 +22,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
: QWidget(parent){
this->Tool = nullptr;
this->setLayerDimensions(maxWidth, maxHeight);
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
this->addLayer(200,200,0,0,IntelliImage::ImageType::Shaped_Image);
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
std::vector<QPoint> polygon;
polygon.push_back(QPoint(100,000));
@@ -31,7 +31,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
polygon.push_back(QPoint(000,100));
layerBundle[0].image->setPolygon(polygon);
this->addLayer(200,200,150,150);
this->addLayer(200,200,150,150,IntelliImage::ImageType::Raster_Image);
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
layerBundle[1].alpha=200;
@@ -53,15 +53,15 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
}
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){
LayerObject newLayer;
newLayer.width = width;
newLayer.height = height;
newLayer.widthOffset = widthOffset;
newLayer.heightOffset = heightOffset;
if(type==ImageType::Raster_Image) {
if(type==IntelliImage::ImageType::Raster_Image) {
newLayer.image = new IntelliRasterImage(width,height);
}else if(type==ImageType::Shaped_Image) {
}else if(type==IntelliImage::ImageType::Shaped_Image) {
newLayer.image = new IntelliShapedImage(width, height);
}
newLayer.alpha = 255;
@@ -234,6 +234,14 @@ int PaintingArea::getHeightOfActive(){
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].height;
}
IntelliImage::ImageType PaintingArea::getTypeOfImageRealLayer(){
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].image->getTypeOfImage();
}
std::vector<QPoint> PaintingArea::getPolygonDataOfRealLayer(){
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].image->getPolygonData();
}
// If a mouse button is pressed check if it was the
// left button and if so store the current position
// Set that we are currently drawing

View File

@@ -79,7 +79,7 @@ public:
* \param type - Defining the ImageType of the new layer
* \return Returns the number of layers in the project
*/
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image);
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::Raster_Image);
/*!
* \brief The addLayerAt adds a layer to the current project/ painting area at a specific position in the layer stack
* \param idx - ID of the position the new layer should be added
@@ -90,7 +90,7 @@ public:
* \param type - Defining the ImageType of the new layer
* \return Returns the id of the layer position
*/
int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image);
int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::Raster_Image);
/*!
* \brief The deleteLayer method removes a layer at a given index
* \param index - The index of the layer to be removed
@@ -161,6 +161,10 @@ public:
*/
int getHeightOfActive();
IntelliImage::ImageType getTypeOfImageRealLayer();
std::vector<QPoint> getPolygonDataOfRealLayer();
public slots:
// Events to handle
/*!

View File

@@ -49,8 +49,8 @@ void IntelliTool::onWheelScrolled(int value){
void IntelliTool::createToolLayer(){
Area->createTempTopLayer(Area->activeLayer);
this->activeLayer=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
this->Canvas=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer+1)];
this->activeLayer=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
this->Canvas=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer+1)];
}
void IntelliTool::mergeToolLayer(){

View File

@@ -25,7 +25,7 @@ void IntelliToolPen::onMouseRightReleased(int x, int y){
void IntelliToolPen::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->previousPoint=QPoint(x,y);
this->Canvas->image->drawPixel(previousPoint, colorPicker->getFirstColor());
this->Canvas->image->drawPoint(previousPoint, colorPicker->getFirstColor(), penWidth);
Canvas->image->calculateVisiblity();
}

View File

@@ -1,8 +1,8 @@
#include "IntelliToolPolygon.h"
#include "Layer/PaintingArea.h"
#include <QDebug>
#include <QCursor>
#include <QInputDialog>
#include <QDebug>
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
@@ -10,6 +10,7 @@ IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* c
lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",5,1,10,1);
isPointNearStart = false;
isDrawing = false;
isInside = false;
this->ActiveType = Tooltype::POLYGON;
}
@@ -20,7 +21,16 @@ IntelliToolPolygon::~IntelliToolPolygon(){
}
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
if(!isDrawing && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::Shaped_Image && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()){
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(Area->getPolygonDataOfRealLayer());
QPoint Point(x,y);
isInside = IntelliHelper::isInPolygon(Triangles,Point);
}
else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::Raster_Image && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()){
isInside = true;
}
if(isInside && !isDrawing) {
IntelliTool::onMouseLeftPressed(x,y);
QPoint drawingPoint = QPoint(x,y);
@@ -37,6 +47,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
this->Canvas->image->calculateVisiblity();
}
else{
isInside = false;
isDrawing = false;
QPointList.clear();
IntelliTool::onMouseRightPressed(x,y);
@@ -52,6 +63,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
}
void IntelliToolPolygon::onMouseRightPressed(int x, int y){
isInside = false;
isDrawing = false;
isPointNearStart = false;
QPointList.clear();
@@ -60,6 +72,7 @@ void IntelliToolPolygon::onMouseRightPressed(int x, int y){
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
if(isPointNearStart) {
isInside = false;
isPointNearStart = false;
isDrawing = false;
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);

View File

@@ -29,6 +29,11 @@ int lineWidth;
*/
bool isDrawing;
/*!
* \brief isInside Checks if Point is inside Image
*/
bool isInside;
/*!
* \brief PointIsNearStart true, when last click near startpoint, else false.
*/