Commit 344c734b authored by Ahmed's avatar Ahmed

redefine matToArmaMat

parent 06b0a447
......@@ -7,6 +7,7 @@ import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import java.util.HashSet;
import java.util.List;
import static de.monticore.lang.monticar.generator.cpp.MathCommandRegisterCPP.removeBrackets;
......@@ -77,6 +78,19 @@ public abstract class MathCommand {
return "";
}
public void redefineArmaMat(BluePrintCPP bluePrint){
List<Variable> vars= bluePrint.getVariables();
for(Variable var : vars){
VariableType varType = var.getVariableType();
String targetName = varType.getTypeNameTargetLanguage();
if(targetName.equals("mat")){
Variable newVar = var;
newVar.setTypeNameTargetLanguage("arma::mat");
bluePrint.replaceVariable(var, newVar);
}
}
}
public boolean isArgumentNoReturnMathCommand() {
return false;
}
......
......@@ -64,6 +64,7 @@ public class CvtColorCommand extends ArgumentNoReturnMathCommand{
bluePrintCPP.addCVIncludeString("opencv2/imgproc");
bluePrintCPP.addCVIncludeString("ConvHelper");
bluePrint.addMethod(cvtColorHelperMethod);
redefineArmaMat(bluePrintCPP);
}
......
......@@ -64,6 +64,7 @@ public class DilateCommand extends ArgumentNoReturnMathCommand{
bluePrintCPP.addCVIncludeString("opencv2/imgproc");
bluePrintCPP.addCVIncludeString("ConvHelper");
bluePrint.addMethod(dilateHelperMethod);
redefineArmaMat(bluePrintCPP);
}
......
......@@ -65,6 +65,7 @@ public class ErodeCommand extends ArgumentNoReturnMathCommand{
bluePrintCPP.addCVIncludeString("opencv2/imgproc");
bluePrintCPP.addCVIncludeString("ConvHelper");
bluePrint.addMethod(erodeHelperMethod);
redefineArmaMat(bluePrintCPP);
}
......
......@@ -65,6 +65,7 @@ public class FindContoursCommand extends ArgumentNoReturnMathCommand{
bluePrintCPP.addCVIncludeString("ConvHelper");
bluePrintCPP.addCVIncludeString("vector");
bluePrint.addMethod(findContoursHelperMethod);
redefineArmaMat(bluePrintCPP);
}
......
......@@ -64,6 +64,7 @@ public class InRangeCommand extends ArgumentNoReturnMathCommand{
bluePrintCPP.addCVIncludeString("opencv2/core");
bluePrintCPP.addCVIncludeString("ConvHelper");
bluePrint.addMethod(inRangeHelperMethod);
redefineArmaMat(bluePrintCPP);
}
......
......@@ -68,6 +68,7 @@ public class RectangleCommand extends MathCommand{
bluePrintCPP.addCVIncludeString("opencv2/imgproc");
bluePrintCPP.addCVIncludeString("ConvHelper");
bluePrint.addMethod(rectangleHelperMethod);
redefineArmaMat(bluePrintCPP);
}
......
......@@ -417,11 +417,13 @@ public class ComponentConverter {
String nameOfOutput = getNameOfOutput(mathExpressionSymbol);
MathExpressionProperties properties = tuples.get(mathExpressionSymbol);
if (properties.isPreCV()) {
fixVariableType(nameOfFirstParameter, bluePrintCPP, "CommonMatrixType", "cv::Mat", "");
}
if(properties.isSucCV()){
fixVariableType(nameOfOutput, bluePrintCPP, "CommonMatrixType", "cv::Mat", "");
if(properties != null) {
if (properties.isPreCV()) {
fixVariableType(nameOfFirstParameter, bluePrintCPP, "CommonMatrixType", "cv::Mat", "");
}
if (properties.isSucCV()) {
fixVariableType(nameOfOutput, bluePrintCPP, "CommonMatrixType", "cv::Mat", "");
}
}
}
}
......
......@@ -10,26 +10,30 @@ using namespace arma;
using namespace std;
class test_math_erodeCommandTest{
public:
mat src;
arma::mat src;
int erosion_elem;
int iterations;
mat dst;
arma::mat dst;
void init()
{
src=mat(n,m);
dst=mat(n,m);
}
void erodeHelper(mat src, mat dst, int erosion_elem, int iterations)
void erodeHelper(arma::mat src, arma::mat dst, int erosion_elem, int iterations)
{
int erosion_type = 0;
if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }
else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
erosion_size = erosion_elem;
mat element = cv::getStructuringElement( erosion_type,
cv::Mat element = cv::getStructuringElement( erosion_type,
Size( 2*erosion_size + 1, 2*erosion_size+1 ),
Point( -1, -1 ) );
cv::erode( src, dst, element, Point(-1,-1), iterations );
cv::Mat srcCV;
cv::Mat dstCV;
srcCV = ConvHelper::to_cvmat(src);
cv::erode( srcCV, dstCV, element, Point(-1,-1), iterations );
dst = ConvHelper::to_arma(dstCV);
}
void execute()
{
......
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