diff --git a/DisplayMachine.pde b/DisplayMachine.pde index 3c39368..7ec438a 100644 --- a/DisplayMachine.pde +++ b/DisplayMachine.pde @@ -702,6 +702,24 @@ class DisplayMachine extends Machine } } + + int pixel_maxDensity(float penSize, float rowSizeInMM) + { + float numberOfSegments = rowSizeInMM / penSize; + + int maxDens = 1; + + if (numberOfSegments >= 2.0) { + maxDens = int(numberOfSegments); + } + + if (maxDens <= 1) { + maxDens = 1; + } + + return maxDens; + } + void drawExtractedPixelDensities() { @@ -709,20 +727,36 @@ class DisplayMachine extends Machine pixelSize = (pixelSize < 1.0) ? 1.0 : pixelSize; pixelSize = pixelSize * getPixelScalingOverGridSize(); + + float rowSizeInMM = inMM(getGridSize()) * getPixelScalingOverGridSize(); + + int posterizeLevels = 255; + + if (previewPixelDensityRange) { + posterizeLevels = pixel_maxDensity(currentPenWidth, rowSizeInMM); + } + else { + posterizeLevels = densityPreviewPosterize; + } if (getExtractedPixels() != null) { for (PVector cartesianPos : getExtractedPixels()) { - if ((cartesianPos.z <= pixelExtractBrightThreshold) && (cartesianPos.z >= pixelExtractDarkThreshold)) + if ((cartesianPos.z <= pixelExtractBrightThreshold) && + (cartesianPos.z >= pixelExtractDarkThreshold)) { // scale em, danno. PVector scaledPos = scaleToScreen(cartesianPos); noStroke(); + if ((scaledPos.x <= 0) || (scaledPos.x > displayWidth) || + (scaledPos.y <= 0) || (scaledPos.y > displayHeight)) { + continue; + } // Posterize the density value - int reduced = int(map(cartesianPos.z, 1, 255, 1, densityPreviewPosterize)+0.5); - int brightness = int(map(reduced, 1, densityPreviewPosterize, 1, 255)); + int reduced = int(map(cartesianPos.z, 1, 255, 1, posterizeLevels)+0.5); + int brightness = int(map(reduced, 1, posterizeLevels, 1, 255)); fill(brightness); switch (getDensityPreviewStyle()) @@ -732,7 +766,7 @@ class DisplayMachine extends Machine break; case DENSITY_PREVIEW_ROUND_SIZE: fill(0); - previewRoundPixel(scaledPos, map(brightness, 1, densityPreviewPosterize, pixelSize, 1)); + previewRoundPixel(scaledPos, map(brightness, 1, posterizeLevels, pixelSize, 1)); break; case DENSITY_PREVIEW_DIAMOND: previewDiamondPixel(scaledPos, pixelSize, pixelSize, brightness); @@ -741,7 +775,7 @@ class DisplayMachine extends Machine previewNativePixel(scaledPos, pixelSize, brightness); break; case DENSITY_PREVIEW_NATIVE_SIZE: - previewNativePixel(scaledPos, map(brightness, 1, densityPreviewPosterize, pixelSize, 1), 50); + previewNativePixel(scaledPos, map(brightness, 1, posterizeLevels, pixelSize, 1), 50); break; case DENSITY_PREVIEW_NATIVE_ARC: previewRoundPixel(scaledPos, pixelSize*0.8); diff --git a/controlsActions.pde b/controlsActions.pde index de5911a..bb71a5a 100644 --- a/controlsActions.pde +++ b/controlsActions.pde @@ -745,4 +745,9 @@ void numberbox_mode_changeDensityPreviewPosterize(int value) { densityPreviewPosterize = value; } +void minitoggle_mode_previewPixelDensityRange(boolean flag) { + previewPixelDensityRange = flag; + println("previewPixelDensityRange: " + previewPixelDensityRange); +} + diff --git a/controlsSetup.pde b/controlsSetup.pde index bac05fd..0b759f6 100644 --- a/controlsSetup.pde +++ b/controlsSetup.pde @@ -579,7 +579,11 @@ Map initialiseToggleValues(Map map) Toggle t = (Toggle) map.get(key); t.setValue((rotateWebcamImage) ? 1 : 0); } - + else if (MODE_PREVIEW_PIXEL_DENSITY_RANGE.equals(key)) + { + Toggle t = (Toggle) map.get(key); + t.setValue((previewPixelDensityRange) ? 1 : 0); + } } return map; } @@ -725,6 +729,7 @@ List getControlNamesForInputPanel() controlNames.add(MODE_SHOW_QUEUE_PREVIEW); controlNames.add(MODE_SHOW_DENSITY_PREVIEW); controlNames.add(MODE_SHOW_GUIDES); + controlNames.add(MODE_PREVIEW_PIXEL_DENSITY_RANGE); return controlNames; @@ -995,7 +1000,7 @@ Map buildControlLabels() result.put(MODE_CYCLE_DENSITY_PREVIEW_STYLE, "Cycle preview style"); result.put(MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE, "Pixel posterize"); - + result.put(MODE_PREVIEW_PIXEL_DENSITY_RANGE, "Show density range"); return result; @@ -1144,6 +1149,7 @@ Set buildControlNames() result.add(MODE_CYCLE_DENSITY_PREVIEW_STYLE); result.add(MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE); + result.add(MODE_PREVIEW_PIXEL_DENSITY_RANGE); return result; } diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index df7c350..a5930c0 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -57,15 +57,13 @@ import java.awt.BorderLayout; import java.lang.reflect.Method; int majorVersionNo = 2; -int minorVersionNo = 2; -int buildNo = 2; +int minorVersionNo = 3; +int buildNo = 1; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; ControlP5 cp5; Map cp5s = new HashMap(); - - boolean drawbotReady = false; boolean drawbotConnected = false; @@ -343,6 +341,7 @@ static final String MODE_ADJUST_PREVIEW_CORD_OFFSET = "numberbox_mode_previewCor static final String MODE_CYCLE_DENSITY_PREVIEW_STYLE = "button_mode_cycleDensityPreviewStyle"; static final String MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE = "numberbox_mode_changeDensityPreviewPosterize"; +static final String MODE_PREVIEW_PIXEL_DENSITY_RANGE = "minitoggle_mode_previewPixelDensityRange"; PVector statusTextPosition = new PVector(300.0, 12.0); @@ -390,6 +389,7 @@ static final int DENSITY_PREVIEW_NATIVE_SIZE = 5; static final int DEFAULT_DENSITY_PREVIEW_STYLE = DENSITY_PREVIEW_NATIVE; int densityPreviewStyle = DEFAULT_DENSITY_PREVIEW_STYLE; int densityPreviewPosterize = 255; +boolean previewPixelDensityRange = true; static final byte COORD_MODE_NATIVE_STEPS = 0; static final byte COORD_MODE_NATIVE_MM = 1; @@ -485,7 +485,7 @@ RShape vectorShape = null; String vectorFilename = null; float vectorScaling = 100; PVector vectorPosition = new PVector(0.0,0.0); -int minimumVectorLineLength = 0; +int minimumVectorLineLength = 2; public static final int VECTOR_FILTER_LOW_PASS = 0;