Commit 2123b848 authored by Ahmed's avatar Ahmed

define types

parent 640ba3f0
......@@ -5,6 +5,7 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instance
import de.monticore.lang.monticar.generator.optimization.MathInformationRegister;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
......@@ -67,6 +68,9 @@ public class BluePrint {
variables.remove(v);
}
public void replaceVariable(Variable varOld, Variable varNew){
Collections.replaceAll(variables,varOld, varNew);
}
public void addMethod(Method method) {
methods.add(method);
}
......
......@@ -7,6 +7,7 @@ import de.monticore.lang.monticar.generator.BluePrint;
import de.monticore.lang.monticar.generator.MathCommand;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
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;
......@@ -46,10 +47,16 @@ public class BoundingRectCommand extends MathCommand{
public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol;
mathMatrixNameExpressionSymbol.setNameToAccess("");
BluePrintCPP bluePrintCPP = (BluePrintCPP) bluePrint;
String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint);
MathFunctionFixer.fixMathFunctions(accessSymbol, bluePrintCPP);
String nameOfFirstParameter = mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols().get(0).getTextualRepresentation();
ComponentConverter.fixVariableType(nameOfFirstParameter, bluePrintCPP, "Q", "vector<cv::Point>", "");
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("boundingRect" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
......
......@@ -10,6 +10,7 @@ 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;
import de.se_rwth.commons.logging.Log;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import java.util.ArrayList;
import java.util.List;
......@@ -45,11 +46,13 @@ public class LargestContourCommand extends MathCommand {
public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol;
mathMatrixNameExpressionSymbol.setNameToAccess("");
BluePrintCPP bluePrintCPP = (BluePrintCPP) bluePrint;
String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint);
MathFunctionFixer.fixMathFunctions(accessSymbol, bluePrintCPP);
String nameOfFirstParameter = mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols().get(0).getTextualRepresentation();
ComponentConverter.fixVariableType(nameOfFirstParameter, bluePrintCPP, "Q", "vector<vector<cv::Point>>", "");
Method largestContourMethod = getLargestContourMethod();
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
......
......@@ -6,6 +6,7 @@ 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.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;
......@@ -45,10 +46,14 @@ public class RectangleCommand extends MathCommand{
public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol;
mathMatrixNameExpressionSymbol.setNameToAccess("");
BluePrintCPP bluePrintCPP = (BluePrintCPP) bluePrint;
String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint);
MathFunctionFixer.fixMathFunctions(accessSymbol, bluePrintCPP);
String nameOfSecondParameter = mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols().get(1).getTextualRepresentation();
ComponentConverter.fixVariableType(nameOfSecondParameter, bluePrintCPP, "Q", "Rect", "");
Method rectangleHelperMethod = getRectangleHelperMethod();
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
......
......@@ -69,17 +69,17 @@ public class ComponentConverter {
if(mathStatementsSymbol != null) {
List<MathExpressionSymbol> mathExpressionSymbols = mathStatementsSymbol.getMathExpressionSymbols();
for(MathExpressionSymbol mathExpressionSymbol : mathExpressionSymbols){
namesOfFunctions.add(getNameOfMathCommand(mathExpressionSymbol));
String nameOfFunction = getNameOfMathCommand(mathExpressionSymbol);
namesOfFunctions.add(nameOfFunction);
fixFunctionTypes(nameOfFunction, mathExpressionSymbol, bluePrint);
}
}
if(namesOfFunctions != null) {
for(String nameOfFunction : namesOfFunctions){
usedMathCommand.add(bluePrint.getMathCommandRegister().getMathCommand(nameOfFunction));
}
}
if(mathStatementsSymbol != null){
//handleDependenceOfCVCommands(mathStatementsSymbol, BluePrintCPP bluePrint);
}
......@@ -314,7 +314,7 @@ public class ComponentConverter {
initLine.ifPresent(s -> method.addInstruction(new TargetCodeInstruction(s)));
}
}
//TODO: Try to modify this Method
public static void handleDependenceOfCVCommands(MathStatementsSymbol mathStatementsSymbol, BluePrintCPP bluePrint) {
List<MathExpressionSymbol> mathExpressionSymbols = mathStatementsSymbol.getMathExpressionSymbols();
int mathExpressionSymbolsSize = mathExpressionSymbols.size();
......@@ -332,9 +332,6 @@ public class ComponentConverter {
}
}
}
}
}
}
......@@ -395,4 +392,34 @@ public class ComponentConverter {
public static void fixMathFunctions(MathExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrintCPP) {
MathFunctionFixer.fixMathFunctions(mathExpressionSymbol, bluePrintCPP);
}
private static void fixFunctionTypes(String nameOfFunction, MathExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrintCPP) {
String outputName = getNameOfOutput(mathExpressionSymbol);
switch (nameOfFunction) {
case "findContours":
fixVariableType(outputName, bluePrintCPP, "Q", "vector<vector<cv::Point>>", "");
break;
case "largestContour":
fixVariableType(outputName, bluePrintCPP, "Q", "vector<cv::Point>", "");
break;
case "boundingRect":
fixVariableType(outputName, bluePrintCPP, "Q", "Rect", "");
break;
}
}
public static void fixVariableType(String variableName, BluePrintCPP bluePrint, String typeNameMontiCar, String typeNameTargetLanguage, String includeName){
List<Variable> variables = bluePrint.getVariables();
for(Variable var: variables){
if(var.getName().equals(variableName)){
fixType(var,typeNameMontiCar, typeNameTargetLanguage, includeName);
}
}
}
private static void fixType(Variable variable, String typeNameMontiCar, String typeNameTargetLanguage, String includeName){
VariableType varTypeNew = new VariableType(typeNameMontiCar, typeNameTargetLanguage, includeName);
variable.setVariableType(varTypeNew);
}
}
......@@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.List;
import static de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter.getNameOfOutput;
import static de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter.getNameOfMathCommand;
/**
*/
......@@ -195,13 +196,16 @@ public class ComponentConverterMethodGeneration {
MathFunctionFixer.fixMathFunctions(mathExpressionSymbol, bluePrint);
String result = ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, includeStrings);
String outputName = "";
for (MathCommand mathCommand : ComponentConverter.usedMathCommand)
if(mathCommand != null) {
String argumentNoReturnFunctionName = mathCommand.getMathCommandName();
if (mathCommand.isArgumentNoReturnMathCommand() && result.contains(argumentNoReturnFunctionName)) {
outputName = getNameOfOutput(mathExpressionSymbol);
result = fixArgumentNoReturnInstruction(result, outputName);
for (MathCommand mathCommand : ComponentConverter.usedMathCommand) {
if (mathCommand != null) {
String argumentNoReturnFunctionName = mathCommand.getMathCommandName();
if (mathCommand.isArgumentNoReturnMathCommand() && result.contains(argumentNoReturnFunctionName)) {
outputName = getNameOfOutput(mathExpressionSymbol);
result = fixArgumentNoReturnInstruction(result, outputName);
//TODO Add fixType Here ---> think about put the function here or down
}
}
//fixVariableTypes(mathCommand, result,mathExpressionSymbol, bluePrint);
}
TargetCodeMathInstruction instruction = new TargetCodeMathInstruction(result, mathExpressionSymbol);
Log.info(mathExpressionSymbol.getClass().getName() + " " + mathExpressionSymbol.getTextualRepresentation(), "GenerateSymbol:");
......@@ -378,4 +382,6 @@ public class ComponentConverterMethodGeneration {
}
}
......@@ -284,9 +284,9 @@ public class ArmadilloFunctionTest extends AbstractSymtabTest {
public void testRectangleCommand() throws IOException {
testMathCommand("rectangle");
}
/*
@Test //only for testing
public void testErodeAndGaussianBlur() throws IOException{
testMathCommand("erodeAndGaussianBlur");
}*/
}
}
......@@ -9,7 +9,7 @@ using namespace arma;
using namespace cv;
class test_math_boundingRectCommandTest{
public:
double contour;
vector<cv::Point> contour;
double rect;
void init()
{
......
......@@ -5,25 +5,27 @@
#endif
#include "armadillo"
#include "opencv2/imgproc.hpp"
#include <vector>
#include "opencv2/imgproc.hpp"
using namespace arma;
using namespace cv;
class test_math_erodeAndGaussianBlurCommandTest{
public:
mat src;
int erosion_elem;
int iterations;
int sizeX;
int sizeY;
double sigmaX;
double sigmaY;
mat dstB;
cube src;
int erosion_elemIn;
colvec sizeY;
colvec two;
cube outMatrix;
mat out2Matrix;
void init()
{
src=mat(n,m);
dstB=mat(n,m);
src = cube(3, n, m);
sizeY=colvec(3);
two=colvec(2);
outMatrix = cube(3, n, m);
out2Matrix=mat(2,m);
}
void erodeHelper(mat src, mat dst, int erosion_elem, int iterations)
void erodeHelper(cube src, cube dst, int erosion_elem, int iterations)
{
int erosion_type = 0;
if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
......@@ -35,17 +37,10 @@ void erodeHelper(mat src, mat dst, int erosion_elem, int iterations)
Point( -1, -1 ) );
erode( src, dst, element, Point(-1,-1), iterations );
}
void gaussianBlurHelper(mat src, mat dst, int sizeX, int sizeY, double sigmaX, double sigmaY)
{
gaussianBlur(src, dst, Size(sizeX, sizeY), sigmaX, sigmaY);
}
void execute()
{
mat dst=mat(n,m);
findContours(image, contours, mode, method);
erodeHelper(src, dst, erosion_elem, iterations);
mat deterMat = (det(dst));
mat dstB;
gaussianBlurHelper(dst, dstB, sizeX, sizeY, sigmaX, sigmaY);
}
};
......
......@@ -13,17 +13,14 @@ public:
mat image;
int mode;
int method;
mat hierarchy;
mat contours;
vector<vector<cv::Point>> contours;
void init()
{
image=mat(n,m);
hierarchy=mat(x,y);
contours=mat(w,z);
}
void execute()
{
findContours(image, contours, hierarchy, mode, method);
findContours(image, contours, mode, method);
}
};
......
......@@ -9,8 +9,8 @@ using namespace arma;
using namespace cv;
class test_math_largestContourCommandTest{
public:
double contours;
double lContour;
vector<vector<cv::Point>> contours;
vector<cv::Point> lContour;
void init()
{
}
......
......@@ -10,7 +10,7 @@ using namespace cv;
class test_math_rectangleCommandTest{
public:
cube src;
double rect;
Rect rect;
colvec color;
int thickness;
int lineType;
......
......@@ -3,23 +3,16 @@ package test.math;
component ErodeAndGaussianBlurCommandTest{
port
in Q^{n,m} src,
in Q^{3,n,m} src,
in Z erosion_elemIn,
in Z iterationsIn1,
in Z sizeX,
in Z sizeY,
in Q sigmaX,
in Q sigmaY,
out Q^{n,m} dstB;
in Q^{3} sizeY,
in Q^{2} two,
out Q^{3,n,m} outMatrix,
out Q^{2,m} out2Matrix;
instance ErodeCommandTest erode;
connect erosion_elemIn -> erode.erosion_elem;
connect iterationsIn1 -> erode.iterations;
//connect erode.dst -> dilate.dst;
//implementation Math{
//Q^{n,m} dst;
//dst = erode(src, erosion_elem, iterations);
//Q^{2,3} deterMat = det(dst);
//Q^{n,m} dstB = gaussianBlur(dst, sizeX, sizeY, sigmaX, sigmaY);
//}
implementation Math{
contours = findContours(image, mode, method);
dst = erode(src, erosion_elem, iterations);
}
}
......@@ -6,10 +6,9 @@ component FindContoursCommandTest{
in Q^{n,m} image,
in Z mode,
in Z method,
out Q^{x,y} hierarchy,
out Q^{w,z} contours;
out Q contours;
implementation Math {
contours = findContours(image, hierarchy, mode, method);
contours = findContours(image, mode, method);
}
}
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