2017-12-21 12:43:31 +01:00
|
|
|
#pragma once
|
2018-01-25 22:14:00 +01:00
|
|
|
|
2017-12-06 16:25:13 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
|
|
|
#include <opencv2/imgproc/imgproc.hpp>
|
2017-11-18 08:36:50 +01:00
|
|
|
|
2017-12-21 12:20:57 +01:00
|
|
|
#include "../functions/AbstractionLayers/Layer1/AbstractionLayer_1.h"
|
2018-01-20 16:02:44 +01:00
|
|
|
#include "../functions/AbstractionLayers/Layer3_PoempelPosition/AbstractionLayer_PoempelPosition.h"
|
2018-01-25 22:14:00 +01:00
|
|
|
#include "../functions/AbstractionLayers/Layer_SURFFeatures/AbstractionLayer_SURFFeatures.h"
|
2018-01-27 16:27:06 +01:00
|
|
|
#include "../functions/AbstractionLayers/Layer_ColorMatching/AbstractionLayer_ColorMatching.h"
|
2018-01-30 18:16:26 +01:00
|
|
|
#include "../functions/AbstractionLayers/Layer_Histogram/AbstractionLayer_Histogram.h"
|
2017-12-21 12:20:57 +01:00
|
|
|
#include "../functions/AbstractionLayers/DestructionPower/DestructionPower.h"
|
2017-12-20 22:58:00 +01:00
|
|
|
|
2017-12-21 12:20:57 +01:00
|
|
|
using namespace std;
|
2017-12-06 20:56:01 +01:00
|
|
|
|
2017-11-18 08:36:50 +01:00
|
|
|
class LogEntry
|
|
|
|
{
|
|
|
|
public:
|
2018-01-02 13:59:16 +01:00
|
|
|
qualityVector PieceCollector;
|
2017-11-18 08:36:50 +01:00
|
|
|
int abstractionLevel;
|
2017-11-21 10:31:48 +01:00
|
|
|
coor myCoor;
|
2017-11-18 22:48:40 +01:00
|
|
|
|
|
|
|
void advance(){abstractionLevel++;}
|
2017-11-19 22:53:00 +01:00
|
|
|
void Set(){set=1;}
|
|
|
|
bool isSet(){return set;}
|
|
|
|
void advanceRandomed() { randomed++;}
|
|
|
|
void decreaseRandomed() { randomed--;}
|
|
|
|
int hasRandomed(){return randomed;}
|
2017-11-18 08:36:50 +01:00
|
|
|
|
2017-12-22 22:55:55 +01:00
|
|
|
explicit LogEntry(coor newCoor = coor(0,0)): myCoor(newCoor){
|
|
|
|
abstractionLevel=-1;
|
2017-12-21 12:43:31 +01:00
|
|
|
set=false;
|
2017-11-18 08:36:50 +01:00
|
|
|
}
|
|
|
|
private:
|
2017-11-19 22:53:00 +01:00
|
|
|
bool set;
|
|
|
|
static int randomed;
|
2017-11-18 08:36:50 +01:00
|
|
|
};
|
|
|
|
|
2018-01-29 19:32:09 +01:00
|
|
|
struct combinedQualityTop2 {
|
|
|
|
Part* qualityID;
|
|
|
|
float quality1 = 0.0;
|
|
|
|
float quality2 = 0.0;
|
|
|
|
};
|
|
|
|
|
2017-12-21 12:20:57 +01:00
|
|
|
class Puzzle
|
|
|
|
{
|
|
|
|
public:
|
2017-12-22 23:00:31 +01:00
|
|
|
|
2018-01-07 20:08:50 +01:00
|
|
|
Puzzle(unsigned int newcols,unsigned int newrows):cols(newcols),rows(newrows) {}
|
2017-12-29 14:33:22 +01:00
|
|
|
|
|
|
|
bool PreProcessing()
|
2017-12-22 22:55:55 +01:00
|
|
|
{
|
2018-01-06 23:23:42 +01:00
|
|
|
createBox(); createp_box();
|
2018-01-27 10:22:24 +01:00
|
|
|
if(!dp.PreProcessing({cols,rows}, nullptr)) return false;
|
|
|
|
if(!a1.PreProcessing({cols,rows}, &p_myBox)) return false;
|
2018-01-27 16:06:03 +01:00
|
|
|
if(!a3.PreProcessing({cols,rows}, &p_myBox)) return false;
|
2018-01-25 22:14:00 +01:00
|
|
|
if(!a4.PreProcessing({cols,rows}, &p_myBox)) return false;
|
2018-01-27 18:07:42 +01:00
|
|
|
if(!acm.PreProcessing({cols,rows}, &p_myBox)) return false;
|
2018-01-30 18:16:26 +01:00
|
|
|
if(!his.PreProcessing({cols,rows}, &p_myBox)) return false;
|
2018-01-20 11:58:32 +01:00
|
|
|
|
2018-01-06 23:23:42 +01:00
|
|
|
return true;
|
2017-12-22 22:55:55 +01:00
|
|
|
}
|
2017-12-21 12:20:57 +01:00
|
|
|
|
2018-01-06 23:23:42 +01:00
|
|
|
coor getSizeAsCoor() {return {cols,rows};}
|
2017-12-21 12:20:57 +01:00
|
|
|
|
2017-12-22 23:09:23 +01:00
|
|
|
DestructionPower dp;
|
2017-12-22 22:47:14 +01:00
|
|
|
AbstractionLayer_1 a1;
|
2018-01-20 16:02:44 +01:00
|
|
|
AbstractionLayer_PoempelPosition a3;
|
2018-01-25 22:14:00 +01:00
|
|
|
AbstractionLayer_SURFFeatures a4;
|
2018-01-27 16:27:06 +01:00
|
|
|
AbstractionLayer_ColorMatching acm;
|
2018-01-30 18:16:26 +01:00
|
|
|
AbstractionLayer_Histogram his;
|
2017-12-21 12:20:57 +01:00
|
|
|
|
|
|
|
void removeConstrains(coor removeCoordinates);
|
2018-01-07 20:08:50 +01:00
|
|
|
void setConstraints(coor setConstraints, Part *constraintPiece);
|
2018-01-20 09:40:03 +01:00
|
|
|
int removeSimilar(qualityVector&, Part&);
|
|
|
|
|
2017-12-21 12:20:57 +01:00
|
|
|
void printPuzzle();
|
2017-12-23 10:11:07 +01:00
|
|
|
void printBox();
|
2018-01-16 22:53:05 +01:00
|
|
|
Mat resultImage(vector<LogEntry>&);
|
2017-12-21 12:20:57 +01:00
|
|
|
|
2018-01-07 21:58:16 +01:00
|
|
|
void createRandomBox(){
|
|
|
|
myBox.clear();p_myBox.clear();
|
|
|
|
createRandomPuzzle();putIntoBox();
|
|
|
|
printPuzzle();shuffle();createp_box(); clearMat();}
|
2017-12-21 12:43:31 +01:00
|
|
|
void createRandomPuzzle();
|
2017-12-21 12:20:57 +01:00
|
|
|
void putIntoBox();
|
|
|
|
void shuffle();
|
2018-01-06 23:23:42 +01:00
|
|
|
void createBox();
|
2017-12-21 13:07:01 +01:00
|
|
|
void createp_box();
|
2018-01-07 21:58:16 +01:00
|
|
|
void clearMat();
|
2017-12-21 12:20:57 +01:00
|
|
|
|
2018-01-07 14:16:57 +01:00
|
|
|
bool allSet();
|
|
|
|
|
2017-12-21 12:20:57 +01:00
|
|
|
vector<Part> myBox;
|
|
|
|
vector<Part*> p_myBox;
|
|
|
|
|
2018-01-05 01:18:23 +01:00
|
|
|
qualityVector combinedQualityVector;
|
2018-01-29 19:32:09 +01:00
|
|
|
vector<combinedQualityTop2> combinedQualityTop2Vector;
|
2018-01-05 01:18:23 +01:00
|
|
|
|
2018-01-07 21:58:16 +01:00
|
|
|
vector<float> tmp_destructionArray;
|
|
|
|
|
2017-12-21 12:20:57 +01:00
|
|
|
private:
|
|
|
|
|
2018-01-16 22:53:05 +01:00
|
|
|
Mat readImage(int fileIndex, const char* inputDir);
|
2017-12-21 12:20:57 +01:00
|
|
|
unsigned int cols;
|
2018-01-07 20:08:50 +01:00
|
|
|
unsigned int rows;
|
2017-12-21 12:20:57 +01:00
|
|
|
};
|
|
|
|
|
2018-01-07 14:16:57 +01:00
|
|
|
bool next(vector<LogEntry>& log,Puzzle& puzzleMat);
|
|
|
|
coor calculateNextCoor(vector<LogEntry>& log, Puzzle& puzzleMat);
|
|
|
|
void solve(vector<LogEntry>& log, Puzzle& puzzleMat);
|
|
|
|
void setsolution(vector<LogEntry>& log, Puzzle& puzzleMat);
|
|
|
|
bool backtrack(vector<LogEntry>& log,Puzzle& puzzleMat);
|
2017-11-19 17:52:02 +01:00
|
|
|
|
2018-01-07 14:16:57 +01:00
|
|
|
void createNextLogElement(vector<LogEntry>& log,Puzzle& puzzleMat);
|
2017-11-19 17:52:02 +01:00
|
|
|
|