#ifndef HDF5POINTCLOUDSOURCE_H
#define HDF5POINTCLOUDSOURCE_H

#include <H5Cpp.h>


typedef struct _Point2D { float X, Y; } Point2D, PointF, DepthSpacePoint, ColorSpacePoint;

class DepthImage
{
public:
	std::shared_ptr< std::vector<unsigned short> > pImage;
	std::shared_ptr< std::vector<float> > pCamParams;
	std::shared_ptr< uint8_t > pColors;
	unsigned int uiNrOfDepthPoints;

	unsigned int uiWidth;
	unsigned int uiHeight;

	DepthImage()
		: pImage( nullptr )
		, pCamParams( nullptr )
		, pColors( nullptr )
		, uiNrOfDepthPoints( 0 )
		, uiWidth( 0 )
		, uiHeight( 0 )
	{}

	virtual ~DepthImage()
	{
	}
};

class HDF5PointCloudSource
{
public:
	HDF5PointCloudSource();
	~HDF5PointCloudSource();

	bool init( std::string strFilename, bool bOpenColorStream = false, unsigned int uiDepthWidth = 512, unsigned int uiDepthHeight = 424 );

	std::shared_ptr<DepthImage> process();

	void createTransformArray( std::vector<float>* pCamParams );

private:
	// depth unzlibbing
	H5::H5File m_h5File;

	H5::DataSet m_depthDataSet;
	H5::DataSpace m_depthDataSpace;

	H5::DataSet m_paramsDataSet;
	H5::DataSpace m_paramsDataSpace;

	H5::DataSet m_colorDataSet;
	H5::DataSpace m_colorDataSpace;

	unsigned int m_uiDepthWidth;
	unsigned int m_uiDepthHeight;
	unsigned int m_uiNrOfCamParams;

	unsigned int m_uiFrameCounter;

	float* m_pTempDepth;
	uint8_t* m_pTempColor;

	std::vector<float> m_vLastCamParams;
	Point2D* m_pDepthFrameToCameraSpaceTable;

	// color decoding
	bool m_bOpenColorStream;
};

#endif // HDF5POINTCLOUDSOURCE_H
