openni

Using Eclipse with Cinder – A better c++ editor

onedayitwillmake 10 comments

I was really having a hard time with Xcode lately, specifically how its C++ code-completion leaves much to be desired especially if you have a very bad memory. I find myself constantly painfully looking through the header files to find the exact name/case of a function or property.

So I decided to try and see If i could get up and running with Cinder in Eclipse instead, it wasn’t too bad either !!! Just a couple of issues getting the linking right, but that was about it.

Download / Github


Xcode is a great IDE, however it is not great at C++ editing

It provides only very barebones syntax highlighting, even more barebones code completion, and no edit-time error checking.

Cinder is a great library, but it’s very vast – Without code-completion I was very lost/ nearly all the time poking through the header files and opening the .cpp files in other editors so I could learn it more thouroughly.

(Re)-Enter EclipseIDE for C++

This project is presented as is for anyone else who would like to use a C++ editor on osx that is actually aware of your classes.
From what I’ve used it so far, it is much better – but compile times are a little slower, however the time you save while editing is well worth it imo.

Usage

  1. http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/heliossr2
  2. Download this project
  3. Import into eclipse workspace (select import existing project in the ‘general’ drop down)
  4. In terminal browse to the projects path and create a symbolic link named ‘CINDER_PATH_LINK’ to where cinder is located
    1. “ln -s foo/bar CINDER_PATH_LINK”
    2. Where ‘foo/bar’ is the path to Cinder such as ‘~/GIT/LIBRARY/CINDER’
  5. [Optional] – RightClick project root, select properties
    1. Select C/C++ Build
    2. Select Settings
    3. Replace ‘g++’ with ‘clang++’ and ‘gcc’ with ‘clang’ for the:
      • MacOS X C++ Linker
      • GCC C++ Compiler
      • GCC C Compiler
    • [Optional] Do the same for the discovery tab
  6. After hitting, apply/ok and closing that window select Project->Build All and project should build successfully.

Screenshots

Debugger / Hitting a breakpoint

Editor

OpenNIStarterKit Block

Editor

Better syntax highlighting, and code sense

Editor

PostADay-Round2#4 – Cinder Kinect OpenNI – Playing and seeking a .oni file

onedayitwillmake 2 comments

I’ve been using the Kinect for the past two weeks. It’s an amazing device, very fun to code for.
To be honest, the Kinect really provides a webcam image, and a depth map… That’s really all it adds to the mix. While that’s a lot – people (by that i mean gadget blogs, non-coder blogs) seem to think that you can just plug this thing and you will get instant Minority Report.

That’s not how it works, in fact the REAL magic of the kinect is the OpenNI drivers provided by Primesense. Primesense are the people who created the technology which microsoft has licensed. Their OpenNI drivers provide the amazing skeleton tracking / user tracking / hand tracking / gesture tracking stuff that people associate with the Kinect.

When trying to create something using the Kinect it can be somewhat annoying having to get up, calibrate it with the proper use, and then start moving around to test a variable you changed. For that reason, the OpenNI library provides a way to record, and also create files which it calls “.oni”

The easiest way to create your own .oni file, is to record one with the NIViewer sample project. However just as useful if that’s too annoying, is the skeleton.oni file provided by primesense.

These files can actually then be played by the the library, and you can even seek within them to skip around to the interesting parts you want to test.

Here’s how to play back a .oni file, it’s actually very simple. This file makes some assumptions but i’ll explain those later.

void CinderRibbons::setupWithOniFile( std::string filepath ) {
  nRetVal = skeleton->mContext.OpenFileRecording( filepath.c_str() );
		// File opened
		CHECK_RC(nRetVal, "Open File Recording", true);
 
		// Get recording 'player'
		nRetVal = skeleton->mContext.FindExistingNode(XN_NODE_TYPE_PLAYER, skeleton->mPlayer);
		CHECK_RC(nRetVal, "Find player generator", true);
}
void CinderRibbons::seekToFrame( XnUInt32 seekPosition )
{
	CinderOpenNISkeleton *skeleton = CINDERSKELETON;
	XnStatus nRetVal = XN_STATUS_OK;
 
	skeleton->debugOutputNodeTypes();
 
    // Make sure we're ready
	if(!openNIThread || !skeleton->mDepthGenerator)
		return;
 
	const XnChar*	nodeName		= skeleton->mDepthGenerator.GetName();
	XnUInt32		currentFrame	= 0;
	XnUInt32		totalFames		= 0;
 
	nRetVal = skeleton->mPlayer.TellFrame(nodeName, currentFrame);
	CHECK_RC(nRetVal, "Getting CURRENT frame", false);
 
	nRetVal = skeleton->mPlayer.GetNumFrames(nodeName, totalFames);
	CHECK_RC(nRetVal, "Getting TOTAL frames", false);
 
	// Stop the thread before trying to seek
	openNIThread->stop();
 
    // We'll be offset currentFrame and passing this value to the seek funciton which takes a relative position
    XnUInt32        seekAbsolutePos = -currentFrame + seekPosition;
 
    // Seek
	nRetVal = skeleton->mPlayer.SeekToFrame(nodeName, seekAbsolutePosition, XN_PLAYER_SEEK_CUR);
	CHECK_RC(nRetVal, "Seeking to frame", false);
 
	// Update the data now that we're at the new position
	skeleton->mDepthGenerator.GetMetaData( skeleton->mDepthMD );
	skeleton->mUserGenerator.GetUserPixels(0, skeleton->mSceneMD);
 
	// Restart the thread...
	// Thread count stays the same - but there is a race condition on a nanoscale
	// Had some problems, will have to look into later - for now we're creating a new thread.
	openNIThread = new OpenNIThreadRunner();
	openNIThread->go();
 
	// Output debug
	app::console() << "Seeked to frame" << currentFrame+seekPosition << std::endl;
}