Skip to content

generated java code for filterLines() is incorrect #920

@mfkahn

Description

@mfkahn

Version: latest GRIP Mac OSX Binary 1.5.2

When using Filter Lines, generated GripPipeline.java is incorrect:

@Override public void process(Mat source0) {
      ...
      filterLines(filterLinesLines, filterLinesMinLength, filterLinesAngle, filterLinesOutput);
}

...

	private void filterLines(List<Line> inputs,double minLength,double[] angle,
		List<Line> outputs) {
		outputs = inputs.stream()
				.filter(line -> line.lengthSquared() >= Math.pow(minLength,2))
				.filter(line -> (line.angle() >= angle[0] && line.angle() <= angle[1])
				|| (line.angle() + 180.0 >= angle[0] && line.angle() + 180.0 <= angle[1]))
				.collect(Collectors.toList());
	}

outputs is passed by reference from process(), simply reassigning outputs to a different List has no effect on the instance property filterLinesOutput, which is what needs to be filled with the detected lines. The impact is line count in the GUI will seem to work, but the generated code will always have ZERO lines returned by filterLinesOutput(), and students will not know why their vision pipeline works in GRIP but not in their bot.

Potential corrections:

    private void filterLines(List<Line> inputs,double minLength,double[] angle,
		List<Line> outputs) {
                outputs.clear();
		outputs.addAll(inputs.stream()
				.filter(line -> line.lengthSquared() >= Math.pow(minLength,2))
				.filter(line -> (line.angle() >= angle[0] && line.angle() <= angle[1])
				|| (line.angle() + 180.0 >= angle[0] && line.angle() + 180.0 <= angle[1]))
				.collect(Collectors.toList()));
    }

or

@Override public void process(Mat source0) {
      ...
      filterLines(filterLinesLines, filterLinesMinLength, filterLinesAngle); // remove last arg
}
   
    private void filterLines(List<Line> inputs,double minLength,double[] angle) {
                
		filterLinesOutput = inputs.stream()
				.filter(line -> line.lengthSquared() >= Math.pow(minLength,2))
				.filter(line -> (line.angle() >= angle[0] && line.angle() <= angle[1])
				|| (line.angle() + 180.0 >= angle[0] && line.angle() + 180.0 <= angle[1]))
				.collect(Collectors.toList());
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions