#pragma once

#include "blobx.h"


class BLOBX_API CComponentAlign :	public CAreaCal
{
public:
	CComponentAlign(void);
	virtual ~CComponentAlign(void);

	virtual BOOL    Serialize(HANDLE device, BOOL bIn );
	virtual CUCObj* Clone(  CUCObj *twin) ;
	   
	//virtual BOOL    Learn(const RvImage image=NULL, int* pErrCode = NULL);  
	virtual int     Recognize(const RvImage image=NULL, int* pErrCode = NULL);
	virtual void    Clear();  
	virtual RV_BOOL Inspect(int* pErrCode=NULL)  ;
	 
	BOOL    AddMother(const RvContour contour);
	int     AddChild(const RvContour contour);  //返回0，添加不成功,否则返回当前子数量
	void    RemoveChildAt(int index);
	int     GetChildCount();
	BOOL    IsMotherExist();
	const RvContour GetMother();
	const RvContour GetChildAt(int index);

	void  RemoveAll();

	//外部程序需要释放seq所有资源
	RvSequence  Retrieve(  RvImage image, int minSize, const RvMask mask =NULL);
	 
	virtual void    Show(CDelegate* pDelegate,int mode, BOOL bForce) ;
	
	//将提取blob的轮廓，即仅边缘点
	RvContour  ConvertBlobToContour(RvBlob blob, int minsize);


	//获得所有轮廓组成后形成的矩形
	RvRect     GetComponentRect();

	//将component转成图像
	RvImage    ConvertComponentToImage(RvRect* pRect);

public:
	double  m_nPerimToler ;        //周长长度允许误差, x%
	double  m_nAspectRatioToler;   //长宽比允许误差,   x%， 各向同性时无效,保留
	BOOL    m_bIsotropic ;         //各向同性
	double  m_nDistToler;          //最小距离错误
	UINT    m_nMinSize;            //最小的BLOB大小
	int     m_nRemoveNoise;        //移除小物体
protected:
	 RvSequence RetrieveProperContour(const RvSequence sequence);
	 BOOL       CompareContourInPattern(const RvContour contour, double toler);
protected:
	void*  m_pPattern;
};

