Skip to content

Commit 76be2bb

Browse files
phurleySamCarlberg
authored andcommitted
Remove using namespace from generated header, fix the fall out (#734)
* Remove using namespace from generated header, fix the fall out * Move all pipeline code into grip namespace * Include testing code in grip namespace during C++ code generation
1 parent bce378f commit 76be2bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+179
-152
lines changed

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/Pipeline.h.vm

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
\#include <opencv2/objdetect/objdetect.hpp>
88
\#include <opencv2/highgui/highgui.hpp>
99
\#include <opencv2/imgproc/imgproc.hpp>
10+
\#include <opencv2/contrib/contrib.hpp>
1011
\#include <opencv2/core/core.hpp>
1112
\#include <opencv2/features2d.hpp>
1213
\#include <iostream>
1314
\#include <stdio.h>
1415
\#include <stdlib.h>
1516
\#include <map>
1617
\#include <math.h>
17-
using namespace cv;
18-
using namespace std;
18+
19+
namespace grip {
1920

2021
#foreach($step in $pipeline.getUniqueSteps())
2122
#if($step.name().equals("Find_Lines") || $step.name().equals("Filter_Lines"))
@@ -50,7 +51,7 @@ class $fileName #if($testing): public AbsPipeline #end{
5051
#end
5152
#end
5253
#foreach($moving in $pipeline.getMovingThresholds())
53-
Mat lastImage$moving.num();
54+
cv::Mat lastImage$moving.num();
5455
#end
5556
#foreach($step in $pipeline.getUniqueSteps())
5657
#if($step.name() == "Switch" || $step.name() == "Valve")
@@ -77,7 +78,11 @@ class $fileName #if($testing): public AbsPipeline #end{
7778
#foreach($step in $pipeline.getSteps())
7879
#foreach($out in $step.getOutputs())
7980
#set($outSym = "#funPassType($output.type())")
80-
#if($outSym.equals("&") || $testing)
81+
#if($out.type().equals("Boolean"))
82+
#set($ptr = false)
83+
#elseif($out.type().equals("Number"))
84+
#set($ptr = false)
85+
#elseif($outSym.equals("&") || $testing)
8186
#set($ptr = true)
8287
#else
8388
#set($ptr = false)
@@ -86,6 +91,10 @@ class $fileName #if($testing): public AbsPipeline #end{
8691
#end
8792
#end
8893
};
94+
8995
#if($testing)
9096
extern "C" DLL_TYPE AbsPipeline * makePipeline();
9197
#end
98+
99+
} // end namespace grip
100+

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/Pipeline.vm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/**
33
* Initializes a ${fileName}.
44
*/
5+
6+
namespace grip {
7+
58
$fileName::$fileName() {
69
#foreach($source in $pipeline.getSources())
710
## this->$source.value() = new #cType($source.type())();
@@ -114,8 +117,11 @@ void $fileName::set$step.name()${step.num()}(bool value){
114117
#parse($toParse)
115118

116119
#end
120+
117121
#if($testing)
118122
extern "C" AbsPipeline * makePipeline(){
119123
return new ${fileName}();
120124
}
121125
#end
126+
127+
} // end grip namespace

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/macros.vm

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ int#elseif($type.equalsIgnoreCase("BlurType"))
1212
BlurType#elseif($type.contains("Type"))
1313
int#elseif($type.equalsIgnoreCase("MaskSize"))
1414
string#elseif($type.equalsIgnoreCase("Interpolation"))
15-
int#else
16-
$type#end#end
15+
int#elseif($type.equalsIgnoreCase("FlipCode"))
16+
FlipCode#elseif($type.equalsIgnoreCase("List"))
17+
List#else
18+
cv::$type#end#end
1719

1820
#macro(funPassType $baseType)
1921
#set($type = "#cType($baseType)")
@@ -36,7 +38,7 @@ $type #funPassType($inp.type())$name#end#end
3638
#if($name.toLowerCase().contains("switch"))
3739
pipeline$name(bool sw, T &onTrue, T &onFalse, T &output)#elseif($name.toLowerCase().contains("valve"))
3840
pipeline$name(bool sw, T &input, T &output)#else
39-
$name(#foreach($inp in $step.getInputs())#param($inp $names[$count])#set($count = $count + 1), #end#if($name.equalsIgnoreCase("ThresholdMoving"))Mat &lastImage, #end#foreach($out in $step.getOutputs())#cType($out.type()) &$names[$count]#set($count = $count + 1)#if($velocityCount <$step.getOutputs().size()), #end#end)#end#end
41+
$name(#foreach($inp in $step.getInputs())#param($inp $names[$count])#set($count = $count + 1), #end#if($name.equalsIgnoreCase("ThresholdMoving"))cv::Mat &lastImage, #end#foreach($out in $step.getOutputs())#cType($out.type()) &$names[$count]#set($count = $count + 1)#if($velocityCount <$step.getOutputs().size()), #end#end)#end#end
4042

4143
#macro(headerFunc $step)
4244
#set($numVars = $step.getInputs().size() + $step.getOutputs().size())
@@ -50,10 +52,20 @@ $name(#foreach($inp in $step.getInputs())#param($inp $names[$count])#set($count
5052
#macro (newInput $input)
5153
#if ($input.value().toLowerCase().contains("source") || $input.value().toLowerCase().contains("output"))
5254
#cType($input.type()) ${tMeth.name($input.name())} = $tMeth.name($input.value());
55+
#elseif ($input.type().contains("BorderTypesEnumCoreEnum"))
56+
int ${tMeth.name($input.name())} = cv::$input.value();
5357
#elseif ($input.type().contains("CoreEnum"))
5458
int ${tMeth.name($input.name())} = $input.value();
59+
#elseif ($input.type().equals("ColorConversionCodesEnum"))
60+
int ${tMeth.name($input.name())} = cv::$input.value();
61+
#elseif ($input.type().equals("ColormapTypesEnum"))
62+
int ${tMeth.name($input.name())} = cv::$input.value();
63+
#elseif ($input.type().equals("InterpolationFlagsEnum"))
64+
int ${tMeth.name($input.name())} = cv::$input.value();
65+
#elseif ($input.type().equals("CVThresholdTypesEnum"))
66+
int ${tMeth.name($input.name())} = cv::$input.value();
5567
#elseif ($input.type().contains("Enum"))
56-
int ${tMeth.name($input.name())} = $input.value();
68+
int ${tMeth.name($input.name())} = $input.value(); // ENUM $input.type()
5769
#elseif ($input.type().equals("MaskSize") )
5870
string ${tMeth.name($input.name())} = "$input.value()";
5971
#elseif ($input.type().equals("FlipCode") || $input.type().equals("BlurType") )
@@ -72,19 +84,19 @@ $name(#foreach($inp in $step.getInputs())#param($inp $names[$count])#set($count
7284
#elseif ($input.type().equals("Mat"))
7385
#cType($input.type()) ${tMeth.name($input.name())}$input.value();
7486
#else
75-
#cType($input.type()) ${tMeth.name($input.name())} = $input.value();
87+
#cType($input.type()) ${tMeth.name($input.name())} = $input.value(); // default $input.type()
7688
#end#end
7789

7890
#macro (cvVal $value)#if($value.equals("INF"))
79-
NORM_INF#elseif($value.equals("L1"))
80-
NORM_L1#elseif($value.equals("L2"))
81-
NORM_L2#elseif($value.equals("MINMAX"))
82-
NORM_MINMAX#elseif($value.equals("None"))
83-
INTER_NEAREST#elseif($value.equals("Linear"))
84-
INTER_LINEAR#elseif($value.equals("Cubic"))
85-
INTER_CUBIC#elseif($value.equals("Lanczos"))
86-
INTER_LANCZOS4#elseif($value.equals("Area"))
87-
INTER_AREA#elseif($value.equals("Box Blur"))
91+
cv::NORM_INF#elseif($value.equals("L1"))
92+
cv::NORM_L1#elseif($value.equals("L2"))
93+
cv::NORM_L2#elseif($value.equals("MINMAX"))
94+
cv::NORM_MINMAX#elseif($value.equals("None"))
95+
cv::INTER_NEAREST#elseif($value.equals("Linear"))
96+
cv::INTER_LINEAR#elseif($value.equals("Cubic"))
97+
cv::INTER_CUBIC#elseif($value.equals("Lanczos"))
98+
cv::INTER_LANCZOS4#elseif($value.equals("Area"))
99+
cv::INTER_AREA#elseif($value.equals("Box Blur"))
88100
BOX#elseif($value.equals("Gaussian Blur"))
89101
GAUSSIAN#elseif($value.equals("Median Filter"))
90102
MEDIAN#elseif($value.equals("Bilateral Filter"))

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/Blur.vm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
switch(type) {
1313
case BOX:
1414
kernelSize = 2 * radius + 1;
15-
blur(input,output,Size(kernelSize, kernelSize));
15+
cv::blur(input,output,cv::Size(kernelSize, kernelSize));
1616
break;
1717
case GAUSSIAN:
1818
kernelSize = 6 * radius + 1;
19-
GaussianBlur(input, output, Size(kernelSize, kernelSize), radius);
19+
cv::GaussianBlur(input, output, cv::Size(kernelSize, kernelSize), radius);
2020
break;
2121
case MEDIAN:
2222
kernelSize = 2 * radius + 1;
23-
medianBlur(input, output, kernelSize);
23+
cv::medianBlur(input, output, kernelSize);
2424
break;
2525
case BILATERAL:
26-
bilateralFilter(input, output, -1, radius, radius);
26+
cv::bilateralFilter(input, output, -1, radius, radius);
2727
break;
2828
}
2929
}

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/CV_Canny.vm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
* @param edges output of the canny.
99
*/
1010
void $fileName::#func($step ["image", "thres1", "thres2", "apertureSize", "gradient", "edges"]) {
11-
Canny(image, edges, thres1, thres2, (int)apertureSize, gradient);
12-
}
11+
cv::Canny(image, edges, thres1, thres2, (int)apertureSize, gradient);
12+
}

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/CV_GaussianBlur.vm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
* @param dst the output image.
99
*/
1010
void $fileName::#func($step ["src", "kSize", "sigmaX", "sigmaY", "borderType", "dst"]) {
11-
GaussianBlur(src, dst, kSize, sigmaX, sigmaY, borderType);
12-
}
11+
cv::GaussianBlur(src, dst, kSize, sigmaX, sigmaY, borderType);
12+
}

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/CV_Laplacian.vm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
* @param dst Ouput of Laplacian.
99
*/
1010
void $fileName::#func($step ["src", "size", "scale", "delta", "borderType", "dst"]) {
11-
Laplacian(src, dst, 0, (int)size, scale, delta, borderType);
12-
}
11+
cv::Laplacian(src, dst, 0, (int)size, scale, delta, borderType);
12+
}

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/CV_Sobel.vm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
* @param dst Image that is output of Sobel.
1111
*/
1212
void $fileName::#func($step ["src", "dx", "dy", "kSize", "scale", "delta", "borderType", "dst"]) {
13-
Sobel(src, dst, 0, (int)dx, (int)dy, (int)kSize, scale, delta, borderType);
14-
}
13+
cv::Sobel(src, dst, 0, (int)dx, (int)dy, (int)kSize, scale, delta, borderType);
14+
}

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/CV_Threshold.vm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
* @param dst output Image.
88
*/
99
void $fileName::#func($step ["src", "thresh", "maxVal", "type", "dst"]) {
10-
threshold(src, dst, thresh, maxVal, type);
11-
}
10+
cv::threshold(src, dst, thresh, maxVal, type);
11+
}

ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/CV_absdiff.vm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
* @param out the Mat that is the absolute difference between the two Mats.
66
*/
77
void $fileName::#func($step, ["src1", "src2", "out"]) {
8-
absdiff(src1, src2, out);
9-
}
8+
cv::absdiff(src1, src2, out);
9+
}

0 commit comments

Comments
 (0)