/* A work unit holds information related to feature map
 * computation and the image being processed.  One work
 * unit is needed per processing thread.  Image updates
 * are saved in the work struct for reference by color,
 * hue, intensity, and motion functions.
 */

#ifndef __WORKUNIT_H
#define __WORKUNIT_H

#include "huethread.h"
#include "intensitythread.h"
#include "motionthread.h"
#include "colorthread.h"
#include "learn.h"
#include "coordinate.h"
#include <opencv/cv.h>

struct work {
	// Structure pointers for feature map computation
	color_t *color;
	hue_t *hue;
	intensity_t *intensity;
	motion_t *motion;

	// Maintain a copy of the current working image frame
	IplImage *image;

	// Used when displaying feature maps the merged
	// saliency map in an OpenCV window
	IplImage *temp;
	IplImage *saliency;
	IplImage *saliency_conv;
	IplImage *saliency_conv8u;

	// Map giving the inhibition value of each pixel
	// in the range [0,1].  Zero means the pixel is
	// supressed as a recently attended location while
	// one means the pixel receives full weighting.
	// This is applied to the feature maps directly
	// rather than to the post-combined saliency map.
	IplImage *inhibition;

	// Weighted combination of feature map data
	double *merged;

	// Recursive least squares used to learn
	// feature map contribution weights
	learn_t *model;

	// List of attention points for learning
	buffer_t *attention_buffer;
};

typedef struct work work_t;

// Structure object allocation and deallocation
work_t * workunit_init(CvSize);
void workunit_destroy(work_t *);

// Store image data in the structure for use by
// the workunit_begin function.  It is up to the
// programmer to ensure any frame data is converted
// to IplImage format.  Function in image.h can
// assist with this conversion.
void workunit_update_image(work_t *, IplImage *);

// This function launches full saliency processing
// on the image saved in the work_t structure.
// Feature maps and saliency are computed and
// results displayed in OpenCV windows.  If the
// variable learn_frames is greater than zero,
// the first 'learn_frames' number of frames are
// used for recursive linear regression learning
// of the conspicuity map weights.  To disable
// learning pass the function either zero or a
// negative values.
void workunit_begin(work_t *);

#endif

