diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 26ef6a8..3be9ee9 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -10,6 +10,7 @@ set(SOURCE_FILES functions/solve/structure.cpp functions/AbstractionLayers/AbstraktionLayer_Base.h functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp + functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition.cpp functions/AbstractionLayers/DestructionPower/DestructionPower.cpp header/solve.h header/input.h diff --git a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h index 8d8eb9f..f51fc35 100644 --- a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h +++ b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h @@ -1,6 +1,6 @@ #pragma once //TODO!! increase Destructioncount -#define DESTRUCTION_COUNT 1 +#define DESTRUCTION_COUNT 2 #include "DestructionPower_Properties.h" #include "../AbstraktionLayer_Base.h" diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp index e4c0100..ef3ccba 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp @@ -36,7 +36,7 @@ bool AbstractionLayer_1::PreProcessing(coor mySize, const vector* partAr //Zugriff auf den vector mit den einzelnen teilen: part[0].getConnenctions() entspricht pömpel von bild 0.jpg und liefert ein unsigned char, poempl Belegung wie ausgemacht - InitialiseConstraintMatrixSize(mySize.col+2, mySize.row+2); //col row switched in this function + InitialiseConstraintMatrixSize(mySize.col+2, mySize.row+2); setEdgeZero(); cout << "Done!" << endl; @@ -73,15 +73,11 @@ int AbstractionLayer_1::PoempelSum(uint8_t constraint) //it through qualityVector and removes all that do not trigger PlaceOfPartGood bool AbstractionLayer_1::EvaluateQuality (const coor constraintCoordinate, qualityVector& qVector) { - if(constraintCoordinate.row==23 && constraintCoordinate.col==35) - cout << "in" << endl; - //evaluateQuality = evaluateProbabilaty for(int i = 0;im_a1.m_connections)) { qVector[i].first=1; - continue; } qVector[i].first=0; diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h index 42189c8..6e770b4 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h @@ -45,10 +45,10 @@ using namespace cv; class AbstractionLayer_1 : public AbstractionLayer_Base { public: - bool PreProcessing(coor mySize, const vector* partArray) override ; - bool EvaluateQuality ( coor constraintCoordinate, qualityVector& qVector)override; - bool SetConstraintOnPosition( coor constraintCoordinate, AbstractionLayer_1_Properties constraint)override; - bool RemoveConstraintOnPosition( coor constraintCoordinate)override; + bool PreProcessing(coor mySize, const vector* partArray) final ; + bool EvaluateQuality ( coor constraintCoordinate, qualityVector& qVector)final; + bool SetConstraintOnPosition( coor constraintCoordinate, AbstractionLayer_1_Properties constraint)final; + bool RemoveConstraintOnPosition( coor constraintCoordinate)final; int RemoveSimilar(qualityVector&,uint8_t&); bool PlaceOfPartGood(coor myCoor, uint8_t& myPart); diff --git a/Source/functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition.cpp b/Source/functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition.cpp new file mode 100644 index 0000000..0393000 --- /dev/null +++ b/Source/functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition.cpp @@ -0,0 +1,56 @@ +#include "AbstractionLayer_PoempelPosition.h" +#include "../../../header.h" + +bool AbstractionLayer_PoempelPosition::PreProcessing(coor mySize, const vector* partArray) +{ + //get layer information here + cout << "Abstraction Poempel Position Preprocessing... " << flush; + + + InitialiseConstraintMatrixSize(mySize.col, mySize.row); + + cout << "Done" << endl; + return false; +} + +//it through qualityVector and removes all that do not trigger PlaceOfPartGood +bool AbstractionLayer_PoempelPosition::EvaluateQuality (const coor constraintCoordinate, qualityVector& qVector) +{ + for(int i = 0;im_a3.SideLength)); + if(value > 0.8)//TODO find threshold + { + qVector[i].first=value; + continue; + } + qVector[i].first=0; + } +} + +bool AbstractionLayer_PoempelPosition::SetConstraintOnPosition(const coor constraintCoordinate, const AbstractionLayer_PoempelPosition_Properties constraint) +{ + m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].SideLength=constraint.SideLength; +} + +bool AbstractionLayer_PoempelPosition::RemoveConstraintOnPosition(const coor constraintCoordinate) +{ + m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].SideLength={0,0,0,0,0,0,0,0}; +} + +float AbstractionLayer_PoempelPosition::PlaceOfPartGood(coor myCoor, vector myPart) +{ + //sets coordinates to correct position for layer + + //create negativePart, watch out for edges + + //check vector against negative part + + //return of well it fits within threshold +} + +//shifts vector i steps to the right (8-2i to the left) +void AbstractionLayer_PoempelPosition_Properties::shift(int i) +{ + rotate(SideLength.begin(),SideLength.begin()+(8-2*i),SideLength.end()); +} diff --git a/Source/functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition.h b/Source/functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition.h new file mode 100644 index 0000000..8db2906 --- /dev/null +++ b/Source/functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition.h @@ -0,0 +1,22 @@ +#pragma once + +#include "AbstractionLayer_PoempelPosition_Properties.h" +#include "../AbstraktionLayer_Base.h" +#include "opencv2/highgui/highgui.hpp" +#include "opencv2/imgproc/imgproc.hpp" + +using namespace std; +using namespace cv; + +class AbstractionLayer_PoempelPosition : public AbstractionLayer_Base +{ +public: + bool PreProcessing(coor mySize, const vector* partArray) final ; + bool EvaluateQuality ( coor constraintCoordinate, qualityVector& qVector)final; + bool SetConstraintOnPosition( coor constraintCoordinate, AbstractionLayer_PoempelPosition_Properties constraint)final; + bool RemoveConstraintOnPosition( coor constraintCoordinate)final; + + float PlaceOfPartGood(coor myCoor, vector myPart); + +private: +}; \ No newline at end of file diff --git a/Source/functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition_Properties.h b/Source/functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition_Properties.h new file mode 100644 index 0000000..5664c5a --- /dev/null +++ b/Source/functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition_Properties.h @@ -0,0 +1,17 @@ + +#pragma once +#include +using namespace std; +class AbstractionLayer_PoempelPosition_Properties +{ +public: + AbstractionLayer_PoempelPosition_Properties():SideLength({0,0,0,0,0,0,0,0}){} + float getSideLength(int i){if (i<8 && i>=0)return SideLength[i]; else return -1;}; + void shift(int i); +private: + + vector SideLength; + friend class AbstractionLayer_PoempelPosition; +}; + + diff --git a/Source/functions/AbstractionLayers/LayerMeanDifference/AbstractionLayer_MeanDifference.h b/Source/functions/AbstractionLayers/LayerMeanDifference/AbstractionLayer_MeanDifference.h deleted file mode 100644 index b3556c2..0000000 --- a/Source/functions/AbstractionLayers/LayerMeanDifference/AbstractionLayer_MeanDifference.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// Created by Niko on 1/15/2018. -// - -#ifndef MPK_PUZZLE_ABSTRACTIONLAYER_MEANDIFFERENCE_H -#define MPK_PUZZLE_ABSTRACTIONLAYER_MEANDIFFERENCE_H -#define DISPLAY false -#define PATH "..\\..\\..\\pieces\\%04d.jpg" - -using namespace std; -using namespace cv; - -class AbstractionLayer_MeanDifference : public AbstractionLayer_Base -{ -public: - bool PreProcessing(coor mySize, const vector* partArray) override ; - bool EvaluateQuality ( coor constraintCoordinate, qualityVector& qVector)override; - bool SetConstraintOnPosition( coor constraintCoordinate, AbstractionLayer_1_Properties constraint)override; - bool RemoveConstraintOnPosition( coor constraintCoordinate)override; - bool PlaceOfPartGood(coor myCoor, Mat& myPart); - - qualityVector returnInBox(vector& PuzzleBox); - void printConstraintMatrix(); - -private: -}; - -class cMeanDifference{ -public: - Mat readImages(int); - bool calculateMeanDifference(Mat Part, Mat RefPart); -private: - -}; -#endif //MPK_PUZZLE_ABSTRACTIONLAYER_MEANDIFFERENCE_H diff --git a/Source/functions/AbstractionLayers/LayerMeanDifference/AbstractionLayer_MeanDifference_Properties.h b/Source/functions/AbstractionLayers/LayerMeanDifference/AbstractionLayer_MeanDifference_Properties.h deleted file mode 100644 index 2a1cdd9..0000000 --- a/Source/functions/AbstractionLayers/LayerMeanDifference/AbstractionLayer_MeanDifference_Properties.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Created by Niko on 1/15/2018. -// - -#ifndef MPK_PUZZLE_ABSTRACTIONLAYER_MEANDIFFERENCE_PROPERTIES_H -#define MPK_PUZZLE_ABSTRACTIONLAYER_MEANDIFFERENCE_PROPERTIES_H - -class AbstractionLayer_MeanDifference_Properties -{ -public: - AbstractionLayer_MeanDifference_Properties() : MeanDifference(-1){} - double getMeanDifference(){return MeanDifference;}; - -private: - - double MeanDifference; - friend class AbstractionLayer_MeanDifference; - Mat image; -}; -#endif //MPK_PUZZLE_ABSTRACTIONLAYER_MEANDIFFERENCE_PROPERTIES_H diff --git a/Source/functions/solve/puzzleExtension.cpp b/Source/functions/solve/puzzleExtension.cpp index 82a9c64..2b26476 100644 --- a/Source/functions/solve/puzzleExtension.cpp +++ b/Source/functions/solve/puzzleExtension.cpp @@ -37,12 +37,14 @@ void Puzzle::putIntoBox() { tmpPart.m_a1=this->a1.m_constraintMatrix[i+1][j+1]; + tmpPart.m_a3=this->a3.m_constraintMatrix[i][j]; //sets part id tmpPart.SetPartID(id++); // adds all 4 rotations to Box for(int rotations=0;rotations<4;rotations++) { tmpPart.m_a1.shift(1); + tmpPart.m_a3.shift(1); //TODO! add all other layer with their rotaionvariance into "tmpPart" //if it piece is roation invariant no need to do anything myBox.emplace_back(tmpPart); @@ -63,6 +65,7 @@ void Puzzle::shuffle() void Puzzle::removeConstrains(coor removeCoordinates) { this->a1.RemoveConstraintOnPosition(removeCoordinates); + this->a3.RemoveConstraintOnPosition(removeCoordinates); //TODO!! Add other layer remove here } void Puzzle::setConstraints(coor setConstraints, Part* constraintPiece) @@ -75,6 +78,8 @@ void Puzzle::setConstraints(coor setConstraints, Part* constraintPiece) //a1 this->a1.SetConstraintOnPosition(setConstraints,constraintPiece->m_a1); + //a3 + this->a3.SetConstraintOnPosition(setConstraints,constraintPiece->m_a3); //TODO!! Add other layer remove here } @@ -139,6 +144,7 @@ Mat Puzzle::readImage(int fileIndex, const char* inputDir){ Mat source = imread(inputstr,1); return source; } + Mat Puzzle::resultImage( vector& log){ int Y_size = 1200; // chose this to fit your monitor! int separator = 1; diff --git a/Source/header/input.h b/Source/header/input.h index 6cee3da..dff917f 100755 --- a/Source/header/input.h +++ b/Source/header/input.h @@ -8,7 +8,7 @@ #include "../functions/AbstractionLayers/Layer1/AbstractionLayer_1_Properties.h" #include "../functions/AbstractionLayers/DestructionPower/DestructionPower_Properties.h" - +#include "../functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition_Properties.h" class LayerContainer; class Part @@ -42,6 +42,7 @@ public: bool set; AbstractionLayer_1_Properties m_a1; + AbstractionLayer_PoempelPosition_Properties m_a3; private: int32_t m_partID; uint8_t m_numOfRotations; diff --git a/Source/header/solve.h b/Source/header/solve.h index 08485f3..f0d557a 100755 --- a/Source/header/solve.h +++ b/Source/header/solve.h @@ -1,6 +1,3 @@ -// -// Created by mpapa on 05.12.2017. -// #pragma once #include #include @@ -8,6 +5,7 @@ #include #include "../functions/AbstractionLayers/Layer1/AbstractionLayer_1.h" +#include "../functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition.h" #include "../functions/AbstractionLayers/DestructionPower/DestructionPower.h" using namespace std; @@ -54,6 +52,7 @@ public: DestructionPower dp; AbstractionLayer_1 a1; + AbstractionLayer_PoempelPosition a3; void removeConstrains(coor removeCoordinates); void setConstraints(coor setConstraints, Part *constraintPiece);