Commit 640ba3f0 authored by Ahmed's avatar Ahmed

add neu funktion to MathCommand

parent 60227903
......@@ -4,6 +4,7 @@ package de.monticore.lang.monticar.generator;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import java.util.HashSet;
......@@ -62,6 +63,20 @@ public abstract class MathCommand {
return false;
}
public String getTypeOfFirstInput(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrintCPP){
String nameOfFirstParameter = mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols().get(0).getTextualRepresentation();
for(Variable var: bluePrintCPP.getVariables()){
String varName = var.getName();
if(varName.equals(nameOfFirstParameter)){
VariableType varType = var.getVariableType();
String typeName = varType.getTypeNameTargetLanguage();
return typeName;
}
}
return "";
}
public boolean isArgumentNoReturnMathCommand() {
return false;
}
......
......@@ -50,7 +50,7 @@ public class DilateCommand extends ArgumentNoReturnMathCommand{
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint);
Method dilateHelperMethod = getDilateHelperMethod();
Method dilateHelperMethod = getDilateHelperMethod(mathMatrixNameExpressionSymbol, (BluePrintCPP) bluePrint);
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("dilateHelper" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
......@@ -62,14 +62,19 @@ public class DilateCommand extends ArgumentNoReturnMathCommand{
}
private Method getDilateHelperMethod(){
private Method getDilateHelperMethod(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol,BluePrintCPP bluePrintCPP){
Method method = new Method("dilateHelper", "void");
String typeName = getTypeOfFirstInput(mathMatrixNameExpressionSymbol, bluePrintCPP);
if(typeName.equals("")){
typeName = "mat";
}
//add parameters
Variable src = new Variable();
method.addParameter(src, "src", "CommonMatrix",MathConverter.curBackend.getMatrixTypeName(), MathConverter.curBackend.getIncludeHeaderName());;
method.addParameter(src, "src", "CommonMatrix", typeName, MathConverter.curBackend.getIncludeHeaderName());;
Variable dst = new Variable();
method.addParameter(dst, "dst", "CommonMatrixType", MathConverter.curBackend.getMatrixTypeName(), MathConverter.curBackend.getIncludeHeaderName());
method.addParameter(dst, "dst", "CommonMatrixType", typeName, MathConverter.curBackend.getIncludeHeaderName());
Variable erosion_elem = new Variable();
method.addParameter(erosion_elem,"dilation_elem", "Integer", "int", "");
Variable iterations = new Variable();
......
......@@ -50,7 +50,7 @@ public class ErodeCommand extends ArgumentNoReturnMathCommand{
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint);
Method erodeHelperMethod = getErodeHelperMethod();
Method erodeHelperMethod = getErodeHelperMethod(mathMatrixNameExpressionSymbol, (BluePrintCPP) bluePrint);
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("erodeHelper" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
......@@ -63,14 +63,19 @@ public class ErodeCommand extends ArgumentNoReturnMathCommand{
}
private Method getErodeHelperMethod(){
private Method getErodeHelperMethod(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrintCPP){
Method method = new Method("erodeHelper", "void");
String typeName = getTypeOfFirstInput(mathMatrixNameExpressionSymbol, bluePrintCPP);
if(typeName.equals("")){
typeName = "mat";
}
//add parameters
Variable src = new Variable();
method.addParameter(src, "src", "CommonMatrixType",MathConverter.curBackend.getMatrixTypeName(), MathConverter.curBackend.getIncludeHeaderName());
method.addParameter(src, "src", "CommonMatrixType", typeName, MathConverter.curBackend.getIncludeHeaderName());
Variable dst = new Variable();
method.addParameter(dst, "dst", "CommonMatrixType", MathConverter.curBackend.getMatrixTypeName(), MathConverter.curBackend.getIncludeHeaderName());
method.addParameter(dst, "dst", "CommonMatrixType", typeName, MathConverter.curBackend.getIncludeHeaderName());
Variable erosion_elem = new Variable();
method.addParameter(erosion_elem,"erosion_elem", "Integer", "int", "");
Variable iterations = new Variable();
......
......@@ -51,7 +51,7 @@ public class GaussianBlurCommand extends ArgumentNoReturnMathCommand{
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint);
Method gaussianBlurHelperMethod = getGaussianBlurHelperMethod();
Method gaussianBlurHelperMethod = getGaussianBlurHelperMethod(mathMatrixNameExpressionSymbol,(BluePrintCPP) bluePrint);
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("gaussianBlurHelper" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
......@@ -63,14 +63,20 @@ public class GaussianBlurCommand extends ArgumentNoReturnMathCommand{
}
private Method getGaussianBlurHelperMethod(){
private Method getGaussianBlurHelperMethod(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrintCPP){
Method method = new Method("gaussianBlurHelper", "void");
String typeName = getTypeOfFirstInput(mathMatrixNameExpressionSymbol, bluePrintCPP);
if(typeName.equals("")){
typeName = "mat";
}
//add parameters
Variable src = new Variable();
method.addParameter(src, "src", "CommonMatrix",MathConverter.curBackend.getMatrixTypeName(), MathConverter.curBackend.getIncludeHeaderName());;
method.addParameter(src, "src", "CommonMatrix",typeName, MathConverter.curBackend.getIncludeHeaderName());;
Variable dst = new Variable();
method.addParameter(dst, "dst", "CommonMatrixType", MathConverter.curBackend.getMatrixTypeName(), MathConverter.curBackend.getIncludeHeaderName());
method.addParameter(dst, "dst", "CommonMatrixType", typeName, MathConverter.curBackend.getIncludeHeaderName());
Variable sizeX = new Variable();
method.addParameter(sizeX, "sizeX", "Integer", "int", "");
Variable sizeY = new Variable();
......
......@@ -67,9 +67,9 @@ public class InRangeCommand extends ArgumentNoReturnMathCommand{
//add parameters
Variable src = new Variable();
method.addParameter(src, "src", "CommonMatrix","Mat", "");;
method.addParameter(src, "src", "CommonMatrix", "cube", "");;
Variable dst = new Variable();
method.addParameter(dst, "dst", "CommonMatrixType", "Mat", "");
method.addParameter(dst, "dst", "CommonMatrixType", "mat", "");
Variable lowerBoundary = new Variable();
method.addParameter(lowerBoundary, "lowerB", "colvec", "colvec", "" );
Variable upperBoundary = new Variable();
......
......@@ -9,18 +9,18 @@ using namespace arma;
using namespace cv;
class test_math_gaussianBlurCommandTest{
public:
mat src;
cube src;
int sizeX;
int sizeY;
double sigmaX;
double sigmaY;
mat dst;
cube dst;
void init()
{
src=mat(n,m);
dst=mat(n,m);
src = cube(3, n, m);
dst = cube(3, n, m);
}
void gaussianBlurHelper(mat src, mat dst, int sizeX, int sizeY, double sigmaX, double sigmaY)
void gaussianBlurHelper(cube src, cube dst, int sizeX, int sizeY, double sigmaX, double sigmaY)
{
gaussianBlur(src, dst, Size(sizeX, sizeY), sigmaX, sigmaY);
}
......
......@@ -20,7 +20,7 @@ lowerBoundary=colvec(3);
upperBoundary=colvec(3);
dst=mat(n,m);
}
void inRangeHelper(Mat src, Mat dst, colvec lowerB, colvec upperB)
void inRangeHelper(cube src, mat dst, colvec lowerB, colvec upperB)
{
inRange(src, Scalar(lowerB(0), lowerB(1), lowerB(2)),
Scalar(upperB(0), upperB(1), upperB(2)), dst);
......
......@@ -3,12 +3,12 @@ package test.math;
component GaussianBlurCommandTest {
port
in Q^{n,m} src,
in Q^{3,n,m} src,
in Z sizeX,
in Z sizeY,
in Q sigmaX,
in Q sigmaY,
out Q^{n,m} dst;
out Q^{3,n,m} dst;
implementation Math {
dst = gaussianBlur(src, sizeX, sizeY, sigmaX, sigmaY);
......
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