#ifndef KINECTNITERIMAGESOURCE_H__
#define KINECTNITERIMAGESOURCE_H__

// Include before ITK due to namespace issues
#include <XnCppWrapper.h>

#include "KinectImage.h"
#include "ritkRImageSource.h"

template<class TRImage, class TKinectImage>
class KinectNITERImageSource : public ritk::RImageSource<TRImage>
{
public:
	/** @name Typedefs */
	//@{

	/** @name Standard typedefs */
	//@{
	typedef KinectNITERImageSource				Self;
	typedef ritk::RImageSource<TRImage>			Superclass;
	typedef itk::SmartPointer<Self>				Pointer;
	typedef itk::SmartPointer<const Self>		ConstPointer;
	//@}

	/**	@name The RImage types */
	//@{
	typedef typename Superclass::RImageType		RImageType;
	typedef typename RImageType::Pointer		RImagePointer;
	typedef TKinectImage						KinectImageType;
	typedef typename KinectImageType::Pointer	KinectImagePointer;
	//@}

	//@}

	/// Object creation
	itkNewMacro(Self);

	/// RTTI
	itkTypeMacro(KinectNITERImageSource, ritk::RImageSource);

	/** @brief	Generate the output information
	 *
	 *	@details
	 *	Prepare the allocation of the output image during the first back propagation of the pipeline.
	 *	In particular, the regions of the output image and the camera parameters are set.
	 */
	void GenerateOutputInformation();

	/**	@name Connect/disconnect */
	//@{
	void Connect();
	void Disconnect();
	//@}


	//void XN_CALLBACK_TYPE User_NewUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie);

protected:
	/// Constructor
	KinectNITERImageSource();
	/// Destructorthe
	virtual ~KinectNITERImageSource();

	/// Generate the TOF image here
	virtual void GenerateRImage();

protected:
	/// @todo docu
	bool m_TrackingStarted;
	/// @todo docu
	bool m_CalibrationRequested;
	/// The OpenNI context
	xn::Context m_Context;
	/// The depth generatro
	xn::DepthGenerator m_DepthGenerator;
	/// The image (RGB) generator
	xn::ImageGenerator m_ImageGenerator;
	/// The IR generator
	xn::IRGenerator m_IRGenerator;
	/// The user generator
	xn::UserGenerator m_UserGenerator;
	/// Connected flag
	bool m_Connected;
	/// Indicates that we're generating
	bool m_Generating;
	/** @name Real time clock */
	//@{
	typedef itk::RealTimeClock::TimeStampType TimeStampType;
	itk::RealTimeClock::Pointer m_Clock;
	//@}


private:
	/// purposely not implemented
	KinectNITERImageSource(Self&); 
	/// purposely not implemented
	void operator=(const Self&); 

		


};

/// Explicit template instantiation
typedef KinectNITERImageSource<ritk::RImageF2,KinectImageF2> KinectNITERImageSourceF2;



#endif // KINECTNITERIMAGESOURCE_H__
