Made polygonizer changeable, and polygonizerLength too. Also fixed the machine origin while zooming, yep - they said it couldn't be done. I done it.

This commit is contained in:
Sandy Noble 2016-03-28 15:37:20 +01:00
parent 71713b5246
commit d584624791
5 changed files with 161 additions and 35 deletions

View File

@ -316,6 +316,10 @@ class DisplayMachine extends Machine
{
drawExtractedPixelCentres();
}
if (displayingGridSpots)
{
drawGridIntersections();
}
if (displayingDensityPreview)
{
drawExtractedPixelDensities();
@ -532,10 +536,13 @@ class DisplayMachine extends Machine
beginShape();
inShape = true;
}
// PVector nativeCoords = asNativeCoords(inSteps(p));
// println(j + "! Adding point " + nativeCoords);
p = scaleToScreen(p);
stroke(strokeColour);
vertex(p.x, p.y);
// ellipse(p.x, p.y, 3, 3);
// ellipse(p.x, p.y, 2, 2);
}
else
{
@ -660,10 +667,18 @@ class DisplayMachine extends Machine
*/
public void drawRows()
{
PVector mVect = getMouseVector();
float rowThickness = inMM(getGridSize()) * getScaling();
rowThickness = (rowThickness < 1.0) ? 1.0 : rowThickness;
strokeWeight(rowThickness);
stroke(150, 200, 255, 50);
strokeCap(SQUARE);
drawRow(getMouseVector(), true, true);
noStroke();
}
public void drawRow(PVector mouse, boolean left, boolean right) {
// scale it to find out the coordinates on the machine that the mouse is pointing at.
mVect = scaleToDisplayMachine(mVect);
PVector mVect = scaleToDisplayMachine(mouse);
// convert it to the native coordinates system
mVect = convertToNative(mVect);
// snap it to the grid
@ -674,17 +689,15 @@ class DisplayMachine extends Machine
// and finally, because scaleToScreen also allows for the machine position (offset), subtract it.
mVect.sub(getOffset());
float rowThickness = inMM(getGridSize()) * getScaling();
rowThickness = (rowThickness < 1.0) ? 1.0 : rowThickness;
strokeWeight(rowThickness);
stroke(150, 200, 255, 50);
strokeCap(SQUARE);
float dia = mVect.x*2;
arc(getOutline().getLeft(), getOutline().getTop(), dia, dia, 0, 1.57079633);
if (left) {
arc(getOutline().getLeft(), getOutline().getTop(), dia, dia, 0, 1.57079633);
}
dia = mVect.y*2;
arc(getOutline().getRight(), getOutline().getTop(), dia, dia, 1.57079633, 3.14159266);
if (right) {
arc(getOutline().getRight(), getOutline().getTop(), dia, dia, 1.57079633, 3.14159266);
}
}
@ -701,7 +714,11 @@ class DisplayMachine extends Machine
line(scaledPos.x-1, scaledPos.y+1, scaledPos.x+1, scaledPos.y-1);
}
}
void drawGridIntersections()
{
// println("oh");
}
int pixel_maxDensity(float penSize, float rowSizeInMM)
{

View File

@ -163,12 +163,17 @@ void button_mode_liveConfirmDraw()
float scaling = getDisplayMachine().inMM(getDisplayMachine().getImageFrame().getWidth()) / captureShape.getWidth();
PVector position = new PVector(getDisplayMachine().inMM(getDisplayMachine().getImageFrame().getPosition().x),
getDisplayMachine().inMM(getDisplayMachine().getImageFrame().getPosition().y));
int oldPolygonizer = polygonizer;
polygonizer = RG.ADAPTATIVE;
setupPolygonizer();
sendVectorShapes(captureShape, scaling, position, PATH_SORT_CENTRE_FIRST);
button_mode_penUp();
// save shape as SVG
trace_saveShape(captureShape);
polygonizer = oldPolygonizer;
setupPolygonizer();
}
}
void toggle_mode_showWebcamRawVideo(boolean flag)
@ -750,4 +755,25 @@ void minitoggle_mode_previewPixelDensityRange(boolean flag) {
println("previewPixelDensityRange: " + previewPixelDensityRange);
}
void numberbox_mode_changePolygonizerLength(float value) {
polygonizerLength = value;
setupPolygonizer();
}
void button_mode_cyclePolygonizer()
{
// this is a bit silly for only two choices
if (polygonizer == 1) {
polygonizer = 0;
}
else {
polygonizer++;
}
setupPolygonizer();
Controller c = cp5.getController(MODE_CHANGE_POLYGONIZER);
c.setLabel(this.controlLabels.get(MODE_CHANGE_POLYGONIZER) + ": " + polygonizer);
}

View File

@ -285,11 +285,34 @@ Map<String, Controller> buildAllControls()
}
}
initialiseButtonValues(map);
initialiseToggleValues(map);
initialiseNumberboxValues(map);
return map;
}
Map<String, Controller> initialiseButtonValues(Map<String, Controller> map)
{
for (String key : map.keySet())
{
if (key.startsWith("button_"))
{
Button n = (Button) map.get(key);
if (MODE_CYCLE_DENSITY_PREVIEW_STYLE.equals(key)) {
n.setValue(densityPreviewStyle);
n.setLabel(this.controlLabels.get(MODE_CYCLE_DENSITY_PREVIEW_STYLE) + ": " + densityPreviewStyle);
}
else if (MODE_CHANGE_POLYGONIZER.equals(key)) {
n.setValue(polygonizer);
n.setLabel(this.controlLabels.get(MODE_CHANGE_POLYGONIZER) + ": " + polygonizer);
}
}
}
return map;
}
Map<String, Controller> initialiseNumberboxValues(Map<String, Controller> map)
{
for (String key : map.keySet())
@ -517,10 +540,6 @@ Map<String, Controller> initialiseNumberboxValues(Map<String, Controller> map)
n.setValue(0);
n.setMultiplier(0.5);
}
else if (MODE_CYCLE_DENSITY_PREVIEW_STYLE.equals(key))
{
n.setValue(densityPreviewStyle);
}
else if (MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE.equals(key))
{
n.setValue(densityPreviewPosterize);
@ -529,6 +548,13 @@ Map<String, Controller> initialiseNumberboxValues(Map<String, Controller> map)
n.setDecimalPrecision(1);
n.setMultiplier(0.1);
}
else if (MODE_CHANGE_POLYGONIZER_LENGTH.equals(key)) {
n.setValue(polygonizerLength);
n.setMin(1.0);
n.setDecimalPrecision(1);
n.setMultiplier(0.1);
}
}
}
return map;
@ -723,6 +749,8 @@ List<String> getControlNamesForInputPanel()
controlNames.add(MODE_RENDER_VECTORS);
controlNames.add(MODE_ADJUST_PREVIEW_CORD_OFFSET);
controlNames.add(MODE_CHANGE_POLYGONIZER);
controlNames.add(MODE_CHANGE_POLYGONIZER_LENGTH);
controlNames.add(MODE_SHOW_IMAGE);
controlNames.add(MODE_SHOW_VECTOR);
@ -1002,6 +1030,9 @@ Map<String, String> buildControlLabels()
result.put(MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE, "Pixel posterize");
result.put(MODE_PREVIEW_PIXEL_DENSITY_RANGE, "Show density range");
result.put(MODE_CHANGE_POLYGONIZER, "Cycle polygonizer");
result.put(MODE_CHANGE_POLYGONIZER_LENGTH, "Polygonizer length");
return result;
}
@ -1151,6 +1182,9 @@ Set<String> buildControlNames()
result.add(MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE);
result.add(MODE_PREVIEW_PIXEL_DENSITY_RANGE);
result.add(MODE_CHANGE_POLYGONIZER_LENGTH);
result.add(MODE_CHANGE_POLYGONIZER);
return result;
}

View File

@ -684,7 +684,6 @@ void sendVectorShapes(RShape vec, float scaling, PVector position, int pathSorti
if (pointPaths[i] != null)
{
boolean firstPointFound = false;
if (pointPaths[i].length > pathLengthHighPassCutoff)
{
List<PVector> filteredPoints = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength, scaling, position);
@ -701,7 +700,7 @@ void sendVectorShapes(RShape vec, float scaling, PVector position, int pathSorti
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";
command = CMD_CHANGELENGTHDIRECT+Math.round(p.x)+","+Math.round(p.y)+","+getMaxSegmentLength()+",END";
addToCommandQueue(command);
if (liftToGetToNewPoint)
addToCommandQueue(CMD_PENDOWN+"END");
@ -712,7 +711,7 @@ void sendVectorShapes(RShape vec, float scaling, PVector position, int pathSorti
for (int j=1; j<filteredPoints.size(); j++)
{
p = filteredPoints.get(j);
command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END";
command = CMD_CHANGELENGTHDIRECT+Math.round(p.x)+","+Math.round(p.y)+","+getMaxSegmentLength()+",END";
addToCommandQueue(command);
}
lastPoint = new PVector(p.x, p.y);
@ -890,6 +889,7 @@ List<PVector> filterPointsLowPass(RPoint[] points, long filterParam, float scali
// scale and convert all the points first
List<PVector> scaled = new ArrayList<PVector>(points.length);
println("a filterPointsLowPass: Scaled length: " + points.length);
for (int j = 0; j<points.length; j++)
{
RPoint firstPoint = points[j];
@ -904,7 +904,8 @@ List<PVector> filterPointsLowPass(RPoint[] points, long filterParam, float scali
}
}
if (scaled.size() > 1)
println("b filterPointsLowPass: Scaled length: " + scaled.size());
if (scaled.size() > 1.0)
{
PVector p = scaled.get(0);
result.add(p);
@ -918,12 +919,13 @@ List<PVector> filterPointsLowPass(RPoint[] points, long filterParam, float scali
if (abs(diffx) > filterParam || abs(diffy) > filterParam)
{
//println("Adding point " + p + ", last: " + result.get(result.size()-1));
println(j + ". Adding point " + p + ", last: " + result.get(result.size()-1));
result.add(p);
}
}
}
println("c filterPointsLowPass: Scaled length: " + result.size());
if (result.size() < 2)
result.clear();

View File

@ -57,7 +57,7 @@ import java.awt.BorderLayout;
import java.lang.reflect.Method;
int majorVersionNo = 2;
int minorVersionNo = 3;
int minorVersionNo = 4;
int buildNo = 0;
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;
@ -343,6 +343,12 @@ static final String MODE_CYCLE_DENSITY_PREVIEW_STYLE = "button_mode_cycleDensity
static final String MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE = "numberbox_mode_changeDensityPreviewPosterize";
static final String MODE_PREVIEW_PIXEL_DENSITY_RANGE = "minitoggle_mode_previewPixelDensityRange";
static final String MODE_CHANGE_POLYGONIZER = "button_mode_cyclePolygonizer";
static final String MODE_CHANGE_POLYGONIZER_LENGTH = "numberbox_mode_changePolygonizerLength";
PVector statusTextPosition = new PVector(300.0, 12.0);
@ -369,6 +375,7 @@ boolean pixelTimerRunning = false;
boolean displayingSelectedCentres = false;
boolean displayingRowGridlines = false;
boolean displayingInfoTextOnInputPage = false;
boolean displayingGridSpots = true;
boolean displayingImage = true;
boolean displayingVector = true;
@ -532,6 +539,10 @@ static PApplet parentPapplet = null;
boolean rescaleDisplayMachine = true;
// Polygonization. It's a geomerative thing.
int polygonizer = 0;
float polygonizerLength = 0.0;
void setup()
{
println("Running polargraph controller");
@ -539,9 +550,6 @@ void setup()
initLogging();
parentPapplet = this;
RG.init(this);
RG.setPolygonizer(RG.UNIFORMLENGTH);
// RG.setPolygonizer(RG.ADAPTATIVE);
try
{
@ -551,6 +559,8 @@ void setup()
{
e.printStackTrace();
}
RG.init(this);
loadFromPropertiesFile();
size(windowWidth, windowHeight);
@ -639,10 +649,11 @@ void addEventListeners()
{
public void componentResized(ComponentEvent event)
{
if (event.getSource()==frame)
{
windowResized();
}
windowResized();
// if (event.getSource()==frame)
// {
// windowResized();
// }
}
}
);
@ -1625,7 +1636,7 @@ boolean mouseOverQueue()
void changeMachineScaling(int delta)
{
boolean scalingChanged = true;
machineScaling += (delta * 0.1);
machineScaling += (delta * (machineScaling * 0.1));
if (machineScaling < MIN_SCALING)
{
machineScaling = MIN_SCALING;
@ -1791,6 +1802,7 @@ void machineDragged()
lastMachineDragPosition = new PVector(currentPos.x, currentPos.y);
PVector currentPosition = getDisplayMachine().getOutline().getPosition();
getDisplayMachine().getOffset().add(change);
cursor(MOVE);
}
}
@ -1893,7 +1905,25 @@ void leftButtonMachineClick()
void mouseWheel(int delta)
{
noLoop();
// get the mouse position on the machine, before changing the machine scaling
PVector pos = getDisplayMachine().scaleToDisplayMachine(getMouseVector());
changeMachineScaling(delta);
// now work out what the machine position needs to be to line the pos up with mousevector again
PVector scaledPos = getDisplayMachine().scaleToDisplayMachine(getMouseVector());
// println("original pos: " + pos);
// println("scaled pos: " + scaledPos);
PVector change = PVector.sub(scaledPos, pos);
// println("change: " + change);
// and adjust for the new scaling factor
change.mult(machineScaling);
// finally update the machine offset (position)
getDisplayMachine().getOffset().add(change);
loop();
}
void setChromaKey(PVector p)
@ -1935,7 +1965,7 @@ boolean toggleShowConsole() {
System.setOut(savedOut);
}
println("Ow");
// println("Ow");
return console == null;
}
@ -2017,6 +2047,7 @@ void previewQueue(boolean forceRebuild)
ellipse(p.x, p.y, 5,5);
noFill();
}
// ellipse(p.x, p.y, 5,5); // Circle at each node
}
@ -3021,6 +3052,11 @@ void loadFromPropertiesFile()
}
this.homePointCartesian = new PVector(getDisplayMachine().inSteps(homePointX), getDisplayMachine().inSteps(homePointY));
// println("home point loaded: " + homePointCartesian + ", " + getHomePoint());
// Geomerative stuff
polygonizer = getIntProperty("controller.geomerative.polygonizer", RG.ADAPTATIVE);
polygonizerLength = getFloatProperty("controller.geomerative.polygonizerLength", 1.0);
setupPolygonizer();
setVectorFilename(getStringProperty("controller.vector.filename", null));
if (getVectorFilename() != null)
@ -3048,8 +3084,7 @@ void loadFromPropertiesFile()
getVectorPosition().x = getFloatProperty("controller.vector.position.x", 0.0);
getVectorPosition().y = getFloatProperty("controller.vector.position.y", 0.0);
this.minimumVectorLineLength = getIntProperty("controller.vector.minLineLength", 0);
println("Finished loading configuration from properties file.");
}
@ -3122,6 +3157,9 @@ void savePropertiesFile()
props.setProperty("controller.vector.position.x", df.format(getVectorPosition().x));
props.setProperty("controller.vector.position.y", df.format(getVectorPosition().y));
props.setProperty("controller.vector.minLineLength", new Integer(this.minimumVectorLineLength).toString());
props.setProperty("controller.geomerative.polygonizer", new Integer(polygonizer).toString());
props.setProperty("controller.geomerative.polygonizerLength", df.format(polygonizerLength));
FileOutputStream propertiesOutput = null;
@ -3275,6 +3313,15 @@ Integer getBaudRate()
return baudRate;
}
void setupPolygonizer() {
RG.setPolygonizer(polygonizer); // http://www.polargraph.co.uk/forum/polargraphs-group2/troubleshooting-forum5/svg-differences-between-polargraphcontroller-2-1-1-2-3-0-thread523.0
switch(polygonizer) {
case 1: RG.setPolygonizerLength(polygonizerLength); break;
}
println("Polygonizer: " + polygonizer);
println("PolygonizerLength: " + polygonizerLength);
}
void initLogging()
{
try