#pragma once

#include "pixelmatch.h"

//该类仅识别一个实例
class PATMAT_API CComponentLocater :	public CMatchCal
{
public:
	enum CL_BINZ 
	{
		CL_AUTO=0,    //自动
		CL_ADAPTIVE,  //自适应
		CL_SIMPLE,    //简单
		CL_REVERSE,   //反向
		CL_INNER,     //内区间
		CL_OUTER,     //外区间
	};

public:
	CComponentLocater(void);
	virtual ~CComponentLocater(void);

	virtual BOOL Serialize(HANDLE device, BOOL bIn );
	virtual CUCObj* Clone(  CUCObj *twin) ;

//	virtual BOOL    Learn(const RvImage image , int* pErrCode  ) ;
	virtual int     Recognize(const RvImage image , int* pErrCode  ) ;
	virtual void    Clear() ; //清除所有已经学习的模板，恢复到未学习状态
	virtual void Reset() ;

	//轮廓点数据以相机图像坐标为准，不是模板区域坐标系
	BOOL    AddContour(  RvContour contour,  int dx, int dy, BOOL  bDuplicate=TRUE);  //返回0，添加不成功,否则返回当前子数量
	void    RemoveContourAt(int index);
	int     GetContourCount();
	const   RvContour GetContourAt(int index);

	void    RemoveAll ();

	//外部程序需要释放seq所有资源
	RvSequence  Retrieve(  RvImage image, int minSize, const RvMask mask =NULL);

	RvRect      GetPatternRect();
	RvPoint_f64   GetPatternCenter();
	double     GetPatternAngle();


	virtual void Show(CDelegate* pDelegate,int mode, BOOL bForce) ;
	BOOL  IsResultValid(){return m_bResultValid;}
	 
	RvOffset_f64 GetOffset(){ return m_offset; };
	 
	double       GetAngle() { return m_angle; }; //偏移角度

	

public:
	double  m_nPerimToler ;        //周长长度允许误差, x%
	double  m_nAspectRatioToler;   //长宽比允许误差,   x%， 各向同性时无效,保留
	BOOL    m_bIsotropic ;         //各向同性
	//double  m_nDistToler;          //最小距离错误
	UINT    m_nMinSize;            //最小的BLOB大小
	BOOL    m_bExternalOnly;       //最外轮廓

	int  m_nMethod;
	int  m_nThres1, m_nThres2;  
	int  m_nBlockSize;
	
protected:
	  
	void* m_pPattern;

	//检测结果
	 BOOL       m_bResultValid;
	 RvOffset_f64  m_offset; 
	 //RvPoint_f64   m_center;
	 double        m_angle;

};

