
// ThresholdToolsDlg.h: 头文件
//

#pragma once

#include "filehelp.h"

// CThresholdToolsDlg 对话框
class CThresholdToolsDlg : public CDialogEx
{
// 构造
public:
	CThresholdToolsDlg(CWnd* pParent = nullptr);	// 标准构造函数

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_THRESHOLDTOOLS_DIALOG };
#endif

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持



public:
	void DrawMat(Mat &img, UINT uId);
	// 刷新画布;
	void RefreshCanvas();
	// 图像二值化;
	BOOL ImgThreshold(long nThresholdVal, long nMaxThresholdVal = 255);
	// 轮廓填充;
	BOOL DrawContours(BOOL bPerimeter, long nMinPerimeter, long nMaxPerimeter, BOOL bArea, long nMinArea, long nMaxArea);
	// 点是否在轮廓内;
	void GetPointInfo(CPoint pt, long &nPerimeter, long &nArea, Rect &rc);
	// 屏幕坐标转成窗口坐标;
	// 窗口坐标转成控件坐标;
	// 控件坐标转成图像坐标;
	CPoint WndPt2ImgPt(CPoint WndPt);
	// ROI
	void GetROI();

	// 原图;
	Mat m_Img;
	// 截图;
	Mat m_ImgShow;
	// ROI;
	Mat m_ImgROI;
	// 效果图;
	Mat *m_pRenderings;
	// 二值化;
	Mat m_ImgThreshold;
	// 轮廓图;
	Mat m_ImgContours;
	// 轮廓;
	vector<vector<Point>> m_contours;
	// 轮廓关系;
	vector<Vec4i> m_hierarchy;
	// 文件;
	STR_VEC m_files;

	CRect m_WndRect;
	BOOL m_bThreshold;
	BOOL m_bSquare;
	BOOL m_bPerimeter;
public:
	// 模板图片;
	Mat m_ImgTemp;
	// 起始坐标;
	Point m_firstPt;
	// 最后坐标;
	Point m_lastPt;
	// 是否松开鼠标;
	BOOL  m_bPress;

// 实现
protected:
	HICON m_hIcon;

	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnBnClickedOpenimg();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	CSliderCtrl m_slider;
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	CString m_strMaxVal;
	afx_msg void OnBnClickedOk();
	afx_msg void OnBnClickedCancel();
	afx_msg void OnBnClickedReset();
	afx_msg void OnBnClickedButton2();
	afx_msg void OnBnClickedCheck1();
	afx_msg void OnBnClickedCheck2();
	afx_msg void OnEnChangePerimeter();
	afx_msg void OnEnChangeSquare();
	CSpinButtonCtrl m_Spin1;
	CSpinButtonCtrl m_Spin2;
	afx_msg void OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnDeltaposSpin2(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnEnChangePerimeter2();
	afx_msg void OnEnChangeSquare2();
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnBnClickedCheck3();
	CComboBox m_cbThresholdType;
	CString m_strLeft;
	CString m_strTop;
	CString m_strRight;
	CString m_strBottom;
	afx_msg void OnCbnSelchangeThresholdType();
	afx_msg void OnEnChangeLeft();
	afx_msg void OnEnChangeTop();
	afx_msg void OnEnChangeRight();
	afx_msg void OnEnChangeBottom();
	afx_msg void OnBnClickedPreve();
	afx_msg void OnBnClickedNext();

	int m_curIndex;
	void OpenImg(LPCTSTR lpFile, BOOL bResetROI = FALSE);
	int GetFileIndex(LPCTSTR lpCurFile, STR_VEC &vtFiles);
	int m_nRadio;
	afx_msg void OnBnClickedThreshold();
	afx_msg void OnBnClickedOpenTemp();
	afx_msg void OnBnClickedFindTemp();
	void DrawTempContours();
};
