import processing.dxf.*; import peasy.*; //Camera PeasyCam cam; //Image PImage a; //Pixel Array int[][] aPixels; //Values extracted from the pixel array int[][] values; PVector[][] vectors; //Image size int imgX=100; int imgY=100; //Font PFont fontA; void setup() { //init processing window size(800,640,P3D); //setup camera setupCamera(150); //Initialize arrays using image aPixels = new int[imgX][imgY]; values = new int[imgX][imgY]; vectors = new PVector[imgX][imgY]; //load image a = loadImage("array-obama-col.jpg"); //process image for (int i=0; i< imgX; i++) { for (int j=0; j< imgY; j++) { aPixels[j][i] = a.pixels[i*imgX + j]; values[j][i] = int(red(aPixels[j][i])); //r-> azi; g-> alt; b-> magnitude float azi = red(aPixels[j][i])/255 * TWO_PI; float alt = green(aPixels[j][i])/255 * TWO_PI; float mgn = blue(aPixels[j][i])/255 * TWO_PI; //calculate vector components float vx = mgn* cos(azi) * cos(alt); float vy = mgn* sin(azi) * cos(alt); float vz = mgn* sin(alt); //create vectors vectors[j][i] = new PVector(vx, vy, vz); }//end for j } //end for i // Set the font and its size (in units of pixels) fontA = loadFont("CourierNew36.vlw"); textFont(fontA, 0.5); } void draw() { //clean up background background(175); //draw grid etc drawWorld(); //draw processed image for (int i=0; i< imgX; i+=2) { for (int j=0; j< imgY; j+=2) { //set colors stroke(red(aPixels[j][i]),green(aPixels[j][i]),blue(aPixels[j][i])); fill(values[j][i], 204); //translate and draw geometry pushMatrix(); translate(j-50, i-50, values[j][i]/10); box(0.1); text("r:"+red(aPixels[j][i])+" g:"+green(aPixels[j][i]), 0, 0,0); line(0,0,0,vectors[j][i].x,vectors[j][i].y,vectors[j][i].z); popMatrix(); } } } boolean setupCamera(double dis) { cam = new PeasyCam(this, dis); cam.rotateX(-1.0); cam.rotateY(-0.5); cam.rotateZ(0.2); return true; } boolean drawWorld() { float markerSz = 5f; stroke(255,0,0); line(0f,0f,.3,markerSz ,0f,.3); stroke(0,255,0); line(0f,0f,.3,0f,-markerSz ,.3); stroke(0,0,255); line(0f,0f,.3,0f,0f,markerSz ); int gridSzX = 100; int gridSzY = 100; int gridStep=5; for(int i = -gridSzY/2; i <= gridSzY/2; i+=gridStep) { if(i%15 != 0) stroke(200,200,200); else stroke(150,150,150); line(-gridSzX/2,i,0,gridSzX/2,i,0); line(i,-gridSzY/2,0,i,gridSzY/2,0); } return true; }