Aww.. 3D point clouds.. in ten minutes.

Been playing with those awesome processing examples for a bit, combining them and stuff. They are georgeous and I love the smooth feeling.. however ou define that.

Since I’ve been meaning to visualize 3d-data for one of my apps @ work, I wrote (well, copy-pasted, but it’s so easy to understand!) a quick app that draws a OpenGL point cloud, rotateable (is that a word?) with those scrollbars.. I took a (really good, btw) class on OpenGL a few years ago, and remember that it was a pain just to set it up..


import processing.opengl.*;
PImage img; // The source image
int cellsize = 5; // Dimensions of each cell in the grid
int columns, rows; // Number of columns and rows in our system
float rotation =0;
HScrollbar hs1;

void setup() {
size(800, 600, OPENGL);
img = loadImage("something.png");
columns = img.width / cellsize; // Calculate # of columns
rows = img.height / cellsize; // Calculate # of rows
hs1 = new HScrollbar(0, 20, width, 10, 3*5+1);
}

void draw(){

background(240);
hs1.update();
hs1.display();
translate(0, height/2 , -100);
rotation = hs1.getPos()-width/2;
rotateX(radians(180));
rotateX(radians(rotation));
rotateZ(radians(10));
for ( int i = 0; i < columns; i++) {
// Begin loop for rows
for ( int j = 0; j < rows; j++) {
stroke(10);
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*img.width; // Pixel array location
float z = brightness(img.pixels[loc]);
point(x,y,z);
}
}
}

Add to that the HScrollBar class from the examples.

A 3D pic in Processing

A 3D point cloud in Processing

I’m considering turning it into some sort of surface plot and add some lights and shadows, but I’ll research before I do this.

Anyways, back to my original weekend project.

Advertisements

One comment

  1. […] fact, the only things I changed from my old program were […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: