Added KantenLaenge

This commit is contained in:
Raphael Maenle
2018-01-30 18:45:54 +01:00
parent 6f02bf4f97
commit dd69066c76
14 changed files with 179 additions and 280 deletions

View File

@ -0,0 +1,90 @@
#include "AbstractionLayer_KantenLaenge.h"
#include "../../../header.h"
bool AbstractionLayer_KantenLaenge::PreProcessing(coor mySize, const vector<Part*>* partArray)
{
//get layer information here
cout << "Abstraction Poempel Position Preprocessing... " << flush;
InitialiseConstraintMatrixSize(mySize.col, mySize.row);
cout << "Done" << endl;
return true;
}
//it through qualityVector and removes all that do not trigger PlaceOfPartGood
bool AbstractionLayer_KantenLaenge::EvaluateQuality (const coor constraintCoordinate, qualityVector& qVector)
{
for(int i = 0;i<qVector.size();i++)
{
float value = PlaceOfPartGood(constraintCoordinate, qVector[i].second->m_a2.SideLength);
qVector[i].first=value;
}
}
bool AbstractionLayer_KantenLaenge::SetConstraintOnPosition(const coor constraintCoordinate, const AbstractionLayer_KantenLaenge_Properties constraint)
{
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].SideLength=constraint.SideLength;
}
bool AbstractionLayer_KantenLaenge::RemoveConstraintOnPosition(const coor constraintCoordinate)
{
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].SideLength={0,0,0,0,0,0,0,0};
}
float AbstractionLayer_KantenLaenge::PlaceOfPartGood(coor myCoor, vector<double> myPart)
{
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]);
}
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>500)
return 0;
if(sum==0)
return 1;
sum/=500;
return 1-sum;
//check vector against negative part, use sad
//return of well it fits within threshold
}
//shifts vector i steps to the right (8-2i to the left)
void AbstractionLayer_KantenLaenge_Properties::shift(int i)
{
rotate(SideLength.begin(),SideLength.begin()+(8-2*i),SideLength.end());
}

View File

@ -0,0 +1,22 @@
#pragma once
#include "AbstractionLayer_KantenLaenge_Properties.h"
#include "../AbstraktionLayer_Base.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
class AbstractionLayer_KantenLaenge : public AbstractionLayer_Base<AbstractionLayer_KantenLaenge_Properties>
{
public:
bool PreProcessing(coor mySize, const vector<Part*>* partArray) final ;
bool EvaluateQuality ( coor constraintCoordinate, qualityVector& qVector)final;
bool SetConstraintOnPosition( coor constraintCoordinate, AbstractionLayer_KantenLaenge_Properties constraint)final;
bool RemoveConstraintOnPosition( coor constraintCoordinate)final;
float PlaceOfPartGood(coor myCoor, vector<double> myPart);
private:
};

View File

@ -0,0 +1,19 @@
#pragma once
#include <vector>
using namespace std;
class AbstractionLayer_KantenLaenge_Properties
{
public:
AbstractionLayer_KantenLaenge_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<double> SideLength;
friend class AbstractionLayer_KantenLaenge;
friend class AbstractionLayer_PoempelPosition;
friend class AbstractionLayer_1;
};