#pragma once

 

#include "cnccls.h"
#include <sst\ucb.h>




class CNCCLS_API CMarkLocater : public CCaliber
{
public:
	CMarkLocater(void);
	virtual ~CMarkLocater(void);

	virtual BOOL    Serialize(HANDLE device, BOOL bIn );
	virtual CUCObj* Clone(  CUCObj *twin) ;
	virtual void  Show(CDelegate* pDelegate, int mode, BOOL bForced);
	virtual void  ShowSketch(CDelegate* pDelegate,CSketchMark* pMark,   HGPD hGpd,int grabType, GPoint grabPos);
	virtual void  ShowExtender(CDelegate* pDelegate, CLeadMark* pMark);
	virtual void  ShowGrabber(CDelegate* pDelegate, CLeadMark* pMark);	
	virtual void  ShowRotater(CDelegate* pDelegate, CRotatorMark* pMark );

	virtual CCaliber* GetOperator() {return m_pOperator;};
	  
	virtual BOOL  Create( const TCHAR* strName = NULL, UINT id =-1, int style = RV_UC_DEFAULT_STYLE) =0 ;
	virtual void  Destroy() =0 ;

	//学习的时候，如果成功，将采集模板图
	virtual BOOL    Learn(const RvImage image, double machPosX, double machPosY, int* pErrCode  ) =0;
	virtual BOOL    Locate(const RvImage image, RvPoint_f* pResult, int* pErrCode ) =0;

	virtual void     SetStyle(int style) ;    

	//该函数删除当前学习的模板，恢复到未学习模板状态。
	virtual void  ClearPatterns()  ;

	//将识别结果清除
	virtual void  Reset();

	//调用程序不可删除返回的Image对象
	const RvImage  GetLearnedSceneImage()   { return m_imLearnedScene;   };
	const RvImage  GetLearnedPatternImage() { return m_imLearnedPattern; };
	  
	void  DestroyLearnedImages(void);
	 
	BOOL     IsPatternLearnt(){ return m_bPatternLearned; };
	RvPoint_f64 GetLearntMachPos() { return m_learntMachPos;};
	RvPoint_f  GetLearntImagePos() { return m_learntPos; };


	BOOL  GetResult(RvPoint_f* pResult);
	
	virtual RvRect GetPatternRect() =0;
	virtual RvRect GetSearchRect() =0;

	virtual void SetPatternRect(RvRect rect) =0;
	virtual void SetSearchRect(RvRect rect) =0;

	 
	//重载交互函数
public:

	virtual void SetVisible( BOOL flag ) ;

	virtual int  HitTest(CDelegate* pDelegate, GPoint point) ;
	virtual void OnBeginTrack(CDelegate* pDelegate,HGPD hCur, GPoint point, int nHitType) ;
	virtual void OnEndTrack(CDelegate* pDelegate,HGPD hCur,  GPoint point, int nHitType) ;

	virtual BOOL OnPositionChange(HGPD hOri,HGPD hCur,HGPD hNew, GPoint grabPos, RvOffset &offset) ;
	virtual BOOL OnRotationChange( HGPD hCur, HGPD hNew, GPoint &curPos) ;
	             
	virtual BOOL OnExtenderChange( HGPD hCur, HGPD hNew, int index, GPoint &curPos) ;
	 
	virtual void DestroyGraphicDescriptor(HGPD hGpd)  ;

	virtual void CopyGraphicDescriptor(const HGPD src, HGPD dest)  ;

	virtual HGPD CreateGraphicDescriptor(CDelegate* pDelegate) ;

	virtual GRect  GetGrabberRect(CDelegate* pDelegate,RvSize size) ;
	virtual GRect  GetExtenderRect(CDelegate* pDelegate,int index, RvSize size) ;
 
	virtual int     GetExtenderCount() ;

	//virtual  void  SetSelectState(CDelegate::SELECT_STATE state) ;
	virtual void   SetSelectState(BOOL state) ;

public:
	//显示mark大小
	int     m_nCrossSize;
	double  m_nConfidence;  //Range: 0 - 1.0
protected:
	void  Update(const RvImage scene, const RvImage pattern, RvPoint_f imagePos, RvPoint_f64 machPos);

protected:
	BOOL    m_bValid;
	RvPoint_f m_curPos; 

	CCaliber* m_pOperator;

	BOOL    m_bPatternLearned;   //模板是否已经学习
	RvPoint_f64 m_learntMachPos;
	RvPoint_f   m_learntPos;  //学习到的(模板)图像位置。
	RvImage m_imLearnedScene;
	RvImage m_imLearnedPattern;
	//RvImage m_imFullScene; //实际真个场景图
	 
};

