From 7091fdbb4493eb1a6cc71c5de250048c1cabdf13 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Wed, 17 Sep 2014 23:45:09 +0100 Subject: [PATCH] Changed the line filtering back to safer territory. --- drawing.pde | 129 +++++++++++++++------------------------ polargraphcontroller.pde | 2 +- 2 files changed, 50 insertions(+), 81 deletions(-) diff --git a/drawing.pde b/drawing.pde index 36be186..8a4756b 100644 --- a/drawing.pde +++ b/drawing.pde @@ -674,7 +674,7 @@ void sendVectorShapes(RShape vec, float scaling, PVector position, int pathSorti String command = ""; PVector lastPoint = new PVector(); boolean liftToGetToNewPoint = true; - + // go through and get each path for (int i = 0; i pathLengthHighPassCutoff) { - List> filteredPaths = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength, scaling, position); - for (List filteredPoints : filteredPaths) + List filteredPoints = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength, scaling, position); + if (!filteredPoints.isEmpty()) { - if (!filteredPoints.isEmpty()) + // draw the first one with a pen up and down to get to it + PVector p = filteredPoints.get(0); + if ( p.x == lastPoint.x && p.y == lastPoint.y ) + liftToGetToNewPoint = false; + else + liftToGetToNewPoint = true; + + // pen UP! (IF THE NEW POINT IS DIFFERENT FROM THE LAST ONE!) + if (liftToGetToNewPoint) + addToCommandQueue(CMD_PENUP+"END"); + // move to this point and put the pen down + command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END"; + addToCommandQueue(command); + if (liftToGetToNewPoint) + addToCommandQueue(CMD_PENDOWN+"END"); + + + + // then just iterate through the rest + for (int j=1; j removeShortPaths(List list, int cutoff) return list; } -List> filterPoints(RPoint[] points, int filterToUse, long filterParam, float scaling, PVector position) +List filterPoints(RPoint[] points, int filterToUse, long filterParam, float scaling, PVector position) { return filterPointsLowPass(points, filterParam, scaling, position); } -List> filterPointsLowPass(RPoint[] points, long filterParam, float scaling, PVector position) +List filterPointsLowPass(RPoint[] points, long filterParam, float scaling, PVector position) { - List> result = new ArrayList>(); + List result = new ArrayList(); - // scale and convert all the points first, and filter them by area. - List> areaFiltered = new ArrayList>(); - List scaledPoints = null; + // scale and convert all the points first + List scaled = new ArrayList(points.length); for (int j = 0; j> filterPointsLowPass(RPoint[] points, long filterParam, float p = PVector.mult(p, scaling); p = PVector.add(p, position); p = getDisplayMachine().inSteps(p); - - // Check if the point is on the drawable area if (getDisplayMachine().getPictureFrame().surrounds(p)) { - if (scaledPoints == null) - { - scaledPoints = new ArrayList(points.length); - } p = getDisplayMachine().asNativeCoords(p); - scaledPoints.add(p); - } - else - { // if the point is NOT in the drawable area, then check to see if there is a - // scaledPoints list, and if there is, that means this is the first point in - // the current path that is NOT in the drawable area. That is, the line was on - // the drawable area, but it's just gone off it. - // In this case, append the current list of scaled points into the results list, - // and then nullify scaledPoints so it'll be restarted as a new list if a - // subsequent point ends up coming back on the drawable area. - if (scaledPoints != null && scaledPoints.size() > 0) - { - areaFiltered.add(scaledPoints); - scaledPoints = null; - } + scaled.add(p); } } - - // Now filter by length - if (!areaFiltered.isEmpty()) + if (scaled.size() > 1) { - for (List filteredPoints : areaFiltered) + PVector p = scaled.get(0); + result.add(p); + + for (int j = 1; j lengthFiltered = new ArrayList(); - PVector p = filteredPoints.get(0); - lengthFiltered.add(p); - - for (int j = 1; j filterParam || abs(diffy) > filterParam) { - p = filteredPoints.get(j); - // and even then, only bother drawing if it's a move of over "x" steps - int diffx = int(p.x) - int(lengthFiltered.get(lengthFiltered.size()-1).x); - int diffy = int(p.y) - int(lengthFiltered.get(lengthFiltered.size()-1).y); - - if (abs(diffx) > filterParam || abs(diffy) > filterParam) - { - //println("Adding point " + p + ", last: " + result.get(result.size()-1)); - lengthFiltered.add(p); - } - } - if (lengthFiltered.size() >= 2) - { - result.add(lengthFiltered); + //println("Adding point " + p + ", last: " + result.get(result.size()-1)); + result.add(p); } } } - - println("finished filter."); + + if (result.size() < 2) + result.clear(); + + //println("finished filter."); return result; } diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index cf9d39f..38d426f 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -52,7 +52,7 @@ import java.awt.event.*; int majorVersionNo = 1; int minorVersionNo = 10; -int buildNo = 0; +int buildNo = 2; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; ControlP5 cp5;