Choosable line sorting types.

This commit is contained in:
Sandy Noble 2013-04-20 00:41:27 +01:00
parent 782f6000bb
commit 0bff66fcd5
3 changed files with 33 additions and 27 deletions

View File

@ -152,7 +152,7 @@ void button_mode_liveConfirmDraw()
PVector position = new PVector(getDisplayMachine().inMM(getDisplayMachine().getPictureFrame().getPosition().x),
getDisplayMachine().inMM(getDisplayMachine().getPictureFrame().getPosition().y));
sendVectorShapes(captureShape, scaling, position);
sendVectorShapes(captureShape, scaling, position, PATH_SORT_CENTRE_FIRST);
button_mode_penUp();
// save shape as SVG

View File

@ -71,6 +71,11 @@ static final String CMD_DRAW_NORWEGIAN = "C43,";
static final String CMD_DRAW_NORWEGIAN_OUTLINE = "C44,";
static final String CMD_SETPENLIFTRANGE = "C45,";
static final int PATH_SORT_NONE = 0;
static final int PATH_SORT_MOST_POINTS_FIRST = 1;
static final int PATH_SORT_GREATEST_AREA_FIRST = 2;
static final int PATH_SORT_CENTRE_FIRST = 3;
private PVector mouseVector = new PVector(0, 0);
Comparator xAscending = new Comparator()
@ -646,18 +651,21 @@ void sendOutlineOfBox()
void sendVectorShapes()
{
sendVectorShapes(getVectorShape(), vectorScaling/100, getVectorPosition());
sendVectorShapes(getVectorShape(), vectorScaling/100, getVectorPosition(), PATH_SORT_NONE);
}
void sendVectorShapes(RShape vec, float scaling, PVector position)
void sendVectorShapes(RShape vec, float scaling, PVector position, int pathSortingAlgorithm)
{
println("Send vector shapes.");
RPoint[][] pointPaths = vec.getPointsInPaths();
// sort the paths to optimise the draw sequence
// pointPaths = sortPathsLongestFirst(pointPaths, pathLengthHighPassCutoff);
// pointPaths = sortPathsGreatestAreaFirst(vec, pathLengthHighPassCutoff);
pointPaths = sortPathsCentreFirst(vec, pathLengthHighPassCutoff);
switch (pathSortingAlgorithm) {
case PATH_SORT_MOST_POINTS_FIRST: pointPaths = sortPathsLongestFirst(pointPaths, pathLengthHighPassCutoff); break;
case PATH_SORT_GREATEST_AREA_FIRST: pointPaths = sortPathsGreatestAreaFirst(vec, pathLengthHighPassCutoff); break;
case PATH_SORT_CENTRE_FIRST: pointPaths = sortPathsCentreFirst(vec, pathLengthHighPassCutoff); break;
}
String command = "";
PVector lastPoint = new PVector();
@ -708,7 +716,7 @@ void sendVectorShapes(RShape vec, float scaling, PVector position)
println("finished.");
}
public RPoint[][] sortPathLongestFirst(RPoint[][] pointPaths, int highPassCutoff)
public RPoint[][] sortPathsLongestFirst(RPoint[][] pointPaths, int highPassCutoff)
{
// put the paths into a list
List<RPoint[]> pathsList = new ArrayList<RPoint[]>(pointPaths.length);

View File

@ -1,22 +1,3 @@
import processing.video.*;
import diewald_CV_kit.libraryinfo.*;
import diewald_CV_kit.utility.*;
import diewald_CV_kit.blobdetection.*;
import geomerative.*;
import org.apache.batik.svggen.font.table.*;
import org.apache.batik.svggen.font.*;
import java.util.zip.CRC32;
// for OSX
import java.text.*;
import java.util.*;
import java.io.*;
import java.util.logging.*;
//import java.util.concurrent.CopyOnWriteArrayList;
//import processing.opengl.PGraphicsOpenGL;
/**
Polargraph controller
Copyright Sandy Noble 2012.
@ -46,13 +27,30 @@ import java.util.logging.*;
http://code.google.com/p/polargraph/
*/
import processing.video.*;
import diewald_CV_kit.libraryinfo.*;
import diewald_CV_kit.utility.*;
import diewald_CV_kit.blobdetection.*;
import geomerative.*;
import org.apache.batik.svggen.font.table.*;
import org.apache.batik.svggen.font.*;
import java.util.zip.CRC32;
// for OSX
import java.text.*;
import java.util.*;
import java.io.*;
import java.util.logging.*;
import javax.swing.*;
import processing.serial.*;
import controlP5.*;
import java.awt.event.*;
int majorVersionNo = 1;
int minorVersionNo = 3;
int minorVersionNo = 4;
int buildNo = 0;
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;