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

First Commit #10

Open
wants to merge 17 commits 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
40 changes: 40 additions & 0 deletions Processing/Misc/Barebones/Barebones.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
int projectorWidth = 1920;
int projectorHeight = 1200;
int projectorOffset = 1842;

int screenWidth = 1842;
int screenHeight = 1026;

int displayU = 18;
int displayV = 22;

int IDMax = 15;

// Table Canvas Width and Height
int TABLE_IMAGE_HEIGHT = 1000;
int TABLE_IMAGE_WIDTH = 1000;

// Arrays that holds ID information of rectilinear tile arrangement.
int tablePieceInput[][][] = new int[displayU][displayV][2];

void setup() {
size(screenWidth, screenHeight, P3D);

// Initial Projection-Mapping Canvas
initializeProjection2D();

// Allows application to receive information from Colortizer via UDP
initUDP();

}

void draw() {

background(255);
fill(#FF0000);
rect(0,0,350, 350);

// Exports table Graphic to Projector
projector = get(0, 0, TABLE_IMAGE_WIDTH, TABLE_IMAGE_HEIGHT);

}
10 changes: 10 additions & 0 deletions Processing/Misc/Barebones/CONTROLS.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
`

void keyPressed() {
switch(key) {

case '`': // "Enable Projection (`)"
toggle2DProjection();
break;
}
}
185 changes: 185 additions & 0 deletions Processing/Misc/Barebones/PROJECTION.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
//
// This is a script that allows one to open a new canvas for the purpose
// of simple 2D projection mapping, such as on a flat table surface
//
// Right now, only appears to work in windows...
//
// To use this example in the real world, you need a projector
// and a surface you want to project your Processing sketch onto.
//
// Simply press the 'c' key and drag the corners of the
// CornerPinSurface so that they
// match the physical surface's corners. The result will be an
// undistorted projection, regardless of projector position or
// orientation.
//
// You can also create more than one Surface object, and project
// onto multiple flat surfaces using a single projector.
//
// This extra flexbility can comes at the sacrifice of more or
// less pixel resolution, depending on your projector and how
// many surfaces you want to map.
//

import javax.swing.JFrame;
import deadpixel.keystone.*;

// Visualization may show 2D projection visualization, or not
boolean displayProjection2D = false;
//int projectorOffset = screenWidth;

boolean testProjectorOnMac = false;

// defines Keystone settings from xml file in parent folder
Keystone ks;

// defines various drawing surfaces, all pre-calibrated, to project
CornerPinSurface surface;
PGraphics offscreen;
PImage projector;

// New Application Window Parameters
PFrame proj2D = null; // f defines window to open new applet in
projApplet applet; // applet acts as new set of setup() and draw() functions that operate in parallel

// Run Anything Needed to have Projection mapping work
void initializeProjection2D() {
println("Projector Info: " + projectorWidth + ", " + projectorHeight + ", " + projectorOffset);
//toggleProjection(getButtonIndex(buttonNames[21]));
}

public class PFrame extends JFrame {
public PFrame() {
setBounds(0, 0, projectorWidth, projectorHeight );
setLocation(projectorOffset, 0);
applet = new projApplet();
setResizable(false);
setUndecorated(true);
setAlwaysOnTop(true);
add(applet);
applet.init();
show();
setTitle("Projection2D");
}
}

public void showProjection2D() {
if (proj2D == null) {
proj2D = new PFrame();
}
proj2D.setVisible(true);
}

public void closeProjection2D() {
proj2D.setVisible(false);
}

public void resetProjection2D() {
initializeProjection2D();
if (proj2D != null) {
proj2D.dispose();
proj2D = new PFrame();
if (displayProjection2D) {
showProjection2D();
} else {
closeProjection2D();
}
}
}

public class projApplet extends PApplet {
public void setup() {
// Keystone will only work with P3D or OPENGL renderers,
// since it relies on texture mapping to deform
size(projectorWidth, projectorHeight, P2D);

ks = new Keystone(this);;

reset();
}

public void reset() {
surface = ks.createCornerPinSurface(TABLE_IMAGE_HEIGHT, TABLE_IMAGE_HEIGHT, 20);
offscreen = createGraphics(TABLE_IMAGE_HEIGHT, TABLE_IMAGE_HEIGHT);

try{
ks.load();
} catch(RuntimeException e){
println("No Keystone.xml. Save one first if you want to load one.");
}
}

public void draw() {

// Convert the mouse coordinate into surface coordinates
// this will allow you to use mouse events inside the
// surface from your screen.
PVector surfaceMouse = surface.getTransformedMouse();

// most likely, you'll want a black background to minimize
// bleeding around your projection area
background(0);

// Draw the scene, offscreen
renderCanvas(offscreen, 0);
surface.render(offscreen);

}

void renderCanvas(PGraphics p, int x_offset) {
// Draw the scene, offscreen
p.beginDraw();
p.clear();
p.translate(x_offset, 0);
p.image(projector, 0, 0);
p.endDraw();
}

void keyPressed() {
switch(key) {
case 'c':
// enter/leave calibration mode, where surfaces can be warped
// and moved
ks.toggleCalibration();
break;

case 'l':
// loads the saved layout
ks.load();
break;

case 's':
// saves the layout
ks.save();
break;

case '`':
if (displayProjection2D) {
displayProjection2D = false;
closeProjection2D();
} else {
displayProjection2D = true;
showProjection2D();
}
break;
}
}
}

void toggle2DProjection() {
if (System.getProperty("os.name").substring(0,3).equals("Mac")) {
testProjectorOnMac = !testProjectorOnMac;
println("Test on Mac = " + testProjectorOnMac);
println("Projection Mapping Currently not Supported for MacOS");
} else {
if (displayProjection2D) {
displayProjection2D = false;
closeProjection2D();
} else {
displayProjection2D = true;
showProjection2D();
}
}
}


98 changes: 98 additions & 0 deletions Processing/Misc/Barebones/UDP.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Principally, this script ensures that a string is "caught" via UDP and coded into principal inputs of:
// - tablePieceInput[][] or tablePieceInput[][][2] (rotation)
// - UMax, VMax


int portIN = 6152;

import hypermedia.net.*;
UDP udp; // define the UDP object

boolean busyImporting = false;
boolean viaUDP = true;
boolean changeDetected = false;
boolean outputReady = false;

void initUDP() {
if (viaUDP) {
udp = new UDP( this, portIN );
//udp.log( true ); // <-- printout the connection activity
udp.listen( true );
}
}

void ImportData(String inputStr[]) {
if (inputStr[0].equals("COLORTIZER")) {
parseColortizerStrings(inputStr);
}
busyImporting = false;
}

void parseColortizerStrings(String data[]) {

for (int i=0 ; i<data.length;i++) {

String[] split = split(data[i], "\t");

// Checks maximum possible ID value
if (split.length == 2 && split[0].equals("IDMax")) {
IDMax = int(split[1]);
}

// Checks if row format is compatible with piece recognition. 3 columns for ID, U, V; 4 columns for ID, U, V, rotation
if (split.length == 3 || split.length == 4) {

//Finds UV values of Lego Grid:
int u_temp = int(split[1]);
int v_temp = tablePieceInput.length - int(split[2]) - 1;

if (split.length == 3 && !split[0].equals("gridExtents")) { // If 3 columns

// detects if different from previous value
if ( v_temp < tablePieceInput.length && u_temp < tablePieceInput[0].length ) {
if ( tablePieceInput[v_temp][u_temp][0] != int(split[0]) ) {
// Sets ID
tablePieceInput[v_temp][u_temp][0] = int(split[0]);
changeDetected = true;
}
}

} else if (split.length == 4) { // If 4 columns

// detects if different from previous value
if ( v_temp < tablePieceInput.length && u_temp < tablePieceInput[0].length ) {
if ( tablePieceInput[v_temp][u_temp][0] != int(split[0]) || tablePieceInput[v_temp][u_temp][1] != int(split[3])/90 ) {
// Sets ID
tablePieceInput[v_temp][u_temp][0] = int(split[0]);
//Identifies rotation vector of piece [WARNING: Colortizer supplies rotation in degrees (0, 90, 180, and 270)]
tablePieceInput[v_temp][u_temp][1] = int(split[3])/90;
changeDetected = true;
}
}
}
}
}
}

void receive( byte[] data, String ip, int port ) { // <-- extended handler
// get the "real" message =
String message = new String( data );
//println("catch!");
println(message);
//saveStrings("data.txt", split(message, "\n"));
String[] split = split(message, "\n");

if (!busyImporting) {
busyImporting = true;
ImportData(split);
}
}

void sendCommand(String command, int port) {
if (viaUDP) {
String dataToSend = "";
dataToSend += command;
udp.send( dataToSend, "localhost", port );
}
}

Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading