Skip to content

Comments

Code Generation#597

Merged
SamCarlberg merged 289 commits intoWPIRoboticsProjects:masterfrom
osulacam:DataModel
Oct 3, 2016
Merged

Code Generation#597
SamCarlberg merged 289 commits intoWPIRoboticsProjects:masterfrom
osulacam:DataModel

Conversation

@PatrickPenguinTurtle
Copy link
Contributor

@PatrickPenguinTurtle PatrickPenguinTurtle commented Jun 2, 2016

@osulacam and myself are working on an extension to GRIP that generates code. Eventually it will generate code for the users choice of Java, C++ and Python. For now it only generates Java code.

The idea behind this is so that users do not have to run a jvm containing GRIP to get pipelines to run. Instead they would include this file in their code and call the processImage function to run the pipeline once.

As mentioned this is in progress and at this time is not finished enough to be merged into GRIP.

Things to do:

@codecov-io
Copy link

codecov-io commented Jun 2, 2016

Current coverage is 55.09% (diff: 0.00%)

Merging #597 into master will decrease coverage by 3.37%

@@             master       #597   diff @@
==========================================
  Files           198        209    +11   
  Lines          6282       6663   +381   
  Methods           0          0          
  Messages          0          0          
  Branches        569        646    +77   
==========================================
- Hits           3673       3671     -2   
- Misses         2442       2824   +382   
- Partials        167        168     +1   

Sunburst

Powered by Codecov. Last update 1c1a5f6...3b46891

@SamCarlberg
Copy link
Member

SamCarlberg commented Jun 2, 2016

I would put the Velocity templates into language-specific directories (e.g. /generation/templates/c++, /generation/templates/java, /generation/templates/python, etc.) and outside of the jar file to make it easy to add new languages or adjust/add to the stock templates that we bundle.

What's with all the T-prefixed classes? What does T stand for?

What's with the weird function names? (e.g. Find_Blobs -- follow the language conventions!)

MutableOf seems like a C-style way to return objects. If you're generating Java code, it should follow Java conventions. Use references for generated C/C++/C# code, not for Java.

Why did you remove two UI tests from version control?

And please, please, add some documentation.

I'll add more comments after I checkout this PR and play around with it.

@@ -0,0 +1,8 @@
public static void Switch(boolean sw, Object onTrue,Object onFalse, Object output){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method won't actually do anything. You're just reassigning a local reference.

Why not something like

public static <T> T Switch(boolean sw, T onTrue, T onFalse) {
    return sw ? onTrue : onFalse;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't write this one and we also know that Switch currently doesn't work.

@PatrickPenguinTurtle
Copy link
Contributor Author

@SamCarlberg The reason behind MutableOf is it follows OpenCV's own convention. Further otherwise we would need to create several objects that did not exist before and fight with the TPipeline trying to make it recognize a new object.

*
* <P>Make sure to set all sources using the setters before running processImage().
*
* <P>Tutorials and examples can be found online
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where online?

@AustinShalit AustinShalit modified the milestones: v1.5.0, 1.6.0 Aug 27, 2016
@SamCarlberg
Copy link
Member

SamCarlberg commented Aug 29, 2016

Edit: this has all been addressed in 11f967c


Breaks when using publishing operations. Publishing operations should be ignored from generation and the user should be alerted.

Edit: just saw you addressed this in the meeting.

Also, the generated method names could be a lot nicer.

  • setsourceX(...) should be setSourceX(...) in Java and C++ (python's okay)
  • Inconsistent naming scheme between languages (findBlobsOutput0() is a Java getter, getFind_Blobs0Output0() for C++, and python is find_blobs0output0).
    • Seems like Java's working right and C++ and Python didn't get updated
  • Operations with only one output have redundant '0's at the end of getter methods

Getters for the outputs should be styled like get[op_name][op_number]Output[out_number], where op_number and out_number are optional if there's only one operation with that name or only one output for that operation, respectively.

Language Operation Instances of that operation Number of outputs Example of a generated getter
Java Find blobs 1 1 getFindBlobsOutput
C++ getFindBlobsOutput
Python find_blobs_output
Java Split 2 3 getSplit0Output2
C++ getSplit1Output0
Python split_1_output_1

If an operation has multiple outputs (eg Split could have Red plane, Green plane, and Blue plane), it would be good to name the pipeline outputs with those names (eg getSplitRedPlane, split_red_plane)

@SamCarlberg
Copy link
Member

Generated code that uses Switch will fail if the inputs are not both Mats , or have different types (Java and C++). I don't think that's very likely to happen though, but I do think it would be worthwhile to inline the switch and valve operations

SamCarlberg and others added 3 commits September 8, 2016 16:39
Variables and methods no longer have numbers if there's only one of that operation, or if an operation only has one output.
Operations with multiple outputs have the outputs named the same as on the socket (instead of just 'output0', 'output1', ...)
Rename `MutableOf` to `Ref` because it's really just holding a reference and it's used similarly to output parameters in C/C++
Don't try to generate code for network operations and improve generated variable and method names
@SamCarlberg
Copy link
Member

OpenCV artifacts are available here

Artifacts for an installer are also in that repository. The project is here

osulacam and others added 4 commits September 14, 2016 12:53
Add alert when trying to generate code for a pipeline with non-exportable operations
Fix code gen directory name not matching package name
}

@Override
public String getterName(String name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "get" + WordUtils.capitalize(name(name)), otherwise you'll get stuff like "getblobsOutput" instead of "getBlobsOutput"

}

@Override
public String setterName(String name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "set" + WordUtils.capitalize(name(name)) (see comment for getterName)

}

@Override
public String getterName(String name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on CppTMethods

}

@Override
public String setterName(String name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on CppTMethods

}

@Override
public String getterName(String name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on CppTMethods

}

@Override
public String setterName(String name) {
Copy link
Member

@SamCarlberg SamCarlberg Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on CppTMethods. Will this cause a naming conflict?

@Override
public Object getOutput(String name, GenType type) {
String newName = name.toLowerCase().replaceAll("_", "");
String newName = tMeth.getterName(name);
Copy link
Member

@SamCarlberg SamCarlberg Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it would make more sense to pass in the actual name instead of having to use the intermediate format that would then get transformed.

Calling

getOutput("convexHullsOutput", ...)

makes much more sense to me than

getOutput("Convex_Hulls_Output", ...)

@JLLeitschuh
Copy link
Member

JLLeitschuh commented Oct 3, 2016

@SamCarlberg SamCarlberg merged commit 273959e into WPIRoboticsProjects:master Oct 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants