Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Cpp
Commits
7e90dbae
Commit
7e90dbae
authored
Dec 29, 2019
by
Ahmed
Browse files
extend the erode and dilate components
parent
0e48bc12
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/generator/cpp/commands/DilateCommand.java
View file @
7e90dbae
...
...
@@ -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
;
...
...
@@ -45,13 +44,65 @@ public class DilateCommand extends MathCommand{
String
valueListString
=
""
;
for
(
MathMatrixAccessSymbol
accessSymbol
:
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getMathMatrixAccessSymbols
())
MathFunctionFixer
.
fixMathFunctions
(
accessSymbol
,
(
BluePrintCPP
)
bluePrint
);
Method
dilateHelperMethod
=
getDilateHelperMethod
();
valueListString
+=
ExecuteMethodGenerator
.
generateExecuteCode
(
mathExpressionSymbol
,
new
ArrayList
<
String
>());
List
<
MathMatrixAccessSymbol
>
newMatrixAccessSymbols
=
new
ArrayList
<>();
MathStringExpression
stringExpression
=
new
MathStringExpression
(
"dilate"
+
valueListString
,
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getMathMatrixAccessSymbols
());
MathStringExpression
stringExpression
=
new
MathStringExpression
(
"dilate
Helper
"
+
valueListString
,
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getMathMatrixAccessSymbols
());
newMatrixAccessSymbols
.
add
(
new
MathMatrixAccessSymbol
(
stringExpression
));
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
setMathMatrixAccessSymbols
(
newMatrixAccessSymbols
);
((
BluePrintCPP
)
bluePrint
).
addCVIncludeString
(
"opencv2/imgproc"
);
bluePrint
.
addMethod
(
dilateHelperMethod
);
}
private
Method
getDilateHelperMethod
(){
Method
method
=
new
Method
(
"dilateHelper"
,
"void"
);
//parameter
Variable
src
=
new
Variable
();
src
.
setName
(
"src"
);
src
.
setVariableType
(
new
VariableType
(
"CommonMatrixType"
,
MathConverter
.
curBackend
.
getMatrixTypeName
(),
MathConverter
.
curBackend
.
getIncludeHeaderName
()));
Variable
dst
=
new
Variable
();
dst
.
setName
(
"dst"
);
dst
.
setVariableType
(
new
VariableType
(
"CommonMatrixType"
,
MathConverter
.
curBackend
.
getMatrixTypeName
(),
MathConverter
.
curBackend
.
getIncludeHeaderName
()));
Variable
dilation_elem
=
new
Variable
();
dilation_elem
.
setName
(
"erosion_elem"
);
dilation_elem
.
setVariableType
(
new
VariableType
(
"Integer"
,
"int"
,
""
));
Variable
iteration
=
new
Variable
();
iteration
.
setName
(
"iteration"
);
iteration
.
setVariableType
(
new
VariableType
(
"Integer"
,
"int"
,
""
));
//add variable to method
method
.
addParameter
(
src
);
method
.
addParameter
(
dst
);
method
.
addParameter
(
dilation_elem
);
method
.
addParameter
(
iteration
);
//add an instruction to the method
method
.
addInstruction
(
methodBody
());
return
method
;
}
private
Instruction
methodBody
()
{
return
new
Instruction
()
{
@Override
public
String
getTargetLanguageInstruction
()
{
return
" int dilation_type = 0;\n"
+
" if( dilation_elem == 0 ){ dilation_type = MORPH_RECT; }\n"
+
" else if( dilation_elem == 1 ){ dilation_type = MORPH_CROSS; }\n"
+
" else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }\n"
+
" dilation_size = dilation_elem;\n"
+
" mat element = getStructuringElement( dilation_type,\n"
+
" Size( 2*dilation_size + 1, 2*dilation_size+1 ),\n"
+
" Point( dilation_size, dilation_size ) );\n"
+
" dilate( src, dst, element, Point(-1,-1), iteration );"
;
}
@Override
public
boolean
isConnectInstruction
()
{
return
false
;
}
};
}
}
src/main/java/de/monticore/lang/monticar/generator/cpp/commands/ErodeCommand.java
View file @
7e90dbae
...
...
@@ -3,7 +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.
*
;
import
de.monticore.lang.monticar.generator.cpp.BluePrintCPP
;
import
de.monticore.lang.monticar.generator.cpp.converter.ExecuteMethodGenerator
;
import
de.monticore.lang.monticar.generator.cpp.MathFunctionFixer
;
...
...
@@ -44,14 +44,66 @@ public class ErodeCommand extends ArgumentReturnMathCommand{
String
valueListString
=
""
;
for
(
MathMatrixAccessSymbol
accessSymbol
:
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getMathMatrixAccessSymbols
())
MathFunctionFixer
.
fixMathFunctions
(
accessSymbol
,
(
BluePrintCPP
)
bluePrint
);
Method
erodeHelperMethod
=
getErodeHelperMethod
();
valueListString
+=
ExecuteMethodGenerator
.
generateExecuteCode
(
mathExpressionSymbol
,
new
ArrayList
<
String
>());
List
<
MathMatrixAccessSymbol
>
newMatrixAccessSymbols
=
new
ArrayList
<>();
MathStringExpression
stringExpression
=
new
MathStringExpression
(
"erode"
+
valueListString
,
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getMathMatrixAccessSymbols
());
MathStringExpression
stringExpression
=
new
MathStringExpression
(
"erode
Helper
"
+
valueListString
,
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getMathMatrixAccessSymbols
());
newMatrixAccessSymbols
.
add
(
new
MathMatrixAccessSymbol
(
stringExpression
));
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
setMathMatrixAccessSymbols
(
newMatrixAccessSymbols
);
((
BluePrintCPP
)
bluePrint
).
addCVIncludeString
(
"opencv2/imgproc"
);
bluePrint
.
addMethod
(
erodeHelperMethod
);
}
private
Method
getErodeHelperMethod
(){
Method
method
=
new
Method
(
"erodeHelper"
,
"void"
);
//parameter
Variable
src
=
new
Variable
();
src
.
setName
(
"src"
);
src
.
setVariableType
(
new
VariableType
(
"CommonMatrixType"
,
MathConverter
.
curBackend
.
getMatrixTypeName
(),
MathConverter
.
curBackend
.
getIncludeHeaderName
()));
Variable
dst
=
new
Variable
();
dst
.
setName
(
"dst"
);
dst
.
setVariableType
(
new
VariableType
(
"CommonMatrixType"
,
MathConverter
.
curBackend
.
getMatrixTypeName
(),
MathConverter
.
curBackend
.
getIncludeHeaderName
()));
Variable
erosion_elem
=
new
Variable
();
erosion_elem
.
setName
(
"erosion_elem"
);
erosion_elem
.
setVariableType
(
new
VariableType
(
"Integer"
,
"int"
,
""
));
Variable
iteration
=
new
Variable
();
iteration
.
setName
(
"iteration"
);
iteration
.
setVariableType
(
new
VariableType
(
"Integer"
,
"int"
,
""
));
//add variable to method
method
.
addParameter
(
src
);
method
.
addParameter
(
dst
);
method
.
addParameter
(
erosion_elem
);
method
.
addParameter
(
iteration
);
//add an instruction to the method
method
.
addInstruction
(
methodBody
());
return
method
;
}
private
Instruction
methodBody
()
{
return
new
Instruction
()
{
@Override
public
String
getTargetLanguageInstruction
()
{
return
" int erosion_type = 0;\n"
+
" if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }\n"
+
" else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }\n"
+
" else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }\n"
+
" erosion_size = erosion_elem;\n"
+
" mat element = getStructuringElement( erosion_type,\n"
+
" Size( 2*erosion_size + 1, 2*erosion_size+1 ),\n"
+
" Point( erosion_size, erosion_size ) );\n"
+
" erode( src, dst, element, Point(-1,-1), iteration );"
;
}
@Override
public
boolean
isConnectInstruction
()
{
return
false
;
}
};
}
}
src/test/resources/results/armadillo/testMath/l0/test_math_dilateCommandTest.h
View file @
7e90dbae
...
...
@@ -9,13 +9,30 @@ using namespace arma;
using
namespace
cv
;
class
test_math_dilateCommandTest
{
public:
mat
src
;
int
dilation_elem
;
int
iteration
;
mat
dst
;
void
init
()
{
src
=
mat
(
n
,
m
);
dst
=
mat
(
n
,
m
);
}
void
dilateHelper
(
mat
src
,
mat
dst
,
int
erosion_elem
,
int
iteration
)
{
int
dilation_type
=
0
;
if
(
dilation_elem
==
0
){
dilation_type
=
MORPH_RECT
;
}
else
if
(
dilation_elem
==
1
){
dilation_type
=
MORPH_CROSS
;
}
else
if
(
dilation_elem
==
2
)
{
dilation_type
=
MORPH_ELLIPSE
;
}
dilation_size
=
dilation_elem
;
mat
element
=
getStructuringElement
(
dilation_type
,
Size
(
2
*
dilation_size
+
1
,
2
*
dilation_size
+
1
),
Point
(
dilation_size
,
dilation_size
)
);
dilate
(
src
,
dst
,
element
,
Point
(
-
1
,
-
1
),
iteration
);}
void
execute
()
{
d
ouble
a
=
(
dilate
(
0
,
0
,
0
,
0
,
0
));
d
st
=
(
dilate
Helper
(
src
,
dilation_elem
,
iteration
));
}
};
#endif
#endif
\ No newline at end of file
src/test/resources/results/armadillo/testMath/l0/test_math_erodeCommandTest.h
View file @
7e90dbae
#ifndef TEST_MATH_ERODECOMMANDTEST
#define TEST_MATH_ERODECOMMANDTEST
#ifndef M_PI
...
...
@@ -9,16 +10,29 @@ using namespace arma;
using
namespace
cv
;
class
test_math_erodeCommandTest
{
public:
mat
arrayIn
;
mat
arrayOut
;
mat
src
;
int
erosion_elem
;
int
iteration
;
mat
dst
;
void
init
()
{
arrayIn
=
mat
(
n
,
m
);
arrayOu
t
=
mat
(
n
,
m
);
src
=
mat
(
n
,
m
);
ds
t
=
mat
(
n
,
m
);
}
void
erodeHelper
(
mat
src
,
mat
dst
,
int
erosion_elem
,
int
iteration
)
{
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
=
getStructuringElement
(
erosion_type
,
Size
(
2
*
erosion_size
+
1
,
2
*
erosion_size
+
1
),
Point
(
erosion_size
,
erosion_size
)
);
erode
(
src
,
dst
,
element
,
Point
(
-
1
,
-
1
),
iteration
);}
void
execute
()
{
erode
(
arrayIn
,
arrayOut
);
erode
Helper
(
src
,
dst
,
erosion_elem
,
iteration
);
}
};
...
...
src/test/resources/test/math/DilateCommandTest.emam
View file @
7e90dbae
...
...
@@ -2,7 +2,13 @@
package
test
.
math
;
component
DilateCommandTest
{
port
in
Q
^{
n
,
m
}
src
,
in
Z
dilation_elem
,
in
Z
iteration
,
out
Q
^{
n
,
m
}
dst
;
implementation
Math
{
Q
a
=
dilate
(
0
,
0
,
0
,
0
,
0
);
dst
=
dilate
(
src
,
dilation_elem
,
iteration
);
}
}
src/test/resources/test/math/ErodeCommandTest.emam
View file @
7e90dbae
...
...
@@ -3,10 +3,12 @@ package test.math;
component
ErodeCommandTest
{
port
in
Q
^{
n
,
m
}
arrayIn
,
out
Q
^{
n
,
m
}
arrayOut
;
in
Q
^{
n
,
m
}
src
,
in
Z
erosion_elem
,
in
Z
iteration
,
out
Q
^{
n
,
m
}
dst
;
implementation
Math
{
arrayOu
t
=
erode
(
arrayI
n
);
ds
t
=
erode
(
src
,
erosion_elem
,
iteratio
n
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment