| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 | #include "stdafx.h"#include "BSEImgClr.h"#include "../OTSLog/COTSUtilityDllFunExport.h"namespace OTSCLRINTERFACE {	using namespace System;	using namespace OTSDATA;	const unsigned int CHART_NUM = 0xff;		CBSEImgClr::CBSEImgClr()	{		//m_LpBSEImg = new CBSEImgPtr(new CBSEImg());	}	CBSEImgClr::CBSEImgClr(System::Drawing::Rectangle^ a_pRect)										// constructor	{		CRect r =  CRect(a_pRect->Left, a_pRect->Top, a_pRect->Right, a_pRect->Bottom);		m_LpBSEImg = new CBSEImgPtr(new CBSEImg(r));		}		CBSEImgClr::CBSEImgClr(CBSEImgPtr pBSEImg)									// copy constructor	{		ASSERT(pBSEImg);		if (!pBSEImg)		{			LogErrorTrace(__FILE__, __LINE__, _T("CBSEImgClr: Generate CBSEImgClr pointer failed."));			return;		}					m_LpBSEImg = new CBSEImgPtr(pBSEImg);					}	CBSEImgClr::CBSEImgClr(CBSEImgClr^ a_pSource)	{		auto src = a_pSource->GetBSEImgPtr();		m_LpBSEImg = new CBSEImgPtr(new CBSEImg(src.get()));	}	CBSEImgClr::CBSEImgClr(CBSEImg* a_pSource)							// copy constructor	{		ASSERT(a_pSource);		if (!a_pSource)		{			LogErrorTrace(__FILE__, __LINE__, _T("CBSEImgClr: Generate CBSEImgClr pointer failed."));			return;		}		m_LpBSEImg = new CBSEImgPtr(new CBSEImg(a_pSource));	}		CBSEImgClr::~CBSEImgClr()	{		if (m_LpBSEImg != nullptr)		{			delete m_LpBSEImg;		}	}	CBSEImgClr::!CBSEImgClr()	{		if (m_LpBSEImg != nullptr)		{			delete m_LpBSEImg;		}	}															// image rectangle	System::Drawing::Rectangle^ CBSEImgClr::GetImageRect()	{		CBSEImgPtr img = *m_LpBSEImg;		CRect Crec=img->GetImageRect();		System::Drawing::Rectangle^ r = gcnew System::Drawing::Rectangle((int)Crec.left, (int)Crec.top, (int)Crec.Width(), (int)Crec.Height());		return r;	}	void CBSEImgClr::SetImageRect(System::Drawing::Rectangle^ a_pRect)	{		CRect* r = new CRect(a_pRect->Left, a_pRect->Top, a_pRect->Right, a_pRect->Bottom);		m_LpBSEImg = new CBSEImgPtr(new CBSEImg(r));	}	int CBSEImgClr::GetWidth()	{		if (m_LpBSEImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("GetWidth:invalid pointer."));			return -1;		}		CBSEImgPtr pBSEImg = GetBSEImgPtr();		ASSERT(pBSEImg);		if (!pBSEImg)		{			LogErrorTrace(__FILE__, __LINE__, _T("GetWidth:invalid pointer."));			return -1;		}		return pBSEImg->GetWidth();	}	int CBSEImgClr::GetHeight()	{		CBSEImgPtr img= *m_LpBSEImg;		return img->GetHeight();			}		// image data	void CBSEImgClr::InitImageData(int imgwidth,int imgheight)	{		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("InitImageData: invalid pointer."));			return;		}		pImg->InitImageData(imgwidth,imgheight);	}	array<byte>^ CBSEImgClr::GetImageDataPtr()	{		/*return m_pnImageData;*/		CBSEImgPtr img = *m_LpBSEImg;		BYTE* imgData= img->GetImageDataPointer();		 auto imgSize = img->GetImageSize();		 long lngSize = imgSize.cx * imgSize.cy;		array<byte>^ outData = gcnew array<byte>(lngSize);				for (int i = 0; i < lngSize; i++)		{			outData[i] = imgData[i];		}		return outData;	}	// need a byte array, and array length	void CBSEImgClr::SetImageData(array<byte>^ a_pnImageData, int imgwidth,int imgheight)	{		if (a_pnImageData == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("SetImageData: invalid image data"));			return;		}		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("SetImageData: invalid pointer."));			return;		}		pImg->InitImageData(imgwidth,imgheight);		pin_ptr<byte> pi = &a_pnImageData[0];		byte *pinp = pi;			memcpy(pImg->GetImageDataPointer(), pinp, imgwidth*imgheight);		BYTE* pImgData = pImg->GetImageDataPointer();				int nImgsize = imgwidth * imgheight;		for (int i = 0; i < nImgsize; i++)		{			pImgData[i] = a_pnImageData[i];		}				}	int CBSEImgClr::GetImageSize()	{		CBSEImgPtr pImg = GetBSEImgPtr();		auto imgSize = pImg->GetImageSize();		return imgSize.cx *imgSize.cy;	}	// BSE chart  	// NOTE: to use chart data, call SetChartData method first!	bool CBSEImgClr::SetChartData()	{		CBSEImgPtr pImg = GetBSEImgPtr();				if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("SetChartData: invalid pointer."));			return FALSE;		}		pImg->InitChartData();		return TRUE;	}	void CBSEImgClr::GetBSEChart(array<WORD>^ % a_wChart)	{		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("GetBSEChart: invalid pointer."));			return;		}		WORD* pChart = pImg->GetBSEChart();		pin_ptr<WORD> pi = &a_wChart[0];		WORD *pinp = pi;		memcpy(pinp, pChart, (DWORD)CHART_NUM);		for (int i = 0; i < CHART_NUM; i++)		{			a_wChart[i] = pChart[i];		}	}	long CBSEImgClr::CalBSEChartHigh()	{		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("CalBSEChartHigh: invalid pointer."));			return -1;		}		return pImg->CalBSEChartHigh();	}	long CBSEImgClr::CalBSEChartLow()	{		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("CalBSEChartLow: invalid pointer."));			return -1;		}		return pImg->CalBSEChartLow();	}	// cal BSE value by position	int CBSEImgClr::GetBSEValue(Point^ a_position)	{		if (a_position == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid point"));			return -1;		}		CPoint pt;		pt.x = a_position->X;		pt.y = a_position->Y;				CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid pointer."));			return -1;		}		return pImg->GetBSEValue(pt);	}	int CBSEImgClr::GetBSEValue(const int a_nX, const int a_nY)	{		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid pointer."));			return -1;		}		return pImg->GetBSEValue(a_nX, a_nY);	}	void  CBSEImgClr::SetBSEValue(const int a_nX, const int a_nY, int value)	{		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("GetBSEValue: invalid pointer."));			return ;		}		 pImg->SetBSEValue(a_nX, a_nY,value);		}	int CBSEImgClr::GetValueDirect(Point^ a_position)	{		if (a_position == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("GetValueDirect: invalid point"));			return -1;		}		CPoint pt;		pt.x = a_position->X;		pt.y = a_position->Y;		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("GetValueDirect: invalid pointer."));			return -1;		}		return pImg->GetValueDirect(pt);	}	int CBSEImgClr::GetValueDirectF(int inX, int inY)	{		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("GetValueDirectF: invalid pointer."));			return -1;		}		return pImg->GetBSEValue(inX, inY);	}	bool CBSEImgClr::DoesContainPixelValue(int inValue, int a_nPixel)	{		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("DoesContainPixelValue: invalid pointer."));			return false;		}		return pImg->DoesContainPixelValue(inValue, a_nPixel);	}	// cal area	DWORD CBSEImgClr::CalArea()	{		CBSEImgPtr pImg = GetBSEImgPtr();		if (pImg == nullptr)		{			LogErrorTrace(__FILE__, __LINE__, _T("CalArea: invalid pointer."));			return -1;		}		return pImg->CalArea();	}	CBSEImgPtr CBSEImgClr::GetBSEImgPtr()	{		return *m_LpBSEImg;	}}
 |