Aufgrund einer Wartung wird GitLab am 28.09. zwischen 10:00 und 11:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 28.09. between 10:00 and 11:00 am.

Commit f470d180 authored by Ahmed's avatar Ahmed

extends GaussianBlur Command

parent 7b6ee58a
......@@ -34,6 +34,14 @@ public class MathExpressionProperties {
this.suc = Level.CV;
}
public boolean isPreCV(){
return this.pre == Level.CV;
}
public boolean isSucCV(){
return this.suc == Level.CV;
}
/*public MathExpressionProperties(String name) {
(name);
}*/
......
......@@ -6,7 +6,9 @@ import de.monticore.lang.math._symboltable.matrix.MathMatrixAccessSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.*;
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.converter.ComponentConverter;
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.symbols.MathStringExpression;
......@@ -14,6 +16,7 @@ import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* @author Ahmed Diab
......@@ -46,13 +49,14 @@ public class GaussianBlurCommand extends ArgumentNoReturnMathCommand{
public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol;
mathMatrixNameExpressionSymbol.setNameToAccess("");
MathExpressionProperties properties = ComponentConverter.tuples.get(mathExpressionSymbol);
BluePrintCPP bluePrintCPP = (BluePrintCPP) bluePrint;
String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, bluePrintCPP);
Method gaussianBlurHelperMethod = getGaussianBlurHelperMethod(mathMatrixNameExpressionSymbol,bluePrintCPP);
Method gaussianBlurHelperMethod = getGaussianBlurHelperMethod(mathMatrixNameExpressionSymbol,bluePrintCPP, properties);
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("gaussianBlurHelper" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
......@@ -65,20 +69,33 @@ public class GaussianBlurCommand extends ArgumentNoReturnMathCommand{
}
private Method getGaussianBlurHelperMethod(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrintCPP){
private Method getGaussianBlurHelperMethod(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrintCPP, MathExpressionProperties properties){
Method method = new Method("gaussianBlurHelper", "void");
String typeName = getTypeOfFirstInput(mathMatrixNameExpressionSymbol, bluePrintCPP);
String typeNameIn = "";
String typeNameOut = "";
if(typeName.equals("")){
typeName = "mat";
}
if(properties.isPreCV()){
typeNameIn = "cv::Mat";
} else {
typeNameIn = typeName;
}
if(properties.isSucCV()){
typeNameOut = "cv::Mat";
}else {
typeNameOut = typeName;
}
//add parameters
Variable src = new Variable();
method.addParameter(src, "src", "CommonMatrix",typeName, MathConverter.curBackend.getIncludeHeaderName());;
method.addParameter(src, "src", "CommonMatrix",typeNameIn, MathConverter.curBackend.getIncludeHeaderName());;
Variable dst = new Variable();
method.addParameter(dst, "dst", "CommonMatrixType", typeName, MathConverter.curBackend.getIncludeHeaderName());
method.addParameter(dst, "dst", "CommonMatrixType", typeNameOut, MathConverter.curBackend.getIncludeHeaderName());
Variable sizeX = new Variable();
method.addParameter(sizeX, "sizeX", "Integer", "int", "");
Variable sizeY = new Variable();
......@@ -88,17 +105,43 @@ public class GaussianBlurCommand extends ArgumentNoReturnMathCommand{
Variable sigmaY = new Variable();
method.addParameter(sigmaY, "sigmaY", "Double", "double", "");
//add an instruction to the method
method.addInstruction(methodBody());
method.addInstruction(methodBody(properties, typeNameIn, typeNameOut));
return method;
}
private Instruction methodBody(){
private Instruction methodBody(MathExpressionProperties properties, String typeNameIn, String typeNameOut){
return new Instruction() {
@Override
public String getTargetLanguageInstruction() {
return " cv::gaussianBlur(src, dst, Size(sizeX, sizeY), sigmaX, sigmaY);\n";
String finalInstruction = "";
if(properties.isPreCV() && properties.isSucCV()){
finalInstruction = " gaussianBlur(src, dst, Size(sizeX, sizeY), sigmaX, sigmaY);\n";
}else if(properties.isPreCV()){
finalInstruction = " cv::Mat dstCV;\n" +
" gaussianBlur(src, dstCV, Size(sizeX, sizeY), sigmaX, sigmaY);\n";
if(typeNameOut == "cube"){
finalInstruction += " dst = ConvHelper::to_armaCube(dstCV);\n";
} else {
finalInstruction += " dst = ConvHelper::to_arma(dstCV);\n";
}
} else if(properties.isSucCV()){
finalInstruction = " cv::Mat srcCV;\n" +
" srcCV = ConvHelper::to_cvmat(src);\n" +
" gaussianBlur(srcCV, dst, Size(sizeX, sizeY), sigmaX, sigmaY);\n";
} else {
finalInstruction = " cv::Mat srcCV;\n" +
" cv::Mat dstCV;\n" +
" srcCV = ConvHelper::to_cvmat(src);\n" +
" gaussianBlur(srcCV, dstCV, Size(sizeX, sizeY), sigmaX, sigmaY);\n";
if(typeNameOut == "cube"){
finalInstruction += " dst = ConvHelper::to_armaCube(dstCV);\n";
} else {
finalInstruction += " dst = ConvHelper::to_arma(dstCV);\n";
}
}
return finalInstruction;
}
@Override
......
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