From 57c1f50a8f8bfd7844d6c0714ce78f6e0ccc9e37 Mon Sep 17 00:00:00 2001 From: mreitter <34164743+mreitter@users.noreply.github.com> Date: Sat, 20 Jan 2018 20:03:34 +0100 Subject: [PATCH 1/3] Korrigierte Ecken, Alle Teile richtig --- .../Layer1/AbstractionLayer_1.cpp | 528 ++++++++++++++++-- .../Layer1/AbstractionLayer_1.h | 10 + Source/functions/solve/puzzleExtension.cpp | 5 +- Source/main.cpp | 3 +- 4 files changed, 492 insertions(+), 54 deletions(-) diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp index fe9faef..e507bc7 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp @@ -358,6 +358,7 @@ bool analyseParts::getImages(){ vector > contours; vector hierarchy; vector corners; + vector lens; vector puzzleimages; vector > contours1; @@ -389,6 +390,8 @@ bool analyseParts::getImages(){ } mask.setCorners(corners); mask.setTabs(analyseContour(corners,contours[0])); + mask.setLens(analyseLens(lens, corners)); + mask.setMidpoint(calcMidpoint(corners)); masks.push_back(mask); destroyAllWindows(); } @@ -407,6 +410,23 @@ Point analyseParts::findCenter(Mat img){ return center; } +float pitch2Points(Point one, Point two) //In Header +{ + float pitch=0; + float deltay=0; + float deltax = 0; + deltay = abs(one.y - two.y); + deltax = abs(one.x - two.x); + + if(deltax == 0) + deltax = 0.1; + + if(deltay == 0) + deltay = 0.1; + + pitch = deltay/deltax; + return pitch; +} vector analyseParts::findCorners(vector contour, Point center){ int minContourPoint = 5; @@ -574,136 +594,542 @@ vector analyseParts::findCorners(vector contour, Point center){ if(DISPLAY) imshow("draw",drawing); return corners; } - unsigned char analyseParts::analyseContour(vector corners, vector contour) { vector contour_right; vector contour_top; vector contour_left; vector contour_bottom; - Mat drawing = createEmpty(Point(IMG_SIZE,IMG_SIZE),1); + int count = 0; int corner0 = 0, corner1 = 0, corner2 = 0, corner3 = 0; for(int i = 0; i < contour.size(); i++){ + //cout << "contour " << contour[i] << endl; if(contour[i] == corners[0]) corner0 = i; - if(contour[i] == corners[1]) + else if(contour[i] == corners[1]) corner1 = i; - if(contour[i] == corners[2]) + else if(contour[i] == corners[2]) corner2 = i; - if(contour[i] == corners[3]) + else if(contour[i] == corners[3]) corner3 = i; } + count = corner0; while(contour[count] != contour[corner2]){ count++; count %= contour.size(); contour_right.push_back(contour[count]); - circle(drawing,contour[count],3,Scalar(255,0,0),2,8); } count = corner2; while(contour[count] != contour[corner3]){ count++; count %= contour.size(); contour_top.push_back(contour[count]); - circle(drawing,contour[count],3,Scalar(0,255,0),2,8); } count = corner3; while(contour[count] != contour[corner1]){ count++; count %= contour.size(); contour_left.push_back(contour[count]); - circle(drawing,contour[count],3,Scalar(0,0,255),2,8); } count = corner1; while(contour[count] != contour[corner0]){ count++; count %= contour.size(); contour_bottom.push_back(contour[count]); - circle(drawing,contour[count],3,Scalar(255,255,255),2,8); } - float ref_right = (contour[corner0].x+contour[corner2].x)/2; - float ref_top = (contour[corner2].y+contour[corner3].y)/2; - float ref_left = (contour[corner3].x+contour[corner1].x)/2; - float ref_bottom = (contour[corner1].y+contour[corner0].y)/2; + contour_right.insert(contour_right.begin(),corners[0]); + contour_right.push_back(corners[2]); + + contour_top.insert(contour_top.begin(),corners[2]); + contour_top.push_back(corners[3]); + + contour_left.insert(contour_left.begin(),corners[3]); + contour_left.push_back(corners[1]); + + contour_bottom.insert(contour_bottom.begin(),corners[1]); + contour_bottom.push_back(corners[0]); + + /*-------------------------------------*/ + //ecken Korrektur rechte Kontur + /*-------------------------------------*/ + + vector contour_r; + double laenge = 0; + int idx = 0, counter = 0, c = 0, d = 0; + + while (counter < (contour_right.size()-1)) { + counter++; + c++; + laenge = sqrt((contour_right[idx].x - contour_right[idx + c].x) * (contour_right[idx].x - contour_right[idx + c].x) + + (contour_right[idx].y - contour_right[idx + c].y) * (contour_right[idx].y - contour_right[idx + c].y)); + if (laenge > 4) { + d++; + contour_r.push_back(contour_right[idx]); + idx = counter; + c = 0; + } + } + + float k = 0; + int correct_count = 0; + int correct_idx = 0; + for(correct_count = 0; correct_count < contour_r.size()-2; correct_count++){ + + k = pitch2Points(contour_r[correct_count],contour_r[correct_count+1]); + //cout << "unten: " << k << endl; + if(k >= 2) { + correct_idx = correct_count; + correct_count = contour_r.size(); + } + if(correct_count > 500) + break; + } + /*-----------------------------------*/ + if(correct_idx > 0){ + corners[0] = contour_r[correct_idx]; + } + /*-----------------------------------*/ + vector contour_r1; + laenge = 0; + idx = contour_right.size()-1, counter = contour_right.size()-1, c = 0, d = 0; + + while (counter > 1) { + counter--; + c--; + laenge = sqrt((contour_right[idx].x - contour_right[idx + c].x) * (contour_right[idx].x - contour_right[idx + c].x) + + (contour_right[idx].y - contour_right[idx + c].y) * (contour_right[idx].y - contour_right[idx + c].y)); + if (laenge > 4) { + contour_r1.push_back(contour_right[idx]); + idx = counter; + c = 0; + } + } + + + k = 0; + correct_count = 0; + correct_idx = 0; + for(correct_count = 0; correct_count < contour_r1.size()-2; correct_count++){ + + k = pitch2Points(contour_r1[correct_count],contour_r1[correct_count+1]); + // cout << "oben: " << k << endl; + if(k >= 2) { + correct_idx = correct_count; + correct_count = contour_r1.size(); + } + } + /*-----------------------------------*/ + if(correct_idx > 0){ + corners[2] = contour_r1[correct_idx]; + } + /*-----------------------------------*/ + + /*-------------------------------------*/ + //ecken Korrektur links Kontur + /*-------------------------------------*/ + + vector contour_l; + laenge = 0; + idx = 0, counter = 0, c = 0, d = 0; + + while (counter < (contour_left.size()-1)) { + counter++; + c++; + laenge = sqrt((contour_left[idx].x - contour_left[idx + c].x) * (contour_left[idx].x - contour_left[idx + c].x) + + (contour_left[idx].y - contour_left[idx + c].y) * (contour_left[idx].y - contour_left[idx + c].y)); + if (laenge > 4) { + d++; + contour_l.push_back(contour_left[idx]); + idx = counter; + c = 0; + } + } + + k = 0; + correct_count = 0; + correct_idx = 0; + for(correct_count = 0; correct_count < contour_l.size()-2; correct_count++){ + + k = pitch2Points(contour_l[correct_count],contour_l[correct_count+1]); + // cout << "oben _links: " << k << endl; + if(k >= 2) { + correct_idx = correct_count; + correct_count = contour_l.size(); + } + if(correct_count > 500) + break; + } + /*-----------------------------------*/ + if(correct_idx > 0){ + corners[3] = contour_l[correct_idx]; + } + /*-----------------------------------*/ + vector contour_l1; + laenge = 0; + idx = contour_left.size()-1, counter = contour_left.size()-1, c = 0, d = 0; + + while (counter > 1) { + counter--; + c--; + laenge = sqrt((contour_left[idx].x - contour_left[idx + c].x) * (contour_left[idx].x - contour_left[idx + c].x) + + (contour_left[idx].y - contour_left[idx + c].y) * (contour_left[idx].y - contour_left[idx + c].y)); + if (laenge > 4) { + contour_l1.push_back(contour_left[idx]); + idx = counter; + c = 0; + } + if(correct_count > 500) + break; + } + k = 0; + correct_count = 0; + correct_idx = 0; + for(correct_count = 0; correct_count < contour_l1.size(); correct_count++){ + + k = pitch2Points(contour_l1[correct_count],contour_l1[correct_count+1]); + if(k >= 2) { + // cout << "end _links: " << endl; + correct_idx = correct_count; + correct_count = contour_l1.size(); + } + if(correct_count > 500) + break; + } + /*-----------------------------------*/ + // cout << "unten _links_correct: " << correct_idx << endl; + if(correct_idx > 0){ + corners[1] = contour_l1[correct_idx]; + } + /*-----------------------------------*/ + + /*-------------------------------------*/ + //ecken Korrektur oben Kontur + /*-------------------------------------*/ + + vector contour_t; + laenge = 0; + idx = 0, counter = 0, c = 0, d = 0; + + while (counter < (contour_top.size()-1)) { + counter++; + c++; + laenge = sqrt((contour_top[idx].x - contour_top[idx + c].x) * (contour_top[idx].x - contour_top[idx + c].x) + + (contour_top[idx].y - contour_top[idx + c].y) * (contour_top[idx].y - contour_top[idx + c].y)); + if (laenge > 4) { + d++; + contour_t.push_back(contour_top[idx]); + idx = counter; + c = 0; + } + if(correct_count > 500) + break; + } + + k = 0; + correct_count = 0; + correct_idx = 0; + for(correct_count = 0; correct_count < contour_t.size()-2; correct_count++){ + + k = pitch2Points(contour_t[correct_count],contour_t[correct_count+1]); + // cout << "top _rechts: " << k << endl; + if(k <= 2) { + correct_idx = correct_count; + correct_count = contour_t.size(); + } + if(correct_count > 500) + break; + } + /*-----------------------------------*/ + if(correct_idx > 0){ + corners[2] = contour_t[correct_idx]; + } + /*-----------------------------------*/ + vector contour_t1; + laenge = 0; + idx = contour_top.size()-1, counter = contour_top.size()-1, c = 0, d = 0; + + while (counter > 1) { + counter--; + c--; + laenge = sqrt((contour_top[idx].x - contour_top[idx + c].x) * (contour_top[idx].x - contour_top[idx + c].x) + + (contour_top[idx].y - contour_top[idx + c].y) * (contour_top[idx].y - contour_top[idx + c].y)); + if (laenge > 4) { + contour_t1.push_back(contour_top[idx]); + idx = counter; + c = 0; + } + if(correct_count > 500) + break; + } + k = 0; + correct_idx = 0; + for(correct_count = 0; correct_count < contour_t1.size(); correct_count++){ + k = pitch2Points(contour_t1[correct_count],contour_t1[correct_count+1]); + if(k < 2) { + correct_idx = correct_count; + correct_count = contour_t1.size(); + } + } + /*-----------------------------------*/ + if(correct_idx > 0){ + corners[3] = contour_t1[correct_idx]; + } + /*-------------------------------------*/ + + /*-------------------------------------*/ + //ecken Korrektur unten Kontur + /*-------------------------------------*/ + + vector contour_b; + laenge = 0; + idx = 0, counter = 0, c = 0, d = 0; + + while (counter < (contour_bottom.size()-1)) { + counter++; + c++; + laenge = sqrt((contour_bottom[idx].x - contour_bottom[idx + c].x) * (contour_bottom[idx].x - contour_bottom[idx + c].x) + + (contour_bottom[idx].y - contour_bottom[idx + c].y) * (contour_bottom[idx].y - contour_bottom[idx + c].y)); + if (laenge > 4) { + d++; + contour_b.push_back(contour_bottom[idx]); + idx = counter; + c = 0; + } + if(correct_count > 500) + break; + } + + k = 0; + correct_count = 0; + correct_idx = 0; + for(correct_count = 0; correct_count < contour_b.size()-2; correct_count++){ + + k = pitch2Points(contour_b[correct_count],contour_b[correct_count+1]); + // cout << "bottom _rechts: " << k << endl; + if(k <= 2) { + correct_idx = correct_count; + correct_count = contour_b.size(); + } + if(correct_count > 500) + break; + } + /*-----------------------------------*/ + if(correct_idx > 0){ + corners[1] = contour_b[correct_idx]; + } + /*-----------------------------------*/ + vector contour_b1; + laenge = 0; + idx = contour_bottom.size()-1, counter = contour_bottom.size()-1, c = 0, d = 0; + + while (counter > 1) { + counter--; + c--; + laenge = sqrt((contour_bottom[idx].x - contour_bottom[idx + c].x) * (contour_bottom[idx].x - contour_bottom[idx + c].x) + + (contour_bottom[idx].y - contour_bottom[idx + c].y) * (contour_bottom[idx].y - contour_bottom[idx + c].y)); + if (laenge > 4) { + contour_b1.push_back(contour_bottom[idx]); + idx = counter; + c = 0; + } + if(correct_count > 500) + break; + } + k = 0; + correct_idx = 0; + for(correct_count = 0; correct_count < contour_b1.size(); correct_count++){ + k = pitch2Points(contour_b1[correct_count],contour_b1[correct_count+1]); + if(k < 2) { + correct_idx = correct_count; + correct_count = contour_b1.size(); + } + if(correct_count > 500) + break; + } + /*-----------------------------------*/ + if(correct_idx > 0){ + corners[0] = contour_b1[correct_idx]; + } + /*-----------------------------------*/ + + + /*Korrektur Contour*/ + + vector contour_right_new; + vector contour_top_new; + vector contour_left_new; + vector contour_bottom_new; + + for(int i = 0; i < contour.size(); i++){ + if(contour[i] == corners[0]) + corner0 = i; + else if(contour[i] == corners[1]) + corner1 = i; + else if(contour[i] == corners[2]) + corner2 = i; + else if(contour[i] == corners[3]) + corner3 = i; + } + + count = corner0; + while(contour[count] != contour[corner2]){ + count++; + count %= contour.size(); + contour_right_new.push_back(contour[count]); + } + count = corner2; + while(contour[count] != contour[corner3]){ + count++; + count %= contour.size(); + contour_top_new.push_back(contour[count]); + } + count = corner3; + while(contour[count] != contour[corner1]){ + count++; + count %= contour.size(); + contour_left_new.push_back(contour[count]); + } + count = corner1; + while(contour[count] != contour[corner0]){ + count++; + count %= contour.size(); + contour_bottom_new.push_back(contour[count]); + } + + contour_right_new.insert(contour_right_new.begin(),corners[0]); + contour_right_new.push_back(corners[2]); + + contour_top_new.insert(contour_top_new.begin(),corners[2]); + contour_top_new.push_back(corners[3]); + + contour_left_new.insert(contour_left_new.begin(),corners[3]); + contour_left_new.push_back(corners[1]); + + contour_bottom_new.insert(contour_bottom_new.begin(),corners[1]); + contour_bottom_new.push_back(corners[0]); + /*----------------------*/ + + float ref_right = (corners[0].x+corners[2].x)/2; + float ref_top = (corners[2].y+corners[3].y)/2; + float ref_left = (corners[3].x+corners[1].x)/2; + float ref_bottom = (corners[1].y+corners[0].y)/2; + + /*---------Suche Poempel Rechts---------------*/ float max_dist = 0; float dist = 0; - int max_idx = 0; - for(int i = 0; i < contour_right.size(); i++){ - dist = abs(ref_right-contour_right[i].x); + int max_dist_idx = 0; + for(int i = 0; i < contour_right_new.size(); i++){ + dist = abs(ref_right-contour_right_new[i].x); if(dist > max_dist) { max_dist = dist; - max_idx = i; + max_dist_idx = i; } } - + /*-------------------------------------*/ unsigned char tabs = 0; - circle(drawing,contour_right[max_idx],10,Scalar(255,0,255),2,8); - if (ref_right - contour_right[max_idx].x <= -20) + int poembel_threshold = 15; + if (ref_right - contour_right_new[max_dist_idx].x <= -poembel_threshold) { tabs |= (2 << RIGHT); - if (ref_right - contour_right[max_idx].x >= 20) + } + if (ref_right - contour_right_new[max_dist_idx].x >= poembel_threshold) { tabs |= (1 << RIGHT); - if (abs(ref_right - contour_right[max_idx].x) < 20) + } + if (abs(ref_right - contour_right_new[max_dist_idx].x) < poembel_threshold) { tabs |= (0 << RIGHT); + } + /*---------Suche Poempel Oben---------------*/ max_dist = 0; dist = 0; - max_idx = 0; - for(int i = 0; i < contour_top.size(); i++){ - dist = abs(ref_top-contour_top[i].y); + max_dist_idx = 0; + for(int i = 0; i < contour_top_new.size(); i++){ + dist = abs(ref_top -contour_top_new[i].y); if(dist > max_dist) { max_dist = dist; - max_idx = i; + max_dist_idx = i; } } - circle(drawing,contour_top[max_idx],10,Scalar(255,0,255),2,8); - if (ref_top - contour_top[max_idx].y <= -20) + /*-------------------------------------*/ + + if (ref_top - contour_top_new[max_dist_idx].y <= -poembel_threshold) { tabs |= (1 << TOP); - if (ref_top - contour_top[max_idx].y >= 20) + } + if (ref_top - contour_top_new[max_dist_idx].y >= poembel_threshold) { tabs |= (2 << TOP); - if (abs(ref_top - contour_top[max_idx].y) < 20) + } + if (abs(ref_top - contour_top_new[max_dist_idx].y) < poembel_threshold) { tabs |= (0 << TOP); + } + /*---------Suche Poempel Links---------------*/ max_dist = 0; dist = 0; - max_idx = 0; - for(int i = 0; i < contour_left.size(); i++){ - dist = abs(ref_left-contour_left[i].x); + max_dist_idx = 0; + for(int i = 0; i < contour_left_new.size(); i++){ + dist = abs(ref_left -contour_left_new[i].x); if(dist > max_dist) { max_dist = dist; - max_idx = i; + max_dist_idx = i; } } - circle(drawing,contour_left[max_idx],10,Scalar(255,0,255),2,8); - if (ref_left - contour_left[max_idx].x <= -20) + /*-------------------------------------*/ + if (ref_left - contour_left_new[max_dist_idx].x <= -poembel_threshold) { tabs |= (1 << LEFT); - if (ref_left - contour_left[max_idx].x >= 20) + } + if (ref_left - contour_left_new[max_dist_idx].x >= poembel_threshold) { tabs |= (2 << LEFT); - if (abs(ref_left - contour_left[max_idx].x) < 20) + } + if (abs(ref_left - contour_left_new[max_dist_idx].x) < poembel_threshold) { tabs |= (0 << LEFT); + } + /*---------Suche Poempel Oben---------------*/ max_dist = 0; dist = 0; - max_idx = 0; - for(int i = 0; i < contour_bottom.size(); i++){ - dist = abs(ref_bottom-contour_bottom[i].y); + max_dist_idx = 0; + for(int i = 0; i < contour_bottom_new.size(); i++){ + dist = abs(ref_bottom -contour_bottom_new[i].y); if(dist > max_dist) { max_dist = dist; - max_idx = i; + max_dist_idx = i; } } - circle(drawing,contour_bottom[max_idx],10,Scalar(255,0,255),2,8); - if (ref_bottom - contour_bottom[max_idx].y <= -20) + /*-------------------------------------*/ + if (ref_bottom - contour_bottom_new[max_dist_idx].y <= -poembel_threshold) { tabs |= (2 << BOTTOM); - if (ref_bottom - contour_bottom[max_idx].y >= 20) + } + if (ref_bottom - contour_bottom_new[max_dist_idx].y >= poembel_threshold) { tabs |= (1 << BOTTOM); - if (abs(ref_bottom - contour_bottom[max_idx].y) < 20) + } + if (abs(ref_bottom - contour_bottom_new[max_dist_idx].y) < poembel_threshold) { tabs |= (0 << BOTTOM); - - //cout << bitset (tabs) << "b\n"; - - if(DISPLAY)imshow("corners",drawing); - if(DISPLAY)waitKey(0); + } return tabs; } + +vector analyseParts::analyseLens(vector lens, vector corners){ + Point space = corners[3] - corners[2]; + double dist1 = sqrt(space.x*space.x+space.y*space.y); + lens.push_back(dist1); + space = corners[2] - corners[0]; + dist1 = sqrt(space.x*space.x+space.y*space.y); + lens.push_back(dist1); + space = corners[0] - corners[1]; + dist1 = sqrt(space.x*space.x+space.y*space.y); + lens.push_back(dist1); + space = corners[1] - corners[3]; + dist1 = sqrt(space.x*space.x+space.y*space.y); + lens.push_back(dist1); + + return lens; +} + +Point analyseParts::calcMidpoint(vector corners){ + Point midpoint; + + midpoint = (corners[0] + corners[1] + corners[2] + corners[3])/4; + return midpoint; +} diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h index 7889a14..81def82 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h @@ -75,6 +75,10 @@ public: void setHierarchy(vector hier){hierarchy = std::move(hier);} void setCorners(vector cor){corners = std::move(cor);} void setTabs(unsigned char t){tabs = t;} + vector getLen(){return len;} + void setLens(vector l ){len = l;} + Point getMidpoint(){return midpoint;} + void setMidpoint(Point m ){midpoint = m;} vector getCorners(){return corners;} @@ -84,7 +88,9 @@ private: vector> contour; vector hierarchy; Point center; + vector len; unsigned char tabs; + Point midpoint; }; class analyseParts{ @@ -95,6 +101,10 @@ public: Point getCenter(int i){if(i>= nr_parts)return masks[nr_parts-1].getCenter(); else return masks[i].getCenter();} vector 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 getLen(int i ){return masks[i].getLen();} + vector analyseLens(vector, vector); + Point calcMidpoint(vector); + Point getMidpoint(int i){return masks[i].getMidpoint();} Point findCenter(Mat); vector findCorners(vector,Point); unsigned char analyseContour(vector, vector); diff --git a/Source/functions/solve/puzzleExtension.cpp b/Source/functions/solve/puzzleExtension.cpp index 84de8d3..9f45c27 100644 --- a/Source/functions/solve/puzzleExtension.cpp +++ b/Source/functions/solve/puzzleExtension.cpp @@ -156,7 +156,7 @@ Mat Puzzle::resultImage( vector& log){ char name[100]; for (auto it:log) { - if (it.myCoor.col == 12 && it.myCoor.row == 0) + if (it.myCoor.col == 27 && it.myCoor.row == 5) { ; // imshow("result",result); @@ -176,7 +176,8 @@ Mat Puzzle::resultImage( vector& log){ copyMakeBorder(img,img,200,200,200,200,BORDER_CONSTANT,Scalar(255,255,255)); Mat invert = Mat::ones(img.size(), CV_8UC3); // invert for rotation to work correctly bitwise_not ( img, invert ); - if (it.myCoor.col == 12 && it.myCoor.row == 0) + + if (it.myCoor.col == 35 && it.myCoor.row == 5) { //imshow("img",img); //waitKey(0); diff --git a/Source/main.cpp b/Source/main.cpp index 001c09c..56c683c 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -22,8 +22,9 @@ int main() cout << "Done!" << endl; - cout << log.size() << endl; puzzleMat.resultImage(log); + + puzzleMat.printPuzzle(); return 0; } From cefa63da545a797f854cf115ae8d65bfdc1e4792 Mon Sep 17 00:00:00 2001 From: Raphael Maenle <17550607+g-spacewhale@users.noreply.github.com> Date: Sat, 20 Jan 2018 22:31:56 +0100 Subject: [PATCH 2/3] fixed backtrack bug in logslasher function --- Source/functions/solve/structure.cpp | 55 +++++++++++++--------------- Source/main.cpp | 4 +- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/Source/functions/solve/structure.cpp b/Source/functions/solve/structure.cpp index 213e9c0..062dd0e 100755 --- a/Source/functions/solve/structure.cpp +++ b/Source/functions/solve/structure.cpp @@ -140,7 +140,7 @@ bool backtrack(vector& log, Puzzle& puzzleMat) //if more pieces possible, tset piece as not logged if((log.back().PieceCollector.size())>1) { - cout << " next piece" << endl; + //unset puzzlepieces int count =0; for(int i=0;i& log, Puzzle& puzzleMat) count++; } } + cout << "removed " << count << endl; - if (count !=4) - cerr << "incorrect set set" << endl; + //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!!! - - - if(log.back().PieceCollector.size()==1) - log.back().decreaseRandomed(); - - setsolution(log,puzzleMat); - - return true; + if(log.back().PieceCollector.size()) // this checks if 'removeSimilar' has cleared entire LogElement + { + cout << " next piece" << endl; + if(log.back().PieceCollector.size()==1) + log.back().decreaseRandomed(); + setsolution(log,puzzleMat); + return true; + } } //else remove log element and backtrack once more - else + puzzleMat.removeConstrains(log.back().myCoor); //this should remove constraints from all layers + int count =0; + if((log.back().PieceCollector.size())) { - - puzzleMat.removeConstrains(log.back().myCoor); //this should remove constraints from all layers - int count =0; - if((log.back().PieceCollector.size())) + for(int i=0;iGetPartID()==log.back().PieceCollector.begin()->second->GetPartID())//sets all with partid { - if(puzzleMat.p_myBox[i]->GetPartID()==log.back().PieceCollector.begin()->second->GetPartID())//sets all with partid - { - puzzleMat.p_myBox[i]->set=false; - count++; - } + puzzleMat.p_myBox[i]->set=false; + count++; } - if (count !=4) - cerr << "incorrect set set" << endl; } - cout << " no more pieces" << endl; - - log.pop_back(); - if(!backtrack(log,puzzleMat)) - return false; - return true; + cout << "removed " << count << endl; } + cout << " no more pieces" << endl; + + log.pop_back(); + if(!backtrack(log,puzzleMat)) + return false; + return true; } diff --git a/Source/main.cpp b/Source/main.cpp index 7b5ee70..56c683c 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -15,14 +15,14 @@ int main() return 0; } - puzzleMat.createRandomBox(); + //puzzleMat.createRandomBox(); cout << "Solving Puzzle now..."; while(next(log, puzzleMat)); cout << "Done!" << endl; - //puzzleMat.resultImage(log); + puzzleMat.resultImage(log); puzzleMat.printPuzzle(); From 1f87d00d8b4de6c7a30f4eebab189594c42c9ec3 Mon Sep 17 00:00:00 2001 From: Raphael Maenle <17550607+g-spacewhale@users.noreply.github.com> Date: Sat, 20 Jan 2018 22:41:48 +0100 Subject: [PATCH 3/3] removed debug messages --- .../Layer1/AbstractionLayer_1.cpp | 6 +-- Source/functions/solve/puzzleExtension.cpp | 2 +- Source/functions/solve/structure.cpp | 41 ++----------------- Source/main.cpp | 4 +- 4 files changed, 8 insertions(+), 45 deletions(-) diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp index 064e777..1c7b2a2 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp @@ -73,9 +73,7 @@ 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 + //evaluateQuality = evaluateProbabilaty for(int i = 0;im_a1.m_connections)) @@ -226,8 +224,6 @@ bool AbstractionLayer_1::PlaceOfPartGood(coor myCoor, uint8_t& myPart) || (((negativePart & 0b00000011) == 0b00000000) && ((myPart & 0b00000011) == 0b00000000)) ) ) { - if(myCoor.row==18 && myCoor.col==35) - cout << "gud: " << std::bitset<8>(myPart) << endl; return true; } return false; diff --git a/Source/functions/solve/puzzleExtension.cpp b/Source/functions/solve/puzzleExtension.cpp index 775f078..d3ffca8 100644 --- a/Source/functions/solve/puzzleExtension.cpp +++ b/Source/functions/solve/puzzleExtension.cpp @@ -169,7 +169,7 @@ Mat Puzzle::resultImage( vector& log){ // waitKey(0); } - cout << it.PieceCollector[0].second->GetPartID() << endl; + //cout << it.PieceCollector[0].second->GetPartID() << endl; int imageNumber = it.PieceCollector[0].second->GetPartID(); //cout<<"imageIndex: "<< imageNumber << endl; diff --git a/Source/functions/solve/structure.cpp b/Source/functions/solve/structure.cpp index 062dd0e..1070f3a 100755 --- a/Source/functions/solve/structure.cpp +++ b/Source/functions/solve/structure.cpp @@ -44,7 +44,6 @@ void createNextLogElement(vector& log, Puzzle& puzzleMat) log.emplace_back(LogEntry(coor(0, 0))); log.back().myCoor = calculateNextCoor(log, puzzleMat); puzzleMat.dp.DestructionOfSurrounding(log.back().myCoor);//calculate dp from surrounding - cout << "-----------------------" << endl; //get all not set pieces for(auto it:puzzleMat.p_myBox) if(!it->set) @@ -110,27 +109,13 @@ void setsolution(vector& 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; - int ist=0; - for(auto it:puzzleMat.myBox) - if(!it.set) - ist++; - - int soll = (puzzleMat.getSizeAsCoor().row*puzzleMat.getSizeAsCoor().col*4)-4*((log.back().myCoor.col)*puzzleMat.getSizeAsCoor().row+log.back().myCoor.row+1); - if(soll != ist) - cerr << "soll not ist!!!" << endl; - cout << "ist: " << ist << endl; - cout << "soll: " << soll << endl; - //cout << "log:" << endl; - //for(auto it:log.back().PieceCollector) - // cout << std::bitset<8>(it.second->m_a1.getConnections()) << "|" << it.second->GetPartID() << endl; } bool backtrack(vector& log, Puzzle& puzzleMat) { - cout << "backtracking" ; if(log.empty()) { cout << "Puzzle not solveable!" << endl; @@ -140,17 +125,10 @@ bool backtrack(vector& log, Puzzle& puzzleMat) //if more pieces possible, tset piece as not logged if((log.back().PieceCollector.size())>1) { - //unset puzzlepieces - int count =0; - for(int i=0;iGetPartID()==log.back().PieceCollector.begin()->second->GetPartID())//sets all with partid - { puzzleMat.p_myBox[i]->set=false; - count++; - } - } - cout << "removed " << count << endl; + //remove similar in log Part myPart = *log.back().PieceCollector[0].second;//tmpsaves bad part @@ -159,7 +137,6 @@ bool backtrack(vector& log, Puzzle& puzzleMat) //TODO remove this when further layers are added!!! if(log.back().PieceCollector.size()) // this checks if 'removeSimilar' has cleared entire LogElement { - cout << " next piece" << endl; if(log.back().PieceCollector.size()==1) log.back().decreaseRandomed(); setsolution(log,puzzleMat); @@ -168,20 +145,10 @@ bool backtrack(vector& log, Puzzle& puzzleMat) } //else remove log element and backtrack once more puzzleMat.removeConstrains(log.back().myCoor); //this should remove constraints from all layers - int count =0; - if((log.back().PieceCollector.size())) - { + if((log.back().PieceCollector.size())) //unset all for(int i=0;iGetPartID()==log.back().PieceCollector.begin()->second->GetPartID())//sets all with partid - { puzzleMat.p_myBox[i]->set=false; - count++; - } - } - cout << "removed " << count << endl; - } - cout << " no more pieces" << endl; log.pop_back(); if(!backtrack(log,puzzleMat)) diff --git a/Source/main.cpp b/Source/main.cpp index 56c683c..3520583 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -17,11 +17,11 @@ int main() //puzzleMat.createRandomBox(); - cout << "Solving Puzzle now..."; + cout << "Solving Puzzle now..." << flush; while(next(log, puzzleMat)); cout << "Done!" << endl; - + cout << "Printing Puzzle now..." <