Skip to content

Commit 8d3fa6c

Browse files
authored
Fix various issues with generated C++ (#798)
* Fix various issues with generated C++ Closes #797 * frc namespace, add override keyword * Capital 'P' in 'Process' * Fix integer division in filterContours Closes #810 * Remove include for contrib module * Clean up generated doc comments * Capitalize C++ getter methods All public C++ functions should be PascalCase now
1 parent 0bc1087 commit 8d3fa6c

File tree

5 files changed

+10
-31
lines changed

5 files changed

+10
-31
lines changed

ui/src/main/java/edu/wpi/grip/ui/codegeneration/CppTMethods.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import com.google.common.base.CaseFormat;
77

8+
import org.apache.commons.lang3.text.WordUtils;
9+
810
public class CppTMethods extends TemplateMethods {
911
public CppTMethods() {
1012
super();
@@ -17,7 +19,7 @@ public String name(String name) {
1719

1820
@Override
1921
public String getterName(String name) {
20-
return "get" + name(name);
22+
return "Get" + WordUtils.capitalize(name(name));
2123
}
2224

2325
@Override

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
\#include <String>
66
#end
77
#if($implementVisionPipeline)
8-
\#include "VisionPipeline.h"
8+
\#include "vision/VisionPipeline.h"
99

1010
#end
1111
\#include <opencv2/objdetect/objdetect.hpp>
1212
\#include <opencv2/highgui/highgui.hpp>
1313
\#include <opencv2/imgproc/imgproc.hpp>
14-
\#include <opencv2/contrib/contrib.hpp>
1514
\#include <opencv2/core/core.hpp>
1615
\#include <opencv2/features2d.hpp>
1716
\#include <iostream>
@@ -35,7 +34,7 @@ namespace grip {
3534
*
3635
* An OpenCV pipeline generated by GRIP.
3736
*/
38-
class $className #if($testing or $implementVisionPipeline):#if($testing) public AbsPipeline #else public VisionPipeline #end#end{
37+
class $className #if($testing or $implementVisionPipeline):#if($testing) public AbsPipeline #else public frc::VisionPipeline #end#end{
3938
private:
4039
#foreach($step in $pipeline.getSteps())
4140
#if($step.name() == "Switch" || $step.name() == "Valve")
@@ -63,7 +62,7 @@ class $className #if($testing or $implementVisionPipeline):#if($testing) public
6362

6463
public:
6564
$className();
66-
void process(#foreach($source in $pipeline.getSources())#cType($source.type()) $source.value()#if($pipeline.getSources().indexOf($source) lt $pipeline.getSources().size() - 1), #end#end);
65+
void Process(#foreach($source in $pipeline.getSources())#cType($source.type())& $source.value()#if($pipeline.getSources().indexOf($source) lt $pipeline.getSources().size() - 1), #end#end)#if($implementVisionPipeline) override#end;
6766
#foreach($step in $pipeline.getSteps())
6867
#if($step.name() == "Switch" || $step.name() == "Valve")
6968
#set($boolInp = $step.getInput(0))

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

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
\#include "${className}.h"
2-
/**
3-
* Initializes a ${className}.
4-
*/
52

63
namespace grip {
74

85
$className::$className() {
9-
#foreach($source in $pipeline.getSources())
10-
## this->$source.value() = new #cType($source.type())();
11-
#end
126
#foreach($step in $pipeline.getSteps())
137
#if($step.name() == "Switch" || $step.name() == "Valve")
148
#set($boolInp = $step.getInput(0))
@@ -53,32 +47,16 @@ $className::$className() {
5347
#end
5448
}
5549
/**
56-
* Runs an iteration of the Pipeline and updates outputs.
57-
*
58-
* Sources need to be set before calling this method.
59-
*
50+
* Runs an iteration of the pipeline and updates outputs.
6051
*/
61-
void $className::process(#foreach($source in $pipeline.getSources())#cType($source.type()) $source.value()#if($pipeline.getSources().indexOf($source) lt $pipeline.getSources().size() - 1), #end#end){
52+
void $className::Process(#foreach($source in $pipeline.getSources())#cType($source.type())& $source.value()#if($pipeline.getSources().indexOf($source) lt $pipeline.getSources().size() - 1), #end#end){
6253
#foreach($step in $pipeline.getSteps())
6354
//Step $step.name()$step.num():
6455
#parse("$vmLoc/Step.vm")
6556

6657
#end
6758
}
6859

69-
#foreach($source in $pipeline.getSources())
70-
/**
71-
* This method is a generated setter for $source.value().
72-
* @param source the $source.type() to set
73-
*/
74-
void $className::set${source.value()}(#cType(${source.type()}) #funPassType($source.type())${source.value()}){
75-
#if($source.type().equals("Mat"))
76-
${source.value()}.copyTo(this->${source.value()});
77-
#else
78-
this->$source.value() = ${source.value()};
79-
#end
80-
}
81-
#end
8260
#foreach($step in $pipeline.getSteps())
8361
#if($step.name() == "Switch" || $step.name() == "Valve")
8462
#set($boolInp = $step.getInput(0))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This creates the C++ OpenCV Filter Contours function
3131
double solid = 100 * area / cv::contourArea(hull);
3232
if (solid < solidity[0] || solid > solidity[1]) continue;
3333
if (contour.size() < minVertexCount || contour.size() > maxVertexCount) continue;
34-
double ratio = bb.width / bb.height;
34+
double ratio = (double) bb.width / (double) bb.height;
3535
if (ratio < minRatio || ratio > maxRatio) continue;
3636
output.push_back(contour);
3737
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
params.maxCircularity = circularity[1];
2424
params.filterByConvexity = false;
2525
params.filterByInertia = false;
26-
cv::Ptr<cv::SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
26+
cv::Ptr<cv::SimpleBlobDetector> detector = cv::SimpleBlobDetector::create(params);
2727
detector->detect(input, blobList);
2828
}

0 commit comments

Comments
 (0)