PuzzleSolver/Source/header/solve.h

118 lines
3.4 KiB
C
Raw Permalink Normal View History

#pragma once
2018-01-25 22:14:00 +01:00
#include <vector>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
2017-11-18 08:36:50 +01:00
#include "../functions/AbstractionLayers/Layer1/AbstractionLayer_1.h"
#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:45:54 +01:00
#include "../functions/AbstractionLayers/Layer2_KantenLaenge/AbstractionLayer_KantenLaenge.h"
#include "../functions/AbstractionLayers/DestructionPower/DestructionPower.h"
using namespace std;
2017-11-18 08:36:50 +01:00
class LogEntry
{
public:
qualityVector PieceCollector;
2017-11-18 08:36:50 +01:00
int abstractionLevel;
2017-11-21 10:31:48 +01:00
coor myCoor;
void advance(){abstractionLevel++;}
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;
set=false;
2017-11-18 08:36:50 +01:00
}
private:
bool set;
static int randomed;
2017-11-18 08:36:50 +01:00
};
struct combinedQualityTop2 {
Part* qualityID;
float quality1 = 0.0;
float quality2 = 0.0;
};
class Puzzle
{
public:
2018-01-07 20:08:50 +01:00
Puzzle(unsigned int newcols,unsigned int newrows):cols(newcols),rows(newrows) {}
bool PreProcessing()
2017-12-22 22:55:55 +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:45:54 +01:00
if(!a2.PreProcessing({cols,rows}, &p_myBox)) return false;
return true;
2017-12-22 22:55:55 +01:00
}
coor getSizeAsCoor() {return {cols,rows};}
2017-12-22 23:09:23 +01:00
DestructionPower dp;
2017-12-22 22:47:14 +01:00
AbstractionLayer_1 a1;
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:45:54 +01:00
AbstractionLayer_KantenLaenge a2;
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&);
void printPuzzle();
void printBox();
2018-01-16 22:53:05 +01:00
Mat resultImage(vector<LogEntry>&);
void createRandomBox(){
myBox.clear();p_myBox.clear();
createRandomPuzzle();putIntoBox();
printPuzzle();shuffle();createp_box(); clearMat();}
void createRandomPuzzle();
void putIntoBox();
void shuffle();
void createBox();
void createp_box();
void clearMat();
bool allSet();
vector<Part> myBox;
vector<Part*> p_myBox;
qualityVector combinedQualityVector;
vector<combinedQualityTop2> combinedQualityTop2Vector;
vector<float> tmp_destructionArray;
private:
2018-01-16 22:53:05 +01:00
Mat readImage(int fileIndex, const char* inputDir);
unsigned int cols;
2018-01-07 20:08:50 +01:00
unsigned int rows;
};
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);
void createNextLogElement(vector<LogEntry>& log,Puzzle& puzzleMat);