Commit 8392b428 authored by Ahmed's avatar Ahmed
Browse files

extends inRange

parent 8e0ff35c
...@@ -153,6 +153,4 @@ public class ErodeCommand extends ArgumentNoReturnMathCommand{ ...@@ -153,6 +153,4 @@ public class ErodeCommand extends ArgumentNoReturnMathCommand{
} }
}; };
} }
} }
...@@ -5,7 +5,9 @@ import de.monticore.lang.math._symboltable.matrix.MathMatrixAccessSymbol; ...@@ -5,7 +5,9 @@ import de.monticore.lang.math._symboltable.matrix.MathMatrixAccessSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol; import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.*; import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP; import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import de.monticore.lang.monticar.generator.cpp.MathExpressionProperties;
import de.monticore.lang.monticar.generator.cpp.MathFunctionFixer; import de.monticore.lang.monticar.generator.cpp.MathFunctionFixer;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import de.monticore.lang.monticar.generator.cpp.converter.ExecuteMethodGenerator; import de.monticore.lang.monticar.generator.cpp.converter.ExecuteMethodGenerator;
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter; import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.monticore.lang.monticar.generator.cpp.symbols.MathStringExpression; import de.monticore.lang.monticar.generator.cpp.symbols.MathStringExpression;
...@@ -45,13 +47,14 @@ public class InRangeCommand extends ArgumentNoReturnMathCommand{ ...@@ -45,13 +47,14 @@ public class InRangeCommand extends ArgumentNoReturnMathCommand{
public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) { public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol; MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol;
mathMatrixNameExpressionSymbol.setNameToAccess(""); mathMatrixNameExpressionSymbol.setNameToAccess("");
MathExpressionProperties properties = ComponentConverter.tuples.get(mathExpressionSymbol);
BluePrintCPP bluePrintCPP = (BluePrintCPP) bluePrint; BluePrintCPP bluePrintCPP = (BluePrintCPP) bluePrint;
String valueListString = ""; String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols()) for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, bluePrintCPP); MathFunctionFixer.fixMathFunctions(accessSymbol, bluePrintCPP);
Method inRangeHelperMethod = getInRangeHelperMethod(); Method inRangeHelperMethod = getInRangeHelperMethod(mathMatrixNameExpressionSymbol, bluePrintCPP, properties);
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>()); valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>(); List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("inRangeHelper" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols()); MathStringExpression stringExpression = new MathStringExpression("inRangeHelper" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
...@@ -64,32 +67,69 @@ public class InRangeCommand extends ArgumentNoReturnMathCommand{ ...@@ -64,32 +67,69 @@ public class InRangeCommand extends ArgumentNoReturnMathCommand{
} }
private Method getInRangeHelperMethod(){ private Method getInRangeHelperMethod(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrintCPP, MathExpressionProperties properties){
Method method = new Method("inRangeHelper", "void"); Method method = new Method("inRangeHelper", "void");
String typeNameIn = "";
String typeNameOut = "";
if(properties.isPreCV()){
typeNameIn = "cv::Mat";
} else {
typeNameIn = "arma::cube";
}
if(properties.isSucCV()){
typeNameOut = "cv::Mat";
}else {
typeNameOut = "arma::mat";
}
//add parameters //add parameters
Variable src = new Variable(); Variable src = new Variable();
method.addParameter(src, "src", "CommonMatrix", "cube", "");; method.addParameter(src, "src", "CommonMatrix", typeNameIn, "");;
Variable dst = new Variable(); Variable dst = new Variable();
method.addParameter(dst, "dst", "CommonMatrixType", "mat", ""); method.addParameter(dst, "dst", "CommonMatrixType", typeNameOut, "");
Variable lowerBoundary = new Variable(); Variable lowerBoundary = new Variable();
method.addParameter(lowerBoundary, "lowerB", "colvec", "colvec", "" ); method.addParameter(lowerBoundary, "lowerB", "colvec", "colvec", "" );
Variable upperBoundary = new Variable(); Variable upperBoundary = new Variable();
method.addParameter(upperBoundary, "upperB", "colvec", "colvec", ""); method.addParameter(upperBoundary, "upperB", "colvec", "colvec", "");
//add an instruction to the method //add an instruction to the method
method.addInstruction(methodBody()); method.addInstruction(methodBody(properties, typeNameIn, typeNameOut));
return method; return method;
} }
private Instruction methodBody(){ private Instruction methodBody(MathExpressionProperties properties, String typeNameIn, String typeNameOut){
return new Instruction() { return new Instruction() {
@Override @Override
public String getTargetLanguageInstruction() { public String getTargetLanguageInstruction() {
return " cv::inRange(src, Scalar(lowerB(0), lowerB(1), lowerB(2)),\n" +
" Scalar(upperB(0), upperB(1), upperB(2)), dst);\n"; String finalInstruction ="";
if (properties.isPreCV() && properties.isSucCV()) {
finalInstruction += " cv::inRange(src, cv::Scalar(lowerB(0), lowerB(1), lowerB(2)),\n" +
" cv::Scalar(upperB(0), upperB(1), upperB(2)), dst);\n";
} else if (properties.isPreCV()) {
finalInstruction += " cv::Mat dstCV;\n" +
" cv::inRange(src, cv::Scalar(lowerB(0), lowerB(1), lowerB(2)),\n" +
" cv::Scalar(upperB(0), upperB(1), upperB(2)), dstCV);\n" +
" dst = ConvHelper::to_arma(dstCV);\n";
} else if (properties.isSucCV()) {
finalInstruction += " cv::Mat srcCV;\n" +
" srcCV = ConvHelper::to_cvmat(src);\n" +
" cv::inRange(srcCV, cv::Scalar(lowerB(0), lowerB(1), lowerB(2)),\n" +
" cv::Scalar(upperB(0), upperB(1), upperB(2)), dst);\n";
} else {
finalInstruction += " cv::Mat srcCV;\n" +
" cv::Mat dstCV;\n" +
" srcCV = ConvHelper::to_cvmat(src);\n" +
" cv::inRange(srcCV, cv::Scalar(lowerB(0), lowerB(1), lowerB(2)),\n" +
" cv::Scalar(upperB(0), upperB(1), upperB(2)), dstCV);\n" +
" dst = ConvHelper::to_arma(dstCV);\n";
}
return finalInstruction;
} }
@Override @Override
public boolean isConnectInstruction() { public boolean isConnectInstruction() {
return false; return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment