#ifndef __BASE_CC_ELEMENTS_H__
#define __BASE_CC_ELEMENTS_H__

#include <vector>
using namespace std;

#include "PreprocFuncs.h"
#include "RectElementMapping.h"

struct CConnectedComponent;

class CBaseCCElement :
	public CRect
{
	int m_nId;
	int m_nBlackPoints, m_nGreyValSum, m_nAvgBackGrnd;
	int m_nNeighbors, m_nGoodNeighbors, m_nBadNeighbors;
	int m_nMaxLeftDist, m_nMaxRightDist;
	BOOL m_bEmbedded;
	CBaseCCElement * m_pLeftNeighbor, *m_pRightNeighbor;
	int m_nHeight;
	int m_nLeftHDiff, m_nRightHDiff;
	BOOL m_bAmbiguous;
	int m_nLineId;
public:
	CBaseCCElement(const CConnectedComponent * pCC = NULL, int nId = -1);
	~CBaseCCElement(void);

	inline int GetSize()const{return m_nBlackPoints;}
	inline int GetGreyValSum()const{return m_nGreyValSum;}
	inline int GetAvgBackGrnd()const{return m_nAvgBackGrnd;}
	inline int GetId()const{return m_nId;}
	BOOL GoodLineMatch(const CBaseCCElement *pBccel);
	BOOL CannotBeOnTheSameLine(const CBaseCCElement *pBccel, int nDist2Height);
	inline void AddNeighborCount(){++m_nNeighbors;}
	inline void AddBadNeighborCount(){++m_nBadNeighbors;}
	inline void AddGoodNeighborCount(){++m_nGoodNeighbors;}
	inline void SetEmbedded(BOOL bEmbedded){m_bEmbedded = bEmbedded;}
	void AddLeftNeighbor(CBaseCCElement *pBCC, int nDist2Height);
	void AddRightNeighbor(CBaseCCElement *pBCC, int nDist2Height);
	void UpdateMaxLeftDist(int nDist);
	void UpdateMaxRightDist(int nDist);
	inline void SetAmbiguous(BOOL bAmbiguous){m_bAmbiguous = bAmbiguous;}
	BOOL IsLessAmbiguous(CBaseCCElement *pBCC)const;
	void Draw(IplImage *pImg)const;
	inline CBaseCCElement *GetRightNeighbor(){return m_pRightNeighbor;}
	inline CBaseCCElement *GetLeftNeighbor(){return m_pLeftNeighbor;}
	int GetLineId()const{return m_nLineId;}
	int CheckLineId()const;
	inline void SetLineId(int nLineId){m_nLineId = nLineId;}
	inline BOOL IsAmbiguous()const {return m_bAmbiguous;}
	inline int GetMaxLeftDist()const{ return m_nMaxLeftDist;}
	inline int GetMaxRightDist()const{ return m_nMaxRightDist;}
	void Print(FILE *fp)const;
};

class CBaseCCElements : public vector<CBaseCCElement*>{
	int m_nDist2Height;
public:
	CBaseCCElements();
	~CBaseCCElements();
	void Add(const CConnectedComponent *pCC){
		push_back(new CBaseCCElement(pCC, size()));
	}

//	void SetLeftRightNeighbors();
	inline int GetDist2Height()const{return m_nDist2Height;}
	void SetNoLeftNeighbors();
	void AssembleFirstLines();
	void Draw(const char *sFileName, int nWidth, int nHeight)const;
	void Print(const char *sFileName)const;

};

#endif //__BASE_CC_ELEMENTS_H__
