#ifdef _CH_
#pragma package <opencv>
#endif

#ifndef _EiC
#include "cv.h"
#include "highgui.h"
#endif

#ifndef _FEATURE_H
#define _FEATURE_H

#include <vector>
#include <math.h>

class feature; //forward reference

struct rectangle{
	CvPoint p1;
	CvPoint p2;

	rectangle(const CvPoint &point1, const CvPoint &point2){
		p1=point1;
		p2=point2;
	}

	inline void drawBoundingBox(IplImage * image){
		cvRectangle( image, p1, p2, CV_RGB(255,0,0), 3 );
	}

	inline void drawCenterPoint(IplImage * image){
		CvPoint &p = CenterOfRectangle(p1, p2);
		cvCircle( image, p, 3, CV_RGB(0,0,255));	
	}

	// Take the center of your bounding box for nipples as a point
	//  Given: p1=(a,b) and p2=(c,d)    return p3 = (a+c/2 , b+d/2)
	inline CvPoint& CenterOfRectangle(CvPoint p1, CvPoint p2){	
		CvPoint &p = cvPoint((p1.x+ p2.x) / 2, (p1.y+p2.y) / 2);							
		return p;
	}

	inline CvPoint& CenterOfRectangle(){	
		CvPoint &p = cvPoint((p1.x+ p2.x) / 2, (p1.y+p2.y) / 2);							
		return p;
	}

	inline void printPoints() {
		printf("x1 = %i y1 = %i x2 = %i y2 = %i \n", p1.x, p1.y, p2.x, p2.y);
	}
};

class feature  {

protected:

	IplImage *shape;
	short offsetX;
	short offsetY;
	int scaleX;
	int scaleY;
	int blackmultiplyfactor;	//in case white and black areas are not equal 
	int whitemultiplyfactor;	//their weight must be equalized.
	int value;
	std::vector<rectangle*> whiterectangles;
	std::vector<rectangle*> blackrectangles;

public:
	feature();
	feature(IplImage *feat);
	~feature();
	int width;
	int height;

	void findWH();	//find width and height of feature. now usually 2x2 also find multiply factors if blackarea!=whitearea
	void setfeature(int offx, int offy, int scax, int scay);
	void addRect2(int x1, int y1, int x2, int y2, int colour); //0 for white, 1 for black
	void printRectangles();
	virtual int calcValue(IplImage *input, IplImage **bins, IplImage *red);
};

#endif // !defined(AFX_FEATURE_H__BAA8E6DA_15D0_4B12_9ED8_FDD243E65B31__INCLUDED_)

#ifdef _EiC
main(1,"feature.cpp");
#endif