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
b2aa4ee6
Commit
b2aa4ee6
authored
Feb 26, 2020
by
Ahmed
Browse files
update erode
parent
2500d534
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/generator/MathCommand.java
View file @
b2aa4ee6
...
...
@@ -8,6 +8,7 @@ import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Optional
;
import
static
de
.
monticore
.
lang
.
monticar
.
generator
.
cpp
.
MathCommandRegisterCPP
.
removeBrackets
;
...
...
@@ -85,12 +86,32 @@ public abstract class MathCommand {
String
targetName
=
varType
.
getTypeNameTargetLanguage
();
if
(
targetName
.
equals
(
"mat"
)){
Variable
newVar
=
var
;
newVar
.
setTypeNameTargetLanguage
(
"arma::
m
at"
);
newVar
.
setTypeNameTargetLanguage
(
"arma::
M
at
<unsigned char>
"
);
bluePrint
.
replaceVariable
(
var
,
newVar
);
}
else
if
(
targetName
.
equals
(
"cube"
)){
Variable
newVarCube
=
var
;
newVarCube
.
setTypeNameTargetLanguage
(
"Cube<unsigned char>"
);
bluePrint
.
replaceVariable
(
var
,
newVarCube
);
}
}
}
public
void
redefineInit
(
BluePrintCPP
bluePrint
){
Optional
<
Method
>
methodOpt
=
bluePrint
.
getMethod
(
"init"
);
Method
initMethod
=
methodOpt
.
get
();
List
<
Instruction
>
instructs
=
initMethod
.
getInstructions
();
for
(
Instruction
instruct
:
instructs
){
String
code
=
instruct
.
getTargetLanguageInstruction
();
if
(
code
.
contains
(
"mat("
)){
code
=
code
.
replace
(
"mat("
,
"Mat<unsigned char>("
);
}
else
if
(
code
.
contains
(
"cube("
)){
code
=
code
.
replace
(
"mat("
,
"Cube<unsigned char>("
);
}
((
TargetCodeInstruction
)
instruct
).
setInstruction
(
code
);
}
}
public
boolean
isArgumentNoReturnMathCommand
()
{
return
false
;
}
...
...
src/main/java/de/monticore/lang/monticar/generator/cpp/commands/ErodeCommand.java
View file @
b2aa4ee6
...
...
@@ -51,7 +51,8 @@ public class ErodeCommand extends ArgumentNoReturnMathCommand{
BluePrintCPP
bluePrintCPP
=
(
BluePrintCPP
)
bluePrint
;
String
valueListString
=
""
;
for
(
MathMatrixAccessSymbol
accessSymbol
:
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getMathMatrixAccessSymbols
())
List
<
MathMatrixAccessSymbol
>
mathMatrixAccessSymbols
=
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getMathMatrixAccessSymbols
();
for
(
MathMatrixAccessSymbol
accessSymbol
:
mathMatrixAccessSymbols
)
MathFunctionFixer
.
fixMathFunctions
(
accessSymbol
,
bluePrintCPP
);
Method
erodeHelperMethod
=
getErodeHelperMethod
(
mathMatrixNameExpressionSymbol
,
bluePrintCPP
,
properties
);
...
...
@@ -66,6 +67,7 @@ public class ErodeCommand extends ArgumentNoReturnMathCommand{
bluePrintCPP
.
addCVIncludeString
(
"ConvHelper"
);
bluePrint
.
addMethod
(
erodeHelperMethod
);
redefineArmaMat
(
bluePrintCPP
);
redefineInit
(
bluePrintCPP
);
}
...
...
@@ -77,7 +79,9 @@ public class ErodeCommand extends ArgumentNoReturnMathCommand{
String
typeNameOut
=
""
;
if
(
typeName
.
equals
(
""
)
||
typeName
.
equals
(
"mat"
)){
typeName
=
"arma::mat"
;
typeName
=
"arma::Mat<unsigned char>"
;
}
else
if
(
typeName
.
equals
(
"cube"
)){
typeName
=
"Cube<unsigned char>"
;
}
if
(
properties
.
isPreCV
()){
...
...
@@ -91,12 +95,14 @@ public class ErodeCommand extends ArgumentNoReturnMathCommand{
}
else
{
typeNameOut
=
typeName
;
}
String
typeNameInConst
=
"const "
+
typeNameIn
+
"&"
;
String
typeNameOutRef
=
typeNameOut
+
"&"
;
//add parameters
Variable
src
=
new
Variable
();
method
.
addParameter
(
src
,
"src"
,
"CommonMatrixType"
,
typeNameIn
,
MathConverter
.
curBackend
.
getIncludeHeaderName
());
method
.
addParameter
(
src
,
"src"
,
"CommonMatrixType"
,
typeNameIn
Const
,
MathConverter
.
curBackend
.
getIncludeHeaderName
());
Variable
dst
=
new
Variable
();
method
.
addParameter
(
dst
,
"dst"
,
"CommonMatrixType"
,
typeNameOut
,
MathConverter
.
curBackend
.
getIncludeHeaderName
());
method
.
addParameter
(
dst
,
"dst"
,
"CommonMatrixType"
,
typeNameOut
Ref
,
MathConverter
.
curBackend
.
getIncludeHeaderName
());
Variable
erosion_elem
=
new
Variable
();
method
.
addParameter
(
erosion_elem
,
"erosion_elem"
,
"Integer"
,
"int"
,
""
);
Variable
iterations
=
new
Variable
();
...
...
@@ -112,37 +118,37 @@ public class ErodeCommand extends ArgumentNoReturnMathCommand{
@Override
public
String
getTargetLanguageInstruction
()
{
String
finalInstruction
=
" 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"
+
" if( erosion_elem == 0 ){ erosion_type =
cv::
MORPH_RECT; }\n"
+
" else if( erosion_elem == 1 ){ erosion_type =
cv::
MORPH_CROSS; }\n"
+
" else if( erosion_elem == 2) { erosion_type =
cv::
MORPH_ELLIPSE; }\n"
+
"
int
erosion_size = erosion_elem;\n"
+
" cv::Mat element = cv::getStructuringElement( erosion_type,\n"
+
" Size( 2*erosion_size + 1, 2*erosion_size+1 ),\n"
+
" Point( -1, -1 ) );\n"
;
"
cv::
Size( 2*erosion_size + 1, 2*erosion_size+1 ),\n"
+
"
cv::
Point( -1, -1 ) );\n"
;
if
(
properties
.
isPreCV
()
&&
properties
.
isSucCV
()){
finalInstruction
+=
" cv::erode( src, dst, element, Point(-1,-1), iterations );\n"
;
finalInstruction
+=
" cv::erode( src, dst, element,
cv::
Point(-1,-1), iterations );\n"
;
}
else
if
(
properties
.
isPreCV
()){
finalInstruction
+=
" cv::Mat dstCV;\n"
+
" cv::erode( src, dstCV, element, Point(-1,-1), iterations );\n"
;
" cv::erode( src, dstCV, element,
cv::
Point(-1,-1), iterations );\n"
;
if
(
typeNameOut
==
"cube"
){
finalInstruction
+=
" dst =
ConvHelper::to_armaCube
(dstCV);\n"
;
finalInstruction
+=
" dst =
to_armaCube<unsigned char, 3>
(dstCV);\n"
;
}
else
{
finalInstruction
+=
" dst =
ConvHelper::to_arma
(dstCV);\n"
;
finalInstruction
+=
" dst =
to_arma<unsigned char>
(dstCV);\n"
;
}
}
else
if
(
properties
.
isSucCV
()){
finalInstruction
+=
" cv::Mat srcCV;\n"
+
" srcCV =
ConvHelper::to_cvmat
(src);\n"
+
" cv::erode( srcCV, dst, element, Point(-1,-1), iterations );\n"
;
" srcCV =
to_cvmat<unsigned char>
(src);\n"
+
" cv::erode( srcCV, dst, element,
cv::
Point(-1,-1), iterations );\n"
;
}
else
{
finalInstruction
+=
" cv::Mat srcCV;\n"
+
" cv::Mat dstCV;\n"
+
" srcCV =
ConvHelper::to_cvmat
(src);\n"
+
" cv::erode( srcCV, dstCV, element, Point(-1,-1), iterations );\n"
;
" srcCV =
to_cvmat<unsigned char>
(src);\n"
+
" cv::erode( srcCV, dstCV, element,
cv::
Point(-1,-1), iterations );\n"
;
if
(
typeNameOut
==
"cube"
){
finalInstruction
+=
" dst =
ConvHelper::to_armaCube
(dstCV);\n"
;
finalInstruction
+=
" dst =
to_armaCube<unsigned char, 3>
(dstCV);\n"
;
}
else
{
finalInstruction
+=
" dst =
ConvHelper::to_arma
(dstCV);\n"
;
finalInstruction
+=
" dst =
to_arma<unsigned char>
(dstCV);\n"
;
}
}
return
finalInstruction
;
...
...
src/main/java/de/monticore/lang/monticar/generator/cpp/converter/ComponentConverter.java
View file @
b2aa4ee6
...
...
@@ -79,9 +79,9 @@ public class ComponentConverter {
for
(
MathExpressionSymbol
mathExpressionSymbol
:
mathExpressionSymbols
)
{
MathExpressionProperties
properties
=
new
MathExpressionProperties
();
MathConverter
.
setPropertiesForMathExpression
(
mathExpressionSymbols
,
mathExpressionSymbol
,
bluePrint
,
properties
);
if
(
mathExpressionSymbol
.
isAssignmentExpression
()){
MathExpressionSymbol
mathExpressionSymbol
Temp
=
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
();
if
(
mathExpressionSymbol
Temp
.
isMatrixExpression
())
{
if
(
mathExpressionSymbol
.
isAssignmentExpression
()
&&
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
().
isMatrixExpression
()
){
Math
Matrix
ExpressionSymbol
math
Matrix
ExpressionSymbol
=
(
MathMatrixExpressionSymbol
)
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
();
if
(
math
Matrix
ExpressionSymbol
.
isMatrix
Name
Expression
())
{
MathMatrixNameExpressionSymbol
mathMatrixNameExpressionSymbol
=
(
MathMatrixNameExpressionSymbol
)
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
();
ComponentConverter
.
tuples
.
put
(
mathMatrixNameExpressionSymbol
,
properties
);
}
...
...
@@ -93,9 +93,12 @@ public class ComponentConverter {
}
else
if
(
mathExpressionSymbols
.
size
()
==
1
){
MathExpressionProperties
properties
=
new
MathExpressionProperties
();
MathExpressionSymbol
mathExpressionSymbol
=
mathExpressionSymbols
.
get
(
0
);
if
(
mathExpressionSymbol
.
isAssignmentExpression
()){
MathMatrixNameExpressionSymbol
mathMatrixNameExpressionSymbol
=
(
MathMatrixNameExpressionSymbol
)
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
();
ComponentConverter
.
tuples
.
put
(
mathMatrixNameExpressionSymbol
,
properties
);
if
(
mathExpressionSymbol
.
isAssignmentExpression
()
&&
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
().
isMatrixExpression
()){
MathMatrixExpressionSymbol
mathMatrixExpressionSymbol
=
(
MathMatrixExpressionSymbol
)
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
();
if
(
mathMatrixExpressionSymbol
.
isMatrixNameExpression
())
{
MathMatrixNameExpressionSymbol
mathMatrixNameExpressionSymbol
=
(
MathMatrixNameExpressionSymbol
)
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
();
ComponentConverter
.
tuples
.
put
(
mathMatrixNameExpressionSymbol
,
properties
);
}
}
else
{
ComponentConverter
.
tuples
.
put
(
mathExpressionSymbol
,
properties
);
}
...
...
@@ -415,17 +418,20 @@ public class ComponentConverter {
public
static
void
redefineVariables
(
List
<
MathExpressionSymbol
>
mathExpressionSymbols
,
BluePrintCPP
bluePrintCPP
){
for
(
MathExpressionSymbol
mathExpressionSymbol
:
mathExpressionSymbols
){
if
(
mathExpressionSymbol
.
isAssignmentExpression
()
&&
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
().
isMatrixExpression
())
{
MathMatrixNameExpressionSymbol
mathMatrixNameExpressionSymbol
=
(
MathMatrixNameExpressionSymbol
)
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
();
String
nameOfFirstParameter
=
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getMathMatrixAccessSymbols
().
get
(
0
).
getTextualRepresentation
();
String
nameOfOutput
=
getNameOfOutput
(
mathExpressionSymbol
);
MathExpressionProperties
properties
=
tuples
.
get
(
mathExpressionSymbol
);
if
(
properties
!=
null
)
{
if
(
properties
.
isPreCV
())
{
fixVariableType
(
nameOfFirstParameter
,
bluePrintCPP
,
"CommonMatrixType"
,
"cv::Mat"
,
""
);
}
if
(
properties
.
isSucCV
())
{
fixVariableType
(
nameOfOutput
,
bluePrintCPP
,
"CommonMatrixType"
,
"cv::Mat"
,
""
);
MathMatrixExpressionSymbol
mathMatrixExpressionSymbol
=
(
MathMatrixExpressionSymbol
)
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
();
if
(
mathMatrixExpressionSymbol
.
isMatrixNameExpression
())
{
MathMatrixNameExpressionSymbol
mathMatrixNameExpressionSymbol
=
(
MathMatrixNameExpressionSymbol
)
((
MathAssignmentExpressionSymbol
)
mathExpressionSymbol
).
getExpressionSymbol
();
String
nameOfFirstParameter
=
mathMatrixNameExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getMathMatrixAccessSymbols
().
get
(
0
).
getTextualRepresentation
();
String
nameOfOutput
=
getNameOfOutput
(
mathExpressionSymbol
);
MathExpressionProperties
properties
=
tuples
.
get
(
mathExpressionSymbol
);
if
(
properties
!=
null
)
{
if
(
properties
.
isPreCV
())
{
fixVariableType
(
nameOfFirstParameter
,
bluePrintCPP
,
"CommonMatrixType"
,
"cv::Mat"
,
""
);
}
if
(
properties
.
isSucCV
())
{
fixVariableType
(
nameOfOutput
,
bluePrintCPP
,
"CommonMatrixType"
,
"cv::Mat"
,
""
);
}
}
}
}
...
...
src/test/resources/results/armadillo/testMath/l0/test_math_erodeCommandTest.h
View file @
b2aa4ee6
...
...
@@ -10,30 +10,30 @@ using namespace arma;
using
namespace
std
;
class
test_math_erodeCommandTest
{
public:
arma
::
m
at
src
;
arma
::
M
at
<
unsigned
char
>
src
;
int
erosion_elem
;
int
iterations
;
arma
::
m
at
dst
;
arma
::
M
at
<
unsigned
char
>
dst
;
void
init
()
{
src
=
m
at
(
n
,
m
);
dst
=
m
at
(
n
,
m
);
src
=
M
at
<
unsigned
char
>
(
n
,
m
);
dst
=
M
at
<
unsigned
char
>
(
n
,
m
);
}
void
erodeHelper
(
arma
::
m
at
src
,
arma
::
m
at
dst
,
int
erosion_elem
,
int
iterations
)
void
erodeHelper
(
const
arma
::
M
at
<
unsigned
char
>&
src
,
arma
::
M
at
<
unsigned
char
>&
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
;
if
(
erosion_elem
==
0
){
erosion_type
=
cv
::
MORPH_RECT
;
}
else
if
(
erosion_elem
==
1
){
erosion_type
=
cv
::
MORPH_CROSS
;
}
else
if
(
erosion_elem
==
2
)
{
erosion_type
=
cv
::
MORPH_ELLIPSE
;
}
int
erosion_size
=
erosion_elem
;
cv
::
Mat
element
=
cv
::
getStructuringElement
(
erosion_type
,
Size
(
2
*
erosion_size
+
1
,
2
*
erosion_size
+
1
),
Point
(
-
1
,
-
1
)
);
cv
::
Size
(
2
*
erosion_size
+
1
,
2
*
erosion_size
+
1
),
cv
::
Point
(
-
1
,
-
1
)
);
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
);
srcCV
=
to_cvmat
<
unsigned
char
>
(
src
);
cv
::
erode
(
srcCV
,
dstCV
,
element
,
cv
::
Point
(
-
1
,
-
1
),
iterations
);
dst
=
to_arma
<
unsigned
char
>
(
dstCV
);
}
void
execute
()
{
...
...
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