// bitmapDlg.h : header file
//
#include "pnmio.h"
#include "klt.h"
#include "morphing.h"
//#include "videopro.h"
#include "VideoPro.h"
#include "Servo.h"
#include "Matrix.h"
#include "Matrix2.h"

#if !defined(AFX_BITMAPDLG_H__9C9DC8BC_D882_11D2_94CD_C01555C10000__INCLUDED_)
#define AFX_BITMAPDLG_H__9C9DC8BC_D882_11D2_94CD_C01555C10000__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CBitmapDlg dialog

class CBitmapDlg : public CDialog
{
// Construction
public:
	CBitmapDlg(CWnd* pParent = NULL);	// standard constructor
	CVideoPro *MyCam;
	CServo *panTilt;
	CDC dcmem;
	CDC *mydc;
	CBitmap bitmap;
	CBitmap base_bitmap;
	CBitmap tracked_bitmap;
	CBitmap mosaic_bitmap;
	CBitmap warp_bitmap;
	int filenum;
	HBITMAP hbitmap;
	HBITMAP hbitmap_mos;
	HBITMAP hbitmap_warp;


	BOOL loaded;
	CString directory;
	int my_frame;
	TrackedFeatures base_features[1000];
	TrackedFeatures tracked_features[1000];
	unsigned char *img1, *img2,*img3, *img4, *img_morph, *img_unfinished, *img_mosaic, *err_mosaic, *delta_err_mosaic;
	float *Y,*Z,*X1,*X2, *Res, *Res_global;
	char fnamein[100], fnameout[100];
	bool pause;
	bool reset;
	bool realtime;
	bool mosaic_shift;
	unsigned char *t1;

	KLT_TrackingContext tc;
	KLT_FeatureList fl;
	KLT_FeatureTable ft;
	int nFeatures, nFrames ;
	int ncols, nrows;
	int i;
	int offset_x;
	int offset_y;
	bool automate;
	bool start_automation;
	int auto_frames;
	int total_frames;
	float fl_x[300];
	float fl_y[300];
	float fl_global_x[300];
	float fl_global_y[300];
	float matrx[300][6];
	float PMatrix[50][6];
	float king[6];
	int panAngle;
	int tiltAngle;
	int currPosition;
	int f_x;
	int f_y;
	float mos_r;
	double mos_alpha;
	double mos_beta;

// Dialog Data
	//{{AFX_DATA(CBitmapDlg)
	enum { IDD = IDD_BITMAP_DIALOG };
	int		m_max_features;
	int		m_update_features;
	int     m_mosaic;
	int		m_thresh;
	BOOL	m_all;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CBitmapDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CBitmapDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnNextImage();
	afx_msg void OnStartFeature();
	afx_msg void cleanup();
	afx_msg void OnReset();
	afx_msg void OnClose();
	afx_msg void OnSeqList();
	afx_msg void OnSelchangeSeqlist();
	afx_msg void Onstream1();
	afx_msg void Onstream2();
	afx_msg void Onstream3();
	afx_msg void Onfeaturenumbers();
	afx_msg void OnUpdateFeatures();
	afx_msg void OnRadio1();
	afx_msg void OnRadio2();
	afx_msg void OnStop();
	afx_msg void OnChangeUpdateFeatures();
	afx_msg void Automate();
	afx_msg void OnAutotracker();
	afx_msg void find_tracked_features();
	afx_msg void Onstream4();
	afx_msg void Onstream5();
	afx_msg void find_total_frames();
	afx_msg void copy_base_image();
	afx_msg void copy_base_image1();
	afx_msg void copy_tracked_image();
	afx_msg void OnPause();
	afx_msg void OnCamera();
	afx_msg void GrabImage(unsigned char tt[], int Size);
	afx_msg void OnShoot();
	afx_msg void OnExit();
	afx_msg void OnGrabber();
	afx_msg void OnClosecamera();
	afx_msg void OnButton1();
	afx_msg int minim_vector(int i,int j) ;
	afx_msg void put_blk(int i,int j,int mv0, int mv1, int flg);
	afx_msg void OnAll();
	afx_msg void OnInitialFeature();
	afx_msg void OnFrameNum();
	afx_msg void OnBx();
	afx_msg void fill_mosaic(int B, int H, int b, int h, int dx, int dy, unsigned char* image);
	afx_msg void fill_mosaic_warped(int B, int H, int b, int h, float warp_data[6], unsigned char* image);
	afx_msg void OnChangeFeatures2();
	afx_msg void OnChangeImgFromMos();
	afx_msg void OnMosaicIndex();
	afx_msg void OnChangeMosIndx();
	afx_msg void OnChangeMosaic();
	afx_msg void OnMosButton();
	afx_msg void index_mosaic(int B, int H, int b, int h, float s_x, float s_y);
	afx_msg void OnChangeFeature();
	afx_msg void OnChangeUpdateFeature();
	afx_msg void Onshift();
	afx_msg void DifferenceImage(unsigned char *image1, unsigned char *image2, int b, int h);
	afx_msg void ThresholdDiffImage(int thresh, int b, int h);
	afx_msg int CalcDiff(unsigned char *image, int b, int h, int k);
	afx_msg void index_image(int b, int h, int s_x, int s_y, unsigned char* img_new, unsigned char* img_orig);
	afx_msg void OnStopAll();
	afx_msg void fill_error_mosaic(int B, int H, int b, int h, int dx, int dy, unsigned char* image);
	afx_msg void index_error_mosaic(int B, int H, int b, int h, float s_x, float s_y);
	afx_msg void OnChangeThreshold();
	afx_msg void OnHome(); 
	afx_msg void OnPanLeft();
	afx_msg void OnPanRight();
	afx_msg void reshape_camera_input(int B, int H, int b, int h, float s_x, float s_y, unsigned char *im_ptr, unsigned char *pt);
	afx_msg void OnErrMosaic();
	afx_msg void OnMosButton4();
	afx_msg void OnIMos();
	afx_msg void OnEMos();
	afx_msg void move_to(int angle_initial, int angle_final);
	afx_msg void cluster_moving_objects(unsigned char* diff_image, unsigned char* err_mos_image, int b, int h, int thresh, int k);
	afx_msg int find_com(unsigned char* diff_img, int b, int h);
	afx_msg int track_moving_object();
	afx_msg void OnTrackOn();
	afx_msg void OnTrackOff();
	afx_msg void fill_delta_error_mosaic(int B, int H, int b, int h, int dx, int dy, unsigned char* image);
	afx_msg void spatio_temporal_filter(unsigned char* I, unsigned char* Mos, float *warp_data, float alpha);
	afx_msg void DifferenceCharImage(unsigned char *image1, unsigned char *image2, int result[], int b, int h);
	afx_msg void OnMosaicInc();
	afx_msg void OnMosaicDec();
	afx_msg void OnRadio3();
	afx_msg void OnRadio4();
	afx_msg void calc_warp_params(float d, float theta);
	afx_msg void iwarp(int d_ini, float r, double alpha, double beta, unsigned char image[], unsigned char* img_mos, int b, int h);
	afx_msg void gradient_descent(int size, float *y, float *z, float *x1, float *x2, float res[]) ;
	afx_msg void update_Matrix(int i, float *res);
	afx_msg void update_periodic_Matrix(int i, int update_factor, float *res_global);
	afx_msg void index_mosaic_warped(int B, int H, int b, int h, float warp_data[6], unsigned char image[]); 
	afx_msg void index_error_mosaic_warped(int B, int H, int b, int h, float warp_data[6], unsigned char image[]) ;
	afx_msg void put_mosaic_warped(int B, int H, int b, int h, float warp_data[6], unsigned char *image); 
	afx_msg void put_error_mosaic_warped(int B, int H, int b, int h, float warp_data[6], unsigned char *image);
	afx_msg void show_warped(int B, int H, int b, int h, float warp_data[6], unsigned char* image, unsigned char disp_img[]) ;
	afx_msg void reset_track_status();
	afx_msg void copy_matrix_pmatrix(int i, int update_factor);
	afx_msg void initialise_matrixA(int size, float *x1, float *x2, float A[]); 
	afx_msg void initialise_matrixb(int size, float *y, float b[]);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_BITMAPDLG_H__9C9DC8BC_D882_11D2_94CD_C01555C10000__INCLUDED_)
