Thread channel and kinectV2


I have been working on extending the ofxKinectV2 addon and have made a lot of progress, I have compiled libfreenect2 for windows and linux and have been able to add Cuda support for all platforms. I am really interested in improving the pointcloud and one of the tasks is to thread the creation of the mesh. The threadChannelExample seems a great place to start but I have a few questions.

The first one is that I need to pass a few parameters each frame, not just pixels. In the example there is:

`ofThreadChannel<ofPixels> toAnalyze;`

I am wondering how to add more complexity and keep efficiency. I was thinking about making a struct or class and passing that, but I want to keep it fast.

one example would be:

		struct PointCloudIngredients
			ofPixels registeredPixels;
			float minDistance;
			float maxDistance;


		ofThreadChannel<PointCloudIngredients> toProcess;

Then I can send all the data together and make sure that the values that are used are the ones that were correct for each frame.

The other question I have is the best way to use a function from another class in a thread. In libfreenect2 the function I want to use is:

kinect->getWorldCoordinateAt(x, y)

This is related to the current state and frame of the device.
I could go through all the pixels and grab the world coordinates and feed that into the thread (which will help with speed, by offloading half the process). This

Is it is good idea to also add the kinect device to the thread channel?

Evidently my skills at actual programming a quite lacking, I have been reading up on threads but this structure is a bit difficult for me to plan. Any tips on relevant examples or reading are also appreciated.



the fastest way to do this without having to copy the full data is to store the real data in a vector of PointCloudIngredients and just pas the index to that vector in the thread channel. that way you ensure that each pixels are only accessed by one thread only at any time


Well I had to go quite a different route, but ended up with good results (almost double the framerate). As the addon was already using a threaded structure updating the kinect I could not really find a way to just make the point cloud threaded. I ended up filling up data structures to store the point cloud information in the kinects update thread and using swap in the main thread to update the pointcloud. I still have some work to do but the results are here: