Due to the difficulty of properly debugging real-time applications, as all those involving robotics sensors, it becomes more convenient to do development offline (on a dataset saved to disk) and, only when it seems all work fine, switch to the real thing.
The following example will show you how to do it in a way that doesn’t affect your program structure: switching will be controlled by a simple bool variable.
2. The code
See the entire example in: https://raw.github.com/jlblancoc/mrpt/master/samples/kinect_online_offline_demo/