diff --git a/Bridger.pde b/Bridger.pde index a08d65d..994ba14 100644 --- a/Bridger.pde +++ b/Bridger.pde @@ -125,7 +125,7 @@ void bridgeIslandsSimple (color[] inputBuffer, int inputW, int inputH) { // inputBuffer is an array of colors(i.e. ints), which // are a 'pure' black-and-white version of the QR code. - int gridSize = computeGridSize (inputBuffer, inputW, inputH); // see Utils.pde + gridSize = computeGridSize (inputBuffer, inputW, inputH); // see Utils.pde int ccLabelColors[] = CCL.getLabelColors(); int nLabelColors = ccLabelColors.length; @@ -176,7 +176,7 @@ void bridgeIslandsSimple (color[] inputBuffer, int inputW, int inputH) { //=============================================================== void bridgeIslandsAdvanced (color[] inputBuffer, int inputW, int inputH) { - int gridSize = computeGridSize (inputBuffer, inputW, inputH); // see Utils.pde + gridSize = computeGridSize (inputBuffer, inputW, inputH); // see Utils.pde int ccLabelColors[] = CCL.getLabelColors(); int nLabelColors = ccLabelColors.length; //while (nLabelColors > 2) { diff --git a/QR_STENCILER.pde b/QR_STENCILER.pde index bd3f158..20cbf61 100644 --- a/QR_STENCILER.pde +++ b/QR_STENCILER.pde @@ -116,8 +116,13 @@ boolean DO_ROUNDED_CORNERS = true; // Enables corner rounding and path boolean USE_BEZIER_NOT_ARCS = false; // Enables Bezier exporting instead of generating arc points. boolean DO_ADVANCED_BRIDGING = true; // Chooses between advanced and simple bridging. boolean DO_ALL_COMPUTED_BRIDGES = false; // Invalidates RANDOM_BRIDGE_CULLING_FACTOR -boolean DO_OPEN_PDF_WHEN_DONE = false; // Open the stencil PDF in Acrobat when done? - +boolean DO_OPEN_PDF_WHEN_DONE = false; // Open the stencil PDF in Acrobat when done? +// KDDW +boolean ARTK_MODE = true; // ARToolkit mode for thin border BCH markers +int ARTK_MARKER_ID = 2; // ARTK marker ID +float PDF_STENCIL_SIZE_MM = 50.0; // Size of the stencil (mm) when outputed as a PDF +int PDF_PAGE_WIDTH_MM = 297; // Width (mm) of the pdf page +int PDF_PAGE_HEIGHT_MM = 210; // Height (mm) of the pdf page //===================================================================== @@ -159,6 +164,7 @@ int blackAndWhiteImage[]; int blackAndWhiteImageInverse[]; int coloredLabeledImage[]; int nPixels; +int gridSize; final color white = color(255); final color black = color(0); @@ -170,15 +176,26 @@ final int DIR_DOWN = 1; final int DIR_LEFT = 2; final int DIR_RIGHT = 3; +// KDDW +final int ARTK_MARKER_SIZE = 200; // Size of the final marker image in pixels +final int BCH_MARKER_SIZE = 10; // Size of the small markers in the "ARTK_AllBchThinMarkers.png" file +final int ARTK_MARKER_SCALE = (int) ARTK_MARKER_SIZE / BCH_MARKER_SIZE; + //=============================================================== void setup() { bSetupPhase = true; QRStencilerInfo(); - QRDefaultImageFilename = sketchPath + "/data/" + "QR_hello_world.png"; - QRImageFilename = getUserSelectedQRCodeImageFilename(); // See FileLoading.pde - QR = loadImage (QRImageFilename); + if(ARTK_MODE) { + loadARTKMarker(ARTK_MARKER_ID); + + } else { + QRDefaultImageFilename = sketchPath + "/data/" + "QR_hello_world.png"; + QRImageFilename = getUserSelectedQRCodeImageFilename(); // See FileLoading.pde + QR = loadImage (QRImageFilename); + } + size (1000, 750, JAVA2D); nPixels = QR.width * QR.height; @@ -328,7 +345,14 @@ String drawAndExportPDF() { } QR_PdfFullFilename += ".pdf"; QRStencilPDFFilename = QR_PdfFullFilename; - beginRecord(PDF, QR_PdfFullFilename); + + // KDDW - Controls for the PDF page size + float mmToPt = 2.83464567; + int pdfWidth = ceil(PDF_PAGE_WIDTH_MM * mmToPt); + int pdfHeight = ceil(PDF_PAGE_HEIGHT_MM * mmToPt); + // Sizes are not exact, because createGraphics does not accept decimal values + PGraphicsPDF pdf = (PGraphicsPDF) createGraphics(pdfWidth, pdfHeight, PDF, QR_PdfFullFilename); + beginRecord(pdf); // Generate the text written on the QR code stencil boolean bDrawTitleText = true; @@ -346,9 +370,23 @@ String drawAndExportPDF() { text(QR_StencilText, 10, 10); } + // KDDW - Controls for the size of the stencil + float stencilSizePts = PDF_STENCIL_SIZE_MM * mmToPt; + int stencilAdjWidth; + if(ARTK_MODE) { + // Remove the border on each size + 1 + stencilAdjWidth = QR.width - ARTK_MARKER_SCALE - ARTK_MARKER_SCALE - 1; + } else { + float gridSizeFloat = gridSize; + float qrWidthFloat = QR.width; + stencilAdjWidth = QR.width - (int)((qrWidthFloat / gridSizeFloat) * 2.0) - 1; + } + //float gridSize = + float stencilScale = stencilSizePts / stencilAdjWidth; pushMatrix(); - translate((width - QR.width)/2.0, (height - QR.height)/2.0); + scale(stencilScale, stencilScale); + translate((pdfWidth - stencilSizePts)/2.0, (pdfHeight - stencilSizePts)/2.0); strokeWeight (PDF_LINE_THICKNESS); stroke(0, 0, 0); @@ -370,3 +408,10 @@ String drawAndExportPDF() { return QR_PdfFullFilename; } +// KDDW - Load an artk marker to be processed based on the marker ID +void loadARTKMarker(int markerID) { + QR = createMarkerImage(markerID); + // Create a dummy file name for the PDF processing + QRImageFilename = sketchPath + "/data/ARTK_PDF/ARTK_" + zeroPad(markerID, 4) + ".png"; + bCompleted = false; +} diff --git a/Utils.pde b/Utils.pde index 15cda69..3d0cfad 100644 --- a/Utils.pde +++ b/Utils.pde @@ -61,6 +61,10 @@ int computeGridSize (color[] qrImageBuffer, int qrImageW, int qrImageH) { // we know that the first thing is a black square which is 7 units wide. // use this information to automatically calculate the number of pixels per unit. + if(ARTK_MODE) { + return ARTK_MARKER_SCALE; + } + int marginX = 0; int marginY = 0; color searchColor = black; @@ -154,3 +158,79 @@ void handleInverseStencil(){ } } } +// Author: "Karl D.D. Willis" , 27 August, 2011 +//================================================================ +PImage createMarkerImage(int markerID) { + + // Create an image from a given BCH marker ID + + if(markerID > 4096 || markerID < 0) { + println("Marker ID out of range"); + return null; + } + + int BCH_MARKER_COUNT = 64; + int BCH_EDGE_SIZE = 3; + int BCH_GAP_SIZE = 2; + + // Index in the marker array + int ix = (int) (markerID % BCH_MARKER_COUNT); + int iy = (int) (markerID / BCH_MARKER_COUNT); + + // Pixel location + int x = BCH_EDGE_SIZE + ix * BCH_MARKER_SIZE; + if(ix > 0) { + x += ix * BCH_GAP_SIZE; + } + int y = BCH_EDGE_SIZE + iy * BCH_MARKER_SIZE; + if(iy > 0) { + y += iy * BCH_GAP_SIZE; + } + + PImage subImage = new PImage(ARTK_MARKER_SIZE, ARTK_MARKER_SIZE); + PImage markers = loadImage("data/ARTK_AllBchThinMarkers.png"); + + // For each pixel in the 10x10 sub area of the markers png file + for (int i=0; i len) { + return s.substring(0, len); + // pad on left with zeros + } else if (s.length() < len) { + return "000000000000000000000000000".substring(0, len - s.length()) + s; + } else { + return s; + } +} + diff --git a/data/ARTK_AllBchThinMarkers.png b/data/ARTK_AllBchThinMarkers.png new file mode 100755 index 0000000..ea97cdc Binary files /dev/null and b/data/ARTK_AllBchThinMarkers.png differ