I can't get around a peculiar problem with SimpleOpenNI for Processing ao I'm asking for your help.
I'd like to store snapshots of pixel depth data (returned by .depthMapRealWorld() method as PVector arrays) on discrete time intervals, then process them further for a presentation. I tried adding them in an ArrayList, but it seems that the depthMapRealWorld() method is returning only a reference to a current depth data, not a real array. I tried in this sequence:
Just getting the data and adding it in an arraylist. On every call of the update() method the whole arraylist contained the same PVector array, even if the array at the zero position was added many iterations away!
Then I made the PVector array, along with its creation time, part of a class. Rewrote the sketch a little, but it didn't help. All of the arrays in the arraylist werw still the same.
Finally, in the constructor of the class, I "manually" copied the xyz coordinates of every vector from the PVector array into a int array. That seemed to solve the problem - the int arrays in the arraylist are now different from each other. But this solution introduced serious performance problems.
The question is: is there a more efficient way of storing these PVector arrays and retaining their value?
import processing.opengl.*; import SimpleOpenNI.*; SimpleOpenNI kinect; float rotation = 0; int time = 0; ArrayList dissolver; ArrayList<Integer> timer; int pSize = 10; Past past; void setup() { dissolver = new ArrayList(); timer = new ArrayList(); size(1024, 768, OPENGL); kinect = new SimpleOpenNI(this); kinect.enableDepth(); translate(width/2, height/2, -100); rotateX(radians(180)); stroke(255); } void draw() { background(0); translate(width/2, height/2, 500); rotateX(radians(180)); kinect.update(); stroke (255, 255, 255); past = new Past (kinect.depthMapRealWorld(), time); if (dissolver.size() == pSize) { //remove the oldest arraylist element if when list gets full dissolver.remove(0); // } if (time % 20 == 0) { dissolver.add (past); Past p1 = (Past) dissolver.get (0); float [][] o2 = p1.getVector(); println ("x coord of a random point at arraylist position 0: " + o2[50000][0]); //for testing } if (dissolver.size() == pSize-1) { //dissolve (); } time ++; } void dissolve () { //from the previous nonworking version; ignore for (int offset = 0; offset < pSize-1; offset ++) { PVector[] offPoints = (PVector[]) dissolver.get (offset); int offTime = timer.get(offset); for (int i = 0; i < offPoints.length; i+=10) { int col = (time-offTime)*2; //why?? stroke (255, 0, col); PVector currentPoint = offPoints[i]; if (currentPoint.z <1500) { point(currentPoint.x, currentPoint.y, currentPoint.z); // - 2*(time-offTime) + random(0, 100) } } } } class Past { private PVector [] depth; //should contain this, not int private float [][] depth1; private int time; Past (PVector [] now, int t) { //should be like this: depth = now; //clumsy and performancewise catastrophic solution below depth1 = new float [now.length][3]; for (int i = 0; i< now.length; i+=10) { PVector temp = now[i]; depth1 [i][0] = temp.x; depth1 [i][1] = temp.y; depth1 [i][2] = temp.z; } //arrayCopy(now, depth); this didn't work either time = t; } float [][] getVector () { return depth1; } int getTime () { return time; } }