
#if !defined(__RV_EDGE_DISTANCE_H_INCLUDED_)
#define __RV_EDGE_DISTANCE_H_INCLUDED_


#pragma once

#include "gauge.h"

#define ED_EDGE_COUNT  2
  
 
class GAUGE_API CEdgeDistance :	public CAreaCal
{
public:
	CEdgeDistance(void);
	virtual ~CEdgeDistance(void);

	enum{
	    ED_DEFAULT=0,  //默认,两条边都是直线
		ED_TIPDIST,    //水平或垂直,不一定是直线边缘
	};

	//直线模型和方法
	enum {
		ED_LM_DEFAULT = 0,
		ED_LM_FAIR,
		ED_LM_WELSH,
		ED_LM_HUBER,
        ED_LM_HOUGH =10  ,
	};

	////边缘点确定方法
	//enum{
	//	ED_DARK,    //最暗
	//	ED_LIGHT,   //最亮
	//	ED_CUSTOM,  //自定义
	//};
	      
	virtual void Show(CDelegate* pDelegate, int mode,BOOL bForce);
	virtual CUCObj* Clone( CUCObj* twin) ;
	virtual BOOL Serialize(HANDLE device, BOOL bIn );
	  
	virtual RV_BOOL Inspect(int* pErrCode ) ;

	BOOL IsResultValid() { return m_bValidResult;}

	//一般SetVertical在SetMethod之后调用。
	void SetVertical(BOOL flag);
	BOOL IsVertical() { return m_bVertical;};
	void SetMethod(int method);
	int  GetMethod();
	 
	virtual void Reset();

	//index = 0, 1 
	RvPoint_f GetLinePos(int index);
	 
	
	double  GetDistance();

public:
	virtual void OnEndTrack(CDelegate* pDelegate, HGPD hCur,  GPoint point, int type)  ;

public:
	
    //default type
	float  m_nLinearThresh; //0~1 ,直线度阈值
	int    m_nModelType ;   //ED_DEFAULT有效

	//tip dist type
    BOOL   m_bRemoveInvader;   //移除干扰部分
	int    m_nEdgeThres;       //ED_TIPDIST方式有效： 边缘点阈值
	int    m_nEdgeDeterminer_;  // 保留

private:

	RV_HANDLE DrawLines(HGDC dc, RvPoint_f * pEndPts , int ptCount, RV_HANDLE hStroke);
  
	double      m_nAvgDist;

	RvPoint_f   m_endPos[LD_ENDPOS_COUNT*2];
 
	BOOL   m_bVertical;
	int    m_nMethod;       //方法0 - 默认（任意两直线）， 1 - 两顶点边缘，不是非得为直线      
	BOOL m_bValidResult;
};





#endif