Layer logic done, dispatcher simplified
This commit is contained in:
parent
1161b972ba
commit
7979d28422
@ -70,6 +70,11 @@ float DestructionPower::defaultDestructionPower(int i)
|
||||
//gets next highest valued abstraction layer down from current one (if first, get highest)
|
||||
int DestructionPower::getNextAbstractionLayer(coor newCoordinate, int currentAbstractionLayer)
|
||||
{
|
||||
if(++currentAbstractionLayer>=DESTRUCTION_COUNT)
|
||||
return -1;
|
||||
else
|
||||
return currentAbstractionLayer;
|
||||
|
||||
float currentPower = 1;
|
||||
int nextLayer=-1;
|
||||
float nextLayerPower=0;
|
||||
|
@ -21,11 +21,14 @@ bool AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partAr
|
||||
for(int i = 0; i < mySize.row*mySize.col; i++)
|
||||
{
|
||||
unsigned char poempel = analyse.getTabs(i);
|
||||
|
||||
PSum+=PoempelSum(poempel); //preprocess correct check
|
||||
for (int j=0;j<4;j++)
|
||||
{
|
||||
ref_partArray[iterator]->m_a1.m_connections=poempel;
|
||||
ref_partArray[iterator]->m_a3.SideLength=analyse.getPoempelPosition(i); //do abstraction Layer 3 check
|
||||
shift(poempel,1);
|
||||
ref_partArray[iterator]->m_a3.shift(j);//rotate information
|
||||
iterator++;
|
||||
}
|
||||
}
|
||||
@ -428,7 +431,9 @@ bool analyseParts::getImages(){
|
||||
return false;
|
||||
}
|
||||
mask.setCorners(corners);
|
||||
mask.setTabs(analyseContour(corners,contours[0]));
|
||||
vector<double> tmpPoempelPosition={0,0,0,0,0,0,0,0};//TODO somehow make this code section bearable
|
||||
mask.setTabs(analyseContour(corners,contours[0],tmpPoempelPosition));
|
||||
mask.setPoempelPosition(tmpPoempelPosition);
|
||||
mask.setLens(analyseLens(lens, corners));
|
||||
mask.setMidpoint(calcMidpoint(corners));
|
||||
masks.push_back(mask);
|
||||
@ -633,7 +638,8 @@ vector<Point> analyseParts::findCorners(vector<Point> contour, Point center){
|
||||
if(DISPLAY) imshow("draw",drawing);
|
||||
return corners;
|
||||
}
|
||||
unsigned char analyseParts::analyseContour(vector<Point> corners, vector<Point> contour) {
|
||||
unsigned char analyseParts::analyseContour(vector<Point> corners, vector<Point> contour,vector<double>& PoempelPosition){
|
||||
|
||||
vector<Point> contour_right;
|
||||
vector<Point> contour_top;
|
||||
vector<Point> contour_left;
|
||||
@ -1066,6 +1072,12 @@ unsigned char analyseParts::analyseContour(vector<Point> corners, vector<Point>
|
||||
max_dist_idx = i;
|
||||
}
|
||||
}
|
||||
//saves length between Corners and Poempel right
|
||||
Point diff = corners[2] - contour_right_new[max_dist_idx];
|
||||
PoempelPosition[2] = cv::sqrt(diff.x*diff.x + diff.y*diff.y);
|
||||
diff = corners[0] - contour_right_new[max_dist_idx];
|
||||
PoempelPosition[3] = cv::sqrt(diff.x*diff.x + diff.y*diff.y);
|
||||
|
||||
/*-------------------------------------*/
|
||||
unsigned char tabs = 0;
|
||||
int poembel_threshold = 15;
|
||||
@ -1090,6 +1102,13 @@ unsigned char analyseParts::analyseContour(vector<Point> corners, vector<Point>
|
||||
max_dist_idx = i;
|
||||
}
|
||||
}
|
||||
|
||||
//saves length between Corners and Poempel
|
||||
diff = corners[3] - contour_top_new[max_dist_idx];
|
||||
PoempelPosition[0] = cv::sqrt(diff.x*diff.x + diff.y*diff.y);
|
||||
diff = corners[2] - contour_top_new[max_dist_idx];
|
||||
PoempelPosition[1] = cv::sqrt(diff.x*diff.x + diff.y*diff.y);
|
||||
|
||||
/*-------------------------------------*/
|
||||
|
||||
if (ref_top - contour_top_new[max_dist_idx].y <= -poembel_threshold) {
|
||||
@ -1113,6 +1132,12 @@ unsigned char analyseParts::analyseContour(vector<Point> corners, vector<Point>
|
||||
max_dist_idx = i;
|
||||
}
|
||||
}
|
||||
|
||||
//saves length between Corners and Poempel
|
||||
diff = corners[1] - contour_left_new[max_dist_idx];
|
||||
PoempelPosition[6] = cv::sqrt(diff.x*diff.x + diff.y*diff.y);
|
||||
diff = corners[3] - contour_left_new[max_dist_idx];
|
||||
PoempelPosition[7] = cv::sqrt(diff.x*diff.x + diff.y*diff.y);
|
||||
/*-------------------------------------*/
|
||||
if (ref_left - contour_left_new[max_dist_idx].x <= -poembel_threshold) {
|
||||
tabs |= (1 << LEFT);
|
||||
@ -1124,7 +1149,7 @@ unsigned char analyseParts::analyseContour(vector<Point> corners, vector<Point>
|
||||
tabs |= (0 << LEFT);
|
||||
}
|
||||
|
||||
/*---------Suche Poempel Oben---------------*/
|
||||
/*---------Suche Poempel Unten---------------*/
|
||||
max_dist = 0;
|
||||
dist = 0;
|
||||
max_dist_idx = 0;
|
||||
@ -1135,6 +1160,10 @@ unsigned char analyseParts::analyseContour(vector<Point> corners, vector<Point>
|
||||
max_dist_idx = i;
|
||||
}
|
||||
}
|
||||
diff = corners[0] - contour_bottom_new[max_dist_idx];
|
||||
PoempelPosition[4] = cv::sqrt(diff.x*diff.x + diff.y*diff.y);
|
||||
diff = corners[1] - contour_bottom_new[max_dist_idx];
|
||||
PoempelPosition[5] = cv::sqrt(diff.x*diff.x + diff.y*diff.y);
|
||||
/*-------------------------------------*/
|
||||
if (ref_bottom - contour_bottom_new[max_dist_idx].y <= -poembel_threshold) {
|
||||
tabs |= (2 << BOTTOM);
|
||||
|
@ -82,11 +82,13 @@ public:
|
||||
void setLens(vector<double> l ){len = l;}
|
||||
Point getMidpoint(){return midpoint;}
|
||||
void setMidpoint(Point m ){midpoint = m;}
|
||||
|
||||
vector<double> getPoempelPosition(){return PoempelPosition;}
|
||||
void setPoempelPosition(vector<double>& newPP){PoempelPosition=newPP;}
|
||||
vector<Point> getCorners(){return corners;}
|
||||
|
||||
private:
|
||||
Mat image;
|
||||
vector<double> PoempelPosition;
|
||||
vector<Point> corners;
|
||||
vector<vector<Point>> contour;
|
||||
vector<Vec4i> hierarchy;
|
||||
@ -105,12 +107,13 @@ public:
|
||||
vector<Vec4i> getHierarchy(int i){if(i>= nr_parts)return masks[nr_parts-1].getHierarchy(); else return masks[i].getHierarchy();}
|
||||
unsigned char getTabs(int i){if(i>= nr_parts)return masks[nr_parts-1].getTabs(); else return masks[i].getTabs();}
|
||||
vector<double> getLen(int i ){return masks[i].getLen();}
|
||||
vector<double> getPoempelPosition(int i){return masks[i].getPoempelPosition();}
|
||||
vector<double> analyseLens(vector<double>, vector<Point>);
|
||||
Point calcMidpoint(vector<Point>);
|
||||
Point getMidpoint(int i){return masks[i].getMidpoint();}
|
||||
Point findCenter(Mat);
|
||||
vector<Point> findCorners(vector<Point>,Point);
|
||||
unsigned char analyseContour(vector<Point>, vector<Point>);
|
||||
unsigned char analyseContour(vector<Point>, vector<Point>,vector<double>&);
|
||||
Mat makeBorder(Mat&);
|
||||
Mat readImages(int);
|
||||
Mat morphDilateErode(Mat&);
|
||||
|
@ -18,12 +18,7 @@ bool AbstractionLayer_PoempelPosition::EvaluateQuality (const coor constraintCoo
|
||||
for(int i = 0;i<qVector.size();i++)
|
||||
{
|
||||
float value = PlaceOfPartGood(constraintCoordinate, qVector[i].second->m_a3.SideLength);
|
||||
if(value > 0.8)//TODO find threshold
|
||||
{
|
||||
qVector[i].first=value;
|
||||
continue;
|
||||
}
|
||||
qVector[i].first=0;
|
||||
qVector[i].first=value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,14 +32,54 @@ bool AbstractionLayer_PoempelPosition::RemoveConstraintOnPosition(const coor con
|
||||
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].SideLength={0,0,0,0,0,0,0,0};
|
||||
}
|
||||
|
||||
float AbstractionLayer_PoempelPosition::PlaceOfPartGood(coor myCoor, vector<float> myPart)
|
||||
float AbstractionLayer_PoempelPosition::PlaceOfPartGood(coor myCoor, vector<double> myPart)
|
||||
{
|
||||
//sets coordinates to correct position for layer
|
||||
|
||||
vector<double> comparePosition={0,0,0,0,0,0,0,0};
|
||||
float sum=0;
|
||||
//create negativePart, watch out for edges
|
||||
if(myCoor.col>0 && m_constraintMatrix[myCoor.col-1][myCoor.row].SideLength[3])//get right data from left
|
||||
{
|
||||
comparePosition[6]=m_constraintMatrix[myCoor.col-1][myCoor.row].SideLength[3];
|
||||
comparePosition[7]=m_constraintMatrix[myCoor.col-1][myCoor.row].SideLength[2];
|
||||
//sum absolute difference
|
||||
sum+=abs(comparePosition[6]-myPart[6]);
|
||||
sum+=abs(comparePosition[7]-myPart[7]);
|
||||
}
|
||||
if(myCoor.row>0 && m_constraintMatrix[myCoor.col][myCoor.row-1].SideLength[5])//get bot data from top
|
||||
{
|
||||
comparePosition[0]=m_constraintMatrix[myCoor.col][myCoor.row-1].SideLength[5];
|
||||
comparePosition[1]=m_constraintMatrix[myCoor.col][myCoor.row-1].SideLength[4];
|
||||
//sum absolute difference
|
||||
sum+=abs(comparePosition[0]-myPart[0]);
|
||||
sum+=abs(comparePosition[1]-myPart[1]);
|
||||
|
||||
//check vector against negative part
|
||||
}
|
||||
if(myCoor.col<m_constraintMatrix.size()-1 && m_constraintMatrix[myCoor.col+1][myCoor.row].SideLength[7])// get left data from right
|
||||
{
|
||||
comparePosition[2]=m_constraintMatrix[myCoor.col+1][myCoor.row].SideLength[7];
|
||||
comparePosition[3]=m_constraintMatrix[myCoor.col+1][myCoor.row].SideLength[6];
|
||||
//sum absolute difference
|
||||
sum+=abs(comparePosition[2]-myPart[2]);
|
||||
sum+=abs(comparePosition[3]-myPart[3]);
|
||||
|
||||
}
|
||||
|
||||
if(myCoor.row<m_constraintMatrix[0].size()-1 && m_constraintMatrix[myCoor.col][myCoor.row+1].SideLength[1])//get top data from bot
|
||||
{
|
||||
comparePosition[4]=m_constraintMatrix[myCoor.col][myCoor.row+1].SideLength[1];
|
||||
comparePosition[5]=m_constraintMatrix[myCoor.col][myCoor.row+1].SideLength[0];
|
||||
//sum absolute difference
|
||||
sum+=abs(comparePosition[4]-myPart[4]);
|
||||
sum+=abs(comparePosition[5]-myPart[5]);
|
||||
|
||||
}
|
||||
if(sum>100)
|
||||
return 0;
|
||||
if(sum==0)
|
||||
return 1;
|
||||
sum/=100;
|
||||
return 1-sum;
|
||||
//check vector against negative part, use sad
|
||||
//return of well it fits within threshold
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ public:
|
||||
bool SetConstraintOnPosition( coor constraintCoordinate, AbstractionLayer_PoempelPosition_Properties constraint)final;
|
||||
bool RemoveConstraintOnPosition( coor constraintCoordinate)final;
|
||||
|
||||
float PlaceOfPartGood(coor myCoor, vector<float> myPart);
|
||||
float PlaceOfPartGood(coor myCoor, vector<double> myPart);
|
||||
|
||||
private:
|
||||
};
|
@ -10,8 +10,9 @@ public:
|
||||
void shift(int i);
|
||||
private:
|
||||
|
||||
vector<float> SideLength;
|
||||
vector<double> SideLength;
|
||||
friend class AbstractionLayer_PoempelPosition;
|
||||
friend class AbstractionLayer_1;
|
||||
};
|
||||
|
||||
|
||||
|
@ -72,6 +72,7 @@ coor calculateNextCoor(vector<LogEntry>& log, Puzzle& puzzleMat)
|
||||
void solve(vector<LogEntry>& log,Puzzle& puzzleMat)
|
||||
{
|
||||
log.back().abstractionLevel = puzzleMat.dp.getNextAbstractionLayer(log.back().myCoor,log.back().abstractionLevel); //sets in abstractionLevel
|
||||
cout << "abs: " << log.back().abstractionLevel << endl;
|
||||
//status(log,p_Box,puzzleMat);
|
||||
//TODO!! Add more layers here
|
||||
switch(log.back().abstractionLevel)
|
||||
@ -80,7 +81,7 @@ void solve(vector<LogEntry>& log,Puzzle& puzzleMat)
|
||||
puzzleMat.a1.EvaluateQuality(log.back().myCoor, log.back().PieceCollector);
|
||||
break;
|
||||
case 1://histogram
|
||||
return;
|
||||
puzzleMat.a3.EvaluateQuality(log.back().myCoor,log.back().PieceCollector);
|
||||
break;
|
||||
case -1://random
|
||||
setsolution(log,puzzleMat);
|
||||
@ -109,7 +110,7 @@ void setsolution(vector<LogEntry>& log, Puzzle& puzzleMat)
|
||||
//tell log entry that it is set
|
||||
log.back().Set();
|
||||
puzzleMat.setConstraints(log.back().myCoor,log.back().PieceCollector.begin()->second);
|
||||
//cout << "set:" << log.back().myCoor.col << "," << log.back().myCoor.row << endl;
|
||||
cout << "set:" << log.back().myCoor.col << "," << log.back().myCoor.row << endl;
|
||||
//cout << "ID: " << log.back().PieceCollector[0].second->GetPartID() << endl;
|
||||
|
||||
}
|
||||
@ -131,10 +132,10 @@ bool backtrack(vector<LogEntry>& log, Puzzle& puzzleMat)
|
||||
|
||||
|
||||
//remove similar in log
|
||||
Part myPart = *log.back().PieceCollector[0].second;//tmpsaves bad part
|
||||
log.back().PieceCollector.erase(log.back().PieceCollector.begin());//removes bad part from log
|
||||
puzzleMat.removeSimilar(log.back().PieceCollector,myPart); //removes all pieces from log that are similar to bad part
|
||||
//TODO remove this when further layers are added!!!
|
||||
Part myPart = *log.back().PieceCollector[0].second;//tmpsaves bad part
|
||||
log.back().PieceCollector.erase(log.back().PieceCollector.begin());//removes bad part from log
|
||||
puzzleMat.removeSimilar(log.back().PieceCollector,myPart); //removes all pieces from log that are similar to bad part
|
||||
//TODO reprogram similar removal to allow multilayer tracking
|
||||
if(log.back().PieceCollector.size()) // this checks if 'removeSimilar' has cleared entire LogElement
|
||||
{
|
||||
if(log.back().PieceCollector.size()==1)
|
||||
@ -298,12 +299,13 @@ void CalculateNewCombinedQuality(vector<LogEntry>& log, qualityVector& qVector,
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int i = 0; i < cqVector.size(); i++) {
|
||||
for (unsigned int i = 0; i < cqVector.size();) {
|
||||
for (unsigned int j = 0; j < qVector.size(); j++) {
|
||||
// search same PuzzlePart of qualityVector and combinedQualityVector
|
||||
removePart=true;
|
||||
if (cqVector.at(i).second->GetPartID() == qVector.at(j).second->GetPartID() && cqVector.at(i).second->GetNumOfRotations() == qVector.at(j).second->GetNumOfRotations()) {
|
||||
// sum Quality of PieceCollector (qualityVector) to combinedQualityVector
|
||||
cqVector.at(j).first += qVector.at(i).first;
|
||||
cqVector.at(i).first += qVector.at(j).first;
|
||||
countSummarizedVectors++;
|
||||
removePart=false;
|
||||
break; // skip remaining for loop => save time!
|
||||
@ -318,7 +320,7 @@ void CalculateNewCombinedQuality(vector<LogEntry>& log, qualityVector& qVector,
|
||||
{
|
||||
swap(cqVector.at(i), cqVector.back());
|
||||
cqVector.pop_back();
|
||||
}
|
||||
} else i++;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user