Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARToolkit Support #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Bridger.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
59 changes: 52 additions & 7 deletions QR_STENCILER.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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


//=====================================================================
Expand Down Expand Up @@ -159,6 +164,7 @@ int blackAndWhiteImage[];
int blackAndWhiteImageInverse[];
int coloredLabeledImage[];
int nPixels;
int gridSize;

final color white = color(255);
final color black = color(0);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
80 changes: 80 additions & 0 deletions Utils.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -154,3 +158,79 @@ void handleInverseStencil(){
}
}
}
// Author: "Karl D.D. Willis" <[email protected]>, 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<BCH_MARKER_SIZE; i++) {
for (int j=0; j<BCH_MARKER_SIZE; j++) {

int mainPixelPos = ((j+y) * markers.width + (i+x));

int sx = i * ARTK_MARKER_SCALE;
int sy = j * ARTK_MARKER_SCALE;
int subPixelPos = (sy * ARTK_MARKER_SIZE + sx);

// Enlarge the 10x10 marker area to the display size
for (int k=0; k<ARTK_MARKER_SCALE; k++) {
int krow = k * ARTK_MARKER_SIZE;
for (int l=0; l<ARTK_MARKER_SCALE; l++) {
int subDisplayPixelPos = krow + subPixelPos + l;
subImage.pixels[subDisplayPixelPos] = markers.pixels[mainPixelPos];
}
}
}
}

subImage.updatePixels();
return subImage;
}

/** Zero Pad an int
*
* @param i The number to pad
* @param len The length required
* @return The padded number
*/
public static String zeroPad(int i, int len) {
// converts integer to left-zero padded string, len chars long.
String s = Integer.toString(i);
if (s.length() > 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;
}
}

Binary file added data/ARTK_AllBchThinMarkers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.