//file Cam_lib.h


#include <PvAPI.h>
#include <Windows.h>
#include <stdio.h>
#include <vector>



#include "Img_lib.h"
#ifndef FORM_H
#define FORM_H
//#include "Form1.h"
#endif


using namespace std;
using namespace cv;
using namespace System::Drawing;

#pragma comment(lib, "PvAPI.lib")

#ifndef CLASS_CAMERA
#define CLASS_CAMERA

#define IMG_WINDOW 0
#define IMG_SAVE 1
#define WINDOW_READY 2
#define FORM_READY 3
#define AUTO_CONTINOUOUS 10
#define AUTO_ONCE 11
#define MANUAL 12

#ifndef size
#define WIDTH 800
#define HEIGHT 600 
#endif

#define CONTINUOUS 0
#define SINGLEFRAME 1

#define FREERUN 0
#define FIXEDRATE 1
#define SOFTWARE 2


typedef struct ROI{
	//Region of interest
	tPvUint32 roi_height;
	tPvUint32 roi_width;
	tPvUint32 roi_regY;
	tPvUint32 roi_regX;
	//Image mode
	tPvUint32 binningX;
	tPvUint32 binningY;


}regOfInterest;

typedef struct CMODE{ //
	tPvUint32 acq;				//AcquisitionMode – Enum – R/W
	tPvUint32 frametrig;		//FrameStartTriggerMode – Enum – R/W
	tPvFloat32 framerate;
	tPvUint32 framect;
	char frametrigarr[15];
	char acqarr[15];
}cameraMode;

typedef struct IMGOP{

	bool disp_Options[4];

}imgOperations;


class Camera
{
private:
	tPvHandle handle; //pointer to void data type
	regOfInterest roi;
	imgOperations img_Op;
	tPvUint32 exposure_time;
	tPvUint32 gain_value;
	tPvUint32 bytesPerFrame;
	tPvFrame img_frame; //img + img info
	tPvCameraInfoEx camera_info;
	BOOL opened,stream_ready;
	int exposure_mode;
	int gain_mode;
	cameraMode cmode;
	
	
	

public:
	long unsigned int frameno,multiframe;
	unsigned int cam_index;
	Mat output_Img;
	double freq;
	IMGOP img_process;
	bool roiEnbl;

	Camera(); //default constructor
	~Camera();                   //destructor
	Camera(tPvCameraInfoEx);
	Camera(int); //new constructor using indentified cameras in model
	Camera(const Camera& other); //copy constructor (if we want to use same camera multiple times)

	int set_handle(tPvHandle);
	int set_resolution(void);
	int set_Exposition(UINT32);
	int set_Exposition_Mode(UINT32);
	int set_Gain(UINT32);
	int set_Gain_Mode(UINT32);
	int set_bytesPerFrame(UINT32);
	int set_ready(BOOL);
	int set_cameraMode(void);

	int set_cameraInfo(tPvCameraInfoEx);
	int save_frame(tPvFrame);

	int Camera_open(void);
	int Camera_Start(void);
	int Camera_Capture(void);
	int Camera_getinfo(int i);
	UINT32 Camera_getExpo(void);
	UINT32 Camera_getGain(void);
	int Camera_stream(void);
	int Camera_stopcapt(void);
	int Camera_close(void);

	void Single_frame(void);

	tPvHandle *get_handle(void){return &handle;}
	regOfInterest *get_roi(void){return &roi;}
	cameraMode *get_cameraModep(void){return &cmode;}

	tPvUint32 *get_exposure(void){return &exposure_time;}
	int *get_exposure_mode(void){return &exposure_mode;}
	tPvUint32 *get_gain(void){return &gain_value;}
	int *get_gain_mode(void){return &gain_mode;}
	int pvGetExposureMode(void);
	int pvGetGainMode(void);
	int pvGetAcqMode(void);
	int pvGetTrigMode(void);

	tPvUint32 *get_bytesPerFrame(void){return &bytesPerFrame;}
	tPvCameraInfoEx *get_Camera_info(void){return &camera_info;}
	tPvFrame *get_frame(void){return &img_frame;}
	BOOL get_opened(void){return opened;}
	BOOL get_ready(void){return stream_ready;}

};

void (PVDECL Frame_Callback)(tPvFrame* pFrame);
typedef void (PVDECL Camera::*PT_FB)(tPvFrame*);

class Cameras{
public :
	std::vector<Camera*> list;
	unsigned int celkem;
	IplImage *output_CVimg;
	Mat output_Img;
	CvSize pole;
	BOOL locked1,first_render,updatelarge;

	Cameras(int pocet){
		celkem=pocet;
		for(;pocet>0;pocet--){
			list.push_back( new Camera() );
		}
	}
	void islocked(BOOL is){locked1 = is;}
		
	
	 
};

#endif

string Cam_fcn(unsigned long);
int PvApi_init(void); //Initialize PvApi
int Cam_found(Cameras*, unsigned int);
int PvApi_unInit(void); //Initialize PvApi


