Commit f8c88225 authored by Ahmed's avatar Ahmed

add inRange command

parent fd0ba567
......@@ -3,8 +3,7 @@ package de.monticore.lang.monticar.generator.cpp.commands;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixAccessSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.BluePrint;
import de.monticore.lang.monticar.generator.MathCommand;
import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import de.monticore.lang.monticar.generator.cpp.MathFunctionFixer;
import de.monticore.lang.monticar.generator.cpp.converter.ExecuteMethodGenerator;
......@@ -19,7 +18,7 @@ import java.util.List;
* @author Ahmed Diab
*/
public class InRangeCommand extends MathCommand{
public class InRangeCommand extends ArgumentReturnMathCommand{
public InRangeCommand() {
setMathCommandName("inRange");
}
......@@ -45,13 +44,49 @@ public class InRangeCommand extends MathCommand{
String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint);
Method inRangeHelperMethod = getInRangeHelperMethod();
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("inRange" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
MathStringExpression stringExpression = new MathStringExpression("inRangeHelper" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression));
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols);
((BluePrintCPP) bluePrint).addCVIncludeString("opencv2/core");
bluePrint.addMethod(inRangeHelperMethod);
}
private Method getInRangeHelperMethod(){
Method method = new Method("inRangeHelper", "void");
//add parameters
Variable src = new Variable();
method.addParameter(src, "src", "CommonMatrix","Mat", "");;
Variable dst = new Variable();
method.addParameter(dst, "dst", "CommonMatrixType", "Mat", "");
Variable lowerBoundary = new Variable();
method.addParameter(lowerBoundary, "lowerB", "colvec", "colvec", "" );
Variable upperBoundary = new Variable();
method.addParameter(upperBoundary, "upperB", "colvec", "colvec", "");
//add an instruction to the method
method.addInstruction(methodBody());
return method;
}
private Instruction methodBody(){
return new Instruction() {
@Override
public String getTargetLanguageInstruction() {
return " inRange(src, dst, Scalar(lowerB(0), lowerB(1), lowerB(2)),\n" +
" Scalar(upperB(0), upperB(1), upperB(2)));\n";
}
@Override
public boolean isConnectInstruction() {
return false;
}
};
}
}
......@@ -195,7 +195,8 @@ public class ComponentConverterMethodGeneration {
MathFunctionFixer.fixMathFunctions(mathExpressionSymbol, bluePrint);
String result = ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, includeStrings);
if(ComponentConverter.usedMathCommand != null) {
if (ComponentConverter.usedMathCommand.isArgumentReturnMathCommand()) {
String argumentReturnFunctionName = ComponentConverter.usedMathCommand.getMathCommandName();
if (ComponentConverter.usedMathCommand.isArgumentReturnMathCommand() && result.contains(argumentReturnFunctionName)) {
result = fixArgumentReturnInstruction(result, method, mathExpressionSymbol, bluePrint);
}
}
......
......@@ -9,13 +9,26 @@ using namespace arma;
using namespace cv;
class test_math_inRangeCommandTest{
public:
mat src;
colvec lowerBoundary;
colvec upperBoundary;
mat dst;
void init()
{
src=mat(n,m);
lowerBoundary=colvec(3);
upperBoundary=colvec(3);
dst=mat(n,m);
}
void inRangeHelper(Mat src, Mat dst, colvec lowerB, colvec upperB)
{
inRange(src, dst, Scalar(lowerB(0), lowerB(1), lowerB(2)),
Scalar(upperB(0), upperB(1), upperB(2)));
}
void execute()
{
double a = (inRange(0, 0, 0, 0, 0));
inRangeHelper(src, dst, lowerBoundary, upperBoundary);
}
};
#endif
#endif
\ No newline at end of file
/* (c) https://github.com/MontiCore/monticore */
package test.math;
component InRangeCommandTest{
component InRangeCommandTest {
port
in Q^{n,m} src,
in Q^{3} lowerBoundary,
in Q^{3} upperBoundary,
out Q^{n,m} dst;
implementation Math{
Q a = inRange(0,0,0,0,0);
dst = inRange(src, lowerBoundary, upperBoundary);
}
}
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