Skip to content

Commit

Permalink
Fix various issues with generated C++ (#798)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SamCarlberg authored Jan 30, 2017
1 parent 0bc1087 commit 8d3fa6c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import com.google.common.base.CaseFormat;

import org.apache.commons.lang3.text.WordUtils;

public class CppTMethods extends TemplateMethods {
public CppTMethods() {
super();
Expand All @@ -17,7 +19,7 @@ public String name(String name) {

@Override
public String getterName(String name) {
return "get" + name(name);
return "Get" + WordUtils.capitalize(name(name));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
\#include <String>
#end
#if($implementVisionPipeline)
\#include "VisionPipeline.h"
\#include "vision/VisionPipeline.h"

#end
\#include <opencv2/objdetect/objdetect.hpp>
\#include <opencv2/highgui/highgui.hpp>
\#include <opencv2/imgproc/imgproc.hpp>
\#include <opencv2/contrib/contrib.hpp>
\#include <opencv2/core/core.hpp>
\#include <opencv2/features2d.hpp>
\#include <iostream>
Expand All @@ -35,7 +34,7 @@ namespace grip {
*
* An OpenCV pipeline generated by GRIP.
*/
class $className #if($testing or $implementVisionPipeline):#if($testing) public AbsPipeline #else public VisionPipeline #end#end{
class $className #if($testing or $implementVisionPipeline):#if($testing) public AbsPipeline #else public frc::VisionPipeline #end#end{
private:
#foreach($step in $pipeline.getSteps())
#if($step.name() == "Switch" || $step.name() == "Valve")
Expand Down Expand Up @@ -63,7 +62,7 @@ class $className #if($testing or $implementVisionPipeline):#if($testing) public

public:
$className();
void process(#foreach($source in $pipeline.getSources())#cType($source.type()) $source.value()#if($pipeline.getSources().indexOf($source) lt $pipeline.getSources().size() - 1), #end#end);
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;
#foreach($step in $pipeline.getSteps())
#if($step.name() == "Switch" || $step.name() == "Valve")
#set($boolInp = $step.getInput(0))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
\#include "${className}.h"
/**
* Initializes a ${className}.
*/

namespace grip {

$className::$className() {
#foreach($source in $pipeline.getSources())
## this->$source.value() = new #cType($source.type())();
#end
#foreach($step in $pipeline.getSteps())
#if($step.name() == "Switch" || $step.name() == "Valve")
#set($boolInp = $step.getInput(0))
Expand Down Expand Up @@ -53,32 +47,16 @@ $className::$className() {
#end
}
/**
* Runs an iteration of the Pipeline and updates outputs.
*
* Sources need to be set before calling this method.
*
* Runs an iteration of the pipeline and updates outputs.
*/
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){
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){
#foreach($step in $pipeline.getSteps())
//Step $step.name()$step.num():
#parse("$vmLoc/Step.vm")

#end
}

#foreach($source in $pipeline.getSources())
/**
* This method is a generated setter for $source.value().
* @param source the $source.type() to set
*/
void $className::set${source.value()}(#cType(${source.type()}) #funPassType($source.type())${source.value()}){
#if($source.type().equals("Mat"))
${source.value()}.copyTo(this->${source.value()});
#else
this->$source.value() = ${source.value()};
#end
}
#end
#foreach($step in $pipeline.getSteps())
#if($step.name() == "Switch" || $step.name() == "Valve")
#set($boolInp = $step.getInput(0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This creates the C++ OpenCV Filter Contours function
double solid = 100 * area / cv::contourArea(hull);
if (solid < solidity[0] || solid > solidity[1]) continue;
if (contour.size() < minVertexCount || contour.size() > maxVertexCount) continue;
double ratio = bb.width / bb.height;
double ratio = (double) bb.width / (double) bb.height;
if (ratio < minRatio || ratio > maxRatio) continue;
output.push_back(contour);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
params.maxCircularity = circularity[1];
params.filterByConvexity = false;
params.filterByInertia = false;
cv::Ptr<cv::SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
cv::Ptr<cv::SimpleBlobDetector> detector = cv::SimpleBlobDetector::create(params);
detector->detect(input, blobList);
}

0 comments on commit 8d3fa6c

Please sign in to comment.