#pragma once

#include "gauge.h"

#include <cali\AreaCal.h>
#include <rvb\rvtypes.h>
#include <cali\CurveCal.h>
 

class GAUGE_API CLineDetect :	public CAreaCal
{
public:
	CLineDetect(void);
	virtual ~CLineDetect(void);

	//直线模型和方法
	enum {
		LM_DEFAULT = 0,
		LM_FAIR,
		LM_WELSH,
		LM_HUBER,
        LM_HOUGH =10  ,
	};

	//accuracy
	enum{
		LA_LOW =0,
		LA_MEDIAN,
		LA_HIGH,
	};
	 
	virtual void Show(CDelegate* pDelegate, int mode,BOOL bForce);	 
	virtual CUCObj* Clone( CUCObj* twin) ;
	virtual BOOL Serialize(HANDLE device, BOOL bIn );
	
	//virtual void Shot(const RvImage image )  ;
	//virtual void ShotEx(const RvImage image , int left, int top) ;

	virtual void Reset();

	virtual void BeginAlign();
	virtual void Offset(double dx, double dy, int dir = RV_DIR_BOTH)  ;
	virtual void Unbias(double cx, double cy, double angle) ;
	virtual void EndAlign(BOOL bUpdate);
	//virtual void MoveEx(double dx, double dy, double cx, double cy, double angle) ;

	virtual RV_BOOL Inspect(int* pErrCode=NULL) ;

	virtual BOOL  Create(/*CDelegate* pDelegate=NULL,*/ const TCHAR* strName = NULL, UINT id =-1, int style = RV_UC_DEFAULT_STYLE) ;
	virtual void  Destroy(/*BOOL bEraseStroke=FALSE*/) ;

	virtual void SetShape(int shape);
	virtual void  SetDisplayStyle(int style);

	virtual void Move(double dx, double dy) ;

	//virtual CDelegate* BindDelegate(CDelegate* pDelegate);

	RvPoint_f  GetEndPos(int index);
	RvFloat    GetLength();
	RvFloat    GetSlope();
	RvFloat    GetLinearity();

	int  GetSampleDist();
	void SetSampleDist(int dist);
	 
	int  GetExtendLength();
	void SetExtendLength(int length);
	
	virtual void    SetBodyColor(GRgb& val);
	
	BOOL IsResultValid() { return m_bValidResult;}
 
	CCurveCal* GetCurveCal(){ return &m_curveCal; };

public:
	//double m_nLowThres, m_nHighThres;

	//移除小斑块
	BOOL   m_bRemoveIsolator;
	int    m_nFitAccuracy;
	int    m_nModelType;    //直线模型0,1,2,3-拟合, 10-霍夫  by HDY on 20190711

	////BOOL   m_bShowSampler;

	//int    m_nSubPixelLevel;
	float  m_nLinearThresh; //0~1 ,直线度阈值
	
public:
	virtual void OnEndTrack(CDelegate* pDelegate, HGPD hCur,  GPoint point, int type)  ;

private:	 
	CCurveCal m_curveCal;

	void LayoutCut();


	RvFloat    m_results[4+1];
	RvPoint_f64 m_endPos[LD_ENDPOS_COUNT];
	
	int       m_nSampleDist;  //采样距离
	BOOL      m_bValidResult;
	
	int       m_nExtendLength;//扩展长度
	  
	RV_HANDLE DrawMarks(HGDC dc, RV_HANDLE hStroke);
};

