Made the density preview depth linked to the pen width.

This commit is contained in:
Sandy Noble 2016-01-26 23:11:57 +00:00
parent c221b9456c
commit 2fbe578954
4 changed files with 57 additions and 12 deletions

View File

@ -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);

View File

@ -745,4 +745,9 @@ void numberbox_mode_changeDensityPreviewPosterize(int value) {
densityPreviewPosterize = value;
}
void minitoggle_mode_previewPixelDensityRange(boolean flag) {
previewPixelDensityRange = flag;
println("previewPixelDensityRange: " + previewPixelDensityRange);
}

View File

@ -579,7 +579,11 @@ Map<String, Controller> initialiseToggleValues(Map<String, Controller> 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<String> 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<String, String> 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<String> buildControlNames()
result.add(MODE_CYCLE_DENSITY_PREVIEW_STYLE);
result.add(MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE);
result.add(MODE_PREVIEW_PIXEL_DENSITY_RANGE);
return result;
}

View File

@ -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<String, ControlP5> cp5s = new HashMap<String, ControlP5>();
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;