
		/* function prototypes */
void		PaintImage();
void		UpdateDisplay();
int			OpenVideoFile(char *,int *, int *);
int			ReadVideoFrame(int,unsigned char *);
void		CloseVideoFile();
int			ReadFiles();
int			LoadGT();
int			SaveGT(char *);	  /* sorts by TimeIndex then saves */
int			LoadMDBites(char *);
int			LoadGestures(char *,int *,int *,int *,int *);
void		InitializeDataVariables();
LRESULT		CALLBACK RecordBiteInfo(HWND,UINT,WPARAM,LPARAM); /* record bite info dialogue */
LRESULT		CALLBACK ChangeFFSpeed(HWND,UINT,WPARAM,LPARAM); /* change FF speed */
LRESULT		CALLBACK ChangeAnalysisParams(HWND,UINT,WPARAM,LPARAM); /* change bite detection params */
void		MachineDetectBites();
void		EvaluateBiteDetections();


#define TIMER_SECOND		1								/* ID of timer used during playback */

		/* global variables */
HINSTANCE	  hInst;				/* pointer to program instance (need for dialog boxes) */
HWND		  MainWnd;				/* main window */
char		  DataFilename[320];	/* file that contains the wrist motion tracking data */
char		  VideoFilename[320];	/* file that contains the video */
char		  CurrentPath[320];		/* path where files were last read/saved */
int			  VideoLoaded;			/* 0=>no; 1=>yes (file exists and is opened in ffmpeg library) */
int			  VideoSyncOffset;		/* milliseconds between data[0] and first video frame */
unsigned char *disp_image;			/* image from video to display */
int			  DISPLAY_ROWS;			/* size of video image */
int			  DISPLAY_COLS;			/* size of video image */
char		  NameList[999][320];	/* master list of data filenames, lets user scroll through them */
int			  TotalFilenames;		/* 0=>no master list available; otherwise the total count */

int			  TimeIndex;			/* index of data currently being displayed (units are samples, 1/15 Hz) */
int			  Playing;				/* 0=>no; 1=>yes (video is playing, using timer to repeatedly move TimeIndex) */
int			  PlayJump;				/* amount of samples to jump during each timer */
int			  FFspeed;				/* user-definable amount of frames to skip per iteration during fast forward */
int			  PlayCountdown;		/* used to play brief video sequences, halting when it counts down to zero */

#define MAX_DATA	54000			/* one hour at 15 Hz */
double		  Data[7][MAX_DATA];	/* x y z yaw pitch roll scale */
int			  TotalData;			/* total #samples in the wrist motion tracking data file */
int			  DataLoaded;			/* 0=>no; 1=>yes (file exists and has been read) */
double		  SmoothedData[7][MAX_DATA];	/* x y z yaw pitch roll scale */
int			  ViewSmoothed;			/* 0=>no, 1=>smoothed */
int			  DataDisplayWidth;		/* #pixels horizontal for displaying data; used to control scroll bar */

double		  DataStretch[7];		/* y-axis magnification of data (x y z yaw pitch roll scale) */
double		  ScaleAverage;			/* mean of scale data, for scaling to display */
int			  DisplayAccs,DisplayGyros,DisplayRollOnly,DisplayScale;  /* 0=>no; 1=>yes */
int			  DisplayGT,DisplayMDBites,DisplayEvaluationLinks;	/* 0=>no; 1=>yes */

char		  FoodsLoaded;			/* 0=>no; 1=>yes (file exists and has been read) */
char		  TotalFoodsInMeal;		/* number of entries in foods.txt file */
char		  FoodsInMeal[12][80];	/* names of foods */
int			  FoodKcals[12];		/* number of kcals consumed from each food item, read from food_log_with_kcals.txt */
int			  FoodBites[12];		/* total count of bites of this food listed in GT */
float		  FoodKPB[12];			/* kcals per bite (KPB) of each food, based on above two numbers */

char		  GTFilename[320];		/* file that contains the ground truth bites */
#define MAX_BITES	500
int			  TotalGTBites;			/* #bites in the GT file */
int			  GTBiteIndex[MAX_BITES]; /* data index of GT bite */
char		  GTBiteHand[MAX_BITES][16];  /* left, right or both */
char		  GTBiteUtensil[MAX_BITES][16];	  /* fork, hand, spoon, chopsticks */
char		  GTBiteContainer[MAX_BITES][16];	/* plate, bowl, mug, glass */
char		  GTBiteFood[MAX_BITES][320];		/* anything, see master_menu.txt for list */
int			  CurrentHand,CurrentUtensil,CurrentContainer,CurrentFood;	/* indices used in current bite */

int			  TotalMDBites;			/* #bites in the MD (machine detected) file */
int			  MDBiteIndex[MAX_BITES]; /* data index of MD bite */
double		  RollThresh;			/* deg/sec for machine detection algorithm */
int			  Time1Thresh,Time2Thresh;	/* time1=time between +/- roll, time2=time until next bite */

#define	MAX_PEAKS		1000
int			  TotalPeaks;						/* peak-based method for detecting cycles */
int			  PeakIndex[MAX_PEAKS];				/* center point of local maximum (units are indices @ 15Hz) */
int			  PeakLeft[MAX_PEAKS];				/* index of local minima to left of peak */
int			  PeakRight[MAX_PEAKS];				/* index of local minima to right of peak */
int			  PeakType[MAX_PEAKS];				/* 1=>positive, -1=>negative, 0=>rest (not currently used) */

#define	NOT_MATCHED	-99999	/* sentinel used during matching */
int			  GTMatched[MAX_BITES],MDMatched[MAX_BITES];  /* index of opposite type of bite that matched */
int			  TP,U,FP;				/* evaluation count of detected bites, undetected, and false positives */

#define MAX_GESTURES  1000
int			  TotalGTGestures;		/* #gestures in file */
int			  GTGestureStart[MAX_GESTURES]; /* data index of start of gesture */
int			  GTGestureEnd[MAX_GESTURES];	  /* data index of end of gesture */
int			  GTGestureType[MAX_GESTURES];  /* -1=>unknown; 0=>bite; 1=>drink; 2=>other; 3=>rest; 4=>utensiling */

int			  TotalMDGestures;			/* #gestures in the MD (machine detected) file */
int			  MDGestureStart[MAX_GESTURES]; /* data index of start of gesture */
int			  MDGestureEnd[MAX_GESTURES];	  /* data index of end of gesture */
int			  MDGestureType[MAX_GESTURES];  /* -1=>unknown; 0=>bite; 1=>drink; 2=>other; 3=>rest; 4=>utensiling */

int			  GestureColors[5][3];
char		  GestureNames[5][20];

unsigned char *scale_image;			/* image of scale load cells (simulated for now) to display */
unsigned char *scale_video;			/* series of images, loaded from file */
int			  SCALE_ROWS;			/* size of scale image */
int			  SCALE_COLS;			/* size of scale image */
int			  SCALE_WINDOW;			/* number of screen pixels to use to display each scale pixel */


