#pragma once

#include <conio.h>
#include <chrono>
#include <iostream>
#include <sstream>
#include <queue>
#include "Rx.LFR/LightFieldRuntime.h"
#include "Rx.LFR/ICudaData.h"
#include "Rx.LFR/CameraServer.h"
#include "Rx.LFR/CalibrationManager.h"
#include "Rx.LFR/SeqFileWriter.h"
#include "Rx.LFR/Cuda.h"
#include "Rx.LFR/CudaCompute.h"
#include "Rx.LFR/ImageQueue.h"

#include "Rx.Core\RxException.h"
#include "Rx.CluViz.Core.CluVizTool/CvCluVizTool.h"

#include "ofThread.h"

#include "RxProcessor.h"

#include "DataProcessor.h"

#include "Poco/Timestamp.h"
#include "Poco/Timer.h"
#include "Poco/Stopwatch.h"

class RxCamera : public ofThread {

public:
	
	RxCamera();
	~RxCamera();
	int start();
	int stop();
	void threadedFunction();
	void OnImageCaptured(const Rx::CRxImage& xImage, unsigned uCamIdx);
	void OnSimulatedImage(Poco::Timer&);
	bool haveCamera();
	void startRecording();
	void stopRecording();
	bool isRecording();

private:

	int frameCounter;

	bool bSimCamera;
	bool bRealCamera;
	bool bValidCamera;
	bool bWriteImages;

	queue<unsigned char *> imageQueue;

	Poco::Timer simCameraCapture;

	Rx::LFR::CImageQueue m_xCamBuffer;
	Rx::LFR::CSeqFileWriter seqWriter;
	Rx::LFR::CCameraServer xCamServer;
	Rx::LFR::CCudaCompute xCudaCompute;
	Rx::LFR::CCalibration xDefaultCalibration;
	Rx::CRxString sxCameraName;
	Rx::CRxString sxName;
	Rx::LFR::ICudaDataImages* pxImages;
	Rx::CRxImage xCapturedImage;
	Rx::CRxImage xOutputImage;
	Rx::LFR::CMetaData metaData;

	Rx::CRxImageFormat imageFormat;

	RxProcessor imgProc;

	float frameRate;
	float displayRate;
	float logRate;
	float exposureTime;
	float gain;
	
	double dClockMHz;
	double dGlobalMemMB;
	unsigned int uID;
	unsigned uBufferSize;
	bool bOverwrite;


};
